Belle II Software  release-08-01-10
checkCalibDB.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 TOP calibration in central DB
18 #
19 # usage: basf2 checkCalibDB.py expNo runNo [globalTag]
20 # --------------------------------------------------------------------
21 
22 argvs = sys.argv
23 if len(argvs) < 3:
24  print("usage: basf2", argvs[0], "expNo runNo [globalTag]")
25  sys.exit()
26 
27 expNo = int(argvs[1])
28 runNo = int(argvs[2])
29 tag = '(default)'
30 if len(argvs) == 4:
31  tag = argvs[3]
32 
33 
34 class CheckCalibDB(b2.Module):
35  ''' print calibration status of TOPCal payloads '''
36 
37  def printChannel(self, payload):
38  ''' print status of a payload given by the argument '''
39 
40  db = Belle2.PyDBObj(payload)
41  if not db:
42  b2.B2ERROR(payload + ' not found')
43  return
44  calibrated = 0
45  all_entries = 0
46  for moduleID in range(1, 17):
47  for channel in range(512):
48  all_entries += 1
49  if db.isCalibrated(moduleID, channel):
50  calibrated += 1
51  print(payload + ': ' + str(calibrated) + '/' + str(all_entries) + ' calibrated')
52 
53  def printChannelMask(self):
54  ''' print status of channel masks '''
55 
56  payload = 'TOPCalChannelMask'
57  db = Belle2.PyDBObj(payload)
58  if not db:
59  b2.B2ERROR(payload + ' not found')
60  return
61  active = db.getNumOfActiveChannels()
62  all_entries = db.getNumOfChannels()
63  print(payload + ': ' + str(active) + '/' + str(all_entries) + ' active')
64 
65  def printModule(self, payload):
66  ''' print status of a payload given by the argument '''
67 
68  db = Belle2.PyDBObj(payload)
69  if not db:
70  b2.B2ERROR(payload + ' not found')
71  return
72  calibrated = 0
73  all_entries = 0
74  for moduleID in range(1, 17):
75  all_entries += 1
76  if db.isCalibrated(moduleID):
77  calibrated += 1
78  print(payload + ': ' + str(calibrated) + '/' + str(all_entries) + ' calibrated')
79 
80  def printCommon(self, payload):
81  ''' print status of a payload given by the argument '''
82 
83  db = Belle2.PyDBObj(payload)
84  if not db:
85  b2.B2ERROR(payload + ' not found')
86  return
87  calibrated = 0
88  all_entries = 1
89  if db.isCalibrated():
90  calibrated += 1
91  print(payload + ': ' + str(calibrated) + '/' + str(all_entries) + ' calibrated')
92 
93  def printTimeBase(self):
94  ''' print status of time base calibration '''
95 
96  payload = 'TOPCalTimebase'
97  db = Belle2.PyDBObj(payload)
98  if not db:
99  b2.B2ERROR(payload + ' not found')
100  return
101  calibrated = 0
102  all_entries = 8192
103  for sampleTimes in db.getSampleTimes():
104  if sampleTimes.isCalibrated():
105  calibrated += 1
106  print(payload + ': ' + str(calibrated) + '/' + str(all_entries) + ' calibrated')
107 
108  def event(self):
109  ''' event processing '''
110 
111  print()
112  print('Calibration status of GT =', tag)
113  print('Experiment =', expNo, 'Run =', runNo)
114  print()
115  self.printTimeBaseprintTimeBase()
116  self.printChannelprintChannel('TOPCalChannelT0')
117  self.printModuleprintModule('TOPCalModuleT0')
118  self.printCommonprintCommon('TOPCalCommonT0')
119  self.printChannelprintChannel('TOPCalChannelNoise')
120  self.printChannelprintChannel('TOPCalChannelPulseHeight')
121  self.printChannelprintChannel('TOPCalChannelRQE')
122  self.printChannelprintChannel('TOPCalChannelThresholdEff')
123  self.printChannelprintChannel('TOPCalChannelThreshold')
124  self.printChannelprintChannel('TOPCalIntegratedCharge')
125  self.printModuleprintModule('TOPCalModuleAlignment')
126  self.printChannelMaskprintChannelMask()
127  print()
128 
129 
130 # Central database
131 if len(argvs) == 4:
132  b2.conditions.append_globaltag(tag)
133 
134 # Create path
135 main = b2.create_path()
136 
137 # Set number of events to generate
138 eventinfosetter = b2.register_module('EventInfoSetter')
139 eventinfosetter.param({'evtNumList': [1], 'runList': [runNo], 'expList': [expNo]})
140 main.add_module(eventinfosetter)
141 
142 # Run checker
143 main.add_module(CheckCalibDB())
144 
145 # Process events
146 b2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50
def printModule(self, payload)
Definition: checkCalibDB.py:65
def printCommon(self, payload)
Definition: checkCalibDB.py:80
def printChannel(self, payload)
Definition: checkCalibDB.py:37