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 python %(prog)s -f /TILE/OFL02/NOISE/CELL -t UPD4 -t2 UPD1 -r 497970
31 # Compare specific cell/gain with thresholds
32 python %(prog)s -f /TILE/OFL02/NOISE/CELL -t UPD4 -c 123 -g 0 --maxdiff 0.001 --maxdiffpercent 5.0
34 # Wide format, brief output, all cells
35 python %(prog)s -f /TILE/OFL02/NOISE/CELL -t UPD4 -w -b -r 497970
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
117print(
" ReadCellNoiseFromCrestCompare - Configuration")
119print(f
" {'Run/Lumi:':<14} 1st: run={run:<10} lumi={lumi:<6}")
120print(f
" {' ':<14} 2nd: run={run2:<10} lumi={lumi2:<6}")
121print(f
" {'Folder:':<14} {folderPath}")
122print(f
" {'Folder2:':<14} {folderPath2}")
123print(f
" {'Tag:':<14} {tag}")
124print(f
" {'Tag2:':<14} {tag2}")
125print(f
" {'Schema:':<14} {schema}")
126print(f
" {'Schema2:':<14} {schema2}")
127print(f
" {'Channel:':<14} {chan}")
128print(f
" {'Cell/Gain/Idx:':<14} {cell}/{gain}/{index}")
129print(f
" {'Thresholds:':<14} maxdiff={maxdiff:<8} maxdiffpercent={maxdiffpercent}")
130print(f
" {'Zero thr:':<14} {zthr:.2e}")
131print(f
" {'Format:':<14} wide={args.wide}, brief={brief}, double={doubl}")
134from CaloCondBlobAlgs
import CaloCondLogger
135from TileCalibBlobPython
import TileCalibCrest
136from TileCalibBlobPython
import TileCellTools
139log = CaloCondLogger.getLogger(
"ReadCellNoise")
141log.setLevel(logging.DEBUG)
152hashMgrDef=TileCellTools.TileCellHashMgr(cabling=cabling)
153hashMgrA=TileCellTools.TileCellHashMgr(
"UpgradeA")
154hashMgrBC=TileCellTools.TileCellHashMgr(
"UpgradeBC")
155hashMgrABC=TileCellTools.TileCellHashMgr(
"UpgradeABC")
159tag_upper = tag.upper()
160tag1 = tag_upper.split(
'_')[1][:4]
if '_' in tag_upper
else tag_upper[:4]
161if tag1 ==
"TILE" or tag1 ==
"CALO" or tag1[:3] ==
"LAR" or tag.startswith(
"TILE")
or tag.startswith(
"CALO")
or tag.startswith(
"LAR"):
164 folderPath1=folderPath
165if not os.path.isfile(schema):
166 log.info(
"Initializing folder %s with tag %s (%s)", folderPath1, folderTag, tag1)
169tag2_upper = tag2.upper()
170tag2_1 = tag2_upper.split(
'_')[1][:4]
if '_' in tag2_upper
else tag2_upper[:4]
171if tag2_1 ==
"TILE" or tag2_1 ==
"CALO" or tag2_1[:3] ==
"LAR" or tag2.startswith(
"TILE")
or tag2.startswith(
"CALO")
or tag2.startswith(
"LAR"):
174 folderPath2=folderPath2
175if not os.path.isfile(schema2):
176 log.info(
"Initializing folder2 %s with tag2 %s (%s)", folderPath2, folderTag2, tag2_1)
179 blobReader = TileCalibCrest.TileBlobReaderCrest(schema, folderPath1, folderTag, run, lumi)
180 log.debug(
"Connecting to DB: schema=%s, folder=%s, tag=%s, run=%s, lumi=%s",
181 schema, folderPath1, folderTag, run, lumi)
182 log.info(
"Comment1: %s", blobReader.getComment((run,lumi)))
183 blobReader2 = TileCalibCrest.TileBlobReaderCrest(schema2, folderPath2, folderTag2, run2, lumi2)
184 log.debug(
"Connecting to DB2: schema=%s, folder=%s, tag=%s, run=%s, lumi=%s",
185 schema2, folderPath2, folderTag2, run2, lumi2)
186 log.info(
"Comment1: %s", blobReader2.getComment((run2,lumi2)))
187except Exception
as e:
188 log.error(
"Initialization failed: %s", e)
192blobFlt = blobReader.getDrawer(-1,chan,
None,
False,
False)
194 log.critical(
"Could not locate a data blob in CREST payload for COOL channel %s", chan)
197blobFlt2 = blobReader2.getDrawer(-1,chan,
None,
False,
False)
199 log.critical(
"Could not locate a data blob in CREST payload for COOL channel %s", chan)
203outputfile =
'output_crest.ascii'
204f = open(outputfile,
'w')
206f.write(
"Command line parameters used: \n %s \n\n" % sys.argv[1:])
207f.write(
"=== Source 1 ===\n")
208f.write(
"schema : %s\n" % schema)
209f.write(
"folder : %s\n" % folderPath1)
210f.write(
"tag : %s\n" % folderTag)
211f.write(
"run : %d\n" % run)
212f.write(
"lumi : %d\n" % lumi)
213f.write(
"channel : %d\n" % chan)
214f.write(
"comment : %s\n\n" % blobReader.getComment((run,lumi)))
216f.write(
"=== Source 2 ===\n")
217f.write(
"schema : %s\n" % schema2)
218f.write(
"folder : %s\n" % folderPath2)
219f.write(
"tag : %s\n" % folderTag2)
220f.write(
"run : %d\n" % run2)
221f.write(
"lumi : %d\n" % lumi2)
222f.write(
"channel : %d\n" % chan)
223f.write(
"comment : %s\n\n" % blobReader2.getComment((run2,lumi2)))
225f.write(
"=== Comparison parameters ===\n")
226f.write(
"maxdiff : %f\n" % maxdiff)
227f.write(
"maxdiffpercent : %f\n\n" % maxdiffpercent)
228f.write(
"zero threshold : %e\n\n" % zthr)
235ncell=blobFlt.getNChans()
236ngain=blobFlt.getNGains()
237nval=blobFlt.getObjSizeUint32()
239if cell<0
or cell>=ncell:
246if gain<0
or gain>=ngain:
253if index<0
or index>=nval:
260log.info(
"From DB: ncell: %d ngain %d index nval %d", ncell, ngain, nval)
263 name1 = [
"",
"",
"0.0 "]
264 names = [
"S0 ",
"Pl ",
"S1 ",
"S2 ",
"Ra "]
267 name1 = [
"Noise cell ",
"gain ",
"0.00 "]
268 names = [
" RMS ",
"pileup ",
" RMS1 ",
" RMS2 ",
" Ratio "]
269 for i
in range(len(names),indexmax):
270 names += [
"c"+
str(i)+
" "]
274if ncell>hashMgrA.getHashMax():
276elif ncell>hashMgrBC.getHashMax():
278elif ncell>hashMgrDef.getHashMax():
282log.info(
"Using %s CellMgr with hashMax %d", hashMgr.getGeometry(),hashMgr.getHashMax())
284for cell
in range(cellmin,cellmax):
285 if tile
and len(name1[0]):
286 name1[0] =
"%s %6s hash " % hashMgr.getNames(cell)
287 for gain
in range(gainmin,gainmax):
288 msg=
"%s%4d %s%d\t" % ( name1[0], cell, name1[1], gain)
292 for index
in range(indexmin,indexmax):
293 v=blobFlt.getData(cell, gain, index)
294 v2=blobFlt2.getData(cell, gain, index)
306 if abs(dv12) > maxdiff
and abs(dp12) > maxdiffpercent:
308 s1 =
"{0:<14.9g}".format(v)
if v<0
else "{0:<15.10g}".format(v)
309 s2 =
"{0:<14.9g}".format(v2)
if v2<0
else "{0:<15.10g}".format(v2)
310 s3 =
"{0:<14.9g}".format(dv12)
if dv12<0
else "{0:<15.10g}".format(dv12)
311 s4 =
"{0:<14.9g}".format(dp12)
if dp12<0
else "{0:<15.10g}".format(dp12)
312 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)
314 s1 = name1[2]
if abs(v)<zthr
else "%8.6f" % v
if abs(v)<1
else "{0:<8.7g}".format(v).ljust(8)
315 s2 = name1[2]
if abs(v2)<zthr
else "%8.6f" % v2
if abs(v2)<1
else "{0:<8.7g}".format(v2).ljust(8)
316 s3 = name1[2]
if abs(dv12)<zthr
else "%8.6f" % dv12
if abs(dv12)<1
else "{0:<8.7g}".format(dv12).ljust(8)
317 s4 = name1[2]
if abs(dp12)<zthr
else "%8.6f" % dp12
if abs(dp12)<1
else "{0:<8.7g}".format(dp12).ljust(8)
318 msg +=
"%s v1 %s v2 %s diff %s diffpercent %s%s" % (names[index],s1[:8],s2[:8],s3[:8],s4[:8],dm)
321 output_line = msg[:len(msg)-len(dm)]
322 f.write(output_line +
"\n")
327log.info(
"Output written to %s", outputfile)
void print(char *figname, TCanvas *c1)