From 1cb64918abce441c667a166e71f3f920c9e3bc5c Mon Sep 17 00:00:00 2001 From: John Chapman <jchapman@cern.ch> Date: Mon, 12 Feb 2018 16:15:19 +0100 Subject: [PATCH] Patch mc_channel_number in HITS file metadata if it is missing from EVNT file In ATLASSIM-3579 it was noted that the `mc_channel_number` is missing from the metadata from EVNT files onwards. In order to smooth this issue, this merge request adds code to add the missing metadata from the HITS files onwards. Former-commit-id: 5811b80dae4d16dfc4302ab9460b6318983a05c3 --- .../G4AtlasApps/python/G4Atlas_Metadata.py | 22 +++++++++++++++++++ .../share/G4Atlas.flat.configuration.py | 4 ++++ .../share/Tile2000_2003.flat.configuration.py | 4 ++++ .../ISF/ISF_Example/python/ISF_Metadata.py | 22 +++++++++++++++++++ .../ISF/ISF_Example/python/ISF_Output.py | 4 ++++ 5 files changed, 56 insertions(+) diff --git a/Simulation/G4Atlas/G4AtlasApps/python/G4Atlas_Metadata.py b/Simulation/G4Atlas/G4AtlasApps/python/G4Atlas_Metadata.py index 493979565cb0..3455c8dbe319 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 5ec8de15a7d3..d8ea350ebcb6 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 628f2ad73c07..4d9ac9e5065d 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 3cdcb3388149..21f0795e1796 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 5cd8f80a2f45..2410785b600b 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 -- GitLab