19tag1 =
"" if len(sys.argv) < 2
else sys.argv[1].rpartition(
"=")[2]
20tag2 =
"" if len(sys.argv) < 3
else sys.argv[2].rpartition(
"=")[2]
21opt =
"" if len(sys.argv) < 4
else sys.argv[3].rpartition(
"=")[2]
22run1 =
"" if len(sys.argv) < 5
else sys.argv[4].rpartition(
"=")[2]
23run2 =
"" if len(sys.argv) < 6
else sys.argv[5].rpartition(
"=")[2]
24schema=
"" if len(sys.argv) < 7
else sys.argv[6]
27author = os.getlogin()
if len(sys.argv) < 9
else sys.argv[8]
29from TileCalibBlobPython
import TileCalibTools
30from TileCalibBlobPython
import TileBchTools
31from TileCalibBlobPython.TileCalibTools
import MAXRUN
32from TileCalibBlobObjs.Classes
import TileCalibUtils, TileBchPrbs, \
35from TileCalibBlobPython.TileCalibLogger
import getLogger
36log = getLogger(
"SyncBch")
38log.setLevel(logging.DEBUG)
43 log.error(
"Please, use non-empty tag as first parameter (e.g. UPD1)")
46 log.error(
"Please, use non-empty tag as second parameter (e.g. UPD4)")
49 log.error(
"Please, use different tags as first and second parameter (e.g. UPD1 UPD4)")
52opt=opt[0].
upper()
if len(opt)>0
else " "
53copyall =
not (opt==
"1" or opt==
"Y" or opt==
"T" or opt==
"B")
55 log.info(
"Copying all statuses from %s to %s", tag1,tag2)
57 log.info(
"Copying only BAD statuses from %s to %s", tag1,tag2)
59if not run1.isdigit()
or int(run1) < 0:
62 if not badrun.isdigit():
63 log.info(
"First run number was not specified, using maximal possible run number %d for input DB", run1 )
65 log.warning(
"First run number %s is bad, using maximal possible run number %d for input DB", badrun, run1)
68if not run2.isdigit()
or int(run2) < 0:
70 run2=TileCalibTools.getNextRunNumber()
71 if not badrun.isdigit():
72 log.info(
"Second run number was not specified, using next run number %d for output DB", run2 )
74 log.warning(
"Second run number %s is bad, using next run number %d for output DB", badrun, run2)
75 if run2
is None or run2<0:
76 log.error(
"Still bad run number")
81 schema=
"COOLOFL_TILE/CONDBR2"
82log.info(
"Using schema %s", schema)
83if tag2[0:3].
upper()==
"ONL":
84 schema2=schema.replace(
"COOLOFL_TILE",
"COOLONL_TILE")
85 schema=schema2.replace(
"COOLONL_TILE",
"COOLOFL_TILE")
87 log.info(
"Second schema %s", schema2)
98db1 = TileCalibTools.openDbConn(schema)
99folder1 =
"/TILE/OFL02/STATUS/ADC"
100folderTag1 = TileCalibTools.getFolderTag(db1, folder1, tag1)
103mgr1 = TileBchTools.TileBchMgr()
104mgr1.setLogLvl(logging.DEBUG)
105log.info(
"Initializing with offline bad channels at tag=%s and time=%s", folderTag1, (run1, 0))
106mgr1.initialize(db1, folder1, folderTag1, (run1,0))
111 db2 = TileCalibTools.openDbConn(schema2)
112 folder2 =
"/TILE/ONL01/STATUS/ADC"
115 db2 = TileCalibTools.openDbConn(schema)
116 folder2 =
"/TILE/OFL02/STATUS/ADC"
117 folderTag2 = TileCalibTools.getFolderTag(db2, folder2, tag2)
120mgr2 = TileBchTools.TileBchMgr()
121mgr2.setLogLvl(logging.DEBUG)
122mgr2.initialize(db2, folder2, folderTag2, (run2,0), 2)
126for ros
in range(1,5):
127 for mod
in range(0,64):
130 for chn
in range(0, 48):
131 statlo = mgr1.getAdcStatus(ros, mod, chn, 0)
132 stathi = mgr1.getAdcStatus(ros, mod, chn, 1)
134 statloBefore = mgr2.getAdcProblems(ros,mod,chn,0)
135 stathiBefore = mgr2.getAdcProblems(ros,mod,chn,1)
140 for prb
in [TileBchPrbs.TrigGeneralMask,
141 TileBchPrbs.TrigNoGain,
142 TileBchPrbs.TrigHalfGain,
143 TileBchPrbs.TrigNoisy]:
144 mgr2.delAdcProblem(ros, mod, chn, 0, prb)
145 mgr2.delAdcProblem(ros, mod, chn, 1, prb)
147 if not statlo.isGood():
148 prbs = statlo.getPrbs()
150 if prb
in [TileBchPrbs.TrigGeneralMask,
151 TileBchPrbs.TrigNoGain,
152 TileBchPrbs.TrigHalfGain,
153 TileBchPrbs.TrigNoisy]:
154 mgr2.addAdcProblem(ros, mod, chn, 0, prb)
155 mgr2.addAdcProblem(ros, mod, chn, 1, prb)
157 if copyall
or statlo.isBad()
or stathi.isBad():
160 if statlo.isBad()
and stathi.isBad():
161 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
162 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
163 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
164 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
166 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
167 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
168 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
169 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
171 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
172 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
173 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
174 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
177 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
178 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
179 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
180 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
183 if statlo.isWrongBCID()
or stathi.isWrongBCID():
184 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
185 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
188 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
189 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
192 if statlo.isBadTiming()
or stathi.isBadTiming():
193 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
194 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
197 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
198 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
201 if statlo.isTimingDmuBcOffsetPos()
or stathi.isTimingDmuBcOffsetPos():
202 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
203 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
206 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
207 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
210 if statlo.isTimingDmuBcOffsetNeg()
or stathi.isTimingDmuBcOffsetNeg():
211 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
212 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
215 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
216 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
218 if copyall
or (statlo.isBad()
and not mgr2.getAdcStatus(ros, mod, chn, 0).isBad()):
219 mgr2.setAdcStatus(ros,mod,chn,0,statlo)
220 if copyall
or (stathi.isBad()
and not mgr2.getAdcStatus(ros, mod, chn, 1).isBad()):
221 mgr2.setAdcStatus(ros,mod,chn,1,stathi)
223 statloAfter = mgr2.getAdcProblems(ros,mod,chn,0)
224 stathiAfter = mgr2.getAdcProblems(ros,mod,chn,1)
226 if (statloBefore != statloAfter)
or (stathiBefore != stathiAfter):
227 pbm = [statloBefore, stathiBefore, statloAfter, stathiAfter]
231 if pbm[adc] != pbm[adc + 2]:
237 msg =
"%s %2i %1i " % (modName, chn, adc)
240 for prbCode
in sorted(prbs.keys()):
241 prbDesc = prbs[prbCode]
242 msg +=
" %5i (%s)" % (prbCode, prbDesc)
246 comm +=
" ch %d" % chn
248 comment +=
" " + modName + comm
253 dbw = TileCalibTools.openDb(
'SQLITE',
'CONDBR2',
'RECREATE',
'COOLONL_TILE')
254 mgr2.commitToDb(dbw, folder2, folderTag2, TileBchDecoder.BitPat_onl01, author,
"synchronizing with %s; updated channels:%s" %(tag1, comment), (run2,0))
256 dbw = TileCalibTools.openDb(
'SQLITE',
'CONDBR2',
'RECREATE',
'COOLOFL_TILE')
257 mgr2.commitToDb(dbw, folder2, folderTag2, TileBchDecoder.BitPat_ofl01, author,
"synchronizing with %s; updated channels:%s" %(tag1, comment), (run2,0))
260 log.warning(
"Folders are in sync, nothing to update")
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.