18os.environ[
'TERM'] =
'linux'
21 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
22 print (
"Dumps noise constants from online or offline folders / tags")
24 print (
"-h, --help shows this help")
25 print (
"-s, --schema= specify name of input JSON file or CREST_SERVER_PATH")
26 print (
"-f, --folder= specify status folder to use f.i. /TILE/OFL02/NOISE/CELL or /CALO/Noise/CellNoise")
27 print (
"-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or tag suffix like 14TeV-N200_dT50-01")
28 print (
"-r, --run= specify run number, by default uses latest iov")
29 print (
"-l, --lumi= specify lumi block number, default is 0")
30 print (
"-b, --begin= specify run number of first iov in multi-iov mode, by default uses very first iov")
31 print (
"-e, --end= specify run number of last iov in multi-iov mode, by default uses latest iov")
32 print (
"-C, --comment print comment for every IOV")
33 print (
"-i, --iov print IOVs only for every COOL channel")
34 print (
"-I, --IOV print IOVs only")
35 print (
"-n, --channel= specify COOL channel to read (48 by defalt)")
36 print (
"-c, --cell= specify cell hash (0-5183), default is -1, means all cells")
37 print (
"-g, --gain= specify gain to print (0-3), default is -1, means all gains")
38 print (
"-x, --index= specify parameter index (0-4), default is -1, means all parameters")
39 print (
"-B, --brief print only numbers without character names")
40 print (
"-D, --double print values with double precision")
42letters =
"hs:t:f:r:l:b:e:n:c:g:x:BDCiI"
43keywords = [
"help",
"schema=",
"tag=",
"folder=",
"run=",
"lumi=",
"begin=",
"end=",
"channel=",
"cell=",
"gain=",
"index=",
"brief",
"double",
"comment",
"iov",
"IOV"]
46 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
47except getopt.GetoptError
as err:
56folderPath =
'/TILE/OFL02/NOISE/CELL'
73 if o
in (
"-s",
"--schema"):
75 elif o
in (
"-f",
"--folder"):
77 elif o
in (
"-t",
"--tag"):
79 elif o
in (
"-n",
"--channel"):
81 elif o
in (
"-c",
"--cell"):
83 elif o
in (
"-g",
"--gain"):
85 elif o
in (
"-x",
"--index"):
87 elif o
in (
"-r",
"--run"):
89 elif o
in (
"-l",
"--lumi"):
91 elif o
in (
"-b",
"--begin"):
94 elif o
in (
"-e",
"--end"):
97 elif o
in (
"-i",
"--iov"):
100 elif o
in (
"-I",
"--IOV"):
103 elif o
in (
"-C",
"--comment"):
105 elif o
in (
"-B",
"--brief"):
107 elif o
in (
"-D",
"--double"):
109 elif o
in (
"-h",
"--help"):
118from TileCalibBlobPython
import TileCalibLogger
119from TileCalibBlobPython
import TileCalibCrest
120from TileCalibBlobPython
import TileCellTools
123log = TileCalibLogger.getLogger(
"ReadCellNoise")
135hashMgrDef=TileCellTools.TileCellHashMgr(cabling=cabling)
136hashMgrA=TileCellTools.TileCellHashMgr(
"UpgradeA")
137hashMgrBC=TileCellTools.TileCellHashMgr(
"UpgradeBC")
138hashMgrABC=TileCellTools.TileCellHashMgr(
"UpgradeABC")
143tag1 = tag.split(
'_')[1][:4]
if '_' in tag
else tag[:4]
144if tag1 ==
"TILE" or tag1 ==
"CALO" or tag1[:3] ==
"LAR" or tag.startswith(
"TILE")
or tag.startswith(
"CALO")
or tag.startswith(
"LAR"):
146if not os.path.isfile(schema):
147 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
148blobReader = TileCalibCrest.TileBlobReaderCrest(schema, folderPath, folderTag, run, lumi)
149log.info(
"Comment: %s", blobReader.getComment())
152blobFlt = blobReader.getDrawer(-1,chan,
None,
False,
False)
154 log.critical(
"Could not locate a data blob in CREST payload for COOL channel %s", chan)
162ncell=blobFlt.getNChans()
163ngain=blobFlt.getNGains()
164nval=blobFlt.getObjSizeUint32()
166if ncell>hashMgrA.getHashMax():
168elif ncell>hashMgrBC.getHashMax():
170elif ncell>hashMgrDef.getHashMax():
174log.info(
"Using %s CellMgr with hashMax %d", hashMgr.getGeometry(),hashMgr.getHashMax())
180 if iovonly
or IOVONLY:
184 iovList = blobReader.getIovs((begin,0),(end,0))
189 if begin != be
or end != en:
192 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
196 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
198 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
200 log.info(
"%d IOVs in total", len(iovList))
203 if iovonly
or IOVONLY:
204 option = 1
if iovonly
else 0
205 option += (2
if IOVONLY
else 0)
206 blobReader.dumpIovs(iovList,-1,0,chan,chan+1,option,tile,
False)
209 iovList.append((run,lumi))
214if cell<0
or cell>=ncell:
221if gain<0
or gain>=ngain:
228if index<0
or index>=nval:
236 name1 = [
"",
"",
"0.0 "]
239 for i
in range(indexmax):
242 name1 = [
"Noise cell ",
"gain ",
"0.00 "]
243 names = [
"RMS ",
"pileup ",
"RMS1 ",
"RMS2 ",
"Ratio "]
244 for i
in range(len(names),indexmax):
245 names += [
"c"+str(i)+
" "]
252 pref =
"(%i,%i) " % (iovs[0],iovs[1])
253 newBlob = blobReader.getBlob(-1, chan, iovs,
False)
254 if oldBlob == newBlob:
255 log.info( f
'Cell noise in IOV {iovs} is identical to previous IOV')
257 log.info( pref + str(blobReader.getComment(iovs)) )
261 log.info( f
'Reading IOV {iovs}')
263 log.info( f
'Cell noise was updated in IOV {iovs}')
265 blobFlt = blobReader.getDrawer(-1,chan,iovs,
False,
False)
267 log.info( pref + str(blobReader.getComment(iovs)) )
268 for cell
in range(cellmin,cellmax):
269 if tile
and len(name1[0]):
270 name1[0] =
"%s %6s hash " % hashMgr.getNames(cell)
271 for gain
in range(gainmin,gainmax):
272 msg=
"%s%4d %s%d\t" % ( name1[0], cell, name1[1], gain)
273 for index
in range(indexmin,indexmax):
274 v=blobFlt.getData(cell, gain, index)
276 msg +=
"%s%s%s" % (names[index],
"{0:<15.10g}".format(v).ljust(15),dm)
278 msg +=
"%s%s%s" % (names[index],name1[2],dm)
280 msg +=
"%s%8.6f%s" % (names[index],v,dm)
282 msg +=
"%s%s%s" % (names[index],
"{0:<8.7g}".format(v).ljust(8),dm)