Belle II Software  release-05-01-25
checkDB-commonT0.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 from basf2 import *
5 import sys
6 from ROOT import Belle2
7 
8 # ------------------------------------------------------------------------
9 # useful tool for checking the status of common T0 calibration in DB
10 #
11 # usage: basf2 checkDB-commonT0.py expNo runFirst runLast globalTag/localDB
12 # -------------------------------------------------------------------------
13 
14 argvs = sys.argv
15 if len(argvs) < 5:
16  print("usage: basf2", argvs[0], "expNo runFirst runLast globalTag/localDB")
17  sys.exit()
18 
19 expNo = int(argvs[1])
20 runFirst = int(argvs[2])
21 runLast = int(argvs[3])
22 tag = argvs[4]
23 
24 
25 class CheckCalibDB(Module):
26  ''' print content of TOPCalCommonT0 '''
27 
28  def initialize(self):
29  ''' initialize '''
30 
31 
32  self.db = Belle2.PyDBObj('TOPCalCommonT0')
33 
34  self.lastRun = None
35 
36  self.bunchTimeSep = 47.163878 / 24
37 
38  print()
39  print('Common T0 calibration status of GT =', tag)
40  print('Experiment =', expNo, 'Runs =', runFirst, 'to', runLast)
41  print()
42 
43  def event(self):
44  ''' event processing '''
45 
46  evtMetaData = Belle2.PyStoreObj('EventMetaData')
47  runNo = 'r' + '{:0=5d}'.format(evtMetaData.getRun())
48 
49  if not self.db:
50  B2ERROR(runNo + ': payload not found')
51  return
52  if not self.db.hasChanged():
53  self.lastRun = runNo
54  return
55  if self.lastRun:
56  print('... to ' + self.lastRun)
57  self.lastRun = None
58 
59  if self.db.isCalibrated():
60  status = 'calibrated'
61  elif self.db.isUnusable():
62  status = 'unusable'
63  elif self.db.isRoughlyCalibrated():
64  status = 'roughly calibrated'
65  else:
66  status = 'default'
67  n = round(self.db.getT0() / self.bunchTimeSep, 0)
68  if n == 0:
69  print(runNo + ': T0 =',
70  round(self.db.getT0(), 4), '+/-', round(self.db.getT0Error(), 4),
71  status)
72  else:
73  print(runNo + ': T0 =',
74  round(self.db.getT0(), 4), '+/-', round(self.db.getT0Error(), 4),
75  status, '-- out of range')
76 
77  def terminate(self):
78  ''' terminate '''
79 
80  if self.lastRun:
81  print('... to ' + self.lastRun)
82  self.lastRun = None
83 
84 
85 # Database
86 if '.txt' in tag:
87  use_local_database(tag)
88 else:
89  use_central_database(tag)
90 
91 # Create path
92 main = create_path()
93 
94 # Set number of events to generate
95 evtList = [1 for run in range(runFirst, runLast + 1)]
96 runList = [run for run in range(runFirst, runLast + 1)]
97 expList = [expNo for run in range(runFirst, runLast + 1)]
98 
99 # Event info setter
100 eventinfosetter = register_module('EventInfoSetter')
101 eventinfosetter.param({'evtNumList': evtList, 'runList': runList, 'expList': expList})
102 main.add_module(eventinfosetter)
103 
104 # Run checker
105 main.add_module(CheckCalibDB())
106 
107 # Process events
108 process(main)
checkDB-commonT0.CheckCalibDB.event
def event(self)
Definition: checkDB-commonT0.py:43
checkDB-commonT0.CheckCalibDB.bunchTimeSep
bunchTimeSep
bunch time separation
Definition: checkDB-commonT0.py:36
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:69
checkDB-commonT0.CheckCalibDB.initialize
def initialize(self)
Definition: checkDB-commonT0.py:28
Belle2::PyDBObj
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50
checkDB-commonT0.CheckCalibDB.lastRun
lastRun
last run number
Definition: checkDB-commonT0.py:34
checkDB-commonT0.CheckCalibDB.db
db
payload
Definition: checkDB-commonT0.py:32
checkDB-commonT0.CheckCalibDB
Definition: checkDB-commonT0.py:25
checkDB-commonT0.CheckCalibDB.terminate
def terminate(self)
Definition: checkDB-commonT0.py:77