12 os.environ[
'TERM'] =
'linux'
15 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
16 print (
"Dumps the TileCal constants from various schemas / folders / tags")
18 print (
"-h, --help shows this help")
19 print (
"-f, --folder= specify status folder to use f.i. /TILE/OFL02/CALIB/CIS/LIN ")
20 print (
"-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or full suffix like RUN2-HLT-UPD1-00")
21 print (
"-r, --run= specify run number, by default uses latest iov")
22 print (
"-l, --lumi= specify lumi block number, default is 0")
23 print (
"-b, --begin= specify run number of first iov in multi-iov mode, by default uses very first iov")
24 print (
"-e, --end= specify run number of last iov in multi-iov mode, by default uses latest iov")
25 print (
"-m, --module= specify module to use, default is not set")
26 print (
"-N, --chmin= specify minimal channel to use, default is 0")
27 print (
"-X, --chmax= specify maximal channel to use, default is 47")
28 print (
"-c, --chan= specify channel to use , default is all channels from chmin to chmax")
29 print (
"-g, --gain=, -a, --adc= specify adc(gain) to print or number of adcs to print with - sign, default is -2")
30 print (
"-n, --nval= specify number of values to output, default is all")
31 print (
"-C, --comment print comment for every IOV")
32 print (
"-i, --iov print IOVs only for every module")
33 print (
"-I, --IOV print IOVs only")
34 print (
"-d, --default print also default values stored in AUX01-AUX20")
35 print (
"-B, --blob print additional blob info")
36 print (
"-H, --hex print frag id instead of module name")
37 print (
"-P, --pmt print pmt number in addition to channel number")
38 print (
"-p, --prefix= print some prefix on every line ")
39 print (
"-k, --keep= field numbers or channel numbers to ignore, e.g. '0,2,3,EBch0,EBch1,EBch12,EBch13,EBspD4ch18,EBspD4ch19,EBspC10ch4,EBspC10ch5' ")
40 print (
"-s, --schema= specify name of input JSON file or CREST_SERVER_PATH")
44 letters =
"hr:l:s:t:f:D:S:n:b:e:m:N:X:c:a:g:p:dBCiIHPk:"
45 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"]
48 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
49 except getopt.GetoptError
as err:
61 folderPath =
"/TILE/OFL02/CALIB/CIS/LIN"
93 if o
in (
"-f",
"--folder"):
95 elif o
in (
"-t",
"--tag"):
97 elif o
in (
"-s",
"--schema"):
99 elif o
in (
"-D",
"--dbname"):
101 elif o
in (
"-S",
"--server"):
103 elif o
in (
"-n",
"--nval"):
105 elif o
in (
"-b",
"--begin"):
109 elif o
in (
"-e",
"--end"):
113 elif o
in (
"-i",
"--iov"):
116 if modulename==
'AUX-1':
118 elif o
in (
"-I",
"--IOV"):
121 if modulename==
'AUX-1':
123 elif o
in (
"-a",
"--adc",
"-g",
"--gain"):
125 elif o
in (
"-m",
"--module"):
128 elif o
in (
"-c",
"--chan"):
130 elif o
in (
"-N",
"--chmin"):
132 elif o
in (
"-X",
"--chmax"):
134 elif o
in (
"-C",
"--comment"):
136 elif o
in (
"-r",
"--run"):
138 elif o
in (
"-l",
"--lumi"):
140 elif o
in (
"-d",
"--default"):
142 elif o
in (
"-B",
"--blob"):
144 elif o
in (
"-H",
"--hex"):
146 elif o
in (
"-P",
"--pmt"):
148 elif o
in (
"-p",
"--prefix"):
150 elif o
in (
"-k",
"--keep"):
152 elif o
in (
"-h",
"--help"):
156 raise RuntimeError(
"unhandled option")
159 from TileCalibBlobPython
import TileCalibCrest
160 from TileCalibBlobPython
import TileCalibTools
161 from TileCalibBlobPython.TileCalibTools
import MAXRUN, MAXLBK
162 from TileCalibBlobObjs.Classes
import TileCalibUtils, TileCalibType
165 from TileCalibBlobPython.TileCalibLogger
import getLogger
168 logLevel=logging.DEBUG
169 log.setLevel(logLevel)
171 log1.setLevel(logLevel)
175 partname = modulename[:3]
176 mod =
int(modulename[3:]) -1
178 part_dict = {
'AUX':0,
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4}
179 if partname
in part_dict:
180 ros = part_dict[partname]
197 if folderTag.startswith(
"Tile")
or folderTag.startswith(
"CALO") :
199 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
201 blobReader = TileCalibCrest.TileBlobReaderCrest(schema,folderPath, folderTag, run, lumi,
218 flt = blobReader.getDrawer(r, d, (run,lumi),
True,
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)))
239 if chan_n >= 0
and chan_n < nchan:
250 if nadc >= 0
and nadc < ngain:
265 if iovonly
or IOVONLY:
269 iovList = blobReader.getIovs((begin,0),(end,0))
274 if begin != be
or end != en:
277 for i,iovs
in enumerate(iovList):
280 if (run<begin
and run>be)
or (run==begin
and lumi==0) :
283 if run>=end
and run<en:
288 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
292 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
294 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
296 iovList=iovList[ib:ie]
297 log.info(
"%d IOVs in total", len(iovList))
300 if iovonly
or IOVONLY:
304 for ros
in range(rosmin,rosmax):
308 for since
in iovList:
309 iov=
"(%s,%s)" % since
312 for ros
in range(rosmin,rosmax):
314 flt = blobReader.getDrawer(ros, mod, since,
False,
False)
318 allmods[mod] +=
" " + iov
321 if miss==0
and nmod>1:
322 alliovs[iov] =
" All %d modules" % nmod
324 alliovs[iov] = allmod
328 for key,value
in allmods.items():
331 print(
"%s\t%s" % (key,value))
333 for key,value
in alliovs.items():
336 print(
"%s\t%s" % (key,value))
338 print(
"No IOVs found")
341 iovList.append((run,lumi))
350 barrel = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
351 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
352 27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
353 39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46]
354 extbar = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
355 13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
356 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
357 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46]
359 ch2pmt = [ dummy, barrel, barrel, extbar, extbar ]
362 for i
in range(mgain+1):
363 gname+=[
"g "+
str(i) ]
365 gname = [
"LG",
"HG" ]
371 pref =
"(%i,%i) " % (iovs[0],iovs[1])
373 pref = prefix +
" " + pref
375 log.info( pref +
str(blobReader.getComment(iovs)) )
376 if prefix
and prefix.startswith(
"Write"):
377 comm = blobReader.getComment(iovs)
379 comm = comm[comm.find(
": ")+2:]
380 print (
'%s --update --folder=%s --tag=%s --run=%i --lumi=%i --comment="%s"' % (prefix,folderPath,folderTag,iovs[0],iovs[1],comm))
383 for ros
in range(rosmin,rosmax):
386 modName =
"0x%x" % ((ros<<8)+mod)
389 if modName
in [
'EBA39',
'EBA40',
'EBA41',
'EBA42',
'EBA55',
'EBA56',
'EBA57',
'EBA58',
390 'EBC39',
'EBC40',
'EBC41',
'EBC42',
'EBC55',
'EBC56',
'EBC57',
'EBC58' ]:
392 elif modName
in [
'EBA15',
'EBC18']:
394 elif modName
in [
'EBC29',
'EBC32',
'EBC34',
'EBC37']:
396 elif modName
in [
'EBA07',
'EBA25',
'EBA44',
'EBA53',
397 'EBC07',
'EBC25',
'EBC44',
'EBC53',
398 'EBC28',
'EBC31',
'EBC35',
'EBC38' ]:
400 elif modName
in [
'EBA08',
'EBA24',
'EBA43',
'EBA54',
401 'EBC08',
'EBC24',
'EBC43',
'EBC54' ]:
406 flt = blobReader.getDrawer(ros, mod,iovs,
False,
False)
407 if flt
is None or isinstance(flt, (int)):
409 print (
"%s is missing in DB" % modName)
413 print (
"%s Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d" % (modName, flt.getObjType(), flt.getObjVersion(), flt.getNChans(), flt.getNGains(), flt.getObjSizeUint32()))
416 mval = flt.getObjSizeUint32()
417 if nval<0
and -nval<=mval:
420 elif nval!=0
and nval<mval:
422 mchan=flt.getNChans()
423 mgain=flt.getNGains()
424 chmin = chanmin
if chanmin<mchan
else mchan
425 chmax = chanmax
if chanmax<mchan
else mchan
426 gnmin = gainmin
if gainmin<mgain
else mgain
427 gnmax = gainmax
if gainmax<mgain
else mgain
428 for chn
in range(chmin,chmax):
429 for adc
in range(gnmin,gnmax):
431 msg =
"%s pm %02i ch %02i %s " % ( modName, abs(ch2pmt[ros][chn]), chn, gname[adc] )
433 msg =
"%s %2i %1i " % ( modName, chn, adc )
434 for val
in range(mval0,mval):
435 if str(val)
in keep
or modName
in keep
or modSpec
in keep
or modName[:3]
in keep
or modName[:2]
in keep \
436 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 \
437 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:
441 v = flt.getData(chn, adc, val)
446 elif typeName==
'Bch':
447 msg +=
" %d" % flt.getData(chn, adc, val)
449 msg +=
" %f" % flt.getData(chn, adc, val)
451 except Exception
as e:
454 if iovs[0]!=2147483647:
455 print (
"%3i drawers are present in DB for run %d lb %d" % (good,iovs[0],iovs[1]))
456 print (
"%3i drawers are missing in DB for run %d lb %d" % (miss,iovs[0],iovs[1]))
458 print (
"%3i drawers are present in DB" % (good))
459 print (
"%3i drawers are missing in DB" % (miss))
461 print (
"Please, check that you are using correct schema and correct tag")