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