ATLAS Offline Software
Loading...
Searching...
No Matches
EventGUIDLookupAlgConfig.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3"""Algorithm + CA config for EventGUIDLookup_Skeleton.py."""
4
5from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6from AthenaPython import PyAthena
7from AthenaPython.PyAthena import StatusCode
8from GaudiKernel.Constants import INFO
9
10
12
13 def __init__(self, name='EventGUIDLookupAlg', **kwargs):
14 self.dataType = kwargs.pop('dataType')
15 self.inputDataType = kwargs.pop('inputDataType')
16 self.requestedEvents = kwargs.pop('requestedEvents', set())
17 self.outputFile = kwargs.pop('outputFile', 'eventGUIDLookup.txt')
18 super(EventGUIDLookupAlg, self).__init__(name=name, **kwargs)
19 self._found = set()
20 self._outFH = None
21
22 def initialize(self):
23 self._outFH = open(self.outputFile, 'w')
24 return StatusCode.Success
25
26 def _matchRun(self, ctx_run, evt):
27 """Return the run-like number used for matching and output:
28 the MC channel number (DSID) for simulation, the run number for data.
29 """
30 try:
31 ei = self.evtStore['EventInfo']
32 if ei.eventType(ei.IS_SIMULATION): # isMC
33 dsid = ei.mcChannelNumber()
34 if dsid != 0:
35 return dsid
36 # Some old/private productions have no channel number set
37 self.msg.debug('run=%d event=%d: MC with mcChannelNumber=0; '
38 'using run number', ctx_run, evt)
39 except Exception as e:
40 self.msg.warning('run=%d event=%d: cannot read EventInfo (%s); '
41 'using run number', ctx_run, evt, e)
42 return ctx_run
43
44 def execute(self):
45 from EventGUIDLookup.EventGUIDLookupLib import resolveProvenanceGuid
46
47 # Event number and (data) run number come from the EventContext,
48 # which is format-agnostic. For MC the run number is replaced by
49 # the MC channel number (DSID) read from EventInfo.
50
51 eid = self.getContext().eventID()
52 ctx_run, evt = eid.run_number(), eid.event_number()
53
54 run = self._matchRun(ctx_run, evt) # DSID for MC, run number for data
55 key = (run, evt)
56
57 if key in self.requestedEvents and key not in self._found:
58 guid = resolveProvenanceGuid(self.evtStore, self.dataType,
59 self.inputDataType)
60 if guid is not None:
61 self._outFH.write('%d %d %s\n' % (run, evt, guid))
62 self._outFH.flush()
63 self._found.add(key)
64 else:
65 self.msg.warning('run/dsid=%d event=%d has no %s provenance '
66 'reference', run, evt, self.dataType)
67 return StatusCode.Success
68 def finalize(self):
69 if self._outFH:
70 self._outFH.close()
71 missing = self.requestedEvents - self._found
72 if missing:
73 self.msg.warning('%d of %d requested events had no %s GUID',
74 len(missing), len(self.requestedEvents),
75 self.dataType)
76 for run, evt in sorted(missing):
77 self.msg.warning(' missing: run=%d event=%d', run, evt)
78 else:
79 self.msg.info('Resolved GUIDs for all %d requested events',
80 len(self.requestedEvents))
81 return StatusCode.Success
82
83
84def EventGUIDLookupAlgCfg(flags, dataType, inputDataType, requestedEvents,
85 outputFile, name='EventGUIDLookupAlg', **kwargs):
86 acc = ComponentAccumulator()
87 acc.addEventAlgo(EventGUIDLookupAlg(
88 name=name,
89 dataType=dataType,
90 inputDataType=inputDataType,
91 requestedEvents=requestedEvents,
92 outputFile=outputFile,
93 OutputLevel=kwargs.pop('OutputLevel', INFO)))
94 return acc
const bool debug
__init__(self, name='EventGUIDLookupAlg', **kwargs)
virtual StatusCode finalize() override
virtual StatusCode initialize() override
STL class.
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55
EventGUIDLookupAlgCfg(flags, dataType, inputDataType, requestedEvents, outputFile, name='EventGUIDLookupAlg', **kwargs)