def prepare_singleQuad_xml_files(type_name, type_setting, modules=modulelist): for module in modules: xmlfilename = os.path.join( xmlfolder, 'CMSIT_singleQuad_%s_%s.xml' % (module, type_name)) xmlobject = XMLInfo(xmlfilename) for setting in daqsettings_per_xmltype[type_setting]: xmlobject.set_daq_settings( setting, daqsettings_per_xmltype[type_setting][setting]) for chip in chiplist: xmlobject.set_chip_attribute_by_moduleid(1, chip, 'Lane', str( chip)) # the lane corresponds to the chip ID on the single AB xmlobject.set_chip_attribute_by_moduleid( 1, chip, 'configfile', 'CMSIT_RD53_%s_chip%i_default.txt' % (module, chip)) chip_settings_thismodule = chip_settings[module] keepchips = [] for chip in chip_settings_thismodule: settings = chip_settings_thismodule[chip] for setting in settings: xmlobject.set_chip_setting_by_modulename( module, chip, setting, settings[setting]) xmlobject.keep_only_chips_by_modulename( module, chip_settings_thismodule.keys()) xmlobject.save_xml_as(xmlfilename)
def reset_singleQuad_xml_files(type, modules=modulelist, chips=chiplist): xmlobject = XMLInfo(xmlfile_blueprint) xmlobject.set_module_attribute_by_moduleid(0, 'Id', 1) xmlobject.set_txtfilepath_by_moduleid(1, txtfolder) for chip in chiplist: if chip == 0: continue xmlobject.copy_chip_by_moduleid(1, 0, chip) for module in modules: targetname = os.path.join( xmlfolder, 'CMSIT_singleQuad_%s_%s.xml' % (module, type)) xmlobject.save_xml_as(targetname)
def reset_and_prepare_Ring_xml_file(type_name, type_setting, ids_and_chips_per_module, ring): xmlobject = XMLInfo(xmlfile_blueprint) for setting in daqsettings_per_xmltype[type_setting]: xmlobject.set_daq_settings( setting, daqsettings_per_xmltype[type_setting][setting]) # set up all modules moduleids = [] for mod in ids_and_chips_per_module: moduleids.append(ids_and_chips_per_module[mod][0]) for id in moduleids: if not id == 0: xmlobject.copy_module_by_moduleid(0, id) xmlobject.set_txtfilepath_by_moduleid(id, txtfolder) xmlobject.keep_only_modules_by_moduleid(moduleids) # set up chips per module for module in ids_and_chips_per_module: id = ids_and_chips_per_module[module][0] chips = ids_and_chips_per_module[module][1] # first create all chips, then delete the unwanted ones for chip in [0, 1, 2, 3]: if not chip == 0: xmlobject.copy_chip_by_moduleid(id, 0, chip) if ring == 'R1': xmlobject.set_chip_attribute_by_moduleid( id, chip, 'Lane', str(chip)) elif ring == 'R3': xmlobject.set_chip_attribute_by_moduleid( id, chip, 'Lane', str(0)) else: raise AttributeError('invalid ring specified: %s' % (str(ring))) xmlobject.set_chip_attribute_by_moduleid( id, chip, 'configfile', 'CMSIT_RD53_%s_chip%i_default.txt' % (module, chip)) chip_settings = get_chipsettings_from_json() if str(chip) in chip_settings[module]: settings = chip_settings[module][str(chip)] for setting in settings: xmlobject.set_chip_setting_by_modulename( module, chip, setting, settings[setting]) xmlobject.keep_only_chips_by_moduleid(id, chips) targetname = os.path.join(xmlfolder, 'CMSIT_disk%s_%s.xml' % (str(ring), type_name)) xmlobject.save_xml_as(targetname)
def run_ber_scan(modules, chips_per_module, ring, positions, tap_settings=[], mode='time', value=10): # first, enable TAP1, TAP2 for moduleidx, module in enumerate(modules): for chip in chips_per_module[module]: if ring == 'singleQuad': if not len(modules) == 1: raise AttributeError( 'Trying to run BER in singleQuad mode with mode than one module' ) module = modules[0] xmlfile_for_ber = os.path.join( xmlfolder, 'CMSIT_%s_%s_%s.xml' % (ring, module, 'ber')) reset_singleQuad_xml_files(type='ber', modules=modules, chips=chips) prepare_singleQuad_xml_files(type_name='ber', type_setting='scurve', modules=modules) elif ring == 'R1': xmlfile_for_ber = os.path.join( xmlfolder, 'CMSIT_disk%s_%s.xml' % (ring, 'ber')) reset_and_prepare_Ring_xml_file('ber', 'scurve', ids_and_chips_per_module_R1, ring) elif ring == 'R3': xmlfile_for_ber = os.path.join( xmlfolder, 'CMSIT_disk%s_%s.xml' % (ring, 'ber')) xmlobject = XMLInfo(xmlfile_for_ber) print module, chip xmlobject.keep_only_modules_by_modulename([module]) xmlobject.keep_only_chips_by_modulename(module, [chip]) xmlobject.set_chip_setting_by_modulename(module, chip, 'CML_CONFIG', '127') # now, in a loop, set TAP values to scan through for tap0, tap1, tap2 in tap_settings: print(tap0, tap1, tap2) xmlobject.set_chip_setting_by_modulename( module, chip, 'CML_TAP0_BIAS', str(tap0)) xmlobject.set_chip_setting_by_modulename( module, chip, 'CML_TAP1_BIAS', str(tap1)) xmlobject.set_chip_setting_by_modulename( module, chip, 'CML_TAP2_BIAS', str(tap2)) xmlobject.save_xml_as(xmlfile_for_ber) # assemble the OS command if mode is 'time': tuningstepname = 'prbstime' elif mode is 'frames': tuningstepname = 'prbsframes' else: raise AttributeError( 'Function \'run_ber_scan()\' received invalid argument for \'mode\': %s. Must be \'time\' or \'frames\'' % mode) command_p = 'CMSITminiDAQ -f %s p' % (xmlfile_for_ber) command_ber = 'CMSITminiDAQ -f %s -c %s %i BE-FE 2>&1 | tee %s' % ( xmlfile_for_ber, tuningstepname, value, os.path.join( logfolder, 'ber_%s_%s_chip%i_pos%s_%i_%i_%i.log' % (ring, module, chip, str( positions[moduleidx]), tap0, tap1, tap2))) # execute the OS command print(command_p) os.system(command_p) time.sleep(1) print(command_ber) os.system(command_ber) time.sleep(2)