ATLAS Offline Software
Loading...
Searching...
No Matches
TileSyncBch.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# File: TileSyncBch.py
6# Sanya Solodkov Sanya.Solodkov@cern.ch February 2026
7# Purpose: copy bad status from one tag to another (e.g. from UPD4 to ONL) in CREST DB
8#
9# Usage:
10# TileSynchronizeBch.py <TAG1> <TAG2> [MASKONLY] [RUN1] [RUN2] [SCHEMA] [OUTPUT] [AUTHOR]
11# <TAG1> - origin tag (no default), can be UPD1 or UPD4 or exact tag
12# <TAG2> - destination (no default) can be UPD1 or UPD4 or exact tag or ONL (for online tags)
13# [MASKONLY] - if "1" or "yes" or "True", channels are only masked and never unmasked
14# [RUN1] - run number to use for <TAG1> (default = MAXRUN)
15# [RUN2] - run number to use for <TAG2> and for sqlite (default = next run)
16# [SCHEMA] - full schema string for input database (optional)
17# [OUTPUT] - directory for output file "tileCalib.json" of full path with output file name (optional)
18# [AUTHOR] - user name for comment string (optional)
19
20import os,sys
21
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"):
33 output += ".json"
34
35from TileCalibBlobPython import TileCalibTools
36from TileCalibBlobPython import TileBchCrest
37from TileCalibBlobPython.TileCalibCrest import MAXRUN
38from TileCalibBlobObjs.Classes import TileCalibUtils, TileBchPrbs, \
39 TileBchDecoder
40
41from TileCalibBlobPython.TileCalibLogger import getLogger
42log = getLogger("SyncBch")
43import logging
44log.setLevel(logging.DEBUG)
45
46
47log.info("")
48if tag1=="":
49 log.error( "Please, use non-empty tag as first parameter (e.g. UPD1)")
50 sys.exit(2)
51if tag2=="":
52 log.error( "Please, use non-empty tag as second parameter (e.g. UPD4)")
53 sys.exit(2)
54if tag1==tag2:
55 log.error( "Please, use different tags as first and second parameter (e.g. UPD1 UPD4)")
56 sys.exit(2)
57
58opt=opt[0].upper() if len(opt)>0 else " "
59copyall = not (opt=="1" or opt=="Y" or opt=="T" or opt=="B")
60if copyall:
61 log.info( "Copying all statuses from %s to %s", tag1,tag2)
62else:
63 log.info( "Copying only BAD statuses from %s to %s", tag1,tag2)
64
65if not run1.isdigit() or int(run1) < 0:
66 badrun=run1
67 run1=MAXRUN
68 if not badrun.isdigit():
69 log.info( "First run number was not specified, using maximal possible run number %d for input DB", run1 )
70 else:
71 log.warning( "First run number %s is bad, using maximal possible run number %d for input DB", badrun, run1)
72else:
73 run1=int(run1)
74if not run2.isdigit() or int(run2) < 0:
75 badrun=run2
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 )
79 else:
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")
83 sys.exit(2)
84else:
85 run2=int(run2)
86if not schema:
87 schema="CREST"
88log.info( "Using schema %s", schema)
89
90log.info("")
91
92#===================================================================
93#====================== FILL DB BELOW ==============================
94#===================================================================
95
96#--- check first tag
97folder1 = "/TILE/OFL02/STATUS/ADC"
98if "ONL" in tag1.upper():
99 log.error( "Copy from ONL tag is not supported")
100 sys.exit(2)
101if tag1.upper().startswith("TILE"):
102 folder1 = ""
103
104#--- create first bad channel manager
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()
110
111#--- check second tag
112online = "ONL" in tag2.upper()
113if online:
114 folder2 = "/TILE/ONL01/STATUS/ADC"
115 if tag2.upper().endswith('-HEAD'):
116 tag2 = tag2.upper()
117 else:
118 tag2=""
119else:
120 folder2 = "/TILE/OFL02/STATUS/ADC"
121if tag2.upper().startswith("TILE"):
122 folder2 = ""
123
124#--- create second bad channel manager
125mgr2 = TileBchCrest.TileBchMgr()
126mgr2.setLogLvl(logging.DEBUG)
127mgr2.initialize(schema, folder2, tag2, (run2,0), 2)
128tag2 = mgr2.getBlobReader().getTag()
129
130#=== synchronize
131comment=""
132for ros in range(1,5):
133 for mod in range(0,64):
135 comm = ""
136 for chn in range(0, 48):
137 statlo = mgr1.getAdcStatus(ros, mod, chn, 0)
138 stathi = mgr1.getAdcStatus(ros, mod, chn, 1)
139
140 statloBefore = mgr2.getAdcProblems(ros,mod,chn,0)
141 stathiBefore = mgr2.getAdcProblems(ros,mod,chn,1)
142
143 if online:
144
145 # remove all trigger problems first
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)
152 # and now set new trigger problems (if any)
153 if not statlo.isGood():
154 prbs = statlo.getPrbs()
155 for prb in prbs:
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)
162
163 if copyall or statlo.isBad() or stathi.isBad():
164 #--- add IgnoreInHlt if either of the ADCs has isBad
165 #--- add OnlineGeneralMaskAdc if the ADCs has 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)
171 elif statlo.isBad():
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)
176 elif stathi.isBad():
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)
181 else:
182 #--- delete IgnoreInHlt and OnlineGeneralMaskAdc if both ADCs are not Bad
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)
187
188 #--- add OnlineWrongBCID if either of the ADCs has isWrongBCID
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)
192 else:
193 #--- delete OnlineWrongBCID if the both ADCs has not isWrongBCID
194 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
195 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
196
197 #--- add OnlineBadTiming if either of the ADCs has isBadTiming
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)
201 else:
202 #--- delete OnlineBadTiming if the both ADCs has not isBadTiming
203 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
204 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
205
206 #--- add OnlineTimingDmuBcOffsetPos if either of the ADCs has isTimingDmuBcOffsetPos
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)
210 else:
211 #--- delete OnlineTimingDmuBcOffsetPos if the both ADCs has not isTimingDmuBcOffsetPos
212 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
213 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
214
215 #--- add OnlineTimingDmuBcOffsetNeg if either of the ADCs has isTimingDmuBcOffsetNeg
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)
219 else:
220 #--- delete OnlineTimingDmuBcOffsetNeg if the both ADCs has not isTimingDmuBcOffsetNeg
221 mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
222 mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
223 else:
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)
228
229 statloAfter = mgr2.getAdcProblems(ros,mod,chn,0)
230 stathiAfter = mgr2.getAdcProblems(ros,mod,chn,1)
231
232 if (statloBefore != statloAfter) or (stathiBefore != stathiAfter):
233 pbm = [statloBefore, stathiBefore, statloAfter, stathiAfter]
234 #print modName,"%3d 0"%chn,statloBefore,"=>",statloAfter
235 #print modName,"%3d 1"%chn,stathiBefore,"=>",stathiAfter
236 for adc in range(2):
237 if pbm[adc] != pbm[adc + 2]:
238 msg = ''
239 for pb in range(2):
240 if pb:
241 msg += " =>"
242 else:
243 msg = "%s %2i %1i " % (modName, chn, adc)
244 prbs = pbm[adc+pb*2]
245 if len(prbs):
246 for prbCode in sorted(prbs.keys()):
247 prbDesc = prbs[prbCode]
248 msg += " %5i (%s)" % (prbCode, prbDesc)
249 else:
250 msg += " GOOD"
251 log.info(msg)
252 comm += " ch %d" % chn
253 if len(comm):
254 comment += " " + modName + comm
255
256#=== commit changes
257if len(comment):
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))
259else:
260 log.warning("Folders are in sync, nothing to update")
261
int upper(int c)
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.