def createTBSimulationParametersMetadata(): from IOVDbMetaDataTools import ParameterDbFiller dbFiller = ParameterDbFiller.ParameterDbFiller() from ISF_Example.ISF_Metadata import inputAthFileObject ## Set run numbers minrunnum = 0 maxrunnum = 2147483647 # MAX from AthenaCommon.AthenaCommonFlags import athenaCommonFlags from G4AtlasApps.SimFlags import simFlags if hasattr(simFlags, 'RunNumber') and simFlags.RunNumber.statusOn: minrunnum = simFlags.RunNumber() ## FIXME need to use maxrunnum = 2147483647 for now to keep overlay working but in the future this should be set properly. #maxrunnum = minrunnum + 1 elif inputAthFileObject is not None: if len(inputAthFileObject.run_numbers) > 0: minrunnum = inputAthFileObject.run_numbers[0] maxrunnum = minrunnum + 1 else: raise Exception('IllegalRunNumber') else: simMDlog.info( 'Skipping run number setting - would need to set simFlags.RunNumber for this.' ) simMDlog.info("Using the following run number range for MetaData IOV: (" + str(minrunnum) + "," + str(maxrunnum) + ").") dbFiller.setBeginRun(myMinRunNumber) dbFiller.setEndRun(myMaxRunNumber) fillTestBeamMetadata(dbFiller) if simFlags.ISFRun: fillISFMetadata(dbFiller) ## Write the db info dbFiller.genSimDb() folder = "/Simulation/Parameters" dbConnection = "sqlite://;schema=SimParams.db;dbname=SIMPARAM" import IOVDbSvc.IOVDb from AthenaCommon.AppMgr import ServiceMgr ServiceMgr.IOVDbSvc.Folders += [ folder + "<dbConnection>" + dbConnection + "</dbConnection>" ] ServiceMgr.IOVDbSvc.FoldersToMetaData += [folder] ServiceMgr.IOVSvc.partialPreLoadData = True
def createSimulationParametersMetadata(): from IOVDbMetaDataTools import ParameterDbFiller dbFiller = ParameterDbFiller.ParameterDbFiller() myRunNumber, myEndRunNumber = getRunNumberRangeForOutputMetadata() logFastChainWriteMetadata.info("Using the following run number range for MetaData IOV: ("+str(myRunNumber)+","+str(myEndRunNumber)+").") dbFiller.setBeginRun(myRunNumber) dbFiller.setEndRun(myEndRunNumber) from ISF_Example.ISF_Metadata import fillAtlasMetadata, fillISFMetadata fillAtlasMetadata(dbFiller) from G4AtlasApps.SimFlags import simFlags if simFlags.ISFRun: fillISFMetadata(dbFiller) ## Write the db info dbFiller.genSimDb() folder = "/Simulation/Parameters" dbConnection = "sqlite://;schema=SimParams.db;dbname=SIMPARAM" import IOVDbSvc.IOVDb # noqa: F401 from AthenaCommon.AppMgr import ServiceMgr ServiceMgr.IOVDbSvc.Folders += [ folder + "<dbConnection>" + dbConnection + "</dbConnection>" ] ServiceMgr.IOVDbSvc.FoldersToMetaData += [folder] ServiceMgr.IOVSvc.partialPreLoadData = True
def doParamTest(beginRun, endRun, simParams, digitParams, digitParams64): # create dbs for sim and digit parameters print "doParamTest: Running parameter test:" print "doParamTest: begin/end run", beginRun, endRun print "doParamTest: simParams ", simParams print "doParamTest: digitParams ", digitParams print "doParamTest: digitParams64", digitParams64 if len(simParams) % 2 != 0: print "doParamTest: Must have name/value pairs for simulation \ parameters. Found:", simParams str(parser.print_help() or "") sys.exit(1) if len(digitParams) % 2 != 0: print "doParamTest: Must have name/value pairs for digitization \ parameters. Found:", digitParams str(parser.print_help() or "") sys.exit(1) if len(digitParams64) % 2 != 0: print "doParamTest: Must have name/value pairs for digitization 64 \ parameters. Found:", digitParams64 str(parser.print_help() or "") sys.exit(1) if len(simParams) == 0 and len(digitParams) == 0: print "doParamTest: Must provide sim parameters and/or digit parameters" str(parser.print_help() or "") sys.exit(1) #sys.exit(1) hasSimParams = len(simParams) > 0 hasDigitParams = len(digitParams) > 0 hasDigitParams64 = len(digitParams64) > 0 dbFiller = ParameterDbFiller.ParameterDbFiller() # create db for simulation parameters if hasSimParams: # set iov dbFiller.setBeginRun(beginRun) dbFiller.setEndRun(endRun) # set parameters for i in range(len(simParams) / 2): dbFiller.addSimParam(simParams[2 * i], simParams[2 * i + 1]) # generate db dbFiller.genSimDb() print "doParamTest: created simulation db" # create db for digitization parameters if hasDigitParams: # set iov dbFiller.setBeginRun(beginRun) dbFiller.setEndRun(endRun) # set parameters for i in range(len(digitParams) / 2): dbFiller.addDigitParam(digitParams[2 * i], digitParams[2 * i + 1]) pass if hasDigitParams64: # set parameters for i in range(len(digitParams64) / 2): dbFiller.addDigitParam64(digitParams64[2 * i], digitParams64[2 * i + 1]) pass pass # generate db dbFiller.genDigitDb() print "doParamTest: created digitization db"
def writeDigitizationMetadata(): from IOVDbMetaDataTools import ParameterDbFiller dbFiller = ParameterDbFiller.ParameterDbFiller() myRunNumber, myEndRunNumber = getRunNumberRangeForOutputMetadata() logDigitizationWriteMetadata.debug('ParameterDbFiller BeginRun = %s', str(myRunNumber) ) dbFiller.setBeginRun(myRunNumber) logDigitizationWriteMetadata.debug('ParameterDbFiller EndRun = %s', str(myEndRunNumber) ) dbFiller.setEndRun(myEndRunNumber) #------------------------------------------------- # Adding jobproperties to the list of MetaData #------------------------------------------------- # Here list the digitization jobproperties we want to write out as MetaData. digitMetaDataKeys = ["doInDetNoise", "doCaloNoise", "doMuonNoise", "bunchSpacing", "initialBunchCrossing", "finalBunchCrossing", "FixedT0BunchCrossing", "doLowPtMinimumBias", "doHighPtMinimumBias", "doCavern", "doBeamGas", "doBeamHalo", "rndmSvc", "physicsList", "overrideMetadata","pileupDSID","digiSteeringConf"] #"readSeedsFromFile", "rndmSeedInputFile", from Digitization.DigitizationFlags import digitizationFlags if (not ModifyingEventIdBySvc()): # in run-dependent-conditions digitization jobs these values may vary between jobs with the same IOV digitMetaDataKeys += ["numberOfCollisions", "numberOfLowPtMinBias", "numberOfHighPtMinBias", "numberOfCavern", "numberOfBeamGas", "numberOfBeamHalo", "rndmSeedOffset1", "rndmSeedOffset2", "rndmSeedList"] digitPropertiesDict = digitizationFlags.__dict__ digitPropertiesDictKeys = digitPropertiesDict.keys() logDigitizationWriteMetadata.info('Filling Digitization MetaData') from Digitization.DigitizationFlags import digitizationFlags for o in [ o for o in digitMetaDataKeys if o in digitPropertiesDictKeys ]: testProperty = digitPropertiesDict.get(o) if testProperty.statusOn or 'bool' in testProperty.allowedTypes : testValue = testProperty.get_Value() if not isinstance(testValue, str): testValue = str(testProperty.get_Value()) dbFiller.addDigitParam(o, testValue) logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', o, testValue) else : logDigitizationWriteMetadata.debug('DigitizationMetaData: Not using jobproperty "%s" as it is switched off.', o) del digitMetaDataKeys # Bunch Structure testKey = "BeamIntensityPattern" if digitizationFlags.BeamIntensityPattern.statusOn: testValue = str(digitizationFlags.BeamIntensityPattern.get_Value()) else: testValue = "None" logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', testKey, testValue) dbFiller.addDigitParam64(testKey, testValue) # BeamFlags testKey = "beamType" from AthenaCommon.BeamFlags import jobproperties testValue = jobproperties.Beam.beamType.get_Value() logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', testKey, testValue) dbFiller.addDigitParam(testKey, testValue) # Use Beam.bunchSpacing to specify the most representative spacing (intra-train) between filled bunch-crossings. testKey = "intraTrainBunchSpacing" testValue = str(jobproperties.Beam.bunchSpacing.get_Value()) logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', testKey, testValue) dbFiller.addDigitParam(testKey, testValue) # IOVDbGlobalTag is a special case here: testKey = "IOVDbGlobalTag" testValue = "default" if digitizationFlags.IOVDbGlobalTag.statusOn : testValue = digitizationFlags.IOVDbGlobalTag.get_Value() if testValue == "" : testValue = "default" logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', testKey, testValue) dbFiller.addDigitParam(testKey, testValue) ##these collections can get too large to write out in full, so instead we count the number of files. colsMetaDataKeys = ["LowPtMinBiasInputCols", "HighPtMinBiasInputCols", "cavernInputCols", "beamGasInputCols", "beamHaloInputCols"] for o in [ o for o in colsMetaDataKeys if o in digitPropertiesDictKeys ]: testKey = 'N_' + o.replace('Cols','Files') testValue = '0' if digitPropertiesDict.get(o).statusOn : testList = digitPropertiesDict.get(o).get_Value() if isinstance(testList, list): testValue = str(len(testList)) else : logDigitizationWriteMetadata.warning('DigitizationMetaData: Key %s did not return a list. Ignoring.', o) logDigitizationWriteMetadata.info('DigitizationMetaData: setting %s to be %s', testKey, testValue) dbFiller.addDigitParam(testKey, testValue) del colsMetaDataKeys ##this is also too long to write out in full. Just set flag if run-dependent MC is on. testKey = 'RunAndLumiAreOverriden' testValue = 'False' if digitPropertiesDict.get('RunAndLumiOverrideList').statusOn : testValue = 'True' logDigitizationWriteMetadata.info('DigitizationMetaData: setting %s to be %s', testKey, testValue) dbFiller.addDigitParam(testKey, testValue) ##In case the value used for Digitization differs from that used for simulation. globalMetaDataKeys = ["DetDescrVersion"] from AthenaCommon.GlobalFlags import globalflags globalPropertiesDict = globalflags.__dict__ for o in [ o for o in globalMetaDataKeys if o in globalPropertiesDict.keys() ]: testProperty = globalPropertiesDict.get(o) if testProperty.statusOn or 'bool' in testProperty.allowedTypes : testValue = testProperty.get_Value() if not isinstance(testValue, str): testValue = str(testProperty.get_Value()) dbFiller.addDigitParam(o, testValue) logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', o, testValue) else : logDigitizationWriteMetadata.debug('DigitizationMetaData: Not using jobproperty "%s" as it is switched off.', o) del globalMetaDataKeys ##LVL1 Config Version testKey = "lvl1TriggerMenu" testValue = "NONE" from AthenaCommon.DetFlags import DetFlags if DetFlags.digitize.LVL1_on(): #Protection so that TriggerFlags are not accessed when they have not be configured from TriggerJobOpts.TriggerFlags import TriggerFlags testValue = TriggerFlags.triggerConfig.get_Value() dbFiller.addDigitParam(testKey,testValue) logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', testKey, testValue) del testKey del testValue ## Digitized detector flags: add each enabled detector to the DigitizedDetectors list digiDets = [] for det in ['pixel','SCT','TRT','BCM','Lucid','ZDC','ALFA','AFP','FwdRegion','LAr','HGTD','Tile','MDT','CSC','TGC','RPC','Micromegas','sTGC','Truth','LVL1']: attrname = det+"_on" checkfn = getattr(DetFlags.digitize, attrname, None) if checkfn is None: logDigitizationWriteMetadata.info("No attribute '%s' found on DetFlags.digitize" , attrname) continue if checkfn(): digiDets.append(det) logDigitizationWriteMetadata.info("Setting 'DigitizedDetectors' = %s" , repr(digiDets)) dbFiller.addDigitParam('DigitizedDetectors', repr(digiDets)) #------------------------------------------------- # Make the MetaData Db #------------------------------------------------- dbFiller.genDigitDb() folder = "/Digitization/Parameters" dbConnection = "sqlite://;schema=DigitParams.db;dbname=DIGPARAM" from AthenaCommon.AppMgr import ServiceMgr ServiceMgr.IOVDbSvc.Folders += [ folder + "<dbConnection>" + dbConnection + "</dbConnection>" ] ServiceMgr.IOVDbSvc.FoldersToMetaData += [ folder ] ServiceMgr.IOVSvc.partialPreLoadData = True
digitParams = [] simParams += ['k_a'] simParams += ['v_a'] simParams += ['k_b'] simParams += ['v_b'] simParams += ['k_c'] simParams += ['v_c1 v_c1 v_c1'] digitParams += ['k_d_a'] digitParams += ['v_d_a'] digitParams += ['k_d_b'] digitParams += ['v_d_b'] digitParams += ['k_d_c'] digitParams += ['v_d_c1 v_d_c1 v_d_c1'] # Create simulation parameters db dbFiller = ParameterDbFiller.ParameterDbFiller() # set iov dbFiller.setBeginRun(beginRun) dbFiller.setEndRun(endRun) # set parameters for i in range(len(simParams) // 2): dbFiller.addSimParam(simParams[2 * i], simParams[2 * i + 1]) # generate db dbFiller.genSimDb() # create digit parameters db # set parameters for i in range(len(digitParams) // 2): dbFiller.addDigitParam(digitParams[2 * i], digitParams[2 * i + 1]) # generate db dbFiller.genDigitDb()
def writeDigitizationMetadata(ConfigFlags): from IOVDbMetaDataTools import ParameterDbFiller dbFiller = ParameterDbFiller.ParameterDbFiller() myRunNumber, myEndRunNumber = getRunNumberRangeForOutputMetadata(ConfigFlags) logDigitizationWriteMetadata.debug('ParameterDbFiller BeginRun = %s', str(myRunNumber) ) dbFiller.setBeginRun(myRunNumber) logDigitizationWriteMetadata.debug('ParameterDbFiller EndRun = %s', str(myEndRunNumber) ) dbFiller.setEndRun(myEndRunNumber) #------------------------------------------------- # Adding jobproperties to the list of MetaData #------------------------------------------------- # Here list the digitization jobproperties we want to write out as MetaData. digitMetaDataKeys = { 'doInDetNoise' : 'Digitization.DoInnerDetectorNoise', 'doCaloNoise' : 'Digitization.DoCaloNoise', 'doMuonNoise' : "Digitization.DoMuonNoise", 'bunchSpacing' : 'Beam.BunchSpacing', 'beamType' : 'Beam.Type', 'IOVDbGlobalTag' : 'IOVDb.GlobalTag', 'DetDescrVersion' : 'GeoModel.AtlasVersion' } logDigitizationWriteMetadata.info('Filling Digitization MetaData') for testKey, testFlag in digitMetaDataKeys.items(): if ConfigFlags.hasFlag(testFlag): testValue = ConfigFlags._get(testFlag) if not isinstance(testValue, str): testValue = str(testValue) dbFiller.addDigitParam(testKey, testValue) logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', testKey, testValue) else : logDigitizationWriteMetadata.debug('DigitizationMetaData: ConfigFlags.%s is not available.', testFlag) del digitMetaDataKeys # Bunch Structure - hardcoded for now testKey = "BeamIntensityPattern" testPattern = None # This should be replaced by a ConfigFlag testValue = str(testPattern) logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', testKey, testValue) dbFiller.addDigitParam64(testKey, testValue) # intraTrainBunchSpacing - hardcoded for now testKey = "intraTrainBunchSpacing" testValue = str(25) # This should be either be determined from the BeamIntensityPattern or set as ConfigFlag dbFiller.addDigitParam(testKey, testValue) logDigitizationWriteMetadata.info('DigitizationMetaData: setting "%s" to be %s', testKey, testValue) ## Digitized detector flags: add each enabled detector to the DigitizedDetectors list - might be better to determine this from the OutputStream or CA-itself? Possibly redundant info though? digiDets = [] for det in ['Pixel','SCT','TRT','BCM','Lucid','ZDC','ALFA','AFP','FwdRegion','LAr','HGTD','Tile','MDT','CSC','TGC','RPC','MM','sTGC','Truth','LVL1']: attrname = "Detector.Geometry"+det if ConfigFlags.hasFlag(attrname): testValue = ConfigFlags._get(attrname) if testValue: digiDets.append(det) else: logDigitizationWriteMetadata.info("No flag called '%s' found in ConfigFlags", attrname) logDigitizationWriteMetadata.info("Setting 'DigitizedDetectors' = %s" , repr(digiDets)) dbFiller.addDigitParam('DigitizedDetectors', repr(digiDets)) #------------------------------------------------- # Make the MetaData Db #------------------------------------------------- dbFiller.genDigitDb() from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg cfg = IOVDbSvcCfg(ConfigFlags) folder = "/Digitization/Parameters" dbConnection = "sqlite://;schema=DigitParams.db;dbname=DIGPARAM" cfg.getService("IOVDbSvc").Folders += [ folder + "<dbConnection>" + dbConnection + "</dbConnection>" ] cfg.getService("IOVDbSvc").FoldersToMetaData += [ folder ] #cfg.getService("IOVSvc").partialPreLoadData = True #FIXME IOVSvc missing?? return cfg