ATLAS Offline Software
CreateOutputStreams.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 
7 
8 from __future__ import print_function
9 
10 from AthenaCommon import CfgMgr
11 from AthenaCommon.AppMgr import ServiceMgr as svcMgr
12 from AthenaServices.AthenaServicesConf import AthenaOutputStream
13 from AthenaServices.AthenaServicesConf import AthenaOutputStreamTool
14 
15 _trigNavThinningSvcs = {}
16 def registerTrigNavThinningSvc (streamName, svc):
17  _trigNavThinningSvcs[streamName] = svc
18  return
19 
20 def createOutputStream( streamName, fileName = "", asAlg = False, noTag = False,
21  eventInfoKey = "EventInfo", decisionFilter="",
22  trigNavThinningSvc = None ):
23  if trigNavThinningSvc is None:
24  trigNavThinningSvc = _trigNavThinningSvcs.get (streamName, None)
25 
26 
27  # define athena output stream
28  writingTool = AthenaOutputStreamTool( streamName + "Tool" )
29  outputStream = AthenaOutputStream(
30  streamName,
31  WritingTool = writingTool,
32  ItemList = [ "EventInfo#*" ]
33  )
34  outputStream.ExtraOutputs.add(("DataHeader", "StoreGateSvc+" + streamName))
35  #outputStream.ItemList += [ "xAOD::EventInfo#*" ]
36  outputStream.MetadataStore = svcMgr.MetaDataStore
37  outputStream.MetadataItemList = [
38  "EventStreamInfo#" + streamName,
39  "IOVMetaDataContainer#*",
40  ]
41 
42 
43  from AthenaCommon.AlgSequence import AlgSequence
44  topSequence = AlgSequence()
45  from AthenaCommon.AlgSequence import AthSequencer
46  outSequence = AthSequencer("AthOutSeq")
47 
48  doTag = not noTag
49  if doTag:
50  key = "SimpleTag"
51  # Tell tool to pick it up
52  outputStream.WritingTool.AttributeListKey=key
53  if ('EventInfoTagBuilder/EventInfoTagBuilder' not in topSequence.getProperties()['Members']):
54  # build eventinfo attribute list
55  from .OutputStreamAthenaPoolConf import EventInfoAttListTool, EventInfoTagBuilder
56  EventInfoTagBuilder = EventInfoTagBuilder(AttributeList=key, EventInfoKey=eventInfoKey, FilterString=decisionFilter,
57  Tool=EventInfoAttListTool())
58  from AthenaCommon.GlobalFlags import globalflags
59  if globalflags.InputFormat() == 'bytestream':
60  #No event-tag input in bytestream
61  EventInfoTagBuilder.PropagateInput=False
62  topSequence += EventInfoTagBuilder
63 
64  # decide where to put outputstream in sequencing
65  if asAlg:
66  outSequence += outputStream
67  else:
68  outSequence += outputStream
69 
70  if fileName != "":
71  outputStream.OutputFile = fileName
72  from .OutputStreamAthenaPoolConf import MakeEventStreamInfo
73  streamInfoTool = MakeEventStreamInfo( streamName + "_MakeEventStreamInfo" )
74  streamInfoTool.Key = streamName
75  streamInfoTool.EventInfoKey = eventInfoKey
76  # for xAOD access, add EventFormat to all POOL output streams
77  # Key to use for event format on this stream
78  event_format_key = 'EventFormat{}'.format(streamName)
79  event_format_tool = CfgMgr.xAODMaker__EventFormatStreamHelperTool(
80  "{}_MakeEventFormat".format(streamName),
81  Key=event_format_key,
82  )
83  outputStream.MetadataItemList += ["xAOD::EventFormat#{}".format(event_format_key)]
84 
85  # Create a new xAOD::FileMetaData object
86  file_metadata_key = "FileMetaData"
87  file_metadata_creator_tool = CfgMgr.xAODMaker__FileMetaDataCreatorTool(
88  "FileMetaDataCreatorTool",
89  OutputKey=file_metadata_key,
90  StreamName=streamName,
91  )
92  outputStream.MetadataItemList += [
93  "xAOD::FileMetaData#{}".format(file_metadata_key),
94  "xAOD::FileMetaDataAuxInfo#{}Aux.".format(file_metadata_key),
95  ]
96 
97  outputStream.HelperTools = [
98  streamInfoTool,
99  event_format_tool,
100  file_metadata_creator_tool,
101  ]
102 
103 
104  # Support for MT thinning.
105  from AthenaServices.AthenaServicesConf import Athena__ThinningCacheTool
106  tct = Athena__ThinningCacheTool ('ThinningCacheTool_' + streamName,
107  StreamName = streamName)
108  if trigNavThinningSvc is not None:
109  tct.TrigNavigationThinningSvc = trigNavThinningSvc
110  outputStream.HelperTools += [tct]
111 
112 
113  # Set the list of transient items based on what we know is in the transient
114  # store. The output algorithm will then declare input dependencies
115  # for objects which are both listed here and in the ItemList.
116  # (We do it like this because ItemList is typically configured to include
117  # everything which might possibly be output. If this gets cleaned up,
118  # then we can remove this.)
119  # Some builds don't include RecExConfig, so don't crash in that case.
120  # FIXME: Rather than using ObjKeyStore, we could scan all algorithms
121  # and look for write handles.
122  try:
123  tlist = []
124  from RecExConfig.ObjKeyStore import objKeyStore
125  for typ, klist in objKeyStore['transient'].getProperties().items():
126  for k in klist:
127  tlist.append (typ + '#' + k)
128  outputStream.TransientItems += tlist
129  except ImportError:
130  pass
131 
132  return outputStream
133 
134 def createOutputConditionStream( streamName, fileName = "" ):
135  from RegistrationServices.OutputConditionsAlg import OutputConditionsAlg
136  conditionStream = OutputConditionsAlg(
137  streamName,
138  outputFile = fileName,
139  WriteIOV = False
140  )
141  return conditionStream
142 
143 
144 AthenaPoolOutputStream = createOutputStream
145 AthenaPoolOutputConditionStream = createOutputConditionStream
146 
AthSequencer
ClassName: AthSequencer.
Definition: AthSequencer.h:40
vtune_athena.format
format
Definition: vtune_athena.py:14
EventInfoAttListTool
Definition: EventInfoAttListTool.h:28
python.AlgSequence.AlgSequence
AlgSequence
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py:7
RunGeantinoStepRecordingITk.AthenaOutputStreamTool
AthenaOutputStreamTool
Definition: RunGeantinoStepRecordingITk.py:123
python.CreateOutputStreams.registerTrigNavThinningSvc
def registerTrigNavThinningSvc(streamName, svc)
Definition: CreateOutputStreams.py:16
python.CreateOutputStreams.createOutputConditionStream
def createOutputConditionStream(streamName, fileName="")
Definition: CreateOutputStreams.py:134
python.CreateOutputStreams.createOutputStream
def createOutputStream(streamName, fileName="", asAlg=False, noTag=False, eventInfoKey="EventInfo", decisionFilter="", trigNavThinningSvc=None)
Definition: CreateOutputStreams.py:20
EventInfoTagBuilder
Definition: EventInfoTagBuilder.h:39
OutputConditionsAlg
Definition: OutputConditionsAlg.h:24
MakeEventStreamInfo
This class provides an algorithm to make the EventStreamInfo object and update it.
Definition: MakeEventStreamInfo.h:27
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
RunGeantinoStepRecordingITk.AthenaOutputStream
AthenaOutputStream
Definition: RunGeantinoStepRecordingITk.py:122