18 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
19 print (
"""Uses bch-input-sqlite.db file as input, joins adjacent IOVs with same contents, keeping the
20 comments from the earliest one. Results written to bch-output-sqlite.db""")
22 print (
"-h, --help shows this help")
23 print (
"-f, --folder= specify status folder to use ONL01, OFL01 or OFL02 ")
24 print (
"-t, --tag= specify tag to use, f.i. UPD1 or UPD4")
25 print (
"-o, --outtag= specify output tag to be used for cleaned up result, f.i. UPD4-99")
26 print (
"-i, --instance= specify DB instance (CONDBR2 or COMP200 or OFLP200)")
34 stat = mgr.getAdcStatus(ros,mod,chn,adc)
35 prbs = mgr.getAdcProblems(ros,mod,chn,adc)
37 msg =
"%s %2i %1i " % (modName,chn,adc)
38 for prbCode
in sorted(prbs.keys()):
39 prbDesc = prbs[prbCode]
40 msg +=
" %5i (%s)" % (prbCode,prbDesc)
43 elif stat.isAffected():
51 return (
int(iov >> 32),
int(iov & 0xFFFFFFFF))
55 """ Writes out blob into folder fdout, at channel related to
56 ros,mod and with validity range given by since,until
58 log.info(
"Writing merged IOV: [%i,%i]-[%i,%i)", (since>>32),(since&0xffffffff),(until>>32),(until&0xffffffff))
79 lumSince = since&0xffffffff
81 lumUntil = until&0xffffffff
84 if lumUntil == 4294967295
and runUntil != 2147483647:
88 msg =
'AtlCoolCopy \"%s\" \"%s\" -folder /TILE/OFL02/STATUS/ADC -tag %s -rls %i %i -rlu %i %i -alliov -outtag %s -ch %i -nrls %i %i -nrlu %i %i' % (ischema,oschema,folderTag,runSince,lumSince,runSince,lumSince+1,outtagFull,chanNum,runSince,lumSince,runUntil,lumUntil)
94 if __name__ ==
"__main__":
97 keywords = [
"help",
"tag=",
"folder=",
"outtag=",
"instance="]
99 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
100 except getopt.GetoptError
as err:
107 folderPath =
"/TILE/OFL02/STATUS/ADC"
108 tag =
"OFLCOND-MC16-SDR-28"
114 if o
in (
"-f",
"--folder"):
115 folderPath =
"/TILE/%s/STATUS/ADC" % a
116 elif o
in (
"-t",
"--tag"):
118 elif o
in (
"-o",
"--outtag"):
120 elif o
in (
"-i",
"--instance"):
128 elif o
in (
"-h",
"--help"):
132 raise RuntimeError(
"unhandled option")
135 from TileCalibBlobPython.TileCalibLogger
import getLogger
138 log.setLevel(logging.INFO)
140 ischema =
'sqlite://;schema=bch-input-sqlite.db;dbname='+instance
141 oschema =
'sqlite://;schema=bch-output-sqlite.db;dbname='+instance
142 log.info(
"ischema=%s",ischema)
143 log.info(
"oschema=%s", oschema)
146 from TileCalibBlobPython
import TileCalibTools
147 from TileCalibBlobPython
import TileBchTools
148 from TileCalibBlobObjs.Classes
import TileCalibUtils, TileBchDecoder, \
149 TileCalibDrawerBch, TileBchStatus
152 idb = TileCalibTools.openDbConn(ischema,
'READONLY')
156 folderTag = TileCalibTools.getFolderTag(idb
if 'CONDBR2' in ischema
else ischema, folderPath, tag)
159 blobReader = TileCalibTools.TileBlobReader(idb,folderPath, folderTag)
163 outtagFull =
'TileOfl02StatusAdc-'+outtag
167 log.info(
"Input folder for cleaning: %s with tag %s", folderPath, folderTag)
177 msg =
'AtlCoolCopy \"%s\" \"%s\" -folder /TILE/OFL02/STATUS/ADC -tag %s -outtag %s -ch1 0 -ch2 19 -create' % (ischema,oschema,folderTag,outtagFull)
189 rosinput =
int(sys.argv[1])
if len(sys.argv)>1
else 0
190 log.info(
"rosinput=%i", rosinput)
198 for ros
in range(rosmin,rosmax):
202 log.info(40*
'='+
" ros %d, drawer %s", ros, modName)
204 dbobjs = blobReader.getDBobjsWithinRange(ros, mod)
206 raise Exception(
"No DB objects retrieved for ros=%d mod=%d (%s)" % (ros,mod,modName))
212 mergedSince = mergedUntil =
None
216 blobPrev = blob =
None
217 calibDrawerPrev = calibDrawer =
None
222 while dbobjs.goToNext():
226 calibDrawerPrev = calibDrawer
230 obj = dbobjs.currentRef()
231 objsince = obj.since()
232 objuntil = obj.until()
235 if mergedSince
is None and mergedUntil
is None:
236 mergedSince = objsince
237 mergedUntil = objuntil
240 lum = objsince & 0xFFFFFFFF
241 blob = obj.payload()[0]
245 if iovCounter%10 == 0:
246 log.info(
"Heartbeat %d: blob size=%d - [%d,%d]-[%d,%d)",
247 iovCounter, blob.size(), run, lum, (objuntil>>32), (objuntil&0xFFFFFFFF) )
249 log.debug(
"blob size=%d - [%d,%d]-[%d,%d)",
250 blob.size(), run, lum, (objuntil>>32), (objuntil&0xFFFFFFFF))
252 if blob.size() == 596:
255 except Exception
as err:
256 log.error(
"ros=%i mod=%i last read: runPrev=%i lumPrev=%i\n %s",
257 ros, mod, runPrev, lumPrev,
str(err))
259 if calibDrawer
is None:
261 if calibDrawerPrev
is None:
263 mergedUntil = objuntil
265 log.warning(
"extending IOV due to non-existent blob!!!" )
267 log.info(
"extending IOV due to zero-size blob!!!" )
269 log.warning(
"extending IOV due to invalid-size blob!!!" )
274 log.info(
"types: %s %s",
type(blob),
type(calibDrawerPrev))
278 mergedSince = objsince
279 mergedUntil = objuntil
280 tempRunLum =
"Starting new IOV at: [%d,%d]" % (mergedSince>>32, mergedSince&0xffffffff)
282 log.warning(
"%s (non-existent blob!!!)", tempRunLum )
284 log.info(
"%s (zero-size blob!!!)", tempRunLum )
286 log.warning(
"%s (invalid-size blob!!!)", tempRunLum )
294 mgr = TileBchTools.TileBchMgr()
295 mgr.setLogLvl(logging.ERROR)
296 mgr.initialize(idb, folderPath, folderTag, (run,lum))
297 log.debug(
"TileBchMgr initialized.")
306 if objPrev
is not None:
307 if calibDrawerPrev
is None:
310 sizelo = calibDrawerPrev.getObjSizeByte()//4
311 sizehi = calibDrawer.getObjSizeByte()//4
312 if (sizelo != sizehi):
313 log.error(
"Object sizes are different for ROS %s (%s %s) drawer %s", ros, sizelo, sizehi, modName)
315 typelo = calibDrawerPrev.getObjType()
316 typehi = calibDrawer.getObjType()
322 if (typelo != typehi):
323 log.error(
"Object types %s %s are different", typelo, typehi)
338 adcBits = calibDrawer.getData(chn, adc, ind)
339 chnBits = calibDrawer.getData(chn, 2, ind)
342 adcBits = calibDrawerPrev.getData(chn, adc, ind)
343 chnBits = calibDrawerPrev.getData(chn, 2, ind)
346 adclo = calibDrawerPrev.getData(chn, adc, ind)
347 adchi = calibDrawer.getData(chn, adc, ind)
348 chnlo = calibDrawerPrev.getData(chn, 2, ind)
349 chnhi = calibDrawer.getData(chn, 2, ind)
350 diff = adclo - adchi + chnlo - chnhi
352 if not (status==statusPrev):
354 log.info(
"chn=%i adc=%i ind=%i - vlo=%i, vhi=%i, diffs=%i %i", chn, adc, ind, adclo+chnlo, adchi+chnhi, adclo-adchi, chnlo-chnhi)
358 if identical
is True:
360 mergedUntil = objuntil
364 log.info(
"types: %s %s",
type(blob),
type(calibDrawerPrev))
368 mergedSince = objsince
369 mergedUntil = objuntil
370 log.info(
"Starting new IOV at: [%d,%d]",
371 mergedSince>>32, mergedSince&0xffffffff)
375 if objuntil == 0x7fffffffffffffff:
376 log.info(
"Writing last IOV: calling writeMergedIOV by hand...")