Belle II Software  release-08-01-10
checkDB-commonT0.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 common T0 calibration in DB
18 #
19 # usage: basf2 checkDB-commonT0.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 TOPCalCommonT0 '''
35 
36  def initialize(self):
37  ''' initialize '''
38 
39 
40  self.dbdb = Belle2.PyDBObj('TOPCalCommonT0')
41 
42  self.lastRunlastRun = None
43 
44  self.bunchTimeSepbunchTimeSep = 47.163878 / 24
45 
46  print()
47  print('Common T0 calibration status of GT =', tag)
48  print('Experiment =', expNo, 'Runs =', runFirst, 'to', runLast)
49  print()
50 
51  def event(self):
52  ''' event processing '''
53 
54  evtMetaData = Belle2.PyStoreObj('EventMetaData')
55  runNo = 'r' + '{:0=5d}'.format(evtMetaData.getRun())
56 
57  if not self.dbdb:
58  b2.B2ERROR(runNo + ': payload not found')
59  return
60  if not self.dbdb.hasChanged():
61  self.lastRunlastRun = runNo
62  return
63  if self.lastRunlastRun:
64  print('... to ' + self.lastRunlastRun)
65  self.lastRunlastRun = None
66 
67  if self.dbdb.isCalibrated():
68  status = 'calibrated'
69  elif self.dbdb.isUnusable():
70  status = 'unusable'
71  elif self.dbdb.isRoughlyCalibrated():
72  status = 'roughly calibrated'
73  else:
74  status = 'default'
75  n = round(self.dbdb.getT0() / self.bunchTimeSepbunchTimeSep, 0)
76  if n == 0:
77  print(runNo + ': T0 =',
78  round(self.dbdb.getT0(), 4), '+/-', round(self.dbdb.getT0Error(), 4),
79  status)
80  else:
81  print(runNo + ': T0 =',
82  round(self.dbdb.getT0(), 4), '+/-', round(self.dbdb.getT0Error(), 4),
83  status, '-- out of range')
84 
85  def terminate(self):
86  ''' terminate '''
87 
88  if self.lastRunlastRun:
89  print('... to ' + self.lastRunlastRun)
90  self.lastRunlastRun = None
91 
92 
93 # Database
94 if '.txt' in tag:
95  b2.conditions.append_testing_payloads(tag)
96 else:
97  b2.conditions.append_globaltag(tag)
98 
99 # Create path
100 main = b2.create_path()
101 
102 # Set number of events to generate
103 evtList = [1 for run in range(runFirst, runLast + 1)]
104 runList = [run for run in range(runFirst, runLast + 1)]
105 expList = [expNo for run in range(runFirst, runLast + 1)]
106 
107 # Event info setter
108 eventinfosetter = b2.register_module('EventInfoSetter')
109 eventinfosetter.param({'evtNumList': evtList, 'runList': runList, 'expList': expList})
110 main.add_module(eventinfosetter)
111 
112 # Run checker
113 main.add_module(CheckCalibDB())
114 
115 # Process events
116 b2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
bunchTimeSep
bunch time separation