26 from TileCalibBlobPython
import TileCalibTools
27 from TileCalibBlobObjs.Classes
import TileCalibUtils
28 import os, sys, getopt
29 from builtins
import input
30 os.environ[
'TERM'] =
'linux'
39 folderPath =
"/TILE/OFL02/CALIB/CES"
41 tag =
"RUN2-HLT-UPD1-01"
43 schema =
"COOLOFL_TILE"
55 options, remainder = getopt.getopt(sys.argv[1:],
'h', [
'run=',
'run2=',
'lumi=',
'lumi2=',
'maxdiff=',
'maxdiffpercent=',
'folder=',
'folder2=',
'tag=',
'tag2=',
'schema=',
'schema2=',
'instance=',
'instance2=',
'server=',
'server2=',
'sqlfn=',
'sqlfn2='])
57 for opt, arg
in options:
61 elif opt
in (
'--run'):
63 elif opt
in (
'--run2'):
65 elif opt
in (
'--lumi'):
67 elif opt
in (
'--lumi2'):
69 elif opt
in (
'--maxdiff'):
71 elif opt
in (
'--maxdiffpercent'):
72 maxdiffpercent =
float(arg)
73 elif opt
in (
'--folder'):
75 elif opt
in (
'--folder2'):
77 elif opt
in (
'--tag'):
79 elif opt
in (
'--tag2'):
81 elif opt
in (
'--schema'):
83 elif opt
in (
'--schema2'):
85 elif opt
in (
'--instance'):
87 elif opt
in (
'--instance2'):
89 elif opt
in (
'--server'):
91 elif opt
in (
'--server2'):
93 elif opt
in (
'--sqlfn'):
95 elif opt
in (
'--sqlfn2'):
102 if folderPath2==
"none":
103 folderPath2=folderPath
108 if instance2==
"none":
118 print (
'run ',run,
'lumi ',lumi,
'run2 ',run2,
'lumi2 ',lumi2)
119 print (
'maxdiff ',maxdiff)
120 print (
'maxdiffpercent ',maxdiffpercent)
121 print (
'folder ',folderPath,
'folder2 ',folderPath2)
122 print (
'tag ',tag,
'tag2 ',tag2)
123 print (
'schema ', schema,
'schema2 ', schema2)
124 print (
'instance ', instance,
'instance2 ', instance2)
125 print (
'server ', server,
'server2 ', server2)
126 print (
'sqlfn ',sqlfn,
'sqlfn2 ',sqlfn2)
129 print (
'******** Above, the defaults are shown, one can change them')
130 print (
' using command-line options: ReadFromCoolCompare.py --option=value')
131 print (
' Any number of options in random order can be given')
132 print (
' If run2,lumi2,schema2,tag2 or instance2 are not given, the values')
133 print (
' of run,lumi,schema,tag and instance will be assigned to them')
134 print (
'For singleversion folders (ONL01) there should be option with empty tag: --tag=')
135 print (
'conditions with options maxdiffpercent and maxdiff are used')
136 print (
' in logical AND, so, both have to be TRUE to print the data')
137 print (
'\n Examples:')
138 print (
'\npython ReadFromCoolCompare.py --maxdiff=100 --run=100012 --folder=/TILE/ONL01/CALIB/CES --tag= --schema=COOLONL_TILE --tag2=HLT-REPC-004 --sqlfn2=tileSqlite.db --folder2=/TILE/OFL02/CALIB/CES --schema2=COOLOFL_TILE')
139 print (
'\npython ReadFromCoolCompare.py --folder=/TILE/ONL01/FRAG1 --schema=COOLONL_TILE --tag= --maxdiffpercent=5.5 --run=160000 --run2=999999999')
143 connStr=schema+
'/'+instance
if ':' not in schema
and ';' not in schema
and '/' not in schema
else schema
144 connStr2=schema2+
'/'+instance2
if ':' not in schema2
and ';' not in schema2
and '/' not in schema2
else schema2
152 db = TileCalibTools.openDbConn(connStr, server)
154 db = TileCalibTools.openDb(
'SQLITE', instance,
'READONLY',schema,sqlfn)
156 db2 = TileCalibTools.openDbConn(connStr2, server2)
158 db2 = TileCalibTools.openDb(
'SQLITE', instance2,
'READONLY',schema2,sqlfn2)
169 if tag.startswith(
'TileO'):
176 if tag2.startswith(
'TileO'):
185 from TileCalibBlobPython.TileCalibLogger
import getLogger
188 log.setLevel(logging.DEBUG)
190 if run2!=run
and tag2==tag
and folderPath2==folderPath
and folderPath.startswith(
"/TILE/OFL02/TIME"):
191 fd=
open(
'from_%d_to_%d.dif'%(run2,run),
'w')
196 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
197 log.info(
"Initializing folder %s with tag %s", folderPath2, folderTag2)
199 blobReader = TileCalibTools.TileBlobReader(db,folderPath, folderTag)
200 blobReader2 = TileCalibTools.TileBlobReader(db2,folderPath2, folderTag2)
207 log.info(
"Initializing for run1 %d lumi %d run2 %d lumi2 %d maxdiff %f maxdiffpercent %f", run, lumi, run2, lumi2, maxdiff,maxdiffpercent)
208 log.info(
"Comment1: %s", blobReader.getComment((run,lumi)))
209 log.info(
"Comment2: %s", blobReader2.getComment((run2,lumi2)))
219 log.error(
"No valid drawers in first database")
222 flt = blobReader.getDrawer(r, d, (run,lumi),
False,
False)
224 ot = flt.getObjType()
225 ov = flt.getObjVersion()
226 os = flt.getObjSizeByte()//4
239 log.error(
"No valid drawers in second database")
242 flt2 = blobReader2.getDrawer(r, d, (run2,lumi2),
False,
False)
243 ot2 = flt2.getObjType()
244 os2 = flt2.getObjSizeByte()//4
246 if (os != os2)
or (ot != ot2):
247 log.error(
"Object sizes (%s vs %s) or types (%s vs %s) are different", os, os2, ot, ot2)
248 answ=input(
' continue anyway? (y/n)')
254 for ind
in range(0,os):
258 f.write(
"Command line parameters used: \n %s \n" % sys.argv[1:])
259 f.write(
"---- Object header for ros=%d drawer=%d \n" % (r,d))
260 f.write(
"ObjType : %d \n" % ot)
261 f.write(
"ObjVersion : %d \n" % ov)
262 f.write(
"ObjSize[4bytes]: %d \n" % os)
263 f.write(
"NObjs : %d \n" % no)
264 f.write(
"NChannels : %d \n" % nc)
265 f.write(
"NGains : %d \n" % ng)
269 for ros
in range(0,5):
273 flt = blobReader.getDrawer(ros, mod,(run,lumi),
False,
False)
274 flt2 = blobReader2.getDrawer(ros, mod,(run2,lumi2),
False,
False)
276 osc = flt.getObjSizeByte()//4
277 os2c = flt2.getObjSizeByte()//4
279 if (((os != osc)
or (os2 != os2c))
and answ !=
'y'):
280 if (ros==0
and osc==os2c
and os==os2):
281 log.warning(
"Object sizes are different for last drawer in DB (%s) and default drawer %s (%s)", os, modName, osc)
283 log.error(
"Object sizes are different for last drawer in DB (%s and %s) and drawer %s (%s and %s)", os, os2, modName, osc, os2c)
284 answ=input(
' continue anyway? (y/n)')
288 for ind
in range(0,oscMax):
294 chnName =
" %2i" % chn
295 for adc
in range(ng):
296 for ind
in range(0,oscMax):
298 v[ind] = flt.getData(chn, adc, ind)
300 v2[ind] = flt2.getData(chn, adc, ind)
301 dv12 = v[ind] - v2[ind]
306 dv12percent=dv12*100./v[ind]
308 dv12percent=dv12*100./v2[ind]
310 if abs(dv12) > maxdiff
and abs(dv12percent) > maxdiffpercent:
312 f.write(
'%s chann %2d adc %d ind %d val1 %d val2 %d diff %d \n' % (modName,chn,adc,ind,v[ind],v2[ind],dv12))
314 f.write(
'%s chann %2d adc %d ind %d val1 %s val2 %s diff %f \n' % (modName,chn,adc,ind,hex(
int(v[ind])),hex(
int(v2[ind])),dv12))
316 f.write(
'%s chann %2d adc %d ind %d val1 %.4f val2 %.4f diff %.4f %.2f%%\n' % (modName,chn,adc,ind,v[ind],v2[ind],dv12,dv12percent))
317 if writedif
and adc==0
and ind==0:
318 fd.write(
"%s ch %2d %.4f\n" % (modName,chn,dv12))