2 """Utilities to get and set the AMITag in the metadata
4 The input AMITag is contained in the AMITag attribute of the /TagInfo in-file
7 The AMITag of the current processing step is provided by command line argument
10 The tool provides a function to get and check the AMITags from the input and
11 add the output AMITag, configuring the TagInfoMgr with the information.
14 from PyUtils.AMITagHelperConfig import AMITagCfg
15 cfg.merge(AMITagCfg(ConfigFlags, runArgs))
17 from AthenaCommon.Logging
import logging
18 log = logging.getLogger(
'AMITagHelper')
21 amitagRegex = re.compile(
'^[a-z][0-9]+')
27 from os
import environ
28 varINDS = environ.get(
'INDS',
'')
31 tagsFromINDS = varINDS.split(
'.')[-1].
split(
'_')
32 tagsFromINDS = [tag
for tag
in tagsFromINDS
if amitagRegex.match(tag)]
34 log.debug(
'AMITag from input dataset name: {}'.
format(tagsFromINDS))
39 """Returns AMITag of input, split in a list, e.g. ['e6337','s3681','r13145']
41 Looks up AMITag of input from ConfigFlag input file's in-file
42 metadta. If nothing can be retrieved from the in-file metadata return empty
43 list, otherwise return value from metadata. Inform about differences.
45 if flags.Input.SecondaryFiles
and not flags.Overlay.DataOverlay:
46 files = flags.Input.SecondaryFiles
48 files = flags.Input.Files
50 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
55 tags = tags.split(
'_')
57 from itertools
import groupby
58 tags = [key
for key, _group
in groupby(tags)]
60 log.info(f
'Read AMITag from metadata: {tags}')
62 log.info(
"Cannot access /TagInfo/AMITag from in-file metadata")
66 if tagsFromINDS
and tags != tagsFromINDS:
68 log.warning(
"AMITag mismatch, check metadata of input dataset")
71 log.warning(f
"Will change {tags} to {tagsFromINDS} based on INDS environment variable")
77 def AMITagCfg(flags, runArgs=None, fixBroken=False):
78 """Add input and output AMITag values and set result in in-file metadata
80 The AMITags will be combined with '_' as delimiters. The result is set in
84 if runArgs
is not None:
85 if hasattr(runArgs,
'AMITag')
and runArgs.AMITag
not in tags:
86 tags += [runArgs.AMITag]
87 log.info(f
'Adding AMITag from execution: {runArgs.AMITag}')
88 elif hasattr(runArgs,
'AMIConfig')
and runArgs.AMIConfig
not in tags:
89 tags += [runArgs.AMIConfig]
90 log.info(f
'Adding AMITag from execution: {runArgs.AMIConfig}')
93 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
96 valueAMITag =
'_'.
join(tags)
98 from EventInfoMgt.TagInfoMgrConfig
import TagInfoMgrCfg
99 return TagInfoMgrCfg(flags, tagValuePairs={
'AMITag': valueAMITag})