Belle II Software  release-05-01-25
checkDB-moduleT0.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 module T0 calibration in DB
10 #
11 # usage: basf2 checkDB-moduleT0.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 TOPCalModuleT0 '''
27 
28  def initialize(self):
29  ''' initialize '''
30 
31 
32  self.db = Belle2.PyDBObj('TOPCalModuleT0')
33 
34  self.lastRun = None
35 
36  print()
37  print('Module T0 calibration status of GT =', tag)
38  print('Experiment =', expNo, 'Runs =', runFirst, 'to', runLast)
39  print()
40 
41  def event(self):
42  ''' event processing '''
43 
44  evtMetaData = Belle2.PyStoreObj('EventMetaData')
45  runNo = 'r' + '{:0=5d}'.format(evtMetaData.getRun())
46 
47  if not self.db:
48  B2ERROR(runNo + ': payload not found')
49  return
50  if not self.db.hasChanged():
51  self.lastRun = runNo
52  return
53  if self.lastRun:
54  print('... to ' + self.lastRun)
55  self.lastRun = None
56 
57  print(runNo + ':')
58  for slot in range(1, 17):
59  if self.db.isCalibrated(slot):
60  status = 'calibrated'
61  elif self.db.isUnusable(slot):
62  status = 'unusable'
63  else:
64  status = 'default'
65  print(' slot' + '{:0=2d}'.format(slot) + ': T0 =',
66  round(self.db.getT0(slot), 4), '+/-', round(self.db.getT0Error(slot), 4),
67  status)
68 
69  def terminate(self):
70  ''' terminate '''
71 
72  if self.lastRun:
73  print('... to ' + self.lastRun)
74  self.lastRun = None
75 
76 
77 # Database
78 if '.txt' in tag:
79  use_local_database(tag)
80 else:
81  use_central_database(tag)
82 
83 # Create path
84 main = create_path()
85 
86 # Set number of events to generate
87 evtList = [1 for run in range(runFirst, runLast + 1)]
88 runList = [run for run in range(runFirst, runLast + 1)]
89 expList = [expNo for run in range(runFirst, runLast + 1)]
90 
91 # Event info setter
92 eventinfosetter = register_module('EventInfoSetter')
93 eventinfosetter.param({'evtNumList': evtList, 'runList': runList, 'expList': expList})
94 main.add_module(eventinfosetter)
95 
96 # Run checker
97 main.add_module(CheckCalibDB())
98 
99 # Process events
100 process(main)
checkDB-moduleT0.CheckCalibDB.terminate
def terminate(self)
Definition: checkDB-moduleT0.py:69
checkDB-moduleT0.CheckCalibDB.lastRun
lastRun
last run number
Definition: checkDB-moduleT0.py:34
checkDB-moduleT0.CheckCalibDB
Definition: checkDB-moduleT0.py:25
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:69
checkDB-moduleT0.CheckCalibDB.db
db
payload
Definition: checkDB-moduleT0.py:32
Belle2::PyDBObj
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50
checkDB-moduleT0.CheckCalibDB.event
def event(self)
Definition: checkDB-moduleT0.py:41
checkDB-moduleT0.CheckCalibDB.initialize
def initialize(self)
Definition: checkDB-moduleT0.py:28