diff --git a/Simulation/G4Atlas/G4AtlasApps/python/G4Atlas_Metadata.py b/Simulation/G4Atlas/G4AtlasApps/python/G4Atlas_Metadata.py index 493979565cb05945ace137a05c178c074edff943..3455c8dbe3196348ac58c39239b4272ae503d95f 100644 --- a/Simulation/G4Atlas/G4AtlasApps/python/G4Atlas_Metadata.py +++ b/Simulation/G4Atlas/G4AtlasApps/python/G4Atlas_Metadata.py @@ -45,6 +45,28 @@ def inputFileValidityCheck(): else: simMDlog.info("No input Evgen AthFile object available, so skipping check for input file validity.") +### Check whether mc_channel_number is set in tag_info metadata and add if required. +def patch_mc_channel_numberMetadata(addToFile=True): + from G4AtlasApps.G4Atlas_Metadata import inputAthFileObject + if inputAthFileObject is not None: + mc_channel_number=0 + if 'mc_channel_number' in inputAthFileObject.infos and len(inputAthFileObject.infos['mc_channel_number'])>0: + mc_channel_number=inputAthFileObject.infos['mc_channel_number'][0] + elif 'mc_channel_number' in inputAthFileObject.infos['tag_info'] and len(inputAthFileObject.infos['tag_info']['mc_channel_number'])>0: + mc_channel_number=inputAthFileObject.infos.tag_info['mc_channel_number'][0] + else: + simMDlog.warning("No mc_channel_number in input file metadata. Using run number.") + mc_channel_number=inputAthFileObject.infos['run_number'][0] + if addToFile: + simMDlog.info('Adding mc channel number to taginfo: %s',str(mc_channel_number)) + # Initialize tag info management + import EventInfoMgt.EventInfoMgtInit + from AthenaCommon.AppMgr import ServiceMgr + ServiceMgr.TagInfoMgr.ExtraTagValuePairs += ["mc_channel_number", str(mc_channel_number) ] + return mc_channel_number + else: + simMDlog.info("No input Evgen AthFile 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(): from G4AtlasApps.G4Atlas_Metadata import inputAthFileObject diff --git a/Simulation/G4Atlas/G4AtlasApps/share/G4Atlas.flat.configuration.py b/Simulation/G4Atlas/G4AtlasApps/share/G4Atlas.flat.configuration.py index 5ec8de15a7d3bb6d5ff780f766a92f2d45407a66..d8ea350ebcb6a2c5bf7f20738a48cd7e7b127846 100644 --- a/Simulation/G4Atlas/G4AtlasApps/share/G4Atlas.flat.configuration.py +++ b/Simulation/G4Atlas/G4AtlasApps/share/G4Atlas.flat.configuration.py @@ -371,6 +371,10 @@ if not simFlags.ISFRun: ## Write geometry tag info import EventInfoMgt.EventInfoMgtInit + ## Patch metadata if required + from G4AtlasApps.G4Atlas_Metadata import patch_mc_channel_numberMetadata + patch_mc_channel_numberMetadata() + ## Instantiate StreamHITS if athenaCommonFlags.PoolHitsOutput.statusOn: hits_persistency() diff --git a/Simulation/G4Atlas/G4AtlasApps/share/Tile2000_2003.flat.configuration.py b/Simulation/G4Atlas/G4AtlasApps/share/Tile2000_2003.flat.configuration.py index 628f2ad73c07c58acfbbf7bebeacf3146596fd57..4d9ac9e5065d477b89cb8bc8ce5d3a13db9d8cee 100644 --- a/Simulation/G4Atlas/G4AtlasApps/share/Tile2000_2003.flat.configuration.py +++ b/Simulation/G4Atlas/G4AtlasApps/share/Tile2000_2003.flat.configuration.py @@ -335,6 +335,10 @@ if not simFlags.ISFRun: ## Write geometry tag info import EventInfoMgt.EventInfoMgtInit + ## Patch metadata if required + from G4AtlasApps.G4Atlas_Metadata import patch_mc_channel_numberMetadata + patch_mc_channel_numberMetadata() + ## Instantiate StreamHITS if athenaCommonFlags.PoolHitsOutput.statusOn: hits_persistency() diff --git a/Simulation/ISF/ISF_Example/python/ISF_Metadata.py b/Simulation/ISF/ISF_Example/python/ISF_Metadata.py index 3cdcb33881492260c06010e4085309235453d773..21f0795e179648b3b5883f3001dfc0f86be19136 100644 --- a/Simulation/ISF/ISF_Example/python/ISF_Metadata.py +++ b/Simulation/ISF/ISF_Example/python/ISF_Metadata.py @@ -45,6 +45,28 @@ def inputFileValidityCheck(): else: simMDlog.info("No input Evgen AthFile object available, so skipping check for input file validity.") +### Check whether mc_channel_number is set in tag_info metadata and add if required. +def patch_mc_channel_numberMetadata(addToFile=True): + from ISF_Example.ISF_Metadata import inputAthFileObject + if inputAthFileObject is not None: + mc_channel_number=0 + if 'mc_channel_number' in inputAthFileObject.infos and len(inputAthFileObject.infos['mc_channel_number'])>0: + mc_channel_number=inputAthFileObject.infos['mc_channel_number'][0] + elif 'mc_channel_number' in inputAthFileObject.infos['tag_info'] and len(inputAthFileObject.infos['tag_info']['mc_channel_number'])>0: + mc_channel_number=inputAthFileObject.infos.tag_info['mc_channel_number'][0] + else: + simMDlog.warning("No mc_channel_number in input file metadata. Using run number.") + mc_channel_number=inputAthFileObject.infos['run_number'][0] + if addToFile: + simMDlog.info('Adding mc channel number to taginfo: %s',str(mc_channel_number)) + # Initialize tag info management + #import EventInfoMgt.EventInfoMgtInit + from AthenaCommon.AppMgr import ServiceMgr + ServiceMgr.TagInfoMgr.ExtraTagValuePairs += ["mc_channel_number", str(mc_channel_number) ] + return mc_channel_number + else: + simMDlog.info("No input Evgen AthFile 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(): from ISF_Example.ISF_Metadata import inputAthFileObject diff --git a/Simulation/ISF/ISF_Example/python/ISF_Output.py b/Simulation/ISF/ISF_Example/python/ISF_Output.py index 5cd8f80a2f4596bebd82ca2c0105a31788392233..2410785b600b71b6e1fc9cbf8a7fcaf3a582ead0 100644 --- a/Simulation/ISF/ISF_Example/python/ISF_Output.py +++ b/Simulation/ISF/ISF_Example/python/ISF_Output.py @@ -132,6 +132,10 @@ class ISF_HITSStream: ## Write geometry tag info import EventInfoMgt.EventInfoMgtInit + ## Patch metadata if required + from ISF_Example.ISF_Metadata import patch_mc_channel_numberMetadata + patch_mc_channel_numberMetadata() + ## Instantiate StreamHITS ## NB. Two-arg constructor is needed, since otherwise metadata writing fails! stream1 = None