22tag1 =
"" if len(sys.argv) < 2
else sys.argv[1].rpartition(
"=")[2]
23tag2 =
"" if len(sys.argv) < 3
else sys.argv[2].rpartition(
"=")[2]
24opt =
"" if len(sys.argv) < 4
else sys.argv[3].rpartition(
"=")[2]
25run1 =
"" if len(sys.argv) < 5
else sys.argv[4].rpartition(
"=")[2]
26run2 =
"" if len(sys.argv) < 6
else sys.argv[5].rpartition(
"=")[2]
27schema =
"CREST" if len(sys.argv) < 7
else sys.argv[6]
28output =
"" if len(sys.argv) < 8
else sys.argv[7]
29author = os.getlogin()
if len(sys.argv) < 9
else sys.argv[8]
30if not output
or output.endswith(
"/")
or os.path.isdir(output):
31 output = os.path.join(output,
"tileCalib.json")
32elif not output.endswith(
".json"):
35from TileCalibBlobPython
import TileCalibTools
36from TileCalibBlobPython
import TileBchCrest
37from TileCalibBlobPython.TileCalibCrest
import MAXRUN
38from TileCalibBlobObjs.Classes
import TileCalibUtils, TileBchPrbs, \
41from TileCalibBlobPython.TileCalibLogger
import getLogger
42log = getLogger(
"SyncBch")
44log.setLevel(logging.DEBUG)
49 log.error(
"Please, use non-empty tag as first parameter (e.g. UPD1)")
52 log.error(
"Please, use non-empty tag as second parameter (e.g. UPD4)")
55 log.error(
"Please, use different tags as first and second parameter (e.g. UPD1 UPD4)")
58opt=opt[0].
upper()
if len(opt)>0
else " "
59copyall =
not (opt==
"1" or opt==
"Y" or opt==
"T" or opt==
"B")
61 log.info(
"Copying all statuses from %s to %s", tag1,tag2)
63 log.info(
"Copying only BAD statuses from %s to %s", tag1,tag2)
65if not run1.isdigit()
or int(run1) < 0:
68 if not badrun.isdigit():
69 log.info(
"First run number was not specified, using maximal possible run number %d for input DB", run1 )
71 log.warning(
"First run number %s is bad, using maximal possible run number %d for input DB", badrun, run1)
74if not run2.isdigit()
or int(run2) < 0:
76 run2=TileCalibTools.getNextRunNumber()
77 if not badrun.isdigit():
78 log.info(
"Second run number was not specified, using next run number %d for output DB", run2 )
80 log.warning(
"Second run number %s is bad, using next run number %d for output DB", badrun, run2)
81 if run2
is None or run2<0:
82 log.error(
"Still bad run number")
88log.info(
"Using schema %s", schema)
97folder1 =
"/TILE/OFL02/STATUS/ADC"
98if "ONL" in tag1.upper():
99 log.error(
"Copy from ONL tag is not supported")
101if tag1.upper().startswith(
"TILE"):
105mgr1 = TileBchCrest.TileBchMgr()
106mgr1.setLogLvl(logging.DEBUG)
107log.info(
"Initializing with offline bad channels at tag=%s and time=%s", tag1, (run1, 0))
108mgr1.initialize(schema, folder1, tag1, (run1,0))
109tag1 = mgr1.getBlobReader().getTag()
112online =
"ONL" in tag2.upper()
114 folder2 =
"/TILE/ONL01/STATUS/ADC"
115 if tag2.upper().endswith(
'-HEAD'):
120 folder2 =
"/TILE/OFL02/STATUS/ADC"
121if tag2.upper().startswith(
"TILE"):
125mgr2 = TileBchCrest.TileBchMgr()
126mgr2.setLogLvl(logging.DEBUG)
127mgr2.initialize(schema, folder2, tag2, (run2,0), 2)
128tag2 = mgr2.getBlobReader().getTag()
132for ros
in range(1,5):
133 for mod
in range(0,64):
136 for chn
in range(0, 48):
137 statlo = mgr1.getAdcStatus(ros, mod, chn, 0)
138 stathi = mgr1.getAdcStatus(ros, mod, chn, 1)
140 statloBefore = mgr2.getAdcProblems(ros,mod,chn,0)
141 stathiBefore = mgr2.getAdcProblems(ros,mod,chn,1)
146 for prb
in [TileBchPrbs.TrigGeneralMask,
147 TileBchPrbs.TrigNoGain,
148 TileBchPrbs.TrigHalfGain,
149 TileBchPrbs.TrigNoisy]:
150 mgr2.delAdcProblem(ros, mod, chn, 0, prb)
151 mgr2.delAdcProblem(ros, mod, chn, 1, prb)
153 if not statlo.isGood():
154 prbs = statlo.getPrbs()
156 if prb
in [TileBchPrbs.TrigGeneralMask,
157 TileBchPrbs.TrigNoGain,
158 TileBchPrbs.TrigHalfGain,
159 TileBchPrbs.TrigNoisy]:
160 mgr2.addAdcProblem(ros, mod, chn, 0, prb)
161 mgr2.addAdcProblem(ros, mod, chn, 1, prb)
163 if copyall
or statlo.isBad()
or stathi.isBad():
166 if statlo.isBad()
and stathi.isBad():
167 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
168 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
169 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
170 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
172 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
173 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
174 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
175 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
177 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
178 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
179 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
180 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
183 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
184 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
185 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
186 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
189 if statlo.isWrongBCID()
or stathi.isWrongBCID():
190 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
191 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
194 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
195 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
198 if statlo.isBadTiming()
or stathi.isBadTiming():
199 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
200 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
203 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
204 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
207 if statlo.isTimingDmuBcOffsetPos()
or stathi.isTimingDmuBcOffsetPos():
208 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
209 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
212 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
213 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
216 if statlo.isTimingDmuBcOffsetNeg()
or stathi.isTimingDmuBcOffsetNeg():
217 mgr2.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
218 mgr2.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
221 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
222 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
224 if copyall
or (statlo.isBad()
and not mgr2.getAdcStatus(ros, mod, chn, 0).isBad()):
225 mgr2.setAdcStatus(ros,mod,chn,0,statlo)
226 if copyall
or (stathi.isBad()
and not mgr2.getAdcStatus(ros, mod, chn, 1).isBad()):
227 mgr2.setAdcStatus(ros,mod,chn,1,stathi)
229 statloAfter = mgr2.getAdcProblems(ros,mod,chn,0)
230 stathiAfter = mgr2.getAdcProblems(ros,mod,chn,1)
232 if (statloBefore != statloAfter)
or (stathiBefore != stathiAfter):
233 pbm = [statloBefore, stathiBefore, statloAfter, stathiAfter]
237 if pbm[adc] != pbm[adc + 2]:
243 msg =
"%s %2i %1i " % (modName, chn, adc)
246 for prbCode
in sorted(prbs.keys()):
247 prbDesc = prbs[prbCode]
248 msg +=
" %5i (%s)" % (prbCode, prbDesc)
252 comm +=
" ch %d" % chn
254 comment +=
" " + modName + comm
258 mgr2.commitToDb(output, folder2, tag2, (TileBchDecoder.BitPat_onl01
if online
else 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.