10os.environ[
'TERM'] =
'linux'
15parser = argparse.ArgumentParser(
16 prog=
'ReadCellNoiseFromCrestCompare.py',
17 description=
'Dumps noise constants from online or offline folders/tags in CREST and compares two sources',
18 formatter_class=argparse.RawDescriptionHelpFormatter,
21- Conditions are compared using logical AND: both --maxdiff AND --maxdiffpercent
22 thresholds must be exceeded (both have to be TRUE) to print a difference
23- If *2 parameters (run2, lumi2, folder2, tag2, schema2) are not given,
24 values from primary parameters are used automatically
25- Use --cell, --gain, --index with -1 to process all values
28 # Compare two tags from same folder
29 %(prog)s -f /TILE/OFL02/NOISE/CELL -t UPD4 -t2 UPD1 -r 497970
31 # Compare specific cell/gain with thresholds
32 %(prog)s -f /TILE/OFL02/NOISE/CELL -t UPD4 -r 500000 -r2 400000 -c 123 -g 0 --maxdiff 0.001 --maxdiffpercent 5.0
34 # Wide format, brief output, all cells, full tag name without folder name
35 %(prog)s -t TileOfl02NoiseCell-RUN2-UPD4-36 -w -b -r 497970 -r2 345678
40parser.add_argument(
'-s',
'--schema', default=
'CREST',
41 help=
'CREST server path or schema (default: CREST from env)')
42parser.add_argument(
'-f',
'--folder', default=
'/TILE/OFL02/NOISE/CELL',
43 help=
'Status folder to use, e.g., /TILE/OFL02/NOISE/CELL')
44parser.add_argument(
'-t',
'--tag', default=
'UPD4',
45 help=
'Tag to use, e.g., UPD4 or tag suffix like 14TeV-N200_dT50-01')
46parser.add_argument(
'-r',
'--run', type=int, default=2147483647,
47 help=
'Run number (default: 2147483647, uses latest IOV)')
48parser.add_argument(
'-l',
'--lumi', type=int, default=0,
49 help=
'Luminosity block number (default: 0)')
52parser.add_argument(
'-s2',
'--schema2', default=
'none',
53 help=
'Second schema for comparison (default: same as --schema)')
54parser.add_argument(
'-f2',
'--folder2', default=
'none',
55 help=
'Second folder for comparison (default: same as --folder)')
56parser.add_argument(
'-t2',
'--tag2', default=
'none',
57 help=
'Second tag for comparison (default: same as --tag)')
58parser.add_argument(
'-r2',
'--run2', type=int, default=0,
59 help=
'Second run number (default: same as --run)')
60parser.add_argument(
'-l2',
'--lumi2', type=int, default=-1,
61 help=
'Second lumi block (default: same as --lumi)')
64parser.add_argument(
'-m',
'--maxdiff', type=float, default=-1.0,
65 help=
'Absolute maximal difference to compare constants (default: -1.0 = dump all)')
66parser.add_argument(
'-m2',
'--maxdiffpercent', type=float, default=-1.0,
67 help=
'Maximal difference in percent to compare constants (default: -1.0 = dump all)')
70parser.add_argument(
'-n',
'--channel', type=int, default=48,
71 help=
'COOL channel to read (default: 48 for Tile)')
72parser.add_argument(
'-c',
'--cell', type=int, default=-1,
73 help=
'Cell hash 0-5183 (default: -1 = all cells)')
74parser.add_argument(
'-g',
'--gain', type=int, default=-1,
75 help=
'Gain 0-3 (default: -1 = all gains)')
76parser.add_argument(
'-i',
'--index', type=int, default=-1,
77 help=
'Parameter index 0-4 (default: -1 = all parameters)')
78parser.add_argument(
'-z',
'--zero', type=float, default=5e-7,
79 help=
'Zero threshold: treat DB values below this as zeros (default: 5e-7)')
80parser.add_argument(
'-w',
'--wide', action=
'store_true', default=
False,
81 help=
'Wide format: print all values per cell in one line')
82parser.add_argument(
'-b',
'--brief', action=
'store_true', default=
False,
83 help=
'Brief output: print only numbers without character names')
84parser.add_argument(
'-d',
'--double', action=
'store_true', default=
False,
85 help=
'Print values with double precision')
86parser.add_argument(
'--stdout',
'-o', action=
'store_true',
87 help=
'Print differences to standard output (in addition to file)')
89args = parser.parse_args()
93run2 = args.run2
if args.run2 != 0
else run
95lumi2 = args.lumi2
if args.lumi2 >= 0
else lumi
97schema2 = args.schema2
if args.schema2 !=
"none" else schema
98folderPath = args.folder
99folderPath2 = args.folder2
if args.folder2 !=
"none" else folderPath
101tag2 = args.tag2
if args.tag2 !=
"none" else tag
102maxdiff = args.maxdiff
103maxdiffpercent = args.maxdiffpercent
112print_to_stdout = args.stdout
116if tag.upper().startswith(
'TILE')
or tag.upper().startswith(
'CALO')
or tag.upper().startswith(
'LAR'):
118if tag2.upper().startswith(
'TILE')
or tag2.upper().startswith(
'CALO')
or tag2.upper().startswith(
'LAR'):
121if (schema !=
'CREST' and os.path.isfile(schema)):
124if (schema2 !=
'CREST' and os.path.isfile(schema2)):
129print(
" ReadCellNoiseFromCrestCompare - Configuration")
131print(f
" {'Run/Lumi:':<14} 1st: run={run:<10} lumi={lumi:<6}")
132print(f
" {' ':<14} 2nd: run={run2:<10} lumi={lumi2:<6}")
133print(f
" {'Folder:':<14} {folderPath}")
134print(f
" {'Folder2:':<14} {folderPath2}")
135print(f
" {'Tag:':<14} {tag}")
136print(f
" {'Tag2:':<14} {tag2}")
137print(f
" {'Schema:':<14} {schema}")
138print(f
" {'Schema2:':<14} {schema2}")
139print(f
" {'Channel:':<14} {chan}")
140print(f
" {'Cell/Gain/Idx:':<14} {cell}/{gain}/{index}")
141print(f
" {'Thresholds:':<14} maxdiff={maxdiff:<8} maxdiffpercent={maxdiffpercent}")
142print(f
" {'Zero thr:':<14} {zthr:.2e}")
143print(f
" {'Format:':<14} wide={args.wide}, brief={brief}, double={doubl}")
146from CaloCondBlobAlgs
import CaloCondLogger
147from TileCalibBlobPython
import TileCalibCrest
148from TileCalibBlobPython
import TileCellTools
151log = CaloCondLogger.getLogger(
"ReadCellNoise")
153log.setLevel(logging.DEBUG)
164hashMgrDef=TileCellTools.TileCellHashMgr(cabling=cabling)
165hashMgrA=TileCellTools.TileCellHashMgr(
"UpgradeA")
166hashMgrBC=TileCellTools.TileCellHashMgr(
"UpgradeBC")
167hashMgrABC=TileCellTools.TileCellHashMgr(
"UpgradeABC")
170tag_upper = tag.upper()
171tag1 = tag_upper.split(
'_')[1][:4]
if '_' in tag_upper
else tag_upper[:4]
172if tag1 ==
"TILE" or tag1 ==
"CALO" or tag1[:3] ==
"LAR" or tag.startswith(
"TILE")
or tag.startswith(
"CALO")
or tag.startswith(
"LAR"):
175 folderPath1=folderPath
177tag2_upper = tag2.upper()
178tag2_1 = tag2_upper.split(
'_')[1][:4]
if '_' in tag2_upper
else tag2_upper[:4]
179if tag2_1 ==
"TILE" or tag2_1 ==
"CALO" or tag2_1[:3] ==
"LAR" or tag2.startswith(
"TILE")
or tag2.startswith(
"CALO")
or tag2.startswith(
"LAR"):
182 folderPath2=folderPath2
185 log.info(
"Connecting to DB1: schema=%s, folder=%s, tag=%s, run=%s, lumi=%s",
186 schema, folderPath1, tag, run, lumi)
187 blobReader = TileCalibCrest.TileBlobReaderCrest(schema, folderPath1, tag, run, lumi)
188 folderTag = blobReader.getTag()
189 log.info(
"Comment1: %s", blobReader.getComment((run,lumi)))
190 log.info(
"Connecting to DB2: schema=%s, folder=%s, tag=%s, run=%s, lumi=%s",
191 schema2, folderPath2, tag2, run2, lumi2)
192 blobReader2 = TileCalibCrest.TileBlobReaderCrest(schema2, folderPath2, tag2, run2, lumi2)
193 folderTag2 = blobReader2.getTag()
194 log.info(
"Comment2: %s", blobReader2.getComment((run2,lumi2)))
195except Exception
as e:
196 log.error(
"Initialization failed: %s", e)
200blobFlt = blobReader.getDrawer(-1,chan,
None,
False,
False)
202 log.critical(
"Could not locate a data blob in CREST payload for COOL channel %s", chan)
205blobFlt2 = blobReader2.getDrawer(-1,chan,
None,
False,
False)
207 log.critical(
"Could not locate a data blob in CREST payload for COOL channel %s", chan)
211outputfile =
'output_crest.ascii'
212f = open(outputfile,
'w')
214f.write(
"Command line parameters used: \n %s \n\n" % sys.argv[1:])
215f.write(
"=== Source 1 ===\n")
216f.write(
"schema : %s\n" % schema)
217f.write(
"folder : %s\n" % folderPath1)
218f.write(
"tag : %s\n" % folderTag)
219f.write(
"run : %d\n" % run)
220f.write(
"lumi : %d\n" % lumi)
221f.write(
"channel : %d\n" % chan)
222f.write(
"comment : %s\n\n" % blobReader.getComment((run,lumi)))
224f.write(
"=== Source 2 ===\n")
225f.write(
"schema : %s\n" % schema2)
226f.write(
"folder : %s\n" % folderPath2)
227f.write(
"tag : %s\n" % folderTag2)
228f.write(
"run : %d\n" % run2)
229f.write(
"lumi : %d\n" % lumi2)
230f.write(
"channel : %d\n" % chan)
231f.write(
"comment : %s\n\n" % blobReader2.getComment((run2,lumi2)))
233f.write(
"=== Comparison parameters ===\n")
234f.write(
"maxdiff : %f\n" % maxdiff)
235f.write(
"maxdiffpercent : %f\n\n" % maxdiffpercent)
236f.write(
"zero threshold : %e\n\n" % zthr)
243ncell=blobFlt.getNChans()
244ngain=blobFlt.getNGains()
245nval=blobFlt.getObjSizeUint32()
247if cell<0
or cell>=ncell:
254if gain<0
or gain>=ngain:
261if index<0
or index>=nval:
268log.info(
"From DB: ncell: %d ngain %d index nval %d", ncell, ngain, nval)
271 name1 = [
"",
"",
"0.0 "]
272 names = [
"S0 ",
"Pl ",
"S1 ",
"S2 ",
"Ra "]
275 name1 = [
"Noise cell ",
"gain ",
"0.00 "]
276 names = [
" RMS ",
"pileup ",
" RMS1 ",
" RMS2 ",
" Ratio "]
277 for i
in range(len(names),indexmax):
278 names += [
"c"+str(i)+
" "]
282if ncell>hashMgrA.getHashMax():
284elif ncell>hashMgrBC.getHashMax():
286elif ncell>hashMgrDef.getHashMax():
290log.info(
"Using %s CellMgr with hashMax %d", hashMgr.getGeometry(),hashMgr.getHashMax())
292for cell
in range(cellmin,cellmax):
293 if tile
and len(name1[0]):
294 name1[0] =
"%s %6s hash " % hashMgr.getNames(cell)
295 for gain
in range(gainmin,gainmax):
296 msg=
"%s%4d %s%d\t" % ( name1[0], cell, name1[1], gain)
300 for index
in range(indexmin,indexmax):
301 v=blobFlt.getData(cell, gain, index)
302 v2=blobFlt2.getData(cell, gain, index)
314 if abs(dv12) > maxdiff
and abs(dp12) > maxdiffpercent:
316 s1 =
"{0:<14.9g}".format(v)
if v<0
else "{0:<15.10g}".format(v)
317 s2 =
"{0:<14.9g}".format(v2)
if v2<0
else "{0:<15.10g}".format(v2)
318 s3 =
"{0:<14.9g}".format(dv12)
if dv12<0
else "{0:<15.10g}".format(dv12)
319 s4 =
"{0:<14.9g}".format(dp12)
if dp12<0
else "{0:<15.10g}".format(dp12)
320 msg +=
"%s v1 %s v2 %s diff %s diffpercent %s%s" % (names[index],s1.ljust(15),s2.ljust(15),s3.ljust(15),s4.ljust(15),dm)
322 s1 = name1[2]
if abs(v)<zthr
else "%8.6f" % v
if abs(v)<1
else "{0:<8.7g}".format(v).ljust(8)
323 s2 = name1[2]
if abs(v2)<zthr
else "%8.6f" % v2
if abs(v2)<1
else "{0:<8.7g}".format(v2).ljust(8)
324 s3 = name1[2]
if abs(dv12)<zthr
else "%8.6f" % dv12
if abs(dv12)<1
else "{0:<8.7g}".format(dv12).ljust(8)
325 s4 = name1[2]
if abs(dp12)<zthr
else "%8.6f" % dp12
if abs(dp12)<1
else "{0:<8.7g}".format(dp12).ljust(8)
326 msg +=
"%s v1 %s v2 %s diff %s diffpercent %s%s" % (names[index],s1[:8],s2[:8],s3[:8],s4[:8],dm)
329 output_line = msg[:len(msg)-len(dm)]
330 f.write(output_line +
"\n")
335log.info(
"Output written to %s", outputfile)
void print(char *figname, TCanvas *c1)