ATLAS Offline Software
Loading...
Searching...
No Matches
TileSynchronizeBch.py
Go to the documentation of this file.
1#!/bin/env python
2
3# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4#
5# TileSynchronizeBch.py <TAG1> <TAG2> <MASKONLY> <RUN1> <RUN2> <SCHEMA> <OUTPUT_DIR> <AUTHOR>
6# sanya.solodkov@cern.ch July 2016
7# copy bad status from one tag to another (e.g. from UPD4 to UPD1)
8# <TAG1> - origin tag (no default), can be UPD1 or UPD4 or exact tag
9# <TAG2> - destination (no default) can be UPD1 or UPD4 or ONL (for online DB)
10# <MASKONLY> - if "1" or "yes" or "True", channels are only masked and never unmasked
11# <RUN1> - run number to use for <TAG1> (default = MAXRUN)
12# <RUN2> - run number to use for <TAG2> and for sqlite (default = next run)
13# <SCHEMA> - full schema string for input database (optional)
14# <OUTPUT_DIR> - directory for output file tileSqlite.db (optional)
15# <AUTHOR> - user name for comment string (optional)
16
17import os,sys
18
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]
25if len(sys.argv) >= 8:
26 os.chdir(sys.argv[7])
27author = os.getlogin() if len(sys.argv) < 9 else sys.argv[8]
28
29from TileCalibBlobPython import TileCalibTools
30from TileCalibBlobPython import TileBchTools
31from TileCalibBlobPython.TileCalibTools import MAXRUN
32from TileCalibBlobObjs.Classes import TileCalibUtils, TileBchPrbs, \
33 TileBchDecoder
34
35from TileCalibBlobPython.TileCalibLogger import getLogger
36log = getLogger("SyncBch")
37import logging
38log.setLevel(logging.DEBUG)
39
40
41log.info("")
42if tag1=="":
43 log.error( "Please, use non-empty tag as first parameter (e.g. UPD1)")
44 sys.exit(2)
45if tag2=="":
46 log.error( "Please, use non-empty tag as second parameter (e.g. UPD4)")
47 sys.exit(2)
48if tag1==tag2:
49 log.error( "Please, use different tags as first and second parameter (e.g. UPD1 UPD4)")
50 sys.exit(2)
51
52opt=opt[0].upper() if len(opt)>0 else " "
53copyall = not (opt=="1" or opt=="Y" or opt=="T" or opt=="B")
54if copyall:
55 log.info( "Copying all statuses from %s to %s", tag1,tag2)
56else:
57 log.info( "Copying only BAD statuses from %s to %s", tag1,tag2)
58
59if not run1.isdigit() or int(run1) < 0:
60 badrun=run1
61 run1=MAXRUN
62 if not badrun.isdigit():
63 log.info( "First run number was not specified, using maximal possible run number %d for input DB", run1 )
64 else:
65 log.warning( "First run number %s is bad, using maximal possible run number %d for input DB", badrun, run1)
66else:
67 run1=int(run1)
68if not run2.isdigit() or int(run2) < 0:
69 badrun=run2
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 )
73 else:
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")
77 sys.exit(2)
78else:
79 run2=int(run2)
80if not schema:
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")
86 if schema!=schema2:
87 log.info( "Second schema %s", schema2)
88else:
89 schema2=schema
90
91log.info("")
92
93#===================================================================
94#====================== FILL DB BELOW ==============================
95#===================================================================
96
97#=== get DB1
98db1 = TileCalibTools.openDbConn(schema)
99folder1 = "/TILE/OFL02/STATUS/ADC"
100folderTag1 = TileCalibTools.getFolderTag(db1, folder1, tag1)
101
102#--- create first bad channel manager
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))
107
108#=== get DB2
109online = tag2[0:3].upper()=="ONL"
110if online:
111 db2 = TileCalibTools.openDbConn(schema2)
112 folder2 = "/TILE/ONL01/STATUS/ADC"
113 folderTag2 = ""
114else:
115 db2 = TileCalibTools.openDbConn(schema)
116 folder2 = "/TILE/OFL02/STATUS/ADC"
117 folderTag2 = TileCalibTools.getFolderTag(db2, folder2, tag2)
118
119#--- create second bad channel manager
120mgr2 = TileBchTools.TileBchMgr()
121mgr2.setLogLvl(logging.DEBUG)
122mgr2.initialize(db2, folder2, folderTag2, (run2,0), 2)
123
124#=== synchronize
125comment=""
126for ros in range(1,5):
127 for mod in range(0,64):
129 comm = ""
130 for chn in range(0, 48):
131 statlo = mgr1.getAdcStatus(ros, mod, chn, 0)
132 stathi = mgr1.getAdcStatus(ros, mod, chn, 1)
133
134 statloBefore = mgr2.getAdcProblems(ros,mod,chn,0)
135 stathiBefore = mgr2.getAdcProblems(ros,mod,chn,1)
136
137 if online:
138
139 # remove all trigger problems first
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)
146 # and now set new trigger problems (if any)
147 if not statlo.isGood():
148 prbs = statlo.getPrbs()
149 for prb in prbs:
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)
156
157 if copyall or statlo.isBad() or stathi.isBad():
158 #--- add IgnoreInHlt if either of the ADCs has isBad
159 #--- add OnlineGeneralMaskAdc if the ADCs has 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)
165 elif statlo.isBad():
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)
170 elif stathi.isBad():
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)
175 else:
176 #--- delete IgnoreInHlt and OnlineGeneralMaskAdc if both ADCs are not Bad
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)
181
182 #--- add OnlineWrongBCID if either of the ADCs has isWrongBCID
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)
186 else:
187 #--- delete OnlineWrongBCID if the both ADCs has not isWrongBCID
188 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
189 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
190
191 #--- add OnlineBadTiming if either of the ADCs has isBadTiming
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)
195 else:
196 #--- delete OnlineBadTiming if the both ADCs has not isBadTiming
197 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
198 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
199
200 #--- add OnlineTimingDmuBcOffsetPos if either of the ADCs has isTimingDmuBcOffsetPos
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)
204 else:
205 #--- delete OnlineTimingDmuBcOffsetPos if the both ADCs has not isTimingDmuBcOffsetPos
206 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
207 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
208
209 #--- add OnlineTimingDmuBcOffsetNeg if either of the ADCs has isTimingDmuBcOffsetNeg
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)
213 else:
214 #--- delete OnlineTimingDmuBcOffsetNeg if the both ADCs has not isTimingDmuBcOffsetNeg
215 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
216 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
217 else:
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)
222
223 statloAfter = mgr2.getAdcProblems(ros,mod,chn,0)
224 stathiAfter = mgr2.getAdcProblems(ros,mod,chn,1)
225
226 if (statloBefore != statloAfter) or (stathiBefore != stathiAfter):
227 pbm = [statloBefore, stathiBefore, statloAfter, stathiAfter]
228 #print modName,"%3d 0"%chn,statloBefore,"=>",statloAfter
229 #print modName,"%3d 1"%chn,stathiBefore,"=>",stathiAfter
230 for adc in range(2):
231 if pbm[adc] != pbm[adc + 2]:
232 msg = ''
233 for pb in range(2):
234 if pb:
235 msg += " =>"
236 else:
237 msg = "%s %2i %1i " % (modName, chn, adc)
238 prbs = pbm[adc+pb*2]
239 if len(prbs):
240 for prbCode in sorted(prbs.keys()):
241 prbDesc = prbs[prbCode]
242 msg += " %5i (%s)" % (prbCode, prbDesc)
243 else:
244 msg += " GOOD"
245 log.info(msg)
246 comm += " ch %d" % chn
247 if len(comm):
248 comment += " " + modName + comm
249
250#=== commit changes
251if len(comment):
252 if online:
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))
255 else:
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))
258 dbw.closeDatabase()
259else:
260 log.warning("Folders are in sync, nothing to update")
261
262#=== close databases
263db1.closeDatabase()
264db2.closeDatabase()
int upper(int c)
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.