ATLAS Offline Software
AthenaPoolExample_ReadWrite.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 
14 
15 from AthenaConfiguration.AllConfigFlags import initConfigFlags
16 from AthenaConfiguration.ComponentFactory import CompFactory
17 from AthenaCommon.Constants import DEBUG
18 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName
19 
20 streamName = "ReWrite"
21 outputFileName = "SimplePoolFile3.root"
22 noTag = True
23 
24 # Setup flags
25 flags = initConfigFlags()
26 flags.Input.Files = ["SimplePoolFile1.root"]
27 flags.addFlag(f"Output.{streamName}FileName", outputFileName)
28 flags.Exec.MaxEvents = -1
29 flags.Common.MsgSuppression = False
30 flags.Exec.DebugMessageComponents = [outputStreamName(streamName),
31  "PoolSvc", "AthenaPoolCnvSvc","AthenaPoolAddressProviderSvc", "MetaDataSvc"]
32 flags.lock()
33 
34 # Main services
35 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
36 acc = MainServicesCfg( flags )
37 
38 # Pool reading and writing
39 from AthenaPoolExampleAlgorithms.AthenaPoolExampleConfig import AthenaPoolExampleReadCfg, AthenaPoolExampleWriteCfg
40 acc.merge( AthenaPoolExampleReadCfg(flags, readCatalogs = ["file:Catalog1.xml"]) )
41 acc.merge( AthenaPoolExampleWriteCfg( flags, streamName,
42  writeCatalog = "file:Catalog1.xml",
43  disableEventTag = noTag ) )
44 
45 # Creata and attach the algorithms
46 acc.addEventAlgo( CompFactory.AthPoolEx.ReadData("ReadData", OutputLevel = DEBUG) )
47 acc.addEventAlgo( CompFactory.AthPoolEx.ReWriteData("ReWriteData", OutputLevel = DEBUG) )
48 
49 WriteTag = CompFactory.AthPoolEx.WriteTag("WriteTag", OutputLevel = DEBUG)
50 acc.addEventAlgo( WriteTag )
51 
52 MagicWriteTag = CompFactory.AthPoolEx.WriteTag("MagicWriteTag", OutputLevel = DEBUG)
53 MagicWriteTag.Key = "MagicTag"
54 MagicWriteTag.TagKey = "MagicTag"
55 MagicWriteTag.Magic = 24
56 acc.addEventAlgo( MagicWriteTag )
57 
58 # Produce xAOD::EventInfo from EventInfo
59 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
60 acc.merge( EventInfoCnvAlgCfg(flags, disableBeamSpot = True) )
61 
62 # ---------------- Output Stream configuration
63 streamCA = OutputStreamCfg( flags, streamName, disableEventTag = True,
64  ItemList = [ "ExampleTrackContainer#MyTracks" ] )
65 stream = streamCA.getEventAlgo( outputStreamName( streamName ) )
66 stream.WritingTool.AttributeListKey = MagicWriteTag.Key
67 acc.merge( streamCA )
68 
69 #--------------------------------------------------------------
70 # Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL)
71 #--------------------------------------------------------------
72 stream.WritingTool.OutputLevel = 3
73 stream.HelperTools[0].OutputLevel = 3
74 
75 # Run
76 import sys
77 sc = acc.run(flags.Exec.MaxEvents)
78 sys.exit(sc.isFailure())
79 
80 
81 
82 
83 
84 
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
AthenaPoolExampleConfig.AthenaPoolExampleReadCfg
def AthenaPoolExampleReadCfg(flags, readCatalogs=[])
Definition: AthenaPoolExampleConfig.py:6
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
Constants
some useful constants -------------------------------------------------—
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.xAODEventInfoCnvConfig.EventInfoCnvAlgCfg
def EventInfoCnvAlgCfg(flags, name="EventInfoCnvAlg", inputKey="McEventInfo", outputKey="EventInfo", disableBeamSpot=False, **kwargs)
Definition: xAODEventInfoCnvConfig.py:11