Skip to content
Snippets Groups Projects
Commit 1cb64918 authored by John Chapman's avatar John Chapman
Browse files

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: 5811b80d
parent ba726f08
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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()
......
......@@ -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()
......
......@@ -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
......
......@@ -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
......
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