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 # Create 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.Magic = 24
55 acc.addEventAlgo( MagicWriteTag )
56 
57 # Produce xAOD::EventInfo from EventInfo
58 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
59 acc.merge( EventInfoCnvAlgCfg(flags, disableBeamSpot = True) )
60 
61 # ---------------- Output Stream configuration
62 streamCA = OutputStreamCfg( flags, streamName, disableEventTag = True,
63  ItemList = [ "ExampleTrackContainer#MyTracks" ] )
64 stream = streamCA.getEventAlgo( outputStreamName( streamName ) )
65 stream.WritingTool.AttributeListKey = MagicWriteTag.Key
66 acc.merge( streamCA )
67 
68 #--------------------------------------------------------------
69 # Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL)
70 #--------------------------------------------------------------
71 stream.WritingTool.OutputLevel = 3
72 stream.HelperTools[0].OutputLevel = 3
73 
74 # Run
75 import sys
76 sc = acc.run(flags.Exec.MaxEvents)
77 sys.exit(sc.isFailure())
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=None, MetadataItemList=None, disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, keepProvenanceTagsRegEx=None, AcceptAlgs=None, HelperTools=None)
Definition: OutputStreamConfig.py:13
AthenaPoolExample_WriteCond.outputStreamName
string outputStreamName
Definition: AthenaPoolExample_WriteCond.py:21
AthenaPoolExampleConfig.AthenaPoolExampleWriteCfg
def AthenaPoolExampleWriteCfg(flags, outputStreamName, writeCatalog=None, disableEventTag=True)
Definition: AthenaPoolExampleConfig.py:40
AthenaPoolExampleConfig.AthenaPoolExampleReadCfg
def AthenaPoolExampleReadCfg(flags, readCatalogs=[])
Definition: AthenaPoolExampleConfig.py:6
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:312
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