ATLAS Offline Software
TileSynchronizeOnlBchWithOfl.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 # TileSynchronizeOnlBchWithOfl.py <TAG> <RUN>
6 # lukas.pribyl@cern.ch March 2010
7 # sanya.solodkov@cern.ch November 2014
8 # sanya.solodkov@cern.ch July 2016
9 # taking latest status from given tag in offline DB and prepare sqlite file for online DB
10 # first parameter - tag to use can be UPD1 or UPD4 (default is UPD1)
11 # second parameter - run number for start of IOV in sqlite file (default is current run)
12 # if ADC is bad in offline DB, OnlineGeneralMaskAdc is set in online DB for this ADC
13 # and in addition IgnoredInHlt is set for both ADCs of a channel
14 
15 import sys
16 
17 tag = "UPD1" if len(sys.argv) < 2 else sys.argv[1].rpartition("=")[2]
18 run = None if len(sys.argv) < 3 else int(sys.argv[2].rpartition("=")[2])
19 
20 from TileCalibBlobPython import TileCalibTools
21 from TileCalibBlobPython import TileBchTools
22 from TileCalibBlobPython.TileCalibTools import MAXRUN
23 from TileCalibBlobObjs.Classes import TileCalibUtils, TileBchPrbs, \
24  TileBchDecoder
25 
26 from TileCalibBlobPython.TileCalibLogger import getLogger
27 log = getLogger("SyncOnlWithOfl")
28 import logging
29 log.setLevel(logging.DEBUG)
30 
31 if run is None or run < 0:
32  badrun=run
33  run=TileCalibTools.getLastRunNumber()
34  if badrun is None:
35  log.info( "Run number was not specified, using current run number %d", run )
36  else:
37  log.warning( "Bad run number %d was set, using current run number %d", badrun, run)
38  if run is None or run<0:
39  log.error( "Still bad run number")
40  sys.exit(2)
41 
42 #===================================================================
43 #====================== FILL DB BELOW ==============================
44 #===================================================================
45 
46 #--- run number and folder to synchronize to
47 runOfl = MAXRUN
48 folder = "/TILE/OFL02/STATUS/ADC"
49 
50 #=== get offline DB
51 db1 = TileCalibTools.openDbConn('COOLOFL_TILE/CONDBR2')
52 folderTag = TileCalibTools.getFolderTag(db1, folder, tag)
53 
54 #--- create ofline bad channel manager
55 mgrOfl = TileBchTools.TileBchMgr()
56 mgrOfl.setLogLvl(logging.DEBUG)
57 log.info("Initializing with offline bad channels at tag=%s and time=%s", folderTag, (runOfl, 0))
58 mgrOfl.initialize(db1, folder, folderTag, (runOfl,0))
59 
60 #--- create online bad channel manager
61 runOnl = run
62 folderOnl = "/TILE/ONL01/STATUS/ADC"
63 folderTagOnl = ""
64 
65 #=== get online DB
66 db = TileCalibTools.openDbConn('COOLONL_TILE/CONDBR2')
67 
68 mgrOnl = TileBchTools.TileBchMgr()
69 mgrOnl.setLogLvl(logging.DEBUG)
70 mgrOnl.initialize(db, folderOnl, folderTagOnl, (runOnl,0), 2)
71 
72 #=== print online channel status
73 log.info("================================================================ ")
74 #log.info("online channel status BEFORE update")
75 #mgrOnl.listBadAdcs()
76 
77 #=== synchronize
78 comment=""
79 for ros in range(1,5):
80  for mod in range(0,64):
81  modName = TileCalibUtils.getDrawerString(ros, mod)
82  comm = ""
83  for chn in range(0, 48):
84  statlo = mgrOfl.getAdcStatus(ros, mod, chn, 0)
85  stathi = mgrOfl.getAdcStatus(ros, mod, chn, 1)
86 
87  statloBefore = mgrOnl.getAdcProblems(ros,mod,chn,0)
88  stathiBefore = mgrOnl.getAdcProblems(ros,mod,chn,1)
89 
90  # remove all trigger problems first
91  for prb in [TileBchPrbs.TrigGeneralMask,
92  TileBchPrbs.TrigNoGain,
93  TileBchPrbs.TrigHalfGain,
94  TileBchPrbs.TrigNoisy]:
95  mgrOnl.delAdcProblem(ros, mod, chn, 0, prb)
96  mgrOnl.delAdcProblem(ros, mod, chn, 1, prb)
97  # and now set new trigger problems (if any)
98  if not statlo.isGood():
99  prbs = statlo.getPrbs()
100  for prb in prbs:
101  if prb in [TileBchPrbs.TrigGeneralMask,
102  TileBchPrbs.TrigNoGain,
103  TileBchPrbs.TrigHalfGain,
104  TileBchPrbs.TrigNoisy]:
105  mgrOnl.addAdcProblem(ros, mod, chn, 0, prb)
106  mgrOnl.addAdcProblem(ros, mod, chn, 1, prb)
107 
108  #--- add IgnoreInHlt if either of the ADCs has isBad
109  #--- add OnlineGeneralMaskAdc if the ADCs has isBad
110  if statlo.isBad() and stathi.isBad():
111  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
112  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
113  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
114  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
115  elif statlo.isBad():
116  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
117  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
118  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
119  mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
120  elif stathi.isBad():
121  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
122  mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
123  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
124  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
125  else:
126  #--- delete IgnoreInHlt and OnlineGeneralMaskAdc if both ADCs are not Bad
127  mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.IgnoredInHlt)
128  mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineGeneralMaskAdc)
129  mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.IgnoredInHlt)
130  mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineGeneralMaskAdc)
131 
132  #--- add OnlineWrongBCID if either of the ADCs has isWrongBCID
133  if statlo.isWrongBCID() or stathi.isWrongBCID():
134  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
135  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
136  else:
137  #--- delete OnlineWrongBCID if the both ADCs has not isWrongBCID
138  mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineWrongBCID)
139  mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineWrongBCID)
140 
141  #--- add OnlineBadTiming if either of the ADCs has isBadTiming
142  if statlo.isBadTiming() or stathi.isBadTiming():
143  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
144  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
145  else:
146  #--- delete OnlineBadTiming if the both ADCs has not isBadTiming
147  mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineBadTiming)
148  mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineBadTiming)
149 
150  #--- add OnlineTimingDmuBcOffsetPos if either of the ADCs has isTimingDmuBcOffsetPos
151  if statlo.isTimingDmuBcOffsetPos() or stathi.isTimingDmuBcOffsetPos():
152  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
153  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
154  else:
155  #--- delete OnlineTimingDmuBcOffsetPos if the both ADCs has not isTimingDmuBcOffsetPos
156  mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
157  mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetPos)
158 
159  #--- add OnlineTimingDmuBcOffsetNeg if either of the ADCs has isTimingDmuBcOffsetNeg
160  if statlo.isTimingDmuBcOffsetNeg() or stathi.isTimingDmuBcOffsetNeg():
161  mgrOnl.addAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
162  mgrOnl.addAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
163  else:
164  #--- delete OnlineTimingDmuBcOffsetNeg if the both ADCs has not isTimingDmuBcOffsetNeg
165  mgrOnl.delAdcProblem(ros, mod, chn, 0, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
166  mgrOnl.delAdcProblem(ros, mod, chn, 1, TileBchPrbs.OnlineTimingDmuBcOffsetNeg)
167 
168  statloAfter = mgrOnl.getAdcProblems(ros, mod, chn, 0)
169  stathiAfter = mgrOnl.getAdcProblems(ros, mod, chn, 1)
170  if (statloBefore != statloAfter) or (stathiBefore != stathiAfter):
171  pbm = [statloBefore, stathiBefore, statloAfter, stathiAfter]
172  #print modName,"%3d 0"%chn,statloBefore,"=>",statloAfter
173  #print modName,"%3d 1"%chn,stathiBefore,"=>",stathiAfter
174  for adc in range(2):
175  if pbm[adc] != pbm[adc + 2]:
176  msg = ''
177  for pb in range(2):
178  if pb:
179  msg += " =>"
180  else:
181  msg = "%s %2i %1i " % (modName, chn, adc)
182  prbs = pbm[adc+pb*2]
183  if len(prbs):
184  for prbCode in sorted(prbs.keys()):
185  prbDesc = prbs[prbCode]
186  msg += " %5i (%s)" % (prbCode, prbDesc)
187  else:
188  msg += " GOOD"
189  log.info(msg)
190  comm += " ch %d" % chn
191  if len(comm):
192  comment += " " + modName + comm
193 #=== print online channel status
194 #log.info("online channel status AFTER update")
195 #mgrOnl.listBadAdcs()
196 
197 #=== commit changes
198 if len(comment):
199  db2 = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'RECREATE','COOLONL_TILE')
200  mgrOnl.commitToDb(db2, folderOnl, folderTagOnl, TileBchDecoder.BitPat_onl01, "tilebeam", "synchronizing with %s; updated channels:%s" %(tag, comment), (runOnl,0))
201  db2.closeDatabase()
202 else:
203  log.warning("Folders are in sync, nothing to update")
204 
205 #=== close databases
206 db1.closeDatabase()
207 db.closeDatabase()
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
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