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")
141folderTAG = tag.upper()
142if folderTAG.startswith(
"TILE")
or folderTAG.startswith(
"CALO")
or folderTAG.startswith(
"LAR") :
144if not os.path.isfile(schema):
145 log.info(
"Initializing folder %s with tag %s", folderPath, tag)
146blobReader = TileCalibCrest.TileBlobReaderCrest(schema, folderPath, tag, run, lumi)
147log.info(
"Comment: %s", blobReader.getComment())
150blobFlt = blobReader.getDrawer(-1,chan,
None,
False,
False)
152 log.critical(
"Could not locate a data blob in CREST payload for COOL channel %s", chan)
160ncell=blobFlt.getNChans()
161ngain=blobFlt.getNGains()
162nval=blobFlt.getObjSizeUint32()
164if ncell>hashMgrA.getHashMax():
166elif ncell>hashMgrBC.getHashMax():
168elif ncell>hashMgrDef.getHashMax():
172log.info(
"Using %s CellMgr with hashMax %d", hashMgr.getGeometry(),hashMgr.getHashMax())
178 if iovonly
or IOVONLY:
182 iovList = blobReader.getIovs((begin,0),(end,0))
187 if begin != be
or end != en:
190 log.info(
"Changing begin run from %d to %d (start of IOV)", begin,be)
194 log.info(
"Changing end run from %d to %d (start of next IOV)", end,en)
196 log.info(
"Changing end run from %d to %d (start of last IOV)", end,en)
198 log.info(
"%d IOVs in total", len(iovList))
201 if iovonly
or IOVONLY:
202 option = 1
if iovonly
else 0
203 option += (2
if IOVONLY
else 0)
204 blobReader.dumpIovs(iovList,-1,0,chan,chan+1,option,tile,
False)
207 iovList.append((run,lumi))
212if cell<0
or cell>=ncell:
219if gain<0
or gain>=ngain:
226if index<0
or index>=nval:
234 name1 = [
"",
"",
"0.0 "]
237 for i
in range(indexmax):
240 name1 = [
"Noise cell ",
"gain ",
"0.00 "]
241 names = [
"RMS ",
"pileup ",
"RMS1 ",
"RMS2 ",
"Ratio "]
242 for i
in range(len(names),indexmax):
243 names += [
"c"+str(i)+
" "]
250 pref =
"(%i,%i) " % (iovs[0],iovs[1])
251 newBlob = blobReader.getBlob(-1, chan, iovs,
False)
252 if oldBlob == newBlob:
253 log.info( f
'Cell noise in IOV {iovs} is identical to previous IOV')
255 log.info( pref + str(blobReader.getComment(iovs)) )
259 log.info( f
'Reading IOV {iovs}')
261 log.info( f
'Cell noise was updated in IOV {iovs}')
263 blobFlt = blobReader.getDrawer(-1,chan,iovs,
False,
False)
265 log.info( pref + str(blobReader.getComment(iovs)) )
266 for cell
in range(cellmin,cellmax):
267 if tile
and len(name1[0]):
268 name1[0] =
"%s %6s hash " % hashMgr.getNames(cell)
269 for gain
in range(gainmin,gainmax):
270 msg=
"%s%4d %s%d\t" % ( name1[0], cell, name1[1], gain)
271 for index
in range(indexmin,indexmax):
272 v=blobFlt.getData(cell, gain, index)
274 msg +=
"%s%s%s" % (names[index],
"{0:<15.10g}".format(v).ljust(15),dm)
276 msg +=
"%s%s%s" % (names[index],name1[2],dm)
278 msg +=
"%s%8.6f%s" % (names[index],v,dm)
280 msg +=
"%s%s%s" % (names[index],
"{0:<8.7g}".format(v).ljust(8),dm)