ATLAS Offline Software
Loading...
Searching...
No Matches
ReadLumiFromCool.py
Go to the documentation of this file.
1#!/bin/env python
2
3# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4#
5# ReadLumiFromCool.py
6# Sanya Solodkov <Sanya.Solodkov@cern.ch>
7#
8# Purpose: Read lumi values from CALO COOL DB
9#
10
11import getopt,sys,os
12os.environ['TERM'] = 'linux'
13
14def usage():
15 print ("Usage: ",sys.argv[0]," [OPTION] ... ")
16 print ("Dump Lumi values from online or offline CALO DB or from sqlite file")
17 print ("")
18 print ("-h, --help shows this help")
19 print ("-s, --schema= specify schema to use, ONL or OFL for RUN1 or ONL2 or OFL2 for RUN2 or MC")
20 print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
21 print ("-d, --dbname= specify the database name e.g. CONDBR2")
22 print ("-f, --folder= specify folder to use e.g. /CALO/Ofl/Noise/PileUpNoiseLumi")
23 print ("-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or tag suffix like RUN2-UPD4-04")
24 print ("-c, --channel= specify COOL channel, by default COOL channels 0 and 1 are used")
25 print ("-r, --run= specify run number, by default uses latest iov")
26 print ("-l, --lumi= specify lumi block number, default is 0")
27 print ("-b, --begin= specify run number of first iov in multi-iov mode, by default uses very first iov")
28 print ("-e, --end= specify run number of last iov in multi-iov mode, by default uses latest iov")
29
30letters = "hS:s:d:t:f:c:r:l:b:e:"
31keywords = ["help","server=","schema=","dbname=","tag=","folder=","channel=","run=","lumi=","begin=","end="]
32
33try:
34 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
35except getopt.GetoptError as err:
36 print (str(err))
37 usage()
38 sys.exit(2)
39
40# defaults
41run = 2147483647
42lumi = 0
43server = ''
44schema = 'OFL2'
45folderPath = ''
46dbName = 'CONDBR2'
47tag = 'UPD4'
48begin = -1
49end = 2147483647
50iov = False
51channels = [0,1]
52
53for o, a in opts:
54 a = a.strip()
55 if o in ("-s","--schema"):
56 schema = a
57 elif o in ("-S","--server"):
58 server = a
59 elif o in ("-d","--dbname"):
60 dbName = a
61 elif o in ("-f","--folder"):
62 folderPath = a
63 elif o in ("-t","--tag"):
64 tag = a
65 elif o in ("-c","--channel"):
66 channels = [int(a)]
67 elif o in ("-r","--run"):
68 run = int(a)
69 elif o in ("-l","--lumi"):
70 lumi = int(a)
71 elif o in ("-b","--begin"):
72 begin = int(a)
73 iov = True
74 elif o in ("-e","--end"):
75 end = int(a)
76 iov = True
77 elif o in ("-h","--help"):
78 usage()
79 sys.exit(2)
80 else:
81 usage()
82 sys.exit(2)
83
84from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
85from TileCalibBlobPython import TileCalibTools
86
87#=== get a logger
88log = CaloCondLogger.getLogger("ReadLumi")
89import logging
90log.setLevel(logging.DEBUG)
91
92#=== Set tag and schema name:
93
94if schema=='ONL': # shortcut for COOLONL_CALO/COMP200
95 schema='COOLONL_CALO/COMP200'
96 if tag=='UPD1' or tag=='UPD4':
97 tag='UPD1-00' # change default to latest RUN1 tag
98elif schema=='ONL2': # shortcut for COOLONL_CALO/CONDBR2
99 schema='COOLONL_CALO/CONDBR2'
100 if tag=='UPD1' or tag=='UPD4':
101 tag='RUN2-UPD1-00' # change default to the only tag available online
102elif schema=='OFL': # shortcut for COOLOFL_CALO/COMP200
103 schema='COOLOFL_CALO/COMP200'
104 if tag=='UPD1':
105 tag='UPD1-00' # change default to latest RUN1 tag
106 if tag=='UPD4':
107 tag='UPD4-02' # change default to latest RUN1 tag
108elif schema=='OFL2': # shortcut for COOLOFL_CALO/CONDBR2
109 schema='COOLOFL_CALO/CONDBR2'
110elif schema=='ONLMC': # shortcut for COOLONL_CALO/OFLP200
111 schema='COOLONL_CALO/OFLP200'
112 if tag=='UPD4':
113 tag='OFLCOND-RUN12-SDR-07' # change default to latest RUN1-RUN2 tag
114elif schema=='OFLMC' or schema=='MC': # shortcut for COOLOFL_CALO/OFLP200
115 schema='COOLOFL_CALO/OFLP200'
116 if tag=='UPD4':
117 tag='OFLCOND-MC23-SDR-RUN3-02' # change default to tag used in MC23
118
119if tag=="HEAD":
120 tag=""
121
122if os.path.isfile(schema):
123 schema = 'sqlite://;schema='+schema+';dbname='+dbName
124else:
125 log.info("File %s was not found, assuming it's full schema string" , schema)
126
127#=== Open DB connections
128db = CaloCondTools.openDbConn(schema, server)
129
130if len(folderPath)==0:
131 if 'ONL' in schema:
132 folderPath = '/CALO/Noise/PileUpNoiseLumi'
133 else:
134 folderPath = '/CALO/Ofl/Noise/PileUpNoiseLumi'
135
136folderTag = TileCalibTools.getFolderTag(schema if 'COMP200' in schema or 'OFLP200' in schema else db, folderPath, tag )
137
138log.info("Initializing folder %s with tag %s", folderPath, folderTag)
139
140folder = db.getFolder(folderPath)
141
142#=== Filling the iovList
143iovList = []
144if iov:
145 try:
146 blobReader = CaloCondTools.CaloBlobReader(db,folderPath, folderTag)
147 dbobjs = blobReader.getDBobjsWithinRange(0)
148 if (dbobjs is None):
149 raise Exception("No DB objects retrieved when building IOV list!")
150 while dbobjs.goToNext():
151 obj = dbobjs.currentRef()
152 since = CaloCondTools.runLumiFromIov(obj.since())
153 until = CaloCondTools.runLumiFromIov(obj.until())
154 iovList.append((since, until))
155 except Exception:
156 log.warning( "Warning: can not read IOVs from input DB file" )
157 sys.exit(2)
158
159 be=iovList[0][0][0]
160 en=iovList[-1][0][0]
161
162 if begin != be or end != en:
163 ib=0
164 ie=len(iovList)
165 for i,iovs in enumerate(iovList):
166 run = iovs[0][0]
167 lumi = iovs[0][1]
168 if (run<begin and run>be) or (run==begin and lumi==0) :
169 be=run
170 ib=i
171 if run>=end and run<en:
172 en=run
173 ie=i+1
174 log.info( "" )
175 if be != begin:
176 log.info( "Changing begin run from %d to %d (start of IOV)", begin,be)
177 begin=be
178 if en != end:
179 if en>end:
180 log.info( "Changing end run from %d to %d (start of next IOV)", end,en)
181 else:
182 log.info( "Changing end run from %d to %d (start of last IOV)", end,en)
183 end=en
184 iovList=iovList[ib:ie]
185 log.info( "%d IOVs in total", len(iovList) )
186else:
187 iovList.append(((run,lumi),(CaloCondTools.MAXRUN, CaloCondTools.MAXLBK)))
188
189log.info( "\n" )
190
191#=== loop over all iovs and COOL channels
192obj = None
193pref = ""
194pref1 = ""
195suff = ""
196for iovs in iovList:
197 if iov:
198 pref = "(%i,%i) " % (iovs[0][0],iovs[0][1])
199 pref1 = pref
200 since = CaloCondTools.iovFromRunLumi(iovs[0][0],iovs[0][1])
201 values = []
202 for chan in channels:
203 try:
204 obj = folder.findObject( since, chan, folderTag )
205 try:
206 values += [[obj.payload()[0],obj.payload()[1]]]
207 pref1 = pref+"lumi"
208 except Exception:
209 #log.warning( "Warning: can not interpert data as Lumi values" )
210 pref1 = pref
211 values += [obj.payload()[0]]
212 except Exception:
213 obj = None
214 log.warning( "Warning: can not read data from input DB" )
215 if not iov and obj is not None:
216 (sinceRun,sinceLum) = CaloCondTools.runLumiFromIov(obj.since())
217 (untilRun,untilLum) = CaloCondTools.runLumiFromIov(obj.until())
218 suff = " iov since [%d,%d] until (%d,%d)" % (sinceRun,sinceLum,untilRun,untilLum)
219 if len(values)==1:
220 print(pref1,values[0],suff)
221 else:
222 print(pref1,values,suff)
223
224#=== close DB
225db.closeDatabase()
void print(char *figname, TCanvas *c1)