3 from dataclasses
import dataclass, field
4 from functools
import wraps
6 from AthenaCommon.Logging
import logging
7 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
8 from AthenaConfiguration.ComponentFactory
import CompFactory
9 from AthenaConfiguration.Enums
import Format, MetadataCategory, ProductionStep
10 from OutputStreamAthenaPool.OutputStreamConfig
import addToMetaData, outputStreamName
16 Helper class aggregating lists needed to setup metadata
17 for the output stream configuration and metadata service.
20 helperTools: list =
field(default_factory=list)
21 mdTools: list =
field(default_factory=list)
22 mdToolNames: list =
field(default_factory=list)
23 mdItems: list =
field(default_factory=list)
26 self.helperTools += helperLists.helperTools
27 self.mdTools += helperLists.mdTools
28 self.mdToolNames += helperLists.mdToolNames
29 self.mdItems += helperLists.mdItems
35 Decorator function which:
36 - creates default MetaDataHelperLists() and ComponentAccumulator() instances
37 - passes them to wrapped create*MetaData functions responsible for configuration of helper lists and CA, specific to metadata category
38 - returns configured instances of MetaDataHelperLists() (used by MetaDataSvc and AthenaOutputStream) and CA
42 def wrapper(*args, **kwargs):
45 func(tools, result, *args, **kwargs)
53 from EventBookkeeperTools.EventBookkeeperToolsConfig
import (
64 tools.mdItems += [
"ByteStreamMetadataContainer#*"]
65 if flags.Input.Format == Format.BS
and not flags.Common.isOnline:
66 from ByteStreamCnvSvc.ByteStreamConfig
import ByteStreamReadCfg
73 if flags.Input.Format == Format.BS
and not flags.Common.isOnline:
74 from LumiBlockComps.CreateLumiBlockCollectionFromFileConfig
import (
75 CreateLumiBlockCollectionFromFileCfg,
80 "xAOD::LumiBlockRangeContainer#*",
81 "xAOD::LumiBlockRangeAuxContainer#*",
88 CompFactory.xAODMaker.TriggerMenuMetaDataTool(
"TriggerMenuMetaDataTool")
91 "xAOD::TriggerMenuContainer#*",
92 "xAOD::TriggerMenuAuxContainer#*",
93 "xAOD::TriggerMenuJsonContainer#*",
94 "xAOD::TriggerMenuJsonAuxContainer#*",
101 "xAOD::TruthMetaDataContainer#TruthMetaData",
102 "xAOD::TruthMetaDataAuxContainer#TruthMetaDataAux.",
104 tools.mdTools.append(CompFactory.xAODMaker.TruthMetaDataTool(
"TruthMetaDataTool"))
109 tools.mdItems += [
"IOVMetaDataContainer#*"]
114 Returns the tuple of MetaDataHelperLists and ComponentAccumulator.
115 The former combines the lists needed to setup given metadata category
116 for the output stream configuration and metadata service.
117 The latter contains the CA needed for a given metadata category.
121 log = logging.getLogger(
"SetupMetaDataForStreamCfg")
123 if category == MetadataCategory.FileMetaData:
124 tools.mdToolNames.append(
"xAODMaker::FileMetaDataTool")
126 "xAOD::FileMetaData#FileMetaData",
127 "xAOD::FileMetaDataAuxInfo#FileMetaDataAux.",
129 tools.helperTools.append(
130 CompFactory.xAODMaker.FileMetaDataCreatorTool(
131 f
"{outputStreamName(streamName)}_FileMetaDataCreatorTool",
132 OutputKey=
"FileMetaData",
136 elif category == MetadataCategory.EventStreamInfo:
137 esiTool = CompFactory.MakeEventStreamInfo(
138 f
"{outputStreamName(streamName)}_MakeEventStreamInfo",
141 EventInfoKey=f
"{flags.Overlay.BkgPrefix}EventInfo"
142 if flags.Common.ProductionStep
143 in [ProductionStep.PileUpPresampling, ProductionStep.PileUpPretracking]
147 f
"EventStreamInfo#{outputStreamName(streamName)}",
149 tools.helperTools.append(esiTool)
152 if kwargs.get(
"mergeJob",
False):
154 CompFactory.CopyEventStreamInfo(
155 f
"{outputStreamName(streamName)}_CopyEventStreamInfo"
159 elif category == MetadataCategory.EventFormat:
160 efTool = CompFactory.xAODMaker.EventFormatStreamHelperTool(
161 f
"{outputStreamName(streamName)}_EventFormatStreamHelperTool",
162 Key=f
"EventFormat{outputStreamName(streamName)}",
166 f
"xAOD::EventFormat#EventFormat{outputStreamName(streamName)}",
168 tools.helperTools.append(efTool)
169 tools.mdToolNames.append(
"xAODMaker::EventFormatMetaDataTool")
170 elif category == MetadataCategory.CutFlowMetaData:
171 if "CutBookkeepers" in flags.Input.MetadataItems:
172 from EventBookkeeperTools.EventBookkeeperToolsConfig
import (
176 tools.mdToolNames.append(
"BookkeeperTool")
179 elif category == MetadataCategory.TriggerMenuMetaData:
180 if any(
"TriggerMenu" in item
for item
in flags.Input.MetadataItems):
182 tools.mdTools = _tools.mdTools
183 tools.mdItems = _tools.mdItems
185 elif category == MetadataCategory.TruthMetaData:
186 if "TruthMetaData" in flags.Input.MetadataItems:
188 "xAOD::TruthMetaDataContainer#TruthMetaData",
189 "xAOD::TruthMetaDataAuxContainer#TruthMetaDataAux.",
191 tools.mdTools.append(
192 CompFactory.xAODMaker.TruthMetaDataTool(
"TruthMetaDataTool")
194 elif category == MetadataCategory.ByteStreamMetaData:
195 if "ByteStreamMetadata" in flags.Input.MetadataItems:
196 tools.mdItems += [
"ByteStreamMetadataContainer#*"]
197 elif category == MetadataCategory.LumiBlockMetaData:
199 lb
in flags.Input.MetadataItems
200 for lb
in [
"SuspectLumiBlocks",
"IncompleteLumiBlocks",
"LumiBlocks"]
202 tools.mdToolNames.append(
"LumiBlockMetaDataTool")
204 "xAOD::LumiBlockRangeContainer#*",
205 "xAOD::LumiBlockRangeAuxContainer#*",
207 elif category == MetadataCategory.IOVMetaData:
208 if "IOVMetaDataContainer" in flags.Input.MetadataItems.values():
209 tools.mdItems += [
"IOVMetaDataContainer#*"]
212 log.warning(f
"Requested metadata category: {category} could not be configured")
221 propagateMetadataFromInput=True,
226 Set up metadata for the stream named streamName
228 It takes optional arguments: createMetadata to specify a list of metadata
229 categories to create (empty by default) and propagateMetadataFromInput (bool)
230 to propagate metadata existing in the input (True by default).
232 The additional argument, AcceptAlgs, is needed for workflows with custom kernels.
234 Returns CA to be merged
236 log = logging.getLogger(
"SetupMetaDataForStreamCfg")
238 if not isinstance(streamName, str)
or not streamName:
240 if AcceptAlgs
is None:
242 if createMetadata
is None:
247 if propagateMetadataFromInput:
248 for mdCategory
in MetadataCategory:
257 result.merge(caConfig)
259 for md
in createMetadata:
261 lists, caConfig = globals()[f
"create{md.name}"](
266 f
"Requested metadata category: {md.name} could not be configured"
270 result.merge(caConfig)
276 streamName=streamName,
277 itemOrList=helperLists.mdItems,
278 AcceptAlgs=AcceptAlgs,
279 HelperTools=helperLists.helperTools,
284 from AthenaServices.MetaDataSvcConfig
import MetaDataSvcCfg
288 flags, tools=helperLists.mdTools, toolNames=helperLists.mdToolNames