162def propagateMetaData(flags, streamName="", category=None):
163 """
164 Returns the tuple of MetaDataHelperLists and ComponentAccumulator.
165 The former combines the lists needed to setup given metadata category
166 for the output stream configuration and metadata service.
167 The latter contains the CA needed for a given metadata category.
168 """
169 tools = MetaDataHelperLists()
170 result = ComponentAccumulator()
171 log = logging.getLogger("SetupMetaDataForStreamCfg")
172
173 if category == MetadataCategory.FileMetaData:
174 tools.mdToolNames.append("xAODMaker::FileMetaDataTool")
175 tools.mdItems += [
176 "xAOD::FileMetaData#FileMetaData",
177 "xAOD::FileMetaDataAuxInfo#FileMetaDataAux.",
178 ]
179 tools.helperTools.append(
180 CompFactory.xAODMaker.FileMetaDataCreatorTool(
181 f"{outputStreamName(streamName)}_FileMetaDataCreatorTool",
182 OutputKey="FileMetaData",
183 StreamName=outputStreamName(streamName),
184 EventInfoKey=f"{flags.Overlay.BkgPrefix}EventInfo"
185 if flags.Common.ProductionStep in [ProductionStep.PileUpPresampling, ProductionStep.PileUpPretracking, ProductionStep.MinbiasPreprocessing]
186 else "EventInfo",
187 )
188 )
189 elif category == MetadataCategory.EventStreamInfo:
190 tools.mdTools += [
191 CompFactory.CopyEventStreamInfo(
192 f"{outputStreamName(streamName)}_CopyEventStreamInfo",
193 Keys=[outputStreamName(streamName)],
194 ),
195 ]
196
197 elif category == MetadataCategory.EventFormat:
198 efTool = CompFactory.xAODMaker.EventFormatStreamHelperTool(
199 f"{outputStreamName(streamName)}_EventFormatStreamHelperTool",
200 Key=f"EventFormat{outputStreamName(streamName)}",
201 DataHeaderKey=outputStreamName(streamName),
202 )
203 tools.mdItems += [
204 f"xAOD::EventFormat#EventFormat{outputStreamName(streamName)}",
205 ]
206 tools.helperTools.append(efTool)
207 tools.mdToolNames.append("xAODMaker::EventFormatMetaDataTool")
208 elif category == MetadataCategory.CutFlowMetaData:
209 if "CutBookkeepers" in flags.Input.MetadataItems:
210 from EventBookkeeperTools.EventBookkeeperToolsConfig import (
211 CutFlowOutputList,
212 )
213
214 tools.mdToolNames.append("BookkeeperTool")
215 tools.mdItems += CutFlowOutputList(flags)
216
217 elif category == MetadataCategory.TriggerMenuMetaData:
218 if any("TriggerMenu" in item for item in flags.Input.MetadataItems):
219 _tools, _ = createTriggerMenuMetaData(flags)
220 tools.mdTools = _tools.mdTools
221 tools.mdItems = _tools.mdItems
222
223 elif category == MetadataCategory.TruthMetaData:
224 if "TruthMetaData" in flags.Input.MetadataItems:
225 tools.mdItems += [
226 "xAOD::TruthMetaDataContainer#TruthMetaData",
227 "xAOD::TruthMetaDataAuxContainer#TruthMetaDataAux.",
228 ]
229 tools.mdTools.append(
230 CompFactory.xAODMaker.TruthMetaDataTool("TruthMetaDataTool")
231 )
232 elif category == MetadataCategory.ByteStreamMetaData:
233 if "ByteStreamMetadata" in flags.Input.MetadataItems:
234 tools.mdItems += ["ByteStreamMetadataContainer#*"]
235 elif category == MetadataCategory.LumiBlockMetaData:
236 if any(
237 lb in flags.Input.MetadataItems
238 for lb in ["SuspectLumiBlocks", "IncompleteLumiBlocks", "LumiBlocks"]
239 ):
240 tools.mdToolNames.append("LumiBlockMetaDataTool")
241 tools.mdItems += [
242 "xAOD::LumiBlockRangeContainer#*",
243 "xAOD::LumiBlockRangeAuxContainer#*",
244 ]
245 elif category == MetadataCategory.IOVMetaData:
246 if "IOVMetaDataContainer" in flags.Input.MetadataItems.values():
247 if streamName not in excludeStreamToIOVFolders:
248 tools.mdItems += ["IOVMetaDataContainer#*"]
249 else:
250 tools.mdItems += [
251 f"IOVMetaDataContainer#{folder}"
252 for folder, container in flags.Input.MetadataItems.items()
253 if container == "IOVMetaDataContainer" and folder not in excludeStreamToIOVFolders[streamName]
254 ]
255
256 else:
257 log.warning(f"Requested metadata category: {category} could not be configured")
258 return tools, result
259
260