ATLAS Offline Software
Loading...
Searching...
No Matches
test_athena_variable_shape_ntuple.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3import os
4from AthenaCommon.Utils import unixtools
5
6if 'FNAMES' not in dir():
7 paths = os.getenv('DATAPATH').split(os.pathsep) + [os.getenv('ATLAS_REFERENCE_DATA','')]
8 testdir = unixtools.find_datafile(os.getenv('ATLAS_REFERENCE_TAG'), paths)
9 FNAMES = [os.path.join(testdir, f) for f in ('ntuple.0.root', 'ntuple.1.root')]
10
11if not isinstance(FNAMES, (list,tuple)):
12 FNAMES = [FNAMES]
13 pass
14
15import AthenaRootComps.ReadAthenaRoot
16svcMgr.EventSelector.InputCollections = FNAMES
17svcMgr.EventSelector.TupleName = "egamma"
18
19from AthenaCommon.AlgSequence import AlgSequence
20job = AlgSequence()
21
22from AthenaPython import PyAthena
23StatusCode = PyAthena.StatusCode
24
26
27 def __init__(self, name='MyAlg', **kw):
28 kw['name'] = name
29 self.activeBranches = kw.get(
30 'activeBranches',
31 ['RunNumber',
32 'EventNumber',
33 'el_n',
34 'el_eta',
35 'el_jetcone_dr',
36 ])
37 self.fname = kw.get('fname', 'data.var.txt')
38 super(MyAlg, self).__init__(**kw)
39 return
40
41 def initialize(self):
42 self.evtstore = PyAthena.py_svc('StoreGateSvc')
43 self.fd = open(self.fname, 'w')
44 return StatusCode.Success
45
46 def execute(self):
47 self.msg.info('running execute...')
48 keys = []
49 for p in self.evtstore.proxies():
50 if not p.isValid():
51 continue
52 keys.append(p.name())
53 for br in self.activeBranches:
54 try:
55 if br not in keys:
56 raise KeyError("no such object [%s] in store" % br)
57 o = self.evtstore[br]
58 if hasattr(o, 'at'):
59 o = list(o)
60 for i,v in enumerate(o):
61 if hasattr(v, 'at') and not isinstance(v, str):
62 o[i] = list(v)
63 self.msg.info('%s: %r', br, o)
64 print ("%s: %r" % (br, o), file=self.fd)
65 except Exception as err:
66 self.msg.info(' --> err for [%s]: %s' % (br, err))
67 pass
68 return StatusCode.Success
69
70 def finalize(self):
71 if hasattr(self, 'fd') and self.fd:
72 self.fd.flush()
73 self.fd.close()
74 return StatusCode.Success
75
76 pass # MyAlg
77
78from AthenaCommon.AlgSequence import AlgSequence
79job = AlgSequence()
80job += MyAlg('py_alg')
81
82if 'BRANCHES' in dir():
83 job.py_alg.activeBranches = BRANCHES
84 pass
85
86if not 'EVTMAX' in dir():
87 EVTMAX=-1
88theApp.EvtMax = EVTMAX
89
90if not 'DOWRITE' in dir():
91 DOWRITE=1
92if DOWRITE:
93 svcMgr += CfgMgr.DecisionSvc()
94 import AthenaRootComps.WriteAthenaRoot as arcw
95 out = arcw.createNtupleOutputStream("StreamD3PD", "d3pd.root", "egamma")
96 if 'OUTBRANCHES' not in dir():
97 OUTBRANCHES=[
98 "el_n",
99 "el_eta",
100 "el_jetcone_dr",
101 ]
102 out.ItemList += OUTBRANCHES
103
MsgStream & msg() const
virtual StatusCode execute() override
virtual StatusCode finalize() override
virtual StatusCode initialize() override
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177