Belle II Software  release-08-01-10
SetMetaTimeModule.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 from basf2 import Module
13 from ROOT import Belle2
14 from basf2 import B2DEBUG, B2FATAL
15 
16 
17 class SetMetaTimeModule(Module):
18 
19  """
20  module which sets time in EventMetaData from detector raw data
21 
22  Author: bjoern.spruck@belle2.org
23  """
24 
25 
26  detectorlist = "SVD CDC ECL TOP"
27 
28 
29  meta = None
30 
31 
32  raws = []
33 
34  def initialize(self):
35  """initialize"""
36  self.metameta = Belle2.PyStoreObj('EventMetaData')
37  if not self.metameta:
38  B2FATAL("no EventMetaData object")
39  return
40 
41  self.rawsrawsraws = [Belle2.PyStoreArray(f"Raw{e}s") for e in self.detectorlistdetectorlist.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.rawsrawsraws:
59  if det:
60  for it in det:
61  t = self.calc_timecalc_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
meta
pointer to event meta data
string detectorlist
List of detector names to check in that order (for fallback)
list raws
array of pointers to the detector raw data arrays