16 tag1 =
"" if len(sys.argv) < 2
else sys.argv[1].rpartition(
"=")[2]
17 tag2 =
"" if len(sys.argv) < 3
else sys.argv[2].rpartition(
"=")[2]
18 opt =
"" if len(sys.argv) < 4
else sys.argv[3].rpartition(
"=")[2]
19 run1 =
None if len(sys.argv) < 5
else int(sys.argv[4].rpartition(
"=")[2])
20 run2 =
None if len(sys.argv) < 6
else int(sys.argv[5].rpartition(
"=")[2])
23 from TileCalibBlobPython
import TileCalibTools
24 from TileCalibBlobPython
import TileBchTools
25 from TileCalibBlobPython.TileCalibTools
import MAXRUN
26 from TileCalibBlobObjs.Classes
import TileCalibUtils, TileBchPrbs, \
29 from TileCalibBlobPython.TileCalibLogger
import getLogger
32 log.setLevel(logging.DEBUG)
37 log.error(
"Please, use non-empty tag as first parameter (e.g. UPD1)")
40 log.error(
"Please, use non-empty tag as second parameter (e.g. UPD4)")
43 log.error(
"Please, use different tags as first and second parameter (e.g. UPD1 UPD4)")
46 opt=opt[0].
upper()
if len(opt)>0
else " "
47 copyall =
not (opt==
"1" or opt==
"Y" or opt==
"T" or opt==
"B")
49 log.info(
"Copying all statuses from %s to %s", tag1,tag2)
51 log.info(
"Copying only BAD statuses from %s to %s", tag1,tag2)
53 if run1
is None or run1 < 0:
57 log.info(
"First run number was not specified, using maximal possible run number %d for input DB", run1 )
59 log.warning(
"First run number %d is bad, using maximal possible run number %d for input DB", badrun, run1)
60 if run2
is None or run2 < 0:
62 run2=TileCalibTools.getLastRunNumber()
64 log.info(
"Second run number was not specified, using current run number %d for output DB", run2 )
66 log.warning(
"Second run number %d is bad, using current run number %d for output DB", badrun, run2)
67 if run2
is None or run2<0:
68 log.error(
"Still bad run number")
77 db1 = TileCalibTools.openDbConn(
'COOLOFL_TILE/CONDBR2')
78 folder1 =
"/TILE/OFL02/STATUS/ADC"
79 folderTag1 = TileCalibTools.getFolderTag(db1, folder1, tag1)
82 mgr1 = TileBchTools.TileBchMgr()
83 mgr1.setLogLvl(logging.DEBUG)
84 log.info(
"Initializing with offline bad channels at tag=%s and time=%s", folderTag1, (run1, 0))
85 mgr1.initialize(db1, folder1, folderTag1, (run1,0))
88 online = tag2[0:3].
upper()==
"ONL"
90 db2 = TileCalibTools.openDbConn(
'COOLONL_TILE/CONDBR2')
91 folder2 =
"/TILE/ONL01/STATUS/ADC"
94 db2 = TileCalibTools.openDbConn(
'COOLOFL_TILE/CONDBR2')
95 folder2 =
"/TILE/OFL02/STATUS/ADC"
96 folderTag2 = TileCalibTools.getFolderTag(db2, folder2, tag2)
99 mgr2 = TileBchTools.TileBchMgr()
100 mgr2.setLogLvl(logging.DEBUG)
101 mgr2.initialize(db2, folder2, folderTag2, (run2,0), 2)
105 for ros
in range(1,5):
106 for mod
in range(0,64):
109 for chn
in range(0, 48):
110 statlo = mgr1.getAdcStatus(ros, mod, chn, 0)
111 stathi = mgr1.getAdcStatus(ros, mod, chn, 1)
113 statloBefore = mgr2.getAdcProblems(ros,mod,chn,0)
114 stathiBefore = mgr2.getAdcProblems(ros,mod,chn,1)
119 for prb
in [TileBchPrbs.TrigGeneralMask,
120 TileBchPrbs.TrigNoGain,
121 TileBchPrbs.TrigHalfGain,
122 TileBchPrbs.TrigNoisy]:
123 mgr2.delAdcProblem(ros, mod, chn, 0, prb)
124 mgr2.delAdcProblem(ros, mod, chn, 1, prb)
126 if not statlo.isGood():
127 prbs = statlo.getPrbs()
129 if prb
in [TileBchPrbs.TrigGeneralMask,
130 TileBchPrbs.TrigNoGain,
131 TileBchPrbs.TrigHalfGain,
132 TileBchPrbs.TrigNoisy]:
133 mgr2.addAdcProblem(ros, mod, chn, 0, prb)
134 mgr2.addAdcProblem(ros, mod, chn, 1, prb)
136 if copyall
or statlo.isBad()
or stathi.isBad():
139 if statlo.isBad()
and stathi.isBad():
140 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
141 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
142 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
143 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
145 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
146 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
147 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
148 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
150 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
151 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
152 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
153 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
156 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
157 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
158 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
159 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
162 if statlo.isWrongBCID()
or stathi.isWrongBCID():
163 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
164 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
167 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
168 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
171 if statlo.isBadTiming()
or stathi.isBadTiming():
172 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
173 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
176 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
177 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
180 if statlo.isTimingDmuBcOffsetPos()
or stathi.isTimingDmuBcOffsetPos():
181 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
182 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
185 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
186 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
189 if statlo.isTimingDmuBcOffsetNeg()
or stathi.isTimingDmuBcOffsetNeg():
190 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
191 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
194 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
195 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
197 if copyall
or (statlo.isBad()
and not mgr2.getAdcStatus(ros, mod, chn, 0).isBad()):
198 mgr2.setAdcStatus(ros,mod,chn,0,statlo)
199 if copyall
or (stathi.isBad()
and not mgr2.getAdcStatus(ros, mod, chn, 1).isBad()):
200 mgr2.setAdcStatus(ros,mod,chn,1,stathi)
202 statloAfter = mgr2.getAdcProblems(ros,mod,chn,0)
203 stathiAfter = mgr2.getAdcProblems(ros,mod,chn,1)
205 if (statloBefore != statloAfter)
or (stathiBefore != stathiAfter):
206 pbm = [statloBefore, stathiBefore, statloAfter, stathiAfter]
210 if pbm[adc] != pbm[adc + 2]:
216 msg =
"%s %2i %1i " % (modName, chn, adc)
219 for prbCode
in sorted(prbs.keys()):
220 prbDesc = prbs[prbCode]
221 msg +=
" %5i (%s)" % (prbCode, prbDesc)
225 comm +=
" ch %d" % chn
227 comment +=
" " + modName + comm
232 dbw = TileCalibTools.openDb(
'SQLITE',
'CONDBR2',
'RECREATE',
'COOLONL_TILE')
233 mgr2.commitToDb(dbw, folder2, folderTag2, TileBchDecoder.BitPat_onl01,
"tilebeam",
"synchronizing with %s; updated channels:%s" %(tag1, comment), (run2,0))
235 dbw = TileCalibTools.openDb(
'SQLITE',
'CONDBR2',
'RECREATE',
'COOLOFL_TILE')
236 mgr2.commitToDb(dbw, folder2, folderTag2, TileBchDecoder.BitPat_ofl01,
"tilebeam",
"synchronizing with %s; updated channels:%s" %(tag1, comment), (run2,0))
239 log.warning(
"Folders are in sync, nothing to update")