Belle II Software development
SetMetaTimeModule.py
1#!/usr/bin/env python3
2
3
10
11from basf2 import Module
12from ROOT import Belle2
13from basf2 import B2DEBUG, B2FATAL
14
15
16class SetMetaTimeModule(Module):
17
18 """
19 module which sets time in EventMetaData from detector raw data
20
21 Author: bjoern.spruck@belle2.org
22 """
23
24
25 detectorlist = "SVD CDC ECL TOP"
26
27
28 meta = None
29
30
31 raws = []
32
33 def initialize(self):
34 """initialize"""
35
36 self.metameta = Belle2.PyStoreObj('EventMetaData')
37 if not self.metameta:
38 B2FATAL("no EventMetaData object")
39 return
40
41 self.rawsraws = [Belle2.PyStoreArray(f"Raw{e}s") for e in self.detectorlist.split()]
42
43 def calc_time(self, it):
44 """Calculate the time in ns since epoch from UnixTime and Accelerator Clock count"""
45 # t = it.GetTTTimeNs(0)
46 return it.GetTTUtime(0) * 1000000000 + int(round(it.GetTTCtime(0) / 0.127216))
47
48 def event(self):
49 """event"""
50 if not self.metameta.isValid():
51 B2FATAL("no valid EventMetaData object in this event")
52 return
53
54 t = self.metameta.getTime() # Check if it already set, t=0 means not set
55 if t != 0:
56 return # No need to update
57
58 for det in self.rawsraws:
59 if det:
60 for it in det:
61 t = self.calc_time(it)
62 self.metameta.setTime(t)
63 return
64
65 B2DEBUG(1, "No time for EventMetaData extracted as no raw data entries were available from selected detectors")
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
None meta
pointer to event meta data
meta
Store object of EventMetaData.
str detectorlist
List of detector names to check in that order (for fallback)
list raws
array of pointers to the detector raw data arrays