示例#1
0
def main(): # pylint: disable = C0103
    """
    This is the code for the executable file which downloads the current valid
    geometry. It takes the arguments of the download directory. It will download
    the geometry from the database and translates the geometry into MAUS Module
    format.
    """
    # Read Config Arguments
    configuration = Configreader()
    dl_dir = configuration.geometry_download_directory
    # Set up target location for download
    gdml_cache = os.path.join(dl_dir, GDML_CACHE)
    try:
        os.mkdir(gdml_cache)
    except OSError:
        pass
    #Download file
    geometry_downloader = Downloader()

    if configuration.geometry_download_by == "run_number":
        geometry_downloader.download_geometry_by_run \
                        (configuration.geometry_download_run_number, gdml_cache)
    elif configuration.geometry_download_by == "current":
        geometry_downloader.download_current(gdml_cache)
    elif configuration.geometry_download_by == "id":
        geometry_downloader.download_geometry_by_id \
                                (configuration.geometry_download_id, gdml_cache)
    else:
        raise KeyError("Didn't recognise 'geometry_download_by' option '"+\
               configuration.geometry_download_by+"'. Should be on of\n"+\
               "run_number\ncurrent\nid\n")
    #Unzip file
    zip_filename = os.path.join(gdml_cache, geometry.GDMLtoCDB.GEOMETRY_ZIPFILE)
    zipped_geom = Unpacker(zip_filename, gdml_cache)
    zipped_geom.unzip_file()
    
    survey_fit = ElementRotationTranslation()
    survey_fit.execute()
    
    # format files
    gdmls = Formatter(gdml_cache, dl_dir)
    if gdmls.usegdml:
        gdmls.formatForGDML()
    else:
        gdmls.format()
    # convert to MAUS Modules
    maus_modules = GDMLtomaus(dl_dir)
    if gdmls.usegdml:
        maus_modules.generate_parent(dl_dir)
    else:
        maus_modules.convert_to_maus(dl_dir)
    # clean up if required
    if configuration.geometry_download_cleanup:
        shutil.rmtree(gdml_cache)
    print "Download Complete"
示例#2
0
 def setUp(self): #pylint: disable = C0103
     """
     TestGDMLFormatter::set_up
     
     This method creates a Formatter object ready for testing
     """
     self.constructor = None
     path_in = '/tests/py_unit/test_geometry/testCases/mausModuleSource'
     self.path_in = os.environ['MAUS_ROOT_DIR'] + path_in
     self.path_out = os.path.join(os.environ['MAUS_ROOT_DIR'], 'tmp')
     self.gdml = Formatter(self.path_in, self.path_out)
示例#3
0
def run_formatting():
    """
    Format the output files 
    """
    if os.path.exists(FORMAT_GDML_DIR):
        shutil.rmtree(FORMAT_GDML_DIR)
    os.mkdir(FORMAT_GDML_DIR)

    gdml = Formatter(DSTNTN_DIR, FORMAT_GDML_DIR)

    gdml.formatForGDML()

    maus_modules = GDMLtomaus(FORMAT_GDML_DIR)
    maus_modules.generate_parent(FORMAT_GDML_DIR)
def run_formatting():
    """
    Format the output files 
    """
    if os.path.exists(FORMAT_GDML_DIR):
        shutil.rmtree(FORMAT_GDML_DIR)
    os.mkdir(FORMAT_GDML_DIR)
    
    gdml = Formatter(DSTNTN_DIR, FORMAT_GDML_DIR)
    
    gdml.formatForGDML()
    
    maus_modules = GDMLtomaus(FORMAT_GDML_DIR)
    maus_modules.generate_parent(FORMAT_GDML_DIR)
