ATLAS Offline Software
TileSynchronizeBch.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 #
5 # TileSynchronizeBch.py <TAG1> <TAG2> <MASKONLY> <RUN1> <RUN2>
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 = current run)
13 
14 import sys
15 
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])
21 
22 
23 from TileCalibBlobPython import TileCalibTools
24 from TileCalibBlobPython import TileBchTools
25 from TileCalibBlobPython.TileCalibTools import MAXRUN
26 from TileCalibBlobObjs.Classes import TileCalibUtils, TileBchPrbs, \
27  TileBchDecoder
28 
29 from TileCalibBlobPython.TileCalibLogger import getLogger
30 log = getLogger("SyncBch")
31 import logging
32 log.setLevel(logging.DEBUG)
33 
34 
35 log.info("")
36 if tag1=="":
37  log.error( "Please, use non-empty tag as first parameter (e.g. UPD1)")
38  sys.exit(2)
39 if tag2=="":
40  log.error( "Please, use non-empty tag as second parameter (e.g. UPD4)")
41  sys.exit(2)
42 if tag1==tag2:
43  log.error( "Please, use different tags as first and second parameter (e.g. UPD1 UPD4)")
44  sys.exit(2)
45 
46 opt=opt[0].upper() if len(opt)>0 else " "
47 copyall = not (opt=="1" or opt=="Y" or opt=="T" or opt=="B")
48 if copyall:
49  log.info( "Copying all statuses from %s to %s", tag1,tag2)
50 else:
51  log.info( "Copying only BAD statuses from %s to %s", tag1,tag2)
52 
53 if run1 is None or run1 < 0:
54  badrun=run1
55  run1=MAXRUN
56  if badrun is None:
57  log.info( "First run number was not specified, using maximal possible run number %d for input DB", run1 )
58  else:
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:
61  badrun=run2
62  run2=TileCalibTools.getLastRunNumber()
63  if badrun is None:
64  log.info( "Second run number was not specified, using current run number %d for output DB", run2 )
65  else:
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")
69  sys.exit(2)
70 log.info("")
71 
72 #===================================================================
73 #====================== FILL DB BELOW ==============================
74 #===================================================================
75 
76 #=== get DB1
77 db1 = TileCalibTools.openDbConn('COOLOFL_TILE/CONDBR2')
78 folder1 = "/TILE/OFL02/STATUS/ADC"
79 folderTag1 = TileCalibTools.getFolderTag(db1, folder1, tag1)
80 
81 #--- create first bad channel manager
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))
86 
87 #=== get DB2
88 online = tag2[0:3].upper()=="ONL"
89 if online:
90  db2 = TileCalibTools.openDbConn('COOLONL_TILE/CONDBR2')
91  folder2 = "/TILE/ONL01/STATUS/ADC"
92  folderTag2 = ""
93 else:
94  db2 = TileCalibTools.openDbConn('COOLOFL_TILE/CONDBR2')
95  folder2 = "/TILE/OFL02/STATUS/ADC"
96  folderTag2 = TileCalibTools.getFolderTag(db2, folder2, tag2)
97 
98 #--- create second bad channel manager
99 mgr2 = TileBchTools.TileBchMgr()
100 mgr2.setLogLvl(logging.DEBUG)
101 mgr2.initialize(db2, folder2, folderTag2, (run2,0), 2)
102 
103 #=== synchronize
104 comment=""
105 for ros in range(1,5):
106  for mod in range(0,64):
107  modName = TileCalibUtils.getDrawerString(ros, mod)
108  comm = ""
109  for chn in range(0, 48):
110  statlo = mgr1.getAdcStatus(ros, mod, chn, 0)
111  stathi = mgr1.getAdcStatus(ros, mod, chn, 1)
112 
113  statloBefore = mgr2.getAdcProblems(ros,mod,chn,0)
114  stathiBefore = mgr2.getAdcProblems(ros,mod,chn,1)
115 
116  if online:
117 
118  # remove all trigger problems first
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)
125  # and now set new trigger problems (if any)
126  if not statlo.isGood():
127  prbs = statlo.getPrbs()
128  for prb in prbs:
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)
135 
136  if copyall or statlo.isBad() or stathi.isBad():
137  #--- add IgnoreInHlt if either of the ADCs has isBad
138  #--- add OnlineGeneralMaskAdc if the ADCs has 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)
144  elif statlo.isBad():
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)
149  elif stathi.isBad():
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)
154  else:
155  #--- delete IgnoreInHlt and OnlineGeneralMaskAdc if both ADCs are not Bad
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)
160 
161  #--- add OnlineWrongBCID if either of the ADCs has isWrongBCID
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)
165  else:
166  #--- delete OnlineWrongBCID if the both ADCs has not isWrongBCID
167  mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
168  mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
169 
170  #--- add OnlineBadTiming if either of the ADCs has isBadTiming
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)
174  else:
175  #--- delete OnlineBadTiming if the both ADCs has not isBadTiming
176  mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
177  mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
178 
179  #--- add OnlineTimingDmuBcOffsetPos if either of the ADCs has isTimingDmuBcOffsetPos
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)
183  else:
184  #--- delete OnlineTimingDmuBcOffsetPos if the both ADCs has not isTimingDmuBcOffsetPos
185  mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
186  mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
187 
188  #--- add OnlineTimingDmuBcOffsetNeg if either of the ADCs has isTimingDmuBcOffsetNeg
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)
192  else:
193  #--- delete OnlineTimingDmuBcOffsetNeg if the both ADCs has not isTimingDmuBcOffsetNeg
194  mgr2.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
195  mgr2.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
196  else:
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)
201 
202  statloAfter = mgr2.getAdcProblems(ros,mod,chn,0)
203  stathiAfter = mgr2.getAdcProblems(ros,mod,chn,1)
204 
205  if (statloBefore != statloAfter) or (stathiBefore != stathiAfter):
206  pbm = [statloBefore, stathiBefore, statloAfter, stathiAfter]
207  #print modName,"%3d 0"%chn,statloBefore,"=>",statloAfter
208  #print modName,"%3d 1"%chn,stathiBefore,"=>",stathiAfter
209  for adc in range(2):
210  if pbm[adc] != pbm[adc + 2]:
211  msg = ''
212  for pb in range(2):
213  if pb:
214  msg += " =>"
215  else:
216  msg = "%s %2i %1i " % (modName, chn, adc)
217  prbs = pbm[adc+pb*2]
218  if len(prbs):
219  for prbCode in sorted(prbs.keys()):
220  prbDesc = prbs[prbCode]
221  msg += " %5i (%s)" % (prbCode, prbDesc)
222  else:
223  msg += " GOOD"
224  log.info(msg)
225  comm += " ch %d" % chn
226  if len(comm):
227  comment += " " + modName + comm
228 
229 #=== commit changes
230 if len(comment):
231  if online:
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))
234  else:
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))
237  dbw.closeDatabase()
238 else:
239  log.warning("Folders are in sync, nothing to update")
240 
241 #=== close databases
242 db1.closeDatabase()
243 db2.closeDatabase()
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TileCalibUtils::getDrawerString
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
Definition: TileCalibUtils.cxx:145
python.CaloCondLogger.getLogger
def getLogger(name="CaloCond")
Definition: CaloCondLogger.py:16