ATLAS Offline Software
AthenaPoolExample_Write.py
Go to the documentation of this file.
1 #!/env/python
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 
5 
7 
8 
59 
60 
61 from AthenaConfiguration.AllConfigFlags import initConfigFlags
62 from AthenaConfiguration.ComponentFactory import CompFactory
63 from AthenaCommon.Constants import DEBUG
64 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName
65 
66 stream1name = "Stream1"
67 file1Name = "ROOTTREE:SimplePoolFile1.root"
68 stream2name = "Stream2"
69 file2Name = "ROOTTREE:SimplePoolFile2.root"
70 stream3name = "Stream3"
71 file3Name = "ROOTTREE:EmptyPoolFile.root"
72 noTag = True
73 
74 # Setup flags
75 flags = initConfigFlags()
76 flags.Common.MsgSuppression = False
77 flags.Exec.MaxEvents = 20
78 flags.Input.Files = []
79 flags.addFlag(f"Output.{stream1name}FileName", file1Name)
80 flags.addFlag(f"Output.{stream2name}FileName", file2Name)
81 flags.addFlag(f"Output.{stream3name}FileName", file3Name)
82 flags.Exec.DebugMessageComponents = [ outputStreamName(stream1name) , "PoolSvc", "AthenaPoolCnvSvc", "WriteData" ]
83 flags.lock()
84 
85 # Main services
86 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
87 acc = MainServicesCfg( flags )
88 
89 # Load CutFlowSvc
90 from EventBookkeeperTools.EventBookkeeperToolsConfig import CutFlowSvcCfg
91 acc.merge( CutFlowSvcCfg( flags ) ) #addMetaDataToAllOutputFiles=True ) )
92 # Ensure proper metadata propagation
93 from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg
94 acc.merge( IOVDbSvcCfg( flags ) )
95 
96 # Pool writing
97 acc.addEventAlgo( CompFactory.AthPoolEx.WriteData("WriteData", OutputLevel = DEBUG) )
98 
99 WriteTag = CompFactory.AthPoolEx.WriteTag("WriteTag", OutputLevel = DEBUG)
100 WriteTag.Magic = 1
101 acc.addEventAlgo( WriteTag )
102 
103 MagicWriteTag = CompFactory.AthPoolEx.WriteTag("MagicWriteTag", OutputLevel = DEBUG)
104 MagicWriteTag.Key = "MagicTag"
105 MagicWriteTag.TagKey = "MagicTag"
106 MagicWriteTag.Magic = 24
107 acc.addEventAlgo( MagicWriteTag )
108 
109 
110 # ---------------- Output Stream 1 configuration
111 from AthenaPoolExampleAlgorithms.AthenaPoolExampleConfig import AthenaPoolExampleWriteCfg
112 acc.merge( AthenaPoolExampleWriteCfg( flags, stream1name, writeCatalog = "file:Catalog1.xml",
113  disableEventTag = noTag ) )
114 
115 stream1ca = OutputStreamCfg( flags, stream1name, disableEventTag = noTag,
116  ItemList = [
117  'EventInfo#*', 'EventStreamInfo#*',
118  'ExampleHitContainer#MyHits', 'ExampleHitContainer#PetersHits' ] )
119 stream1 = stream1ca.getEventAlgo( outputStreamName( stream1name ) )
120 stream1.WritingTool.AttributeListKey = MagicWriteTag.Key
121 acc.merge( stream1ca )
122 
123 # ---------------- Output Stream 2 configuration
124 acc.merge( AthenaPoolExampleWriteCfg( flags, stream2name, disableEventTag = noTag ) )
125 stream2ca = OutputStreamCfg(flags, stream2name, disableEventTag = noTag,
126  ItemList = ['EventInfo#*', 'ExampleHitContainer#MyHits'] )
127 stream2 = stream2ca.getEventAlgo( outputStreamName( stream2name ) )
128 stream2.ExcludeList += [ "ExampleHitContainer#MyHits" ]
129 stream2.WritingTool.AttributeListKey = "RunEventTag"
130 acc.merge( stream2ca )
131 
132 # ---------------- Output Stream 3 configuration
133 filterAlg = CompFactory.AthPoolEx.PassNoneFilter("PassNoneFilter", OutputLevel = DEBUG)
134 acc.addEventAlgo( filterAlg )
135 acc.merge( AthenaPoolExampleWriteCfg( flags, stream3name, disableEventTag = noTag ) )
136 stream3ca = OutputStreamCfg(flags, stream3name, disableEventTag = noTag )
137 stream3 = stream3ca.getEventAlgo( outputStreamName( stream3name ) )
138 stream3.RequireAlgs = [ "PassNoneFilter" ]
139 acc.merge( stream3ca )
140 
141 #--------------------------------------------------------------
142 # Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL)
143 #--------------------------------------------------------------
144 stream1.WritingTool.OutputLevel = 3
145 stream1.HelperTools[0].OutputLevel = 3
146 stream2.WritingTool.OutputLevel = 3
147 stream2.HelperTools[0].OutputLevel = 3
148 
149 # Run
150 import sys
151 sc = acc.run(flags.Exec.MaxEvents)
152 sys.exit(sc.isFailure())
153 
154 
155 
156 
157 
158 
AthenaPoolExample_WriteCond.outputStreamName
string outputStreamName
Definition: AthenaPoolExample_WriteCond.py:21
AthenaPoolExampleConfig.AthenaPoolExampleWriteCfg
def AthenaPoolExampleWriteCfg(flags, outputStreamName, writeCatalog=None, disableEventTag=True)
Definition: AthenaPoolExampleConfig.py:38
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=[], MetadataItemList=[], disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:12
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
Constants
some useful constants -------------------------------------------------—
python.IOVDbSvcConfig.IOVDbSvcCfg
def IOVDbSvcCfg(flags, **kwargs)
Definition: IOVDbSvcConfig.py:19
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.EventBookkeeperToolsConfig.CutFlowSvcCfg
def CutFlowSvcCfg(flags, **kwargs)
Definition: EventBookkeeperToolsConfig.py:24