17 tag =
"UPD1" if len(sys.argv) < 2
else sys.argv[1].rpartition(
"=")[2]
18 run =
None if len(sys.argv) < 3
else int(sys.argv[2].rpartition(
"=")[2])
20 from TileCalibBlobPython
import TileCalibTools
21 from TileCalibBlobPython
import TileBchTools
22 from TileCalibBlobPython.TileCalibTools
import MAXRUN
23 from TileCalibBlobObjs.Classes
import TileCalibUtils, TileBchPrbs, \
26 from TileCalibBlobPython.TileCalibLogger
import getLogger
29 log.setLevel(logging.DEBUG)
31 if run
is None or run < 0:
33 run=TileCalibTools.getLastRunNumber()
35 log.info(
"Run number was not specified, using current run number %d", run )
37 log.warning(
"Bad run number %d was set, using current run number %d", badrun, run)
38 if run
is None or run<0:
39 log.error(
"Still bad run number")
48 folder =
"/TILE/OFL02/STATUS/ADC"
51 db1 = TileCalibTools.openDbConn(
'COOLOFL_TILE/CONDBR2')
52 folderTag = TileCalibTools.getFolderTag(db1, folder, tag)
55 mgrOfl = TileBchTools.TileBchMgr()
56 mgrOfl.setLogLvl(logging.DEBUG)
57 log.info(
"Initializing with offline bad channels at tag=%s and time=%s", folderTag, (runOfl, 0))
58 mgrOfl.initialize(db1, folder, folderTag, (runOfl,0))
62 folderOnl =
"/TILE/ONL01/STATUS/ADC"
66 db = TileCalibTools.openDbConn(
'COOLONL_TILE/CONDBR2')
68 mgrOnl = TileBchTools.TileBchMgr()
69 mgrOnl.setLogLvl(logging.DEBUG)
70 mgrOnl.initialize(db, folderOnl, folderTagOnl, (runOnl,0), 2)
73 log.info(
"================================================================ ")
79 for ros
in range(1,5):
80 for mod
in range(0,64):
83 for chn
in range(0, 48):
84 statlo = mgrOfl.getAdcStatus(ros, mod, chn, 0)
85 stathi = mgrOfl.getAdcStatus(ros, mod, chn, 1)
87 statloBefore = mgrOnl.getAdcProblems(ros,mod,chn,0)
88 stathiBefore = mgrOnl.getAdcProblems(ros,mod,chn,1)
91 for prb
in [TileBchPrbs.TrigGeneralMask,
92 TileBchPrbs.TrigNoGain,
93 TileBchPrbs.TrigHalfGain,
94 TileBchPrbs.TrigNoisy]:
95 mgrOnl.delAdcProblem(ros, mod, chn, 0, prb)
96 mgrOnl.delAdcProblem(ros, mod, chn, 1, prb)
98 if not statlo.isGood():
99 prbs = statlo.getPrbs()
101 if prb
in [TileBchPrbs.TrigGeneralMask,
102 TileBchPrbs.TrigNoGain,
103 TileBchPrbs.TrigHalfGain,
104 TileBchPrbs.TrigNoisy]:
105 mgrOnl.addAdcProblem(ros, mod, chn, 0, prb)
106 mgrOnl.addAdcProblem(ros, mod, chn, 1, prb)
110 if statlo.isBad()
and stathi.isBad():
111 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
112 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
113 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
114 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
116 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
117 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
118 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
119 mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
121 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
122 mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
123 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
124 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
127 mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
128 mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
129 mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
130 mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
133 if statlo.isWrongBCID()
or stathi.isWrongBCID():
134 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
135 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
138 mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
139 mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
142 if statlo.isBadTiming()
or stathi.isBadTiming():
143 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
144 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
147 mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
148 mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
151 if statlo.isTimingDmuBcOffsetPos()
or stathi.isTimingDmuBcOffsetPos():
152 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
153 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
156 mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
157 mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
160 if statlo.isTimingDmuBcOffsetNeg()
or stathi.isTimingDmuBcOffsetNeg():
161 mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
162 mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
165 mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
166 mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
168 statloAfter = mgrOnl.getAdcProblems(ros, mod, chn, 0)
169 stathiAfter = mgrOnl.getAdcProblems(ros, mod, chn, 1)
170 if (statloBefore != statloAfter)
or (stathiBefore != stathiAfter):
171 pbm = [statloBefore, stathiBefore, statloAfter, stathiAfter]
175 if pbm[adc] != pbm[adc + 2]:
181 msg =
"%s %2i %1i " % (modName, chn, adc)
184 for prbCode
in sorted(prbs.keys()):
185 prbDesc = prbs[prbCode]
186 msg +=
" %5i (%s)" % (prbCode, prbDesc)
190 comm +=
" ch %d" % chn
192 comment +=
" " + modName + comm
199 db2 = TileCalibTools.openDb(
'SQLITE',
'CONDBR2',
'RECREATE',
'COOLONL_TILE')
200 mgrOnl.commitToDb(db2, folderOnl, folderTagOnl, TileBchDecoder.BitPat_onl01,
"tilebeam",
"synchronizing with %s; updated channels:%s" %(tag, comment), (runOnl,0))
203 log.warning(
"Folders are in sync, nothing to update")