示例#5
0
def main():
    """
    This is the code for the executable file which downloads the current valid
    geometry. It takes the arguments of the download directory. It will download
    the geometry from the database and translates the geometry into MAUS Module
    format.
    """
    # Read Config Arguments
    configuration = Configreader()
    dl_dir = configuration.geometry_download_directory
    # Set up target location for download
    gdml_cache = os.path.join(dl_dir, GDML_CACHE)
    try:
        os.mkdir(gdml_cache)
    except OSError:
        pass
    # Download file
    # geometry_downloader = Downloader()
    #if configuration.geometry_download_by == "run_number":
    #    geometry_downloader.download_geometry_by_run \
    #                   (configuration.geometry_download_run_number, gdml_cache)
    #elif configuration.geometry_download_by == "current":
    #    geometry_downloader.download_current(gdml_cache)
    #elif configuration.geometry_download_by == "id":
    #    geometry_downloader.download_geometry_by_id \
    #                     (configuration.geometry_download_id, gdml_cache)
    #else:
    #    raise KeyError("Didn't recognise 'geometry_download_by' option '"+\
    #            configuration.geometry_download_by+"'. Should be on of\n"+\
    #                       "run_number\ncurrent\nid\n")
    #Unzip file
    #zip_filename = os.path.join
    #               (gdml_cache, geometry.GDMLtoCDB.GEOMETRY_ZIPFILE)
    #zipped_geom = Unpacker(zip_filename, gdml_cache)
    # zipped_geom.unzip_file()
    # fit the detector information to the survey points.
    surveyFit = ElementRotationTranslation()
    surveyFit.execute()
    # format files
    gdmls = Formatter(gdml_cache, dl_dir)
    gdmls.format()
    # convert to MAUS Modules
    maus_modules = GDMLtomaus(dl_dir)
    maus_modules.convert_to_maus(dl_dir)
    # clean up if required
    if configuration.geometry_download_cleanup:
        shutil.rmtree(gdml_cache)
    print "Download Complete"
示例#6
0
 def test_constructor(self):
     """
     TestGDMLFormatter::test_constructor 
     
     This method tests the Formatter constructor
     
     The first test tries to create a Formatter object with an integer which
     isn't allowed. The Formatter class should raise an error. 
     """
     try:
         self.constructor = Formatter(1) # pylint: disable = E1120
         self.assertTrue(False, 'should have raised an exception')
     except: #pylint: disable = W0702
         pass #pylint: disable = W0702
     
     #Now it tests the Formatter constructor by passing an
     #argument of a file which isn't a GDML. An error
     #should be raised.
     try:
         path = '/tests/py_unit/test_geometry/testCases/testFormatter'
         test_case = os.environ['MAUS_ROOT_DIR'] + path
         self.constructor = Formatter(test_case) # pylint: disable = E1120
         self.assertTrue(False, 'Should have raised an exception')
     except: #pylint: disable = W0702
         pass #pylint: disable = W0702
     
     #this next section tests to make sure 
     #the class object is created properly
     materialfile = 'fastradModel_materials.xml'
     self.assertEqual \
                   (self.gdml.material_file, materialfile)
     configfile = 'fastradModel.gdml'
     self.assertEqual(self.gdml.configuration_file, configfile)
     maus_information_file = 'Maus_Information.gdml'
     self.assertEqual(self.gdml.maus_information_file, maus_information_file)
     beamline_file = 'Beamline.gdml'
     self.assertEqual(self.gdml.beamline_file, beamline_file)
