26 from TileCalibBlobPython
import TileCalibTools
27 from TileCalibBlobObjs.Classes
import TileCalibUtils
28 import os, sys, getopt
29 os.environ[
'TERM'] =
'linux'
32 from builtins
import input
44 folderPath =
"/TILE/OFL02/CALIB/CES"
46 tag =
"RUN2-HLT-UPD1-01"
48 schema =
"COOLOFL_TILE"
60 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='])
62 for opt, arg
in options:
66 elif opt
in (
'--run'):
68 elif opt
in (
'--run2'):
70 elif opt
in (
'--lumi'):
72 elif opt
in (
'--lumi2'):
74 elif opt
in (
'--maxdiff'):
76 elif opt
in (
'--maxdiffpercent'):
77 maxdiffpercent =
float(arg)
78 elif opt
in (
'--folder'):
80 elif opt
in (
'--folder2'):
82 elif opt
in (
'--tag'):
84 elif opt
in (
'--tag2'):
86 elif opt
in (
'--schema'):
88 elif opt
in (
'--schema2'):
90 elif opt
in (
'--instance'):
92 elif opt
in (
'--instance2'):
94 elif opt
in (
'--server'):
96 elif opt
in (
'--server2'):
98 elif opt
in (
'--sqlfn'):
100 elif opt
in (
'--sqlfn2'):
107 if folderPath2==
"none":
108 folderPath2=folderPath
113 if instance2==
"none":
123 print (
'run ',run,
'lumi ',lumi,
'run2 ',run2,
'lumi2 ',lumi2)
124 print (
'maxdiff ',maxdiff)
125 print (
'maxdiffpercent ',maxdiffpercent)
126 print (
'folder ',folderPath,
'folder2 ',folderPath2)
127 print (
'tag ',tag,
'tag2 ',tag2)
128 print (
'schema ', schema,
'schema2 ', schema2)
129 print (
'instance ', instance,
'instance2 ', instance2)
130 print (
'server ', server,
'server2 ', server2)
131 print (
'sqlfn ',sqlfn,
'sqlfn2 ',sqlfn2)
134 print (
'******** Above, the defaults are shown, one can change them')
135 print (
' using command-line options: ReadFromCoolCompare.py --option=value')
136 print (
' Any number of options in random order can be given')
137 print (
' If run2,lumi2,schema2,tag2 or instance2 are not given, the values')
138 print (
' of run,lumi,schema,tag and instance will be assigned to them')
139 print (
'For singleversion folders (ONL01) there should be option with empty tag: --tag=')
140 print (
'conditions with options maxdiffpercent and maxdiff are used')
141 print (
' in logical AND, so, both have to be TRUE to print the data')
142 print (
'\n Examples:')
143 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')
144 print (
'\npython ReadFromCoolCompare.py --folder=/TILE/ONL01/FRAG1 --schema=COOLONL_TILE --tag= --maxdiffpercent=5.5 --run=160000 --run2=999999999')
148 connStr=schema+
'/'+instance
if ':' not in schema
and ';' not in schema
and '/' not in schema
else schema
149 connStr2=schema2+
'/'+instance2
if ':' not in schema2
and ';' not in schema2
and '/' not in schema2
else schema2
157 db = TileCalibTools.openDbConn(connStr, server)
159 db = TileCalibTools.openDb(
'SQLITE', instance,
'READONLY',schema,sqlfn)
161 db2 = TileCalibTools.openDbConn(connStr2, server2)
163 db2 = TileCalibTools.openDb(
'SQLITE', instance2,
'READONLY',schema2,sqlfn2)
174 if tag.startswith(
'TileO'):
181 if tag2.startswith(
'TileO'):
190 from TileCalibBlobPython.TileCalibLogger
import getLogger
193 log.setLevel(logging.DEBUG)
195 if run2!=run
and tag2==tag
and folderPath2==folderPath
and folderPath.startswith(
"/TILE/OFL02/TIME"):
196 fd=
open(
'from_%d_to_%d.dif'%(run2,run),
'w')
201 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
202 log.info(
"Initializing folder %s with tag %s", folderPath2, folderTag2)
204 blobReader = TileCalibTools.TileBlobReader(db,folderPath, folderTag)
205 blobReader2 = TileCalibTools.TileBlobReader(db2,folderPath2, folderTag2)
212 log.info(
"Initializing for run1 %d lumi %d run2 %d lumi2 %d maxdiff %f maxdiffpercent %f", run, lumi, run2, lumi2, maxdiff,maxdiffpercent)
213 log.info(
"Comment1: %s", blobReader.getComment((run,lumi)))
214 log.info(
"Comment2: %s", blobReader2.getComment((run2,lumi2)))
224 log.error(
"No valid drawers in first database")
227 flt = blobReader.getDrawer(r, d, (run,lumi),
False,
False)
229 ot = flt.getObjType()
230 ov = flt.getObjVersion()
231 os = flt.getObjSizeByte()//4
244 log.error(
"No valid drawers in second database")
247 flt2 = blobReader2.getDrawer(r, d, (run2,lumi2),
False,
False)
248 ot2 = flt2.getObjType()
249 os2 = flt2.getObjSizeByte()//4
251 if (os != os2)
or (ot != ot2):
252 log.error(
"Object sizes (%s vs %s) or types (%s vs %s) are different", os, os2, ot, ot2)
253 answ=
input(
' continue anyway? (y/n)')
259 for ind
in range(0,os):
263 f.write(
"Command line parameters used: \n %s \n" % sys.argv[1:])
264 f.write(
"---- Object header for ros=%d drawer=%d \n" % (r,d))
265 f.write(
"ObjType : %d \n" % ot)
266 f.write(
"ObjVersion : %d \n" % ov)
267 f.write(
"ObjSize[4bytes]: %d \n" % os)
268 f.write(
"NObjs : %d \n" % no)
269 f.write(
"NChannels : %d \n" % nc)
270 f.write(
"NGains : %d \n" % ng)
274 for ros
in range(0,5):
278 flt = blobReader.getDrawer(ros, mod,(run,lumi),
False,
False)
279 flt2 = blobReader2.getDrawer(ros, mod,(run2,lumi2),
False,
False)
281 osc = flt.getObjSizeByte()//4
282 os2c = flt2.getObjSizeByte()//4
284 if (((os != osc)
or (os2 != os2c))
and answ !=
'y'):
285 if (ros==0
and osc==os2c
and os==os2):
286 log.warning(
"Object sizes are different for last drawer in DB (%s) and default drawer %s (%s)", os, modName, osc)
288 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)
289 answ=
input(
' continue anyway? (y/n)')
293 for ind
in range(0,oscMax):
299 chnName =
" %2i" % chn
300 for adc
in range(ng):
301 for ind
in range(0,oscMax):
303 v[ind] = flt.getData(chn, adc, ind)
305 v2[ind] = flt2.getData(chn, adc, ind)
306 dv12 = v[ind] - v2[ind]
311 dv12percent=dv12*100./v[ind]
313 dv12percent=dv12*100./v2[ind]
315 if abs(dv12) > maxdiff
and abs(dv12percent) > maxdiffpercent:
317 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))
319 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))
321 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))
322 if writedif
and adc==0
and ind==0:
323 fd.write(
"%s ch %2d %.4f\n" % (modName,chn,dv12))