12os.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 (
"-o, --double print values with double precision")
41 print (
"-s, --schema= specify name of input JSON file or CREST_SERVER_PATH")
43letters =
"hr:l:s:t:f:n:b:e:m:N:X:c:a:g:p:dBCiIHPk:o:"
44keywords = [
"help",
"run=",
"lumi=",
"schema=",
"tag=",
"folder=",
"module=",
"begin=",
"end=",
"chmin=",
"chmax=",
"gain=",
"adc=",
"chan=",
"nval=",
"prefix=",
"default",
"blob",
"hex",
"pmt",
"keep=",
"comment",
"iov",
"IOV",
"double"]
47 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
48except getopt.GetoptError
as err:
57folderPath =
"/TILE/OFL02/CALIB/CIS/LIN"
90 if o
in (
"-f",
"--folder"):
92 elif o
in (
"-t",
"--tag"):
94 elif o
in (
"-s",
"--schema"):
96 elif o
in (
"-n",
"--nval"):
98 elif o
in (
"-b",
"--begin"):
102 elif o
in (
"-e",
"--end"):
106 elif o
in (
"-i",
"--iov"):
109 if modulename==
'AUX-1':
111 elif o
in (
"-I",
"--IOV"):
114 if modulename==
'AUX-1':
116 elif o
in (
"-a",
"--adc",
"-g",
"--gain"):
118 elif o
in (
"-m",
"--module"):
121 elif o
in (
"-c",
"--chan"):
123 elif o
in (
"-N",
"--chmin"):
125 elif o
in (
"-X",
"--chmax"):
127 elif o
in (
"-C",
"--comment"):
129 elif o
in (
"-r",
"--run"):
131 elif o
in (
"-l",
"--lumi"):
133 elif o
in (
"-d",
"--default"):
135 elif o
in (
"-B",
"--blob"):
137 elif o
in (
"-H",
"--hex"):
139 elif o
in (
"-P",
"--pmt"):
141 elif o
in (
"-p",
"--prefix"):
143 elif o
in (
"-k",
"--keep"):
145 elif o
in (
"-o",
"--double"):
147 elif o
in (
"-h",
"--help"):
151 raise RuntimeError(
"unhandled option")
154from TileCalibBlobPython
import TileCalibCrest
155from TileCalibBlobObjs.Classes
import TileCalibUtils, TileCalibType
157from TileCalibBlobPython.TileCalibLogger
import getLogger
158log = getLogger(
"ReadCalibFrCrest")
160logLevel=logging.DEBUG
161log.setLevel(logLevel)
162log1 = getLogger(
"TileCalibCrest")
163log1.setLevel(logLevel)
167 partname = modulename[:3]
168 mod = int(modulename[3:]) -1
170part_dict = {
'AUX':0,
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4}
171if partname
in part_dict:
172 ros = part_dict[partname]
188if tag.upper().endswith(
'HEAD'):
190if len(tag)==0
or tag.endswith(
'HEAD'):
191 folderPath=folderPath.replace(
'OFL02',
'ONL01')
192 log.info(
"tag is %s, using %s folder", tag
if tag
else 'empty', folderPath)
198tag1 = tag.split(
'_')[1][:4]
if '_' in tag
else tag[:4]
199if tag1 ==
"TILE" or tag1 ==
"CALO" or tag.startswith(
"TILE")
or tag.startswith(
"CALO"):
201if not os.path.isfile(schema):
202 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
204blobReader = TileCalibCrest.TileBlobReaderCrest(schema,folderPath, folderTag, run, lumi,
221 flt = blobReader.getDrawer(r, d, (run,lumi),
True,
False)
223 blobT=flt.getObjType()
224 blobV=flt.getObjVersion()
225 mchan=flt.getNChans()
226 mgain=flt.getNGains()
227 mval=flt.getObjSizeUint32()
228 log.info(
"Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d", blobT,blobV,mchan,mgain,mval)
240log.info(
"Comment: %s", blobReader.getComment((run,lumi)))
242if chan_n >= 0
and chan_n < nchan:
253if nadc >= 0
and nadc < ngain:
268 if iovonly
or IOVONLY:
272 iovList = blobReader.getIovs((begin,0),(end,0))
277 if begin != be
or end != en:
280 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
284 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
286 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
288 log.info(
"%d IOVs in total", len(iovList))
291 if iovonly
or IOVONLY:
292 option = 1
if iovonly
else 0
293 option += (2
if IOVONLY
else 0)
294 blobReader.dumpIovs(iovList,rosmin,rosmax,modmin,modmax,option,(rosmin<=0),
True)
297 iovList.append((run,lumi))
306barrel = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
307 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
308 27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
309 39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46]
310extbar = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
311 13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
312 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
313 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46]
315ch2pmt = [ dummy, barrel, barrel, extbar, extbar ]
318 for i
in range(mgain+1):
319 gname+=[
"g "+str(i) ]
321 gname = [
"LG",
"HG" ]
324oneModule = ((rosmax-rosmin==1)
and (modmax-modmin==1)
and iov)
329 pref =
"(%i,%i) " % (iovs[0],iovs[1])
331 pref = prefix +
" " + pref
333 log.info( pref + str(blobReader.getComment(iovs)) )
334 if prefix
and prefix.startswith(
"Write"):
335 comm = blobReader.getComment(iovs)
337 comm = comm[comm.find(
": ")+2:]
338 print (
'%s --update --folder=%s --tag=%s --run=%i --lumi=%i --comment="%s"' % (prefix,folderPath,folderTag,iovs[0],iovs[1],comm))
341 for ros
in range(rosmin,rosmax):
344 modName =
"0x%x" % ((ros<<8)+mod)
347 if modName
in [
'EBA39',
'EBA40',
'EBA41',
'EBA42',
'EBA55',
'EBA56',
'EBA57',
'EBA58',
348 'EBC39',
'EBC40',
'EBC41',
'EBC42',
'EBC55',
'EBC56',
'EBC57',
'EBC58' ]:
350 elif modName
in [
'EBA15',
'EBC18']:
352 elif modName
in [
'EBC29',
'EBC32',
'EBC34',
'EBC37']:
354 elif modName
in [
'EBA07',
'EBA25',
'EBA44',
'EBA53',
355 'EBC07',
'EBC25',
'EBC44',
'EBC53',
356 'EBC28',
'EBC31',
'EBC35',
'EBC38' ]:
358 elif modName
in [
'EBA08',
'EBA24',
'EBA43',
'EBA54',
359 'EBC08',
'EBC24',
'EBC43',
'EBC54' ]:
365 newBlob = blobReader.getBlob(ros, mod, iovs,
False)
366 if oldBlob == newBlob:
367 log.info( f
'{modName} in IOV {iovs} is identical to previous IOV')
371 log.info( f
'Reading IOV {iovs} for module {modName}')
373 log.info( f
'{modName} was updated in IOV {iovs}')
375 flt = blobReader.getDrawer(ros, mod,iovs,
False,
False)
376 if flt
is None or isinstance(flt, (int)):
378 print (
"%s is missing in DB" % modName)
382 print (
"%s Blob type: %d Version: %d Nchannels: %d Ngains: %d Nval: %d" % (modName, flt.getObjType(), flt.getObjVersion(), flt.getNChans(), flt.getNGains(), flt.getObjSizeUint32()))
385 mval = flt.getObjSizeUint32()
386 if nval<0
and -nval<=mval:
389 elif nval!=0
and nval<mval:
391 mchan=flt.getNChans()
392 mgain=flt.getNGains()
393 chmin = chanmin
if chanmin<mchan
else mchan
394 chmax = chanmax
if chanmax<mchan
else mchan
395 gnmin = gainmin
if gainmin<mgain
else mgain
396 gnmax = gainmax
if gainmax<mgain
else mgain
397 for chn
in range(chmin,chmax):
398 for adc
in range(gnmin,gnmax):
400 msg =
"%s pm %02i ch %02i %s " % ( modName, abs(ch2pmt[ros][chn]), chn, gname[adc] )
402 msg =
"%s %2i %1i " % ( modName, chn, adc )
403 for val
in range(mval0,mval):
404 if str(val)
in keep
or modName
in keep
or modSpec
in keep
or modName[:3]
in keep
or modName[:2]
in keep \
405 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 \
406 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:
410 v = flt.getData(chn, adc, val)
415 elif typeName==
'Bch':
416 msg +=
" %d" % flt.getData(chn, adc, val)
418 msg +=
" %s" % flt.getData(chn, adc, val)
420 msg +=
" %f" % flt.getData(chn, adc, val)
422 except Exception
as e:
425 if iovs[0]!=2147483647:
426 print (
"%3i drawers are present in DB for run %d lb %d" % (good,iovs[0],iovs[1]))
427 print (
"%3i drawers are missing in DB for run %d lb %d" % (miss,iovs[0],iovs[1]))
429 print (
"%3i drawers are present in DB" % (good))
430 print (
"%3i drawers are missing in DB" % (miss))
432 print (
"Please, check that you are using correct schema and correct tag")
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 getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.