示例#7
0
class  TestGDMLFormatter(unittest.TestCase): #pylint: disable = C0103, R0904
    """
    class TestGDMLFormatter This ensures that GDMLFormatter.py is working as
    expected.
    """
    def setUp(self): #pylint: disable = C0103
        """
        TestGDMLFormatter::set_up
        
        This method creates a Formatter object ready for testing
        """
        self.constructor = None
        path_in = '/tests/py_unit/test_geometry/testCases/mausModuleSource'
        self.path_in = os.environ['MAUS_ROOT_DIR'] + path_in
        self.path_out = os.path.join(os.environ['MAUS_ROOT_DIR'], 'tmp')
        self.gdml = Formatter(self.path_in, self.path_out)

    def test_constructor(self):
        """
        TestGDMLFormatter::test_constructor 
        
        This method tests the Formatter constructor
        
        The first test tries to create a Formatter object with an integer which
        isn't allowed. The Formatter class should raise an error. 
        """
        try:
            self.constructor = Formatter(1) # pylint: disable = E1120
            self.assertTrue(False, 'should have raised an exception')
        except: #pylint: disable = W0702
            pass #pylint: disable = W0702
        
        #Now it tests the Formatter constructor by passing an
        #argument of a file which isn't a GDML. An error
        #should be raised.
        try:
            path = '/tests/py_unit/test_geometry/testCases/testFormatter'
            test_case = os.environ['MAUS_ROOT_DIR'] + path
            self.constructor = Formatter(test_case) # pylint: disable = E1120
            self.assertTrue(False, 'Should have raised an exception')
        except: #pylint: disable = W0702
            pass #pylint: disable = W0702
        
        #this next section tests to make sure 
        #the class object is created properly
        materialfile = 'fastradModel_materials.xml'
        self.assertEqual \
                      (self.gdml.material_file, materialfile)
        configfile = 'fastradModel.gdml'
        self.assertEqual(self.gdml.configuration_file, configfile)
        maus_information_file = 'Maus_Information.gdml'
        self.assertEqual(self.gdml.maus_information_file, maus_information_file)
        beamline_file = 'Beamline.gdml'
        self.assertEqual(self.gdml.beamline_file, beamline_file)
        
    def test_format_schema_location(self):
        """
        TestGDMLFormatter::test_format_schema_location
        
        This passes a file which is not a GDML to the relating method which
        should raise an error.
        """
        #this next section calls format_schema_location
        #and checks the schema has been entered
        try:
            self.gdml.format_schema_location('Gemoetry.not_gdml')
            self.assertTrue(False, 'Should have raised an error')
        except: #pylint: disable = W0702
            pass #pylint: disable = W0702
   
    def test_merge_maus_info(self):
        """
        TestGDMLFormatter::test_merge_maus_info
        
        This method tests merge maus info by checking to see if errors are
        raised when false arguments are entered.
        """
        try:
            self.gdml.merge_maus_info('Gemoetry.not_gdml')
            self.assertTrue(False, 'Should have raised an error')
        except: #pylint: disable = W0702
            pass #pylint: disable = W0702
        
    def test_merge_run_info(self):
        """
        TestGDMLFormatter::test_merge_run_info
        
        This method tests merge maus info by checking to see if errors are
        raised when false arguments are entered.
        """
        try:
            self.gdml.merge_run_info('Gemoetry.not_gdml')
            self.assertTrue(False, 'Should have raised an error')
        except: #pylint: disable = W0702
            pass #pylint: disable = W0702
                     
    def test_format_materials(self):
        """
        TestGDMLFormatter::test_format_materials
        
        This pass a file which is not a GDML to the relating method which should
        raise an error.
        """
        try:
            self.gdml.format_materials('Gemoetry.not_gdml')
            self.assertTrue(False, 'Should have raised an error')
        except: #pylint: disable = W0702
            pass #pylint: disable = W0702

    def test_insert_materials_ref(self):
        """
        TestGDMLFormatter::test_insert_materials_ref
        
        This pass a file which is not a GDML to the relating method which should
        raise an error.
        """
        try:
            self.gdml.insert_materials_ref('Gemoetry.not_gdml')
            self.assertTrue(False, 'Should have raised an error')
        except: #pylint: disable = W0702
            pass #pylint: disable = W0702   

    def test_format_check(self):
        """
        TestGDMLFormatter::test_format_check
        
        This pass a file which is not a GDML to the relating method which should
        raise an error.
        """
        try:
            self.gdml.format_check('Geometry.not_gdml')
            self.assertTrue(False, 'Should have raised an error')
        except: #pylint: disable = W0702
            pass #pylint: disable = W0702
                
    def test_format(self): #pylint: disable = R0912
        """
        TestGDMLFormatter::test_format
        
        This method tests the format method. It does this by firstly calling the 
        format method and then it opens the outputted (formatted) files. The
        input files are known and the output files should be of a known form.
        These files are read in and certain lines which are present are counted
        and compared to numbers which we are known. 
        """
        self.gdml.format()
        for gdml_file in [self.gdml.configuration_file]+self.gdml.stepfiles:
            (schema_found, material_found, formatted_found) = (0, 0, 0)
            (run_found, mice_found, path_out_found) = (0, 0, 0)
            filename = self.path_out+'/'+gdml_file
            fin = open(filename, 'r')
            if gdml_file == self.gdml.configuration_file:
                for line in fin.readlines():
                    if self.gdml.maus_information_file != None:
                        if line.find('</run>') >= 0:
                            run_found += 1
                    if self.gdml.beamline_file != None:
                        if line.find('</MICE_Information>') >= 0:
                            mice_found += 1
                    if line.find(self.gdml.schema) >= 0:
                        schema_found += 1
                    if line.find(self.gdml.material_file) >= 0:
                        material_found += 1
                    if line.find('<!-- Formatted for MAUS -->') >= 0:
                        formatted_found += 1
                    maus = 'location="' + self.gdml.path_out + '"'
                    if line.find(maus) >= 0:
                        path_out_found += 1
                self.assertEqual(run_found, 1,
                            msg="Run tag not found "+filename)
                self.assertEqual(mice_found, 1,
                            msg="MICE Info tag not found "+filename)
                self.assertEqual(path_out_found, 1,
                            msg="path_out tag not found "+filename)
            else:
                for line in fin.readlines():
                    if line.find(self.gdml.schema) >= 0:
                        schema_found += 1
                    if line.find(self.gdml.material_file) >= 0:
                        material_found += 1
                    if line.find('<!-- Formatted for MAUS -->') >= 0:
                        formatted_found += 1
            self.assertEqual(schema_found, 1, msg="Schema "+self.gdml.schema+\
                              " found "+str(schema_found)+" times in "+filename)
            self.assertEqual(material_found, 1,
                                             msg="Material not found "+filename)
            self.assertEqual(formatted_found, 1,
                                        msg="Formatted tag not found "+filename)

            fin.close()
