9os.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 (
"-o, --double print values with double precision")
38 print (
"-s, --schema= specify schema to use, like 'COOLONL_TILE/CONDBR2' or 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2' or tileSqlite.db")
39 print (
"-D, --dbname= specify dbname part of schema if schema only contains file name, default is CONDBR2")
40 print (
"-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
42letters =
"hr:l:s:t:f:D:S:n:b:e:m:N:X:c:a:g:p:dBCiIHPk:o"
43keywords = [
"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",
"double"]
46 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
47except getopt.GetoptError
as err:
55schema =
'COOLOFL_TILE/CONDBR2'
58folderPath =
"/TILE/OFL02/CALIB/CIS/LIN"
91 if o
in (
"-f",
"--folder"):
93 elif o
in (
"-t",
"--tag"):
95 elif o
in (
"-s",
"--schema"):
97 elif o
in (
"-D",
"--dbname"):
99 elif o
in (
"-S",
"--server"):
101 elif o
in (
"-n",
"--nval"):
103 elif o
in (
"-b",
"--begin"):
107 elif o
in (
"-e",
"--end"):
111 elif o
in (
"-i",
"--iov"):
114 if modulename==
'AUX-1':
116 elif o
in (
"-I",
"--IOV"):
119 if modulename==
'AUX-1':
121 elif o
in (
"-a",
"--adc",
"-g",
"--gain"):
123 elif o
in (
"-m",
"--module"):
126 elif o
in (
"-c",
"--chan"):
128 elif o
in (
"-N",
"--chmin"):
130 elif o
in (
"-X",
"--chmax"):
132 elif o
in (
"-C",
"--comment"):
134 elif o
in (
"-r",
"--run"):
136 elif o
in (
"-l",
"--lumi"):
138 elif o
in (
"-d",
"--default"):
140 elif o
in (
"-B",
"--blob"):
142 elif o
in (
"-H",
"--hex"):
144 elif o
in (
"-P",
"--pmt"):
146 elif o
in (
"-p",
"--prefix"):
148 elif o
in (
"-k",
"--keep"):
150 elif o
in (
"-o",
"--double"):
152 elif o
in (
"-h",
"--help"):
156 raise RuntimeError(
"unhandled option")
159from TileCalibBlobPython
import TileCalibTools
160from TileCalibBlobPython.TileCalibTools
import MAXRUN, MAXLBK
161from TileCalibBlobObjs.Classes
import TileCalibUtils, TileCalibType
164from TileCalibBlobPython.TileCalibLogger
import getLogger
165log = getLogger(
"ReadCalibFrCool")
167logLevel=logging.DEBUG
168log.setLevel(logLevel)
169log1 = getLogger(
"TileCalibTools")
170log1.setLevel(logLevel)
174if len(dbname)<7
and run!=2147483647:
175 dbname =
'COMP200' if run<232000
else 'CONDBR2'
177if 'COOLO' not in schema
and ':' not in schema
and ';' not in schema:
178 schema=
'sqlite://;schema='+schema+
';dbname='+(dbname
if len(dbname)
else 'CONDBR2')
180if schema==
'COOLONL_TILE/COMP200':
181 if not (folderPath.startswith(
'/TILE/ONL01/')
or folderPath.startswith(
'/TILE/OFL01/')):
182 print (
"Folder %s doesn't exist in schema %s " % (folderPath,schema))
185if schema==
'COOLONL_TILE/CONDBR2':
186 if not folderPath.startswith(
'/TILE/ONL01/'):
187 print (
"Folder %s doesn't exist in schema %s, only /TILE/ONL01 " % (folderPath,schema))
190if schema==
'COOLOFL_TILE/COMP200' or schema==
'COOLOFL_TILE/CONDBR2':
191 if not folderPath.startswith(
'/TILE/OFL02/'):
192 print (
"Folder %s doesn't exist in schema %s " % (folderPath,schema))
200db = TileCalibTools.openDbConn(schema,server)
201folderTag = TileCalibTools.getFolderTag(schema
if 'COMP200' in schema
or 'OFLP200' in schema
else db, folderPath, tag)
202log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
205blobReader = TileCalibTools.TileBlobReader(db,folderPath, folderTag)
209log.info(
"Initializing for run %d, lumiblock %d", run,lumi)
222 flt = blobReader.getDrawer(r, d, (run,lumi),
False,
False)
224 blobT=flt.getObjType()
225 blobV=flt.getObjVersion()
226 mchan=flt.getNChans()
227 mgain=flt.getNGains()
228 mval=flt.getObjSizeUint32()
229 log.info(
"Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d", blobT,blobV,mchan,mgain,mval)
241log.info(
"Comment: %s", blobReader.getComment((run,lumi)))
245 partname = modulename[:3]
246 mod = int(modulename[3:]) -1
248part_dict = {
'AUX':0,
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4}
249if partname
in part_dict:
250 ros = part_dict[partname]
262if chan_n >= 0
and chan_n < nchan:
273if nadc >= 0
and nadc < ngain:
285if iovonly
or IOVONLY:
292 roslist = list(range(rosmin,rosmax))
304 modName =
"0x%x" % ((ros<<8)+mod)
308 dbobjs = blobReader.getDBobjsWithinRange(ros,mod)
309 while dbobjs.goToNext():
310 obj = dbobjs.currentRef()
311 objsince = obj.since()
312 sinceRun = objsince >> 32
313 sinceLum = objsince & 0xFFFFFFFF
314 since =
"(%d,%d)" % (sinceRun, sinceLum)
319 elif sinceRun>=begin:
324 if since
in allsince:
325 allsince[since] += [modName]
327 allsince[since] = [modName]
331 print(
"%s %s" % (modName,
" ".join(iovs)) )
335 for since
in allsince:
336 all += [
"%s %s" % (since,TileCalibTools.moduleListToString(allsince[since],(rosmin==0),
True,comment))]
342 print(
"No new IOVs after run",lastRun)
359 dbobjs = blobReader.getDBobjsWithinRange(COOL_part,COOL_chan)
361 raise Exception(
"No DB objects retrieved when building IOV list!")
362 while dbobjs.goToNext():
363 obj = dbobjs.currentRef()
364 objsince = obj.since()
365 sinceRun = objsince >> 32
366 sinceLum = objsince & 0xFFFFFFFF
367 since = (sinceRun, sinceLum)
368 objuntil = obj.until()
369 untilRun = objuntil >> 32
370 untilLum = objuntil & 0xFFFFFFFF
371 until = (untilRun, untilLum)
372 iovList.append((since, until))
374 log.warning(
"Warning: can not read IOVs from input DB file" )
380 if begin != be
or end != en:
383 for i,iovs
in enumerate(iovList):
386 if (run<begin
and run>be)
or (run==begin
and lumi==0) :
389 if run>=end
and run<en:
394 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
398 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
400 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
402 iovList=iovList[ib:ie]
403 if COOL_chan == 1000:
404 log.info(
"%d IOVs in total for comment field", len(iovList) )
406 log.info(
"%d IOVs in total for %s", len(iovList),modulename)
408 iovList.append(((run,lumi),(MAXRUN, MAXLBK)))
417barrel = [ 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, 30, 29, 28,-33,-32, 31, 36, 35, 34,
420 39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46]
421extbar = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
422 13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
423 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
424 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46]
426ch2pmt = [ dummy, barrel, barrel, extbar, extbar ]
429 for i
in range(mgain+1):
430 gname+=[
"g "+str(i) ]
432 gname = [
"LG",
"HG" ]
438 pref =
"(%i,%i) " % (iovs[0][0],iovs[0][1])
440 pref = prefix +
" " + pref
442 log.info( pref + blobReader.getComment(iovs[0]) )
443 if prefix
and prefix.startswith(
"Write"):
444 comm = blobReader.getComment(iovs[0])
446 comm = comm[comm.find(
": ")+2:]
447 print (
'%s --update --folder=%s --tag=%s --run=%i --lumi=%i --comment="%s"' % (prefix,folderPath,folderTag,iovs[0][0],iovs[0][1],comm))
450 for ros
in range(rosmin,rosmax):
453 modName =
"0x%x" % ((ros<<8)+mod)
456 if modName
in [
'EBA39',
'EBA40',
'EBA41',
'EBA42',
'EBA55',
'EBA56',
'EBA57',
'EBA58',
457 'EBC39',
'EBC40',
'EBC41',
'EBC42',
'EBC55',
'EBC56',
'EBC57',
'EBC58' ]:
459 elif modName
in [
'EBA15',
'EBC18']:
461 elif modName
in [
'EBC29',
'EBC32',
'EBC34',
'EBC37']:
463 elif modName
in [
'EBA07',
'EBA25',
'EBA44',
'EBA53',
464 'EBC07',
'EBC25',
'EBC44',
'EBC53',
465 'EBC28',
'EBC31',
'EBC35',
'EBC38' ]:
467 elif modName
in [
'EBA08',
'EBA24',
'EBA43',
'EBA54',
468 'EBC08',
'EBC24',
'EBC43',
'EBC54' ]:
473 flt = blobReader.getDrawer(ros, mod,iovs[0],
False,
False)
474 if flt
is None or isinstance(flt, (int)):
476 print (
"%s is missing in DB" % modName)
480 print (
"%s Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d" % (modName, flt.getObjType(), flt.getObjVersion(), flt.getNChans(), flt.getNGains(), flt.getObjSizeUint32()))
483 mval = flt.getObjSizeUint32()
484 if nval<0
and -nval<=mval:
487 elif nval!=0
and nval<mval:
489 mchan=flt.getNChans()
490 mgain=flt.getNGains()
491 chmin = chanmin
if chanmin<mchan
else mchan
492 chmax = chanmax
if chanmax<mchan
else mchan
493 gnmin = gainmin
if gainmin<mgain
else mgain
494 gnmax = gainmax
if gainmax<mgain
else mgain
495 for chn
in range(chmin,chmax):
496 for adc
in range(gnmin,gnmax):
498 msg =
"%s pm %02i ch %02i %s " % ( modName, abs(ch2pmt[ros][chn]), chn, gname[adc] )
500 msg =
"%s %2i %1i " % ( modName, chn, adc )
501 for val
in range(mval0,mval):
502 if str(val)
in keep
or modName
in keep
or modSpec
in keep
or modName[:3]
in keep
or modName[:2]
in keep \
503 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 \
504 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:
508 v = flt.getData(chn, adc, val)
513 elif typeName==
'Bch':
514 msg +=
" %d" % flt.getData(chn, adc, val)
516 msg +=
" %s" % flt.getData(chn, adc, val)
518 msg +=
" %f" % flt.getData(chn, adc, val)
520 except Exception
as e:
523 if iovs[0][0]!=2147483647:
524 print (
"%3i drawers are present in DB for run %d lb %d" % (good,iovs[0][0],iovs[0][1]))
525 print (
"%3i drawers are missing in DB for run %d lb %d" % (miss,iovs[0][0],iovs[0][1]))
527 print (
"%3i drawers are present in DB" % (good))
528 print (
"%3i drawers are missing in DB" % (miss))
530 print (
"Please, check that you are using correct schema and correct tag")
void print(char *figname, TCanvas *c1)
static std::string getClassName(TileCalibType::TYPE type)
Returns the class name.
static unsigned int max_gain()
Python compatibility function.
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static unsigned int max_chan()
Python compatibility function.
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.