ATLAS Offline Software
Loading...
Searching...
No Matches
readDataHeader.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4
5from AthenaPython.PyAthena import Alg, py_svc, StatusCode
6from AthenaCommon.Logging import logging
7
8# A basic algorithm that reads the DataHeader to print some information
10
11 def __init__(self,name='ReadDataHeaderAlg', totalEvents=0):
12 super(ReadDataHeaderAlg,self).__init__(name=name)
13 self.totalEvents = totalEvents
14 self.nevt = 0
15 return
16
17 def initialize(self):
18 self.sg = py_svc('StoreGateSvc')
19 return StatusCode.Success
20
21 def execute(self):
22 if self.sg.contains('DataHeader', 'EventSelector'):
23 dh = self.sg.retrieve('DataHeader', 'EventSelector')
24 sz = dh.size()
25 self.nevt += 1
26 if self.nevt % 100 == 0:
27 logging.info(f'DataHeader Size {sz} in event #{self.nevt}')
28 if sz > 0:
29 it = dh.begin()
30 for idx in range(sz):
31 logging.debug(f' >> Key {it.getKey()} : Token {it.getToken().toString()}')
32 it+=1
33 else:
34 logging.debug(' >> Successfully read through the DataHeader')
35 else:
36 logging.error(f' >> Negative DataHeader size ({sz})!')
37 return StatusCode.Failure
38 else:
39 logging.error('Could NOT find the DataHeader!')
40 return StatusCode.Failure
41
42 return StatusCode.Success
43
44 def finalize(self):
45 # Now this hack is needed because some errors, e.g. those in loading proxies,
46 # don't cause a job failure because most loop managers seem to ignore them.
47 # The problem is that even though we fail here, the job still "succeeds"
48 if self.nevt != self.totalEvents:
49 logging.error(f'Expected {self.totalEvents} events but processed {self.nevt}!')
50 logging.error('This most likely means we could not process some events successfully!')
51 return StatusCode.Failure
52
53 return StatusCode.Success
54
55# A minimal job that reads the DataHeader
56if __name__ == '__main__':
57 """
58 Example usage: readDataHeader.py --filesInput=DAOD_PHYS.pool.root --evtMax=10 --loglevel=DEBUG
59 """
60
61 # Import the common flags/services
62 from AthenaConfiguration.AllConfigFlags import initConfigFlags
63 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
64
65 # Set the necessary configuration flags and lock them
66 # This is filled from the command line arguments as shown above
67 flags = initConfigFlags()
68 flags.fillFromArgs()
69 flags.lock()
70
71 # Figure out how many events we expect
72 if flags.Exec.MaxEvents < 0:
73 totalEvents = 0
74 from AthenaConfiguration.AutoConfigFlags import GetFileMD
75 for filename in flags.Input.Files:
76 totalEvents += GetFileMD(filename).get('nentries', 0)
77 else:
78 totalEvents = flags.Exec.MaxEvents
79
80 # Set up the configuration and add the relevant services
81 cfg = MainServicesCfg(flags)
82
83 # Input reading
84 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
85 cfg.merge(PoolReadCfg(flags))
86
87 # Schedule the Custom Algorithm
88 cfg.addEventAlgo(ReadDataHeaderAlg('ReadDataHeaderAlg', totalEvents=totalEvents), sequenceName = 'AthAllAlgSeq')
89
90 # Now run the job and exit accordingly
91 sc = cfg.run()
92 import sys
93 sys.exit(not sc.isSuccess())
__init__(self, name='ReadDataHeaderAlg', totalEvents=0)
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
void initialize()