示例#8
0
def main(): # pylint: disable = C0103, R0912
    """
    This is the code for the executable file which downloads the current valid
    geometry. It takes the arguments of the download directory. It will download
    the geometry from the database and translates the geometry into MAUS Module
    format.
    """
    # Read Config Arguments
    configuration = Configreader()
    dl_dir = configuration.geometry_download_directory
    # Set up target location for download
    gdml_cache = os.path.join(dl_dir, GDML_CACHE)
    try:
        os.mkdir(gdml_cache)
    except OSError:
        pass
    #Download file
    geometry_downloader = Downloader()
    geoid = configuration.geometry_download_id
    if configuration.geometry_download_by == "run_number":
        geoid = geometry_downloader.download_geometry_by_run \
            (configuration.geometry_download_run_number, gdml_cache)
        print "Downloading geometry id ", geoid, " for run number ", \
            configuration.geometry_download_run_number 
    elif configuration.geometry_download_by == "current":
        geoid = geometry_downloader.download_current(gdml_cache)
        print "Downloading geometry id ", geoid, " for current run"
    elif configuration.geometry_download_by == "id":
        if configuration.download_beamline_for_run != 0:
            geometry_downloader.download_beamline_for_run\
                                (configuration.download_beamline_for_run,\
                                 gdml_cache)
        elif configuration.download_beamline_tag != "":
            geometry_downloader.download_beamline_for_tag\
                                (configuration.download_beamline_tag,
                                 gdml_cache)
        else:
            print "Default beamline currents will be used."
        if configuration.download_coolingchannel_tag != "":
            geometry_downloader.download_coolingchannel_for_tag\
                                (configuration.download_coolingchannel_tag,
                                 gdml_cache)
        else:
            print "Default MICE Channel currents will be used."
        geometry_downloader.download_geometry_by_id(geoid, gdml_cache)
        print "Downloading geometry id ", geoid
    else:
        raise KeyError("Didn't recognise 'geometry_download_by' option '"+\
               configuration.geometry_download_by+"'. Should be on of\n"+\
               "run_number\ncurrent\nid\n")
    #Unzip file
    zip_filename = os.path.join(gdml_cache, geometry.GDMLtoCDB.GEOMETRY_ZIPFILE)
    zipped_geom = Unpacker(zip_filename, gdml_cache)
    zipped_geom.unzip_file()
    # format files
    gdmls = Formatter(gdml_cache, dl_dir)
    if gdmls.usegdml:
        gdmls.formatForGDML(geoid)
    else:
        gdmls.format()
    # convert to MAUS Modules
    maus_modules = GDMLtomaus(dl_dir)
    if gdmls.usegdml:
        maus_modules.generate_parent(dl_dir)
    else:
        maus_modules.convert_to_maus(dl_dir)
    
    # clean up if required
    if configuration.geometry_download_cleanup:
        shutil.rmtree(gdml_cache)
    print "Download Complete"
