13os.environ[
'TERM'] =
'linux'
16 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
17 print (
"Dumps the TileCal status bits from various schemas / folders")
19 print (
"-h, --help shows this help")
20 print (
"-f, --folder= specify status folder to use ONL01 or OFL02, don't need to specify full path")
21 print (
"-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or full suffix like RUN2-HLT-UPD1-00")
22 print (
"-H, --hash= specify hash to use, run/lumi will be ignored if hash is provided")
23 print (
"-r, --run= specify run number, by default uses latest iov")
24 print (
"-l, --lumi= specify lumi block number, default is 0")
25 print (
"-b, --begin= specify run number of first iov in multi-iov mode, by default uses very first iov")
26 print (
"-e, --end= specify run number of last iov in multi-iov mode, by default uses latest iov")
27 print (
"-m, --module= specify module to use, default is not set")
28 print (
"-N, --chmin= specify minimal channel to use, default is 0")
29 print (
"-X, --chmax= specify maximal channel to use, default is 47")
30 print (
"-c, --chan= specify channel to use , default is all channels from chmin to chmax")
31 print (
"-g, --gain=, -a, --adc= specify adc(gain) to use, default is 2 (i.e. both low and high gains)")
32 print (
"-C, --comment print comment for every IOV")
33 print (
"-i, --iov print IOVs only for every module")
34 print (
"-I, --IOV print IOVs only")
35 print (
"-A, --all print all records for every IOV, including those which were overwritten")
36 print (
"-d, --default print also default values stored in AUX01-AUX20")
37 print (
"-B, --blob print additional blob info")
38 print (
"-x, --hex print frag id instead of module name")
39 print (
"-P, --pmt print pmt number in addition to channel number")
40 print (
"-s, --schema= specify name of input JSON file or CREST_SERVER_PATH")
41 print (
"-w, --warning suppress warning messages about missing drawers in DB")
43letters =
"hH:r:l:s:t:f:dBxPwm:b:e:a:g:c:N:X:CiIA"
44keywords = [
"help",
"hash=",
"run=",
"lumi=",
"schema=",
"tag=",
"folder=",
"default",
"blob",
"hex",
"pmt",
"warning",
"module=",
"begin=",
"end=",
"chmin=",
"chmax=",
"gain=",
"adc=",
"chan=",
"comment",
"iov",
"IOV",
"all"]
47 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
48except getopt.GetoptError
as err:
57folderPath =
"/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 (
"-H",
"--hash"):
100 elif o
in (
"-r",
"--run"):
102 elif o
in (
"-l",
"--lumi"):
104 elif o
in (
"-b",
"--begin"):
108 elif o
in (
"-e",
"--end"):
112 elif o
in (
"-A",
"--all"):
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 (
"-x",
"--hex"):
143 elif o
in (
"-P",
"--pmt"):
145 elif o
in (
"-w",
"--warning"):
147 elif o
in (
"-h",
"--help"):
151 raise RuntimeError(
"unhandled option")
159from TileCalibBlobPython
import TileBchCrest
160from TileCalibBlobObjs.Classes
import TileCalibUtils
162from TileCalibBlobPython.TileCalibLogger
import getLogger
163log = getLogger(
"ReadBchFrCrest")
165logLevel=logging.DEBUG
166log.setLevel(logLevel)
167log1 = getLogger(
"TileBchCrest")
168log1.setLevel(logLevel)
169log2 = getLogger(
"TileCalibCrest")
170log2.setLevel(logLevel)
172if tag.upper().endswith(
'HEAD'):
174if len(tag)==0
or tag.endswith(
'HEAD'):
175 folderPath=
'/TILE/ONL01/STATUS/ADC'
176 log.info(
"tag is %s, using %s folder", tag
if tag
else 'empty', folderPath)
182tag1 = tag.split(
'_')[1][:4]
if '_' in tag
else tag[:4]
183if tag1 ==
"TILE" or tag1 ==
"CALO" or tag.startswith(
"TILE")
or tag.startswith(
"CALO"):
185if not os.path.isfile(schema):
186 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
189mgr = TileBchCrest.TileBchMgr()
190mgr.setLogLvl(logLevel)
191mgr.initialize(schema, folderPath, folderTag, (run,lumi), warn, -2)
192blobReader = mgr.getBlobReader()
196if len(list(isBadDef.keys())):
197 log.info(
"isBad Definition: " )
198 for prbCode
in sorted(isBadDef.keys()):
199 prbDesc = isBadDef[prbCode]
200 msg =
"- %2i (%s)" % (prbCode,prbDesc)
204if len(list(isBadTimingDef.keys())):
205 log.info(
"isBadTiming Definition: " )
206 for prbCode
in sorted(isBadTimingDef.keys()):
207 prbDesc = isBadTimingDef[prbCode]
208 msg =
"- %2i (%s)" % (prbCode,prbDesc)
214 partname = modulename[:3]
215 mod = int(modulename[3:]) -1
217part_dict = {
'AUX':0,
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4}
218if partname
in part_dict:
219 ros = part_dict[partname]
254 if iovonly
or IOVONLY:
258 iovList = blobReader.getIovs((begin,0),(end,0))
263 if begin != be
or end != en:
266 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
270 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
272 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
274 log.info(
"%d IOVs in total", len(iovList))
277 if iovonly
or IOVONLY:
280 blobReader.readIov(iovs)
282 phash = blobReader.getPayloadHash()
283 itime = blobReader.getInsertionTime()
284 for i
in range(len(phash)):
285 blobReader.getPayloadByHash(i)
286 log.info(
"(%i,%i) Insertion time %s Hash %s", iovs[0], iovs[1], itime[i], phash[i] )
287 log.info(
"(%i,%i) %s", iovs[0], iovs[1], blobReader.getComment(iovs) )
289 log.info(
"(%i,%i) %s", iovs[0], iovs[1], blobReader.getComment(iovs) )
290 option = 1
if iovonly
else 0
291 option += (2
if IOVONLY
else 0)
292 blobReader.dumpIovs(iovList,rosmin,rosmax,modmin,modmax,option,(rosmin<=0),
True)
295 iovList.append((run,lumi))
304barrel = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
305 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
306 27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
307 39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46]
308extbar = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
309 13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
310 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
311 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46]
313ch2pmt = [ dummy, barrel, barrel, extbar, extbar ]
314gname = [
"LG",
"HG" ]
324oneModule = ((rosmax-rosmin==1)
and (modmax-modmin==1)
and iov)
328 blobReader.readIov(iovs)
329 phash = blobReader.getPayloadHash()
330 itime = blobReader.getInsertionTime()
331 hashmax = len(phash)
if all
else 1
332 for hashind
in range(hashmax):
334 pref =
"(%i,%i) " % (iovs[0],iovs[1])
335 mgr.updateFromDb(schema, folderPath, folderTag, iovs, 1, warn)
337 blobReader.getPayloadByHash(hashind)
338 log.info(
"(%s,%s) Insertion time %s Hash %s", iovs[0], iovs[1], itime[hashind], phash[hashind] )
340 log.info( pref + str(blobReader.getComment(iovs)) )
347 for ros
in range(rosmin,rosmax):
351 modName =
"0x%x" % ((ros<<8)+mod)
355 newBlob = blobReader.getBlob(ros, mod, iovs,
False)
356 if oldBlob == newBlob:
358 log.info( f
'{modName} in IOV {iovs} is identical to previous IOV')
360 log.info( f
'{modName} in payload {hashind+1} of IOV {iovs} is identical to previous payload')
364 log.info( f
'Reading IOV {iovs} for module {modName}')
367 log.info( f
'{modName} was updated in IOV {iovs}')
369 log.info( f
'{modName} was updated in payload {hashind+1} of IOV {iovs}')
372 bch = blobReader.getDrawer(ros, mod, iovs,
False,
False)
380 print (
"%s Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d" % (modName, bch.getObjType(), bch.getObjVersion(), bch.getNChans(), bch.getNGains(), bch.getObjSizeUint32()))
382 for chn
in range(chanmin,chanmax):
383 chnName =
" %2i" % chn
384 for adc
in range(gainmin,gainmax):
386 stat = mgr.getAdcStatus(ros,mod,chn,adc)
392 prbs = mgr.getAdcProblems(ros,mod,chn,adc)
397 msg =
"%s pm %02i ch %02i %s " % ( modName, abs(ch2pmt[ros][chn]), chn, gname[adc] )
399 msg =
"%s %2i %1i " % ( modName,chn,adc )
400 for prbCode
in sorted(prbs.keys()):
401 prbDesc = prbs[prbCode]
402 msg +=
" %5i (%s)" % (prbCode,prbDesc)
406 elif stat.isAffected():
407 msg +=
" => Affected"
413 print (
"%s ALL GOOD" % (modName))
420 print (
"%3i drawers are missing in DB" % miss)
421 print (
"%3i drawers are absolutely good" % good)
422 print (
"%3i drawers have good and affected channels" % (aff-miss))
423 print (
"%3i drawers have some bad channels" % (nMod-good-bad-aff))
424 print (
"%3i drawers are completely bad" % bad)
static unsigned int max_gain()
Python compatibility function.
static unsigned int badtiming_definition_chan()
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.
static unsigned int definitions_draweridx()
Python compatibility function.
static unsigned int bad_definition_chan()
Python compatibility function.