Skip to content
Snippets Groups Projects
Commit febc4f2d authored by Edward Moyse's avatar Edward Moyse
Browse files

Merge branch 'no_AthFile_G4AtlasApps' into 'master'

Replacing AthFile with MetaReader in G4AtlasApps package

See merge request atlas/athena!27203
parents 7261e4a6 d9b50116
No related branches found
No related tags found
No related merge requests found
...@@ -6,75 +6,74 @@ ...@@ -6,75 +6,74 @@
from AthenaCommon.Logging import * from AthenaCommon.Logging import *
simMDlog = logging.getLogger('Sim_Metadata') simMDlog = logging.getLogger('Sim_Metadata')
def getAthFile():
## Allow the input check to be skipped. This should only be done in production def get_metadata(mode='lite'):
## jobs, in order to avoid peeking and spoiling performance on some systems # Allow the input check to be skipped. This should only be done in production
inputAthFileObject = None # jobs, in order to avoid peeking and spoiling performance on some systems
import os import os
if not ('G4ATLAS_SKIPFILEPEEK' in os.environ and os.environ['G4ATLAS_SKIPFILEPEEK']): if not ('G4ATLAS_SKIPFILEPEEK' in os.environ and os.environ['G4ATLAS_SKIPFILEPEEK']):
from AthenaCommon.AthenaCommonFlags import athenaCommonFlags from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
if athenaCommonFlags.PoolEvgenInput.statusOn: if athenaCommonFlags.PoolEvgenInput.statusOn:
try: try:
import PyUtils.AthFile as af from PyUtils.MetaReader import read_metadata
inputAthFileObject = af.fopen(athenaCommonFlags.PoolEvgenInput()[0]) input_file = athenaCommonFlags.PoolEvgenInput()[0]
metadata = read_metadata(input_file, mode = mode)
metadata = metadata[input_file] # promote all keys one level up
return metadata
except: except:
simMDlog.warning("AthFile failed to open %s", athenaCommonFlags.PoolEvgenInput()[0]) simMDlog.warning("MetaReader failed to open %s", athenaCommonFlags.PoolEvgenInput()[0])
else: else:
simMDlog.info("G4ATLAS_SKIPFILEPEEK environment variable present, so skipping all input file peeking.") simMDlog.info("G4ATLAS_SKIPFILEPEEK environment variable present, so skipping all input file peeking.")
return inputAthFileObject return None
inputAthFileObject = getAthFile() metadata_lite = get_metadata(mode = 'lite')
metadata_full = get_metadata(mode = 'full')
### Check that we aren't trying to pass a data file as the input to the simulation! # Check that we aren't trying to pass a data file as the input to the simulation!
def inputFileValidityCheck(): def inputFileValidityCheck():
from G4AtlasApps.G4Atlas_Metadata import inputAthFileObject if metadata_lite is not None:
if inputAthFileObject is not None: # Check that event type is IS_SIMULATION (as it must be)
## Check that event type is SIMULATION (as it must be) if "eventTypes" in metadata_lite:
if "evt_type" in inputAthFileObject.infos.keys(): if 'IS_SIMULATION' not in metadata_lite['eventTypes']:
evttypes = inputAthFileObject.infos["evt_type"] msg = "This input file has incorrect eventTypes: %s\n" % str(metadata_lite['eventTypes'])
evttype0 = str(evttypes[0])
if not evttype0.startswith("IS_SIMULATION"):
msg = "This input file has incorrect evt_type: %s\n" % str(evttypes)
msg += "Please make sure you have set input file metadata correctly - " msg += "Please make sure you have set input file metadata correctly - "
msg += "consider using the job transforms for earlier steps if you aren't already doing so." msg += "consider using the job transforms for earlier steps if you aren't already doing so."
simMDlog.fatal(msg) simMDlog.fatal(msg)
raise SystemExit("Input file evt_type is incorrect: please check your evgen jobs.") raise SystemExit("Input file eventTypes is incorrect: please check your evgen jobs.")
else: else:
simMDlog.warning("Could not find 'evt_type' key in athfile.infos. Unable to that check evt_type is correct.") simMDlog.warning("Could not find 'eventTypes' key in meta-reader Unable to that check eventTypes is correct.")
else: else:
simMDlog.info("No input Evgen AthFile object available, so skipping check for input file validity.") simMDlog.info("No input Evgen MetaData object available, so skipping check for input file validity.")
### Check whether mc_channel_number is set in tag_info metadata and add if required.
# Check whether mc_channel_number is set in tag_info metadata and add if required.
def patch_mc_channel_numberMetadata(addToFile=True): def patch_mc_channel_numberMetadata(addToFile=True):
from G4AtlasApps.G4Atlas_Metadata import inputAthFileObject if metadata_lite is not None:
if inputAthFileObject is not None: mc_channel_number = 0
mc_channel_number=0 if 'mc_channel_number' in metadata_lite:
if 'mc_channel_number' in inputAthFileObject.infos and len(inputAthFileObject.infos['mc_channel_number'])>0: mc_channel_number = int(metadata_lite['mc_channel_number'])
mc_channel_number=inputAthFileObject.infos['mc_channel_number'][0]
elif 'mc_channel_number' in inputAthFileObject.infos['tag_info']:
mc_channel_number=inputAthFileObject.infos['tag_info']['mc_channel_number']
else: else:
simMDlog.warning("No mc_channel_number in input file metadata. Using run number.") simMDlog.warning("No mc_channel_number in input file metadata. Using run number.")
mc_channel_number=inputAthFileObject.infos['run_number'][0] mc_channel_number = metadata_lite['run_number'][0]
if addToFile: if addToFile:
simMDlog.info('Adding mc channel number to taginfo: %s',str(mc_channel_number)) simMDlog.info('Adding mc_channel_number to /TagInfo: %s', str(mc_channel_number))
# Initialize tag info management # Initialize tag info management
import EventInfoMgt.EventInfoMgtInit import EventInfoMgt.EventInfoMgtInit
from AthenaCommon.AppMgr import ServiceMgr from AthenaCommon.AppMgr import ServiceMgr
ServiceMgr.TagInfoMgr.ExtraTagValuePairs += ["mc_channel_number", str(mc_channel_number) ] ServiceMgr.TagInfoMgr.ExtraTagValuePairs += ["mc_channel_number", str(mc_channel_number)]
return mc_channel_number return mc_channel_number
else: else:
simMDlog.info("No input Evgen AthFile object available so skipping patch of mc channel number metadata.") simMDlog.info("No input Evgen MetaData object available so skipping patch of mc_channel_number metadata.")
### Read in special simulation job option fragments based on metadata passed by the evgen stage
def checkForSpecialConfigurationMetadata(): def checkForSpecialConfigurationMetadata():
from G4AtlasApps.G4Atlas_Metadata import inputAthFileObject if metadata_full is not None:
if inputAthFileObject is not None: if 'specialConfiguration' in metadata_full['/TagInfo']:
if "specialConfiguration" in inputAthFileObject.infos["tag_info"]:
from G4AtlasApps.SimFlags import simFlags from G4AtlasApps.SimFlags import simFlags
simFlags.specialConfiguration = dict() simFlags.specialConfiguration = dict()
item = inputAthFileObject.infos["tag_info"]["specialConfiguration"] item = metadata_full['/TagInfo']['specialConfiguration']
## Parse the specialConfiguration string ## Parse the specialConfiguration string
## Format is 'key1=value1;key2=value2;...'. or just ' ## Format is 'key1=value1;key2=value2;...'. or just '
spcitems = item.split(";") spcitems = item.split(";")
...@@ -100,7 +99,7 @@ def checkForSpecialConfigurationMetadata(): ...@@ -100,7 +99,7 @@ def checkForSpecialConfigurationMetadata():
for inc in someIncludes: for inc in someIncludes:
include(inc) include(inc)
else: else:
simMDlog.info("No input Evgen AthFile object available so skipping check for specialConfiguration metadata.") simMDlog.info("No input Evgen MetaData object available so skipping check for specialConfiguration metadata.")
def fillCommonMetadata(dbFiller): def fillCommonMetadata(dbFiller):
pass pass
...@@ -184,25 +183,24 @@ def fillISFMetadata(dbFiller): ...@@ -184,25 +183,24 @@ def fillISFMetadata(dbFiller):
def createSimulationParametersMetadata(): def createSimulationParametersMetadata():
from IOVDbMetaDataTools import ParameterDbFiller from IOVDbMetaDataTools import ParameterDbFiller
dbFiller = ParameterDbFiller.ParameterDbFiller() dbFiller = ParameterDbFiller.ParameterDbFiller()
from G4AtlasApps.G4Atlas_Metadata import inputAthFileObject
## Set run numbers ## Set run numbers
minrunnum = 0 minrunnum = 0
maxrunnum = 2147483647 # MAX maxrunnum = 2147483647 # MAX
from AthenaCommon.AthenaCommonFlags import athenaCommonFlags from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
from G4AtlasApps.SimFlags import simFlags from G4AtlasApps.SimFlags import simFlags
if hasattr(simFlags, 'RunNumber') and simFlags.RunNumber.statusOn: if hasattr(simFlags, 'RunNumber') and simFlags.RunNumber.statusOn:
minrunnum = simFlags.RunNumber() minrunnum = simFlags.RunNumber()
## FIXME need to use maxrunnum = 2147483647 for now to keep overlay working but in the future this should be set properly. ## FIXME need to use maxrunnum = 2147483647 for now to keep overlay working but in the future this should be set properly.
#maxrunnum = minrunnum + 1 #maxrunnum = minrunnum + 1
elif inputAthFileObject is not None: elif metadata_lite is not None:
if len(inputAthFileObject.run_numbers) > 0: if len(metadata_lite['runNumbers']) > 0:
minrunnum = inputAthFileObject.run_numbers[0] minrunnum = metadata_lite['runNumbers'][0]
maxrunnum = minrunnum + 1 maxrunnum = minrunnum + 1
else: else:
raise Exception('IllegalRunNumber') raise Exception('IllegalRunNumber')
else: else:
simMDlog.info('Skipping run number setting - would need to set simFlags.RunNumber for this.') simMDlog.info('Skipping runNumbers setting - would need to set simFlags.RunNumber for this.')
simMDlog.info("Using the following run number range for MetaData IOV: ("+str(minrunnum)+","+str(maxrunnum)+").") simMDlog.info("Using the following runNumbers range for MetaData IOV: ("+str(minrunnum)+","+str(maxrunnum)+").")
dbFiller.setBeginRun(minrunnum) dbFiller.setBeginRun(minrunnum)
dbFiller.setEndRun(maxrunnum) dbFiller.setEndRun(maxrunnum)
...@@ -223,8 +221,7 @@ def createSimulationParametersMetadata(): ...@@ -223,8 +221,7 @@ def createSimulationParametersMetadata():
def createTBSimulationParametersMetadata(): def createTBSimulationParametersMetadata():
from IOVDbMetaDataTools import ParameterDbFiller from IOVDbMetaDataTools import ParameterDbFiller
dbFiller = ParameterDbFiller.ParameterDbFiller() dbFiller = ParameterDbFiller.ParameterDbFiller()
from G4AtlasApps.G4Atlas_Metadata import inputAthFileObject # Set run numbers
## Set run numbers
minrunnum = 0 minrunnum = 0
maxrunnum = 2147483647 # MAX maxrunnum = 2147483647 # MAX
from AthenaCommon.AthenaCommonFlags import athenaCommonFlags from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
...@@ -233,15 +230,15 @@ def createTBSimulationParametersMetadata(): ...@@ -233,15 +230,15 @@ def createTBSimulationParametersMetadata():
minrunnum = simFlags.RunNumber() minrunnum = simFlags.RunNumber()
## FIXME need to use maxrunnum = 2147483647 for now to keep overlay working but in the future this should be set properly. ## FIXME need to use maxrunnum = 2147483647 for now to keep overlay working but in the future this should be set properly.
#maxrunnum = minrunnum + 1 #maxrunnum = minrunnum + 1
elif inputAthFileObject is not None: elif metadata_lite is not None:
if len(inputAthFileObject.run_numbers) > 0: if len(metadata_lite['runNumbers']) > 0:
minrunnum = inputAthFileObject.run_numbers[0] minrunnum = metadata_lite['runNumbers'][0]
maxrunnum = minrunnum + 1 maxrunnum = minrunnum + 1
else: else:
raise Exception('IllegalRunNumber') raise Exception('IllegalRunNumber')
else: else:
simMDlog.info('Skipping run number setting - would need to set simFlags.RunNumber for this.') simMDlog.info('Skipping runNumbers setting - would need to set simFlags.RunNumber for this.')
simMDlog.info("Using the following run number range for MetaData IOV: ("+str(minrunnum)+","+str(maxrunnum)+").") simMDlog.info("Using the following runNumbers range for MetaData IOV: ("+str(minrunnum)+","+str(maxrunnum)+").")
dbFiller.setBeginRun(minrunnum) dbFiller.setBeginRun(minrunnum)
dbFiller.setEndRun(maxrunnum) dbFiller.setEndRun(maxrunnum)
...@@ -265,7 +262,6 @@ def configureRunNumberOverrides(): ...@@ -265,7 +262,6 @@ def configureRunNumberOverrides():
myRunNumber = 1 myRunNumber = 1
myFirstLB = 1 myFirstLB = 1
myInitialTimeStamp = 0 myInitialTimeStamp = 0
from G4AtlasApps.G4Atlas_Metadata import inputAthFileObject
from G4AtlasApps.SimFlags import simFlags from G4AtlasApps.SimFlags import simFlags
if hasattr(simFlags, "RunNumber") and simFlags.RunNumber.statusOn: if hasattr(simFlags, "RunNumber") and simFlags.RunNumber.statusOn:
myRunNumber = simFlags.RunNumber.get_Value() myRunNumber = simFlags.RunNumber.get_Value()
...@@ -289,7 +285,7 @@ def configureRunNumberOverrides(): ...@@ -289,7 +285,7 @@ def configureRunNumberOverrides():
## FIXME need to use maxRunNumber = 2147483647 for now to keep overlay working but in the future this should be set properly. ## FIXME need to use maxRunNumber = 2147483647 for now to keep overlay working but in the future this should be set properly.
# Using event numbers to avoid "some very large number" setting # Using event numbers to avoid "some very large number" setting
from AthenaCommon.AthenaCommonFlags import athenaCommonFlags from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
totalNumber = 1000000 # TODO possibly get this from AthFile?? totalNumber = 1000000 # TODO possibly get this from MetaReader??
if athenaCommonFlags.EvtMax() is not None and athenaCommonFlags.EvtMax()>0: totalNumber = athenaCommonFlags.EvtMax()+1 if athenaCommonFlags.EvtMax() is not None and athenaCommonFlags.EvtMax()>0: totalNumber = athenaCommonFlags.EvtMax()+1
if athenaCommonFlags.SkipEvents() is not None and athenaCommonFlags.SkipEvents()>0: totalNumber += athenaCommonFlags.SkipEvents() if athenaCommonFlags.SkipEvents() is not None and athenaCommonFlags.SkipEvents()>0: totalNumber += athenaCommonFlags.SkipEvents()
try: try:
...@@ -300,15 +296,15 @@ def configureRunNumberOverrides(): ...@@ -300,15 +296,15 @@ def configureRunNumberOverrides():
myInitialTimeStamp = 1 myInitialTimeStamp = 1
ServiceMgr.EvtIdModifierSvc.add_modifier(run_nbr=myRunNumber, lbk_nbr=myFirstLB, time_stamp=myInitialTimeStamp, nevts=totalNumber) ServiceMgr.EvtIdModifierSvc.add_modifier(run_nbr=myRunNumber, lbk_nbr=myFirstLB, time_stamp=myInitialTimeStamp, nevts=totalNumber)
if hasattr(ServiceMgr.EventSelector,'OverrideRunNumberFromInput'): ServiceMgr.EventSelector.OverrideRunNumberFromInput = True if hasattr(ServiceMgr.EventSelector,'OverrideRunNumberFromInput'): ServiceMgr.EventSelector.OverrideRunNumberFromInput = True
elif inputAthFileObject is not None: elif metadata_lite is not None:
## Get evgen run number and lumi block # Get evgen run number and lumi block
if len(inputAthFileObject.run_numbers) > 0: if len(metadata_lite['runNumbers']) > 0:
myRunNumber = inputAthFileObject.run_numbers[0] myRunNumber = metadata_lite['runNumbers'][0]
simMDlog.info('Found run number %d in hits file metadata.'% myRunNumber) simMDlog.info('Found runNumbers %d in hits file metadata.'% myRunNumber)
else: else:
simMDlog.warning('Failed to find run number in hits file metadata.') simMDlog.warning('Failed to find runNumbers in hits file metadata.')
if inputAthFileObject.lumi_block: if metadata_lite['lumiBlockNumbers']:
myFirstLB = inputAthFileObject.lumi_block[0] myFirstLB = metadata_lite['lumiBlockNumbers'][0]
else: else:
simMDlog.warning('Requires simFlags.RunNumber to be specified in this running mode.\ simMDlog.warning('Requires simFlags.RunNumber to be specified in this running mode.\
Using default value of 1 for RunNumber.') Using default value of 1 for RunNumber.')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment