12 os.environ[
'TERM'] =
'linux'
15 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
16 print (
"Dump Lumi values from online or offline CALO DB or from sqlite file")
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")
30 letters =
"hS:s:d:t:f:c:r:l:b:e:"
31 keywords = [
"help",
"server=",
"schema=",
"dbname=",
"tag=",
"folder=",
"channel=",
"run=",
"lumi=",
"begin=",
"end="]
34 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
35 except getopt.GetoptError
as err:
55 if o
in (
"-s",
"--schema"):
57 elif o
in (
"-S",
"--server"):
59 elif o
in (
"-d",
"--dbname"):
61 elif o
in (
"-f",
"--folder"):
63 elif o
in (
"-t",
"--tag"):
65 elif o
in (
"-c",
"--channel"):
67 elif o
in (
"-r",
"--run"):
69 elif o
in (
"-l",
"--lumi"):
71 elif o
in (
"-b",
"--begin"):
74 elif o
in (
"-e",
"--end"):
77 elif o
in (
"-h",
"--help"):
84 from CaloCondBlobAlgs
import CaloCondTools, CaloCondLogger
87 log = CaloCondLogger.getLogger(
"ReadLumi")
89 log.setLevel(logging.DEBUG)
94 schema=
'COOLONL_CALO/COMP200'
95 if tag==
'UPD1' or tag==
'UPD4':
98 schema=
'COOLONL_CALO/CONDBR2'
99 if tag==
'UPD1' or tag==
'UPD4':
102 schema=
'COOLOFL_CALO/COMP200'
108 schema=
'COOLOFL_CALO/CONDBR2'
109 elif schema==
'ONLMC':
110 schema=
'COOLONL_CALO/OFLP200'
112 tag=
'OFLCOND-RUN12-SDR-07'
113 elif schema==
'OFLMC' or schema==
'MC':
114 schema=
'COOLOFL_CALO/OFLP200'
116 tag=
'OFLCOND-MC23-SDR-RUN3-02'
121 if os.path.isfile(schema):
122 schema =
'sqlite://;schema='+schema+
';dbname='+dbName
124 log.info(
"File %s was not found, assuming it's full schema string" , schema)
127 db = CaloCondTools.openDbConn(schema, server)
129 if len(folderPath)==0:
131 folderPath =
'/CALO/Noise/PileUpNoiseLumi'
133 folderPath =
'/CALO/Ofl/Noise/PileUpNoiseLumi'
135 if tag==
'UPD1' or tag==
'UPD4' or 'COND'in tag:
136 from TileCalibBlobPython
import TileCalibTools
137 folderTag = TileCalibTools.getFolderTag(schema
if 'COMP200' in schema
or 'OFLP200' in schema
else db, folderPath, tag )
138 elif folderPath.startswith(
'/CALO/Ofl/Noise/PileUpNoiseLumi'):
139 folderTag =
'CALOOflNoisePileUpNoiseLumi-'+tag
140 elif folderPath.startswith(
'/CALO/Noise/PileUpNoiseLumi'):
141 folderTag =
'CALONoisePileUpNoiseLumi-'+tag
145 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
147 folder = db.getFolder(folderPath)
153 blobReader = CaloCondTools.CaloBlobReader(db,folderPath, folderTag)
154 dbobjs = blobReader.getDBobjsWithinRange(0)
156 raise Exception(
"No DB objects retrieved when building IOV list!")
157 while dbobjs.goToNext():
158 obj = dbobjs.currentRef()
159 since = CaloCondTools.runLumiFromIov(obj.since())
160 until = CaloCondTools.runLumiFromIov(obj.until())
161 iovList.append((since, until))
163 log.warning(
"Warning: can not read IOVs from input DB file" )
169 if begin != be
or end != en:
172 for i,iovs
in enumerate(iovList):
175 if (run<begin
and run>be)
or (run==begin
and lumi==0) :
178 if run>=end
and run<en:
183 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
187 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
189 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
191 iovList=iovList[ib:ie]
192 log.info(
"%d IOVs in total", len(iovList) )
194 iovList.append(((run,lumi),(CaloCondTools.MAXRUN, CaloCondTools.MAXLBK)))
205 pref =
"(%i,%i) " % (iovs[0][0],iovs[0][1])
207 since = CaloCondTools.iovFromRunLumi(iovs[0][0],iovs[0][1])
209 for chan
in channels:
211 obj = folder.findObject( since, chan, folderTag )
213 values += [[obj.payload()[0],obj.payload()[1]]]
218 values += [obj.payload()[0]]
221 log.warning(
"Warning: can not read data from input DB" )
222 if not iov
and obj
is not None:
223 (sinceRun,sinceLum) = CaloCondTools.runLumiFromIov(obj.since())
224 (untilRun,untilLum) = CaloCondTools.runLumiFromIov(obj.until())
225 suff =
" iov since [%d,%d] until (%d,%d)" % (sinceRun,sinceLum,untilRun,untilLum)
227 print(pref1,values[0],suff)
229 print(pref1,values,suff)