12 os.environ[
'TERM'] =
'linux'
15 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
16 print (
"Dumps the TileCal status bits from various schemas / folders")
18 print (
"-h, --help shows this help")
19 print (
"-f, --folder= specify status folder to use ONL01 or OFL02, don't need to specify full path")
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 use, default is 2 (i.e. both low and high gains)")
30 print (
"-C, --comment print comment for every IOV")
31 print (
"-i, --iov print IOVs only for every module")
32 print (
"-I, --IOV print IOVs only")
33 print (
"-d, --default print also default values stored in AUX01-AUX20")
34 print (
"-B, --blob print additional blob info")
35 print (
"-H, --hex print frag id instead of module name")
36 print (
"-P, --pmt print pmt number in addition to channel number")
37 print (
"-s, --schema= specify name of input JSON file or CREST_SERVER_PATH")
40 print (
"-w, --warning suppress warning messages about missing drawers in DB")
42 letters =
"hr:l:s:t:f:D:S:dBHPwm:b:e:a:g:c:N:X:CiI"
43 keywords = [
"help",
"run=",
"lumi=",
"schema=",
"tag=",
"folder=",
"dbname=",
"server=",
"default",
"blob",
"hex",
"pmt",
"warning",
"module=",
"begin=",
"end=",
"chmin=",
"chmax=",
"gain=",
"adc=",
"chan=",
"comment",
"iov",
"IOV"]
46 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
47 except getopt.GetoptError
as err:
59 folderPath =
"/TILE/OFL02/STATUS/ADC"
89 if o
in (
"-f",
"--folder"):
93 folderPath =
"/TILE/%s/STATUS/ADC" % a
94 elif o
in (
"-t",
"--tag"):
96 elif o
in (
"-s",
"--schema"):
98 elif o
in (
"-D",
"--dbname"):
100 elif o
in (
"-S",
"--server"):
102 elif o
in (
"-r",
"--run"):
104 elif o
in (
"-l",
"--lumi"):
106 elif o
in (
"-b",
"--begin"):
110 elif o
in (
"-e",
"--end"):
114 elif o
in (
"-i",
"--iov"):
117 if modulename==
'AUX-1':
119 elif o
in (
"-I",
"--IOV"):
122 if modulename==
'AUX-1':
124 elif o
in (
"-a",
"--adc",
"-g",
"--gain"):
126 elif o
in (
"-m",
"--module"):
129 elif o
in (
"-c",
"--chan"):
131 elif o
in (
"-N",
"--chmin"):
133 elif o
in (
"-X",
"--chmax"):
135 elif o
in (
"-C",
"--comment"):
137 elif o
in (
"-d",
"--default"):
139 elif o
in (
"-B",
"--blob"):
141 elif o
in (
"-H",
"--hex"):
143 elif o
in (
"-P",
"--pmt"):
145 elif o
in (
"-w",
"--warning"):
147 elif o
in (
"-h",
"--help"):
151 raise RuntimeError(
"unhandled option")
154 from TileCalibBlobPython
import TileBchCrest
155 from TileCalibBlobObjs.Classes
import TileCalibUtils
157 from TileCalibBlobPython.TileCalibLogger
import getLogger
160 logLevel=logging.DEBUG
161 log.setLevel(logLevel)
163 log1.setLevel(logLevel)
165 log2.setLevel(logLevel)
167 if tag.upper().endswith(
'HEAD'):
169 if len(tag)==0
or tag.endswith(
'HEAD'):
170 folderPath=
'/TILE/ONL01/STATUS/ADC'
171 log.info(
"tag is %s, using %s folder", tag
if tag
else 'empty', folderPath)
176 if folderTag.upper().startswith(
"TILE")
or folderTag.upper().startswith(
"CALO") :
178 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
181 mgr = TileBchCrest.TileBchMgr()
182 mgr.setLogLvl(logLevel)
183 mgr.initialize(schema, folderPath, folderTag, (run,lumi), warn, -2)
184 if iov
or comment
or warn<0:
185 blobReader = mgr.getBlobReader()
189 if len(
list(isBadDef.keys())):
190 log.info(
"isBad Definition: " )
191 for prbCode
in sorted(isBadDef.keys()):
192 prbDesc = isBadDef[prbCode]
193 msg =
"- %2i (%s)" % (prbCode,prbDesc)
197 if len(
list(isBadTimingDef.keys())):
198 log.info(
"isBadTiming Definition: " )
199 for prbCode
in sorted(isBadTimingDef.keys()):
200 prbDesc = isBadTimingDef[prbCode]
201 msg =
"- %2i (%s)" % (prbCode,prbDesc)
207 partname = modulename[:3]
208 mod =
int(modulename[3:]) -1
210 part_dict = {
'AUX':0,
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4}
211 if partname
in part_dict:
212 ros = part_dict[partname]
247 if iovonly
or IOVONLY:
251 iovList = blobReader.getIovs((begin,0),(end,0))
256 if begin != be
or end != en:
259 for i,iovs
in enumerate(iovList):
262 if (run<begin
and run>be)
or (run==begin
and lumi==0) :
265 if run>=end
and run<en:
270 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
274 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
276 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
278 iovList=iovList[ib:ie]
279 log.info(
"%d IOVs in total", len(iovList))
282 if iovonly
or IOVONLY:
287 for ros
in range(rosmin,rosmax):
291 for since
in iovList:
292 iov=
"(%s,%s)" % since
296 for ros
in range(rosmin,rosmax):
298 flt = blobReader.getDrawer(ros, mod, since,
False,
False)
303 allmod +=
" " + mod +
"_zero"
304 allmods[mod] +=
" " + iov +
"_zero"
307 allmods[mod] +=
" " + iov
310 if miss==0
and nmod>1:
311 alliovs[iov] =
" All %d modules" % nmod
313 alliovs[iov] = allmod
314 zeroiovs[iov] = zeromod
318 for key,value
in allmods.items():
321 print(
"%s\t%s" % (key,value))
323 for key,value
in alliovs.items():
326 if zeroiovs[key]
and zeroiovs[key]>0:
327 print(
"%s\t%s - zero-sized blobs for %d modules" % (key,value,zeroiovs[key]))
329 print(
"%s\t%s" % (key,value))
331 print(
"No IOVs found")
334 iovList.append((run,lumi))
343 barrel = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
344 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
345 27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
346 39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46]
347 extbar = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
348 13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
349 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
350 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46]
352 ch2pmt = [ dummy, barrel, barrel, extbar, extbar ]
353 gname = [
"LG",
"HG" ]
366 pref =
"(%i,%i) " % (iovs[0],iovs[1])
367 mgr.updateFromDb(schema, folderPath, folderTag, iovs, 1, warn)
369 log.info( pref +
str(blobReader.getComment(iovs)) )
376 for ros
in range(rosmin,rosmax):
380 modName =
"0x%x" % ((ros<<8)+mod)
384 bch = blobReader.getDrawer(ros, mod, iovs,
False,
False)
392 print (
"%s Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d" % (modName, bch.getObjType(), bch.getObjVersion(), bch.getNChans(), bch.getNGains(), bch.getObjSizeUint32()))
394 for chn
in range(chanmin,chanmax):
395 chnName =
" %2i" % chn
396 for adc
in range(gainmin,gainmax):
398 stat = mgr.getAdcStatus(ros,mod,chn,adc)
404 prbs = mgr.getAdcProblems(ros,mod,chn,adc)
409 msg =
"%s pm %02i ch %02i %s " % ( modName, abs(ch2pmt[ros][chn]), chn, gname[adc] )
411 msg =
"%s %2i %1i " % ( modName,chn,adc )
412 for prbCode
in sorted(prbs.keys()):
413 prbDesc = prbs[prbCode]
414 msg +=
" %5i (%s)" % (prbCode,prbDesc)
418 elif stat.isAffected():
419 msg +=
" => Affected"
425 print (
"%s ALL GOOD" % (modName))
432 print (
"%3i drawers are missing in DB" % miss)
433 print (
"%3i drawers are absolutely good" % good)
434 print (
"%3i drawers have good and affected channels" % (aff-miss))
435 print (
"%3i drawers have some bad channels" % (nMod-good-bad-aff))
436 print (
"%3i drawers are completely bad" % bad)