9 os.environ[
'TERM'] =
'linux'
12 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
13 print (
"Dumps the TileCal constants from various schemas / folders / tags")
15 print (
"-h, --help shows this help")
16 print (
"-f, --folder= specify status folder to use f.i. /TILE/OFL02/CALIB/CIS/LIN ")
17 print (
"-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or full suffix like RUN2-HLT-UPD1-00")
18 print (
"-r, --run= specify run number, by default uses latest iov")
19 print (
"-l, --lumi= specify lumi block number, default is 0")
20 print (
"-b, --begin= specify run number of first iov in multi-iov mode, by default uses very first iov")
21 print (
"-e, --end= specify run number of last iov in multi-iov mode, by default uses latest iov")
22 print (
"-m, --module= specify module to use, default is not set")
23 print (
"-N, --chmin= specify minimal channel to use, default is 0")
24 print (
"-X, --chmax= specify maximal channel to use, default is 47")
25 print (
"-c, --chan= specify channel to use , default is all channels from chmin to chmax")
26 print (
"-g, --gain=, -a, --adc= specify adc(gain) to print or number of adcs to print with - sign, default is -2")
27 print (
"-n, --nval= specify number of values to output, default is all")
28 print (
"-C, --comment print comment for every IOV")
29 print (
"-i, --iov print IOVs only for every module")
30 print (
"-I, --IOV print IOVs only")
31 print (
"-d, --default print also default values stored in AUX01-AUX20")
32 print (
"-B, --blob print additional blob info")
33 print (
"-H, --hex print frag id instead of module name")
34 print (
"-P, --pmt print pmt number in addition to channel number")
35 print (
"-p, --prefix= print some prefix on every line ")
36 print (
"-k, --keep= field numbers or channel numbers to ignore, e.g. '0,2,3,EBch0,EBch1,EBch12,EBch13,EBspD4ch18,EBspD4ch19,EBspC10ch4,EBspC10ch5' ")
37 print (
"-s, --schema= specify schema to use, like 'COOLONL_TILE/CONDBR2' or 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2' or tileSqlite.db")
38 print (
"-D, --dbname= specify dbname part of schema if schema only contains file name, default is CONDBR2")
39 print (
"-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
41 letters =
"hr:l:s:t:f:D:S:n:b:e:m:N:X:c:a:g:p:dBCiIHPk:"
42 keywords = [
"help",
"run=",
"lumi=",
"schema=",
"tag=",
"folder=",
"dbname=",
"server=",
"module=",
"begin=",
"end=",
"chmin=",
"chmax=",
"gain=",
"adc=",
"chan=",
"nval=",
"prefix=",
"default",
"blob",
"hex",
"pmt",
"keep=",
"comment",
"iov",
"IOV"]
45 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
46 except getopt.GetoptError
as err:
54 schema =
'COOLOFL_TILE/CONDBR2'
57 folderPath =
"/TILE/OFL02/CALIB/CIS/LIN"
89 if o
in (
"-f",
"--folder"):
91 elif o
in (
"-t",
"--tag"):
93 elif o
in (
"-s",
"--schema"):
95 elif o
in (
"-D",
"--dbname"):
97 elif o
in (
"-S",
"--server"):
99 elif o
in (
"-n",
"--nval"):
101 elif o
in (
"-b",
"--begin"):
105 elif o
in (
"-e",
"--end"):
109 elif o
in (
"-i",
"--iov"):
112 if modulename==
'AUX-1':
114 elif o
in (
"-I",
"--IOV"):
117 if modulename==
'AUX-1':
119 elif o
in (
"-a",
"--adc",
"-g",
"--gain"):
121 elif o
in (
"-m",
"--module"):
124 elif o
in (
"-c",
"--chan"):
126 elif o
in (
"-N",
"--chmin"):
128 elif o
in (
"-X",
"--chmax"):
130 elif o
in (
"-C",
"--comment"):
132 elif o
in (
"-r",
"--run"):
134 elif o
in (
"-l",
"--lumi"):
136 elif o
in (
"-d",
"--default"):
138 elif o
in (
"-B",
"--blob"):
140 elif o
in (
"-H",
"--hex"):
142 elif o
in (
"-P",
"--pmt"):
144 elif o
in (
"-p",
"--prefix"):
146 elif o
in (
"-k",
"--keep"):
148 elif o
in (
"-h",
"--help"):
152 raise RuntimeError(
"unhandled option")
155 from TileCalibBlobPython
import TileCalibTools
156 from TileCalibBlobPython.TileCalibTools
import MAXRUN, MAXLBK
157 from TileCalibBlobObjs.Classes
import TileCalibUtils, TileCalibType
160 from TileCalibBlobPython.TileCalibLogger
import getLogger
163 logLevel=logging.DEBUG
164 log.setLevel(logLevel)
166 log1.setLevel(logLevel)
170 if len(dbname)<7
and run!=2147483647:
171 dbname =
'COMP200' if run<232000
else 'CONDBR2'
173 if 'COOLO' not in schema
and ':' not in schema
and ';' not in schema:
174 schema=
'sqlite://;schema='+schema+
';dbname='+(dbname
if len(dbname)
else 'CONDBR2')
176 if schema==
'COOLONL_TILE/COMP200':
177 if not (folderPath.startswith(
'/TILE/ONL01/')
or folderPath.startswith(
'/TILE/OFL01/')):
178 print (
"Folder %s doesn't exist in schema %s " % (folderPath,schema))
181 if schema==
'COOLONL_TILE/CONDBR2':
182 if not folderPath.startswith(
'/TILE/ONL01/'):
183 print (
"Folder %s doesn't exist in schema %s, only /TILE/ONL01 " % (folderPath,schema))
186 if schema==
'COOLOFL_TILE/COMP200' or schema==
'COOLOFL_TILE/CONDBR2':
187 if not folderPath.startswith(
'/TILE/OFL02/'):
188 print (
"Folder %s doesn't exist in schema %s " % (folderPath,schema))
196 db = TileCalibTools.openDbConn(schema,server)
197 folderTag = TileCalibTools.getFolderTag(schema
if 'COMP200' in schema
or 'OFLP200' in schema
else db, folderPath, tag)
198 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
201 blobReader = TileCalibTools.TileBlobReader(db,folderPath, folderTag)
205 log.info(
"Initializing for run %d, lumiblock %d", run,lumi)
218 flt = blobReader.getDrawer(r, d, (run,lumi),
False,
False)
220 blobT=flt.getObjType()
221 blobV=flt.getObjVersion()
222 mchan=flt.getNChans()
223 mgain=flt.getNGains()
224 mval=flt.getObjSizeUint32()
225 log.info(
"Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d", blobT,blobV,mchan,mgain,mval)
237 log.info(
"Comment: %s", blobReader.getComment((run,lumi)))
241 partname = modulename[:3]
242 mod =
int(modulename[3:]) -1
244 part_dict = {
'AUX':0,
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4}
245 if partname
in part_dict:
246 ros = part_dict[partname]
258 if chan_n >= 0
and chan_n < nchan:
269 if nadc >= 0
and nadc < ngain:
281 if iovonly
or IOVONLY:
300 modName =
"0x%x" % ((ros<<8)+mod)
304 dbobjs = blobReader.getDBobjsWithinRange(ros,mod)
305 while dbobjs.goToNext():
306 obj = dbobjs.currentRef()
307 objsince = obj.since()
308 sinceRun = objsince >> 32
309 sinceLum = objsince & 0xFFFFFFFF
310 since =
"(%d,%d)" % (sinceRun, sinceLum)
318 if since
in allsince:
319 allsince[since] += [modName]
321 allsince[since] = [modName]
325 print(
"%s %s" % (modName,
" ".
join(iovs)) )
329 for since
in allsince:
330 if comment
and allsince[since][-1]!=
"Comment":
331 allsince[since] += [
"NO_COMMENT"]
332 all+=[
"%s %s" % (since,
" ".
join(allsince[since]))]
338 print(
"No new IOVs after run",lastRun)
355 dbobjs = blobReader.getDBobjsWithinRange(COOL_part,COOL_chan)
357 raise Exception(
"No DB objects retrieved when building IOV list!")
358 while dbobjs.goToNext():
359 obj = dbobjs.currentRef()
360 objsince = obj.since()
361 sinceRun = objsince >> 32
362 sinceLum = objsince & 0xFFFFFFFF
363 since = (sinceRun, sinceLum)
364 objuntil = obj.until()
365 untilRun = objuntil >> 32
366 untilLum = objuntil & 0xFFFFFFFF
367 until = (untilRun, untilLum)
368 iovList.append((since, until))
370 log.warning(
"Warning: can not read IOVs from input DB file" )
376 if begin != be
or end != en:
379 for i,iovs
in enumerate(iovList):
382 if (run<begin
and run>be)
or (run==begin
and lumi==0) :
385 if run>=end
and run<en:
390 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
394 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
396 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
398 iovList=iovList[ib:ie]
399 if COOL_chan == 1000:
400 log.info(
"%d IOVs in total for comment field", len(iovList) )
402 log.info(
"%d IOVs in total for %s", len(iovList),modulename)
404 iovList.append(((run,lumi),(MAXRUN, MAXLBK)))
413 barrel = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
414 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
415 27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
416 39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46]
417 extbar = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
418 13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
419 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
420 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46]
422 ch2pmt = [ dummy, barrel, barrel, extbar, extbar ]
425 for i
in range(mgain+1):
426 gname+=[
"g "+
str(i) ]
428 gname = [
"LG",
"HG" ]
434 pref =
"(%i,%i) " % (iovs[0][0],iovs[0][1])
436 pref = prefix +
" " + pref
438 log.info( pref + blobReader.getComment(iovs[0]) )
439 if prefix
and prefix.startswith(
"Write"):
440 comm = blobReader.getComment(iovs[0])
442 comm = comm[comm.find(
": ")+2:]
443 print (
'%s --update --folder=%s --tag=%s --run=%i --lumi=%i --comment="%s"' % (prefix,folderPath,folderTag,iovs[0][0],iovs[0][1],comm))
446 for ros
in range(rosmin,rosmax):
449 modName =
"0x%x" % ((ros<<8)+mod)
452 if modName
in [
'EBA39',
'EBA40',
'EBA41',
'EBA42',
'EBA55',
'EBA56',
'EBA57',
'EBA58',
453 'EBC39',
'EBC40',
'EBC41',
'EBC42',
'EBC55',
'EBC56',
'EBC57',
'EBC58' ]:
455 elif modName
in [
'EBA15',
'EBC18']:
457 elif modName
in [
'EBC29',
'EBC32',
'EBC34',
'EBC37']:
459 elif modName
in [
'EBA07',
'EBA25',
'EBA44',
'EBA53',
460 'EBC07',
'EBC25',
'EBC44',
'EBC53',
461 'EBC28',
'EBC31',
'EBC35',
'EBC38' ]:
463 elif modName
in [
'EBA08',
'EBA24',
'EBA43',
'EBA54',
464 'EBC08',
'EBC24',
'EBC43',
'EBC54' ]:
469 flt = blobReader.getDrawer(ros, mod,iovs[0],
False,
False)
470 if flt
is None or isinstance(flt, (int)):
472 print (
"%s is missing in DB" % modName)
476 print (
"%s Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d" % (modName, flt.getObjType(), flt.getObjVersion(), flt.getNChans(), flt.getNGains(), flt.getObjSizeUint32()))
479 mval = flt.getObjSizeUint32()
480 if nval<0
and -nval<=mval:
483 elif nval!=0
and nval<mval:
485 mchan=flt.getNChans()
486 mgain=flt.getNGains()
487 chmin = chanmin
if chanmin<mchan
else mchan
488 chmax = chanmax
if chanmax<mchan
else mchan
489 gnmin = gainmin
if gainmin<mgain
else mgain
490 gnmax = gainmax
if gainmax<mgain
else mgain
491 for chn
in range(chmin,chmax):
492 for adc
in range(gnmin,gnmax):
494 msg =
"%s pm %02i ch %02i %s " % ( modName, abs(ch2pmt[ros][chn]), chn, gname[adc] )
496 msg =
"%s %2i %1i " % ( modName, chn, adc )
497 for val
in range(mval0,mval):
498 if str(val)
in keep
or modName
in keep
or modSpec
in keep
or modName[:3]
in keep
or modName[:2]
in keep \
499 or (
"%sch%i"% (modName,chn))
in keep
or (
"%sch%i"% (modSpec,chn))
in keep
or (
"%sch%i"% (modName[:3],chn))
in keep
or (
"%sch%i"% (modName[:2],chn))
in keep \
500 or (
"%sch%ig%i"% (modName,chn,adc))
in keep
or (
"%sch%ig%i"% (modSpec,chn,adc))
in keep
or (
"%sch%ig%i"% (modName[:3],chn,adc))
in keep
or (
"%sch%ig%i"% (modName[:2],chn,adc))
in keep:
504 v = flt.getData(chn, adc, val)
509 elif typeName==
'Bch':
510 msg +=
" %d" % flt.getData(chn, adc, val)
512 msg +=
" %f" % flt.getData(chn, adc, val)
514 except Exception
as e:
517 if iovs[0][0]!=2147483647:
518 print (
"%3i drawers are preseint in DB for run %d lb %d" % (good,iovs[0][0],iovs[0][1]))
519 print (
"%3i drawers are missing in DB for run %d lb %d" % (miss,iovs[0][0],iovs[0][1]))
521 print (
"%3i drawers are preseint in DB" % (good))
522 print (
"%3i drawers are missing in DB" % (miss))
524 print (
"Please, check that you are using correct schema and correct tag")