示例#9
0
def main():  # pylint: disable = C0103, R0912
    """
    This is the code for the executable file which downloads the current valid
    geometry. It takes the arguments of the download directory. It will download
    the geometry from the database and translates the geometry into MAUS Module
    format.
    """
    # Read Config Arguments
    configuration = Configreader()
    dl_dir = configuration.geometry_download_directory
    # Set up target location for download
    gdml_cache = os.path.join(dl_dir, GDML_CACHE)
    try:
        os.mkdir(gdml_cache)
    except OSError:
        pass
    #Download file
    geometry_downloader = Downloader()
    geoid = configuration.geometry_download_id
    if configuration.geometry_download_by == "run_number":
        geoid = geometry_downloader.download_geometry_by_run \
            (configuration.geometry_download_run_number, gdml_cache)
        print "Downloading geometry id ", geoid, " for run number ", \
            configuration.geometry_download_run_number
    elif configuration.geometry_download_by == "current":
        geoid = geometry_downloader.download_current(gdml_cache)
        print "Downloading geometry id ", geoid, " for current run"
    elif configuration.geometry_download_by == "id":
        if configuration.download_beamline_for_run != 0:
            geometry_downloader.download_beamline_for_run\
                                (configuration.download_beamline_for_run,\
                                 gdml_cache)
        elif configuration.download_beamline_tag != "":
            geometry_downloader.download_beamline_for_tag\
                                (configuration.download_beamline_tag,
                                 gdml_cache)
        else:
            print "Default beamline currents will be used."
        if configuration.download_coolingchannel_tag != "":
            geometry_downloader.download_coolingchannel_for_tag\
                                (configuration.download_coolingchannel_tag,
                                 gdml_cache)
        else:
            print "Default MICE Channel currents will be used."
        geometry_downloader.download_geometry_by_id(geoid, gdml_cache)
        print "Downloading geometry id ", geoid
    else:
        raise KeyError("Didn't recognise 'geometry_download_by' option '"+\
               configuration.geometry_download_by+"'. Should be on of\n"+\
               "run_number\ncurrent\nid\n")
    #Unzip file
    zip_filename = os.path.join(gdml_cache,
                                geometry.GDMLtoCDB.GEOMETRY_ZIPFILE)
    zipped_geom = Unpacker(zip_filename, gdml_cache)
    zipped_geom.unzip_file()
    # format files
    gdmls = Formatter(gdml_cache, dl_dir)
    if gdmls.usegdml:
        gdmls.formatForGDML(geoid)
    else:
        gdmls.format()
    # convert to MAUS Modules
    maus_modules = GDMLtomaus(dl_dir)
    if gdmls.usegdml:
        maus_modules.generate_parent(dl_dir)
    else:
        maus_modules.convert_to_maus(dl_dir)

    # clean up if required
    if configuration.geometry_download_cleanup:
        shutil.rmtree(gdml_cache)
    print "Download Complete"