Belle II Software  release-08-01-10
checkDB-moduleT0.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 import sys
14 from ROOT import Belle2
15 
16 # ------------------------------------------------------------------------
17 # useful tool for checking the status of module T0 calibration in DB
18 #
19 # usage: basf2 checkDB-moduleT0.py expNo runFirst runLast globalTag/localDB
20 # -------------------------------------------------------------------------
21 
22 argvs = sys.argv
23 if len(argvs) < 5:
24  print("usage: basf2", argvs[0], "expNo runFirst runLast globalTag/localDB")
25  sys.exit()
26 
27 expNo = int(argvs[1])
28 runFirst = int(argvs[2])
29 runLast = int(argvs[3])
30 tag = argvs[4]
31 
32 
33 class CheckCalibDB(b2.Module):
34  ''' print content of TOPCalModuleT0 '''
35 
36  def initialize(self):
37  ''' initialize '''
38 
39 
40  self.dbdb = Belle2.PyDBObj('TOPCalModuleT0')
41 
42  self.lastRunlastRun = None
43 
44  print()
45  print('Module T0 calibration status of GT =', tag)
46  print('Experiment =', expNo, 'Runs =', runFirst, 'to', runLast)
47  print()
48 
49  def event(self):
50  ''' event processing '''
51 
52  evtMetaData = Belle2.PyStoreObj('EventMetaData')
53  runNo = 'r' + '{:0=5d}'.format(evtMetaData.getRun())
54 
55  if not self.dbdb:
56  b2.B2ERROR(runNo + ': payload not found')
57  return
58  if not self.dbdb.hasChanged():
59  self.lastRunlastRun = runNo
60  return
61  if self.lastRunlastRun:
62  print('... to ' + self.lastRunlastRun)
63  self.lastRunlastRun = None
64 
65  print(runNo + ':')
66  for slot in range(1, 17):
67  if self.dbdb.isCalibrated(slot):
68  status = 'calibrated'
69  elif self.dbdb.isUnusable(slot):
70  status = 'unusable'
71  else:
72  status = 'default'
73  print(' slot' + '{:0=2d}'.format(slot) + ': T0 =',
74  round(self.dbdb.getT0(slot), 4), '+/-', round(self.dbdb.getT0Error(slot), 4),
75  status)
76 
77  def terminate(self):
78  ''' terminate '''
79 
80  if self.lastRunlastRun:
81  print('... to ' + self.lastRunlastRun)
82  self.lastRunlastRun = None
83 
84 
85 # Database
86 if '.txt' in tag:
87  b2.conditions.append_testing_payloads(tag)
88 else:
89  b2.conditions.append_globaltag(tag)
90 
91 # Create path
92 main = b2.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 = b2.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 b2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67