8Python module for managing TileCal ADC status words.
14from PyCool
import cool
15Blob = cppyy.gbl.coral.Blob
19from TileCalibBlobObjs.Classes
import TileBchStatus, TileCalibUtils, \
20 TileBchPrbs, TileBchDecoder
21from TileCalibBlobPython.TileCalibCrest
import MINRUN, MINLBK, MAXRUN, MAXLBK, \
22 TileBlobReaderCrest, TileBlobWriterCrest
23from TileCalibBlobPython.TileCalibLogger
import TileCalibLogger
24from TileCalibBlobPython.TileCalibTools
import TileASCIIParser
30 This class manages updates to the Tile Calorimeter bad channel database.
31 The usual mode of operation should start with initializing this manager
32 with a current set of bad channels from an existing database.
33 The status of individual ADCs can then be modified using the setAdcStatus,
34 updateFromFile or updateFromDb methods.
35 In a final step, the changes are commited to the database using the commit
42 TileCalibLogger.__init__(self,
"TileBchMgr")
59 Private function, calculating the index of a given ADC
60 for the internal cache.
65 def __updateFromDb(self, db, folderPath, tag, runLumi, fillTable=1, ros=-1, module=-1):
67 Updates the internal bad channel cache with the content
68 found in the database. Server connection string or file name (db) has to
69 be provided. Tag and runLumi are used to locate the set of
70 bad channels to be read from the database.
75 if folderPath
is None:
76 folderPath = self.__folderPath
81 self.log().critical(
"Database is not defined" )
86 self.
__reader = TileBlobReaderCrest(db,folderPath,tag,runLumi[0],runLumi[1])
91 self.
__reader.getIovs(runLumi,(runLumi[0],runLumi[1]+1))
94 self.log().info(
"Comment: %s", self.
__comment)
97 rosmin = ros
if ros>=0
else 0
99 for ros
in range(rosmin,rosmax):
100 modmin = module
if module>=0
else 0
102 for mod
in range(modmin,modmax):
103 bch = self.
__reader.getDrawer(ros, mod, runLumi,
False)
106 self.log().warning(
"Missing IOV in condDB: ros=%i mod=%i runLumi=%s", ros,mod,runLumi)
112 adcBits = bch.getData(chn,adc,0)
114 chnBits = bch.getData(chn, 2,0)
119 elif fillTable==1
or fillTable==-1:
121 elif fillTable==2
or fillTable==-2:
126 status1 =
TileBchStatus( bchDecoder.decode(chnBits,adcBits) )
138 def updateFromDb(self, db, folderPath, tag, runLumi, fillTable=1, mode=None, ros=-1, module=-1):
141 self.
__updateFromDb(db, folderPath, tag, runLumi, fillTable, ros, module)
144 def initialize(self, db, folderPath, tag="", runLumi=(MAXRUN,MAXLBK-1), mode=
None, ros=-1, module=-1):
146 Initializes the internal bad channel cache. Any changes applied to the
147 cache previous to calling this function are lost. Typically this function
148 is called once in the beginning to initialize the cache with a set of
149 current bad channels.
151 self.log().info(
"Initializing from database, resetting all changes!")
171 self.log().info(
"Updating TileBchStatus::isBad() definition from DB")
174 self.log().info(
"No TileBchStatus::isBad() definition found in DB, using defaults")
179 self.log().info(
"Updating TileBchStatus::isBadTiming() definition from DB")
182 self.log().info(
"No TileBchStatus::isBadTiming() definition found in DB, using defaults")
189 Get TileBchStatus for a given ADC.
196 Set TileBchStatus for a given ADC.
203 Returns a dictionary with { problemEnum : 'Description'}
207 if not status.isGood():
208 prbs = status.getPrbs()
216 Expects a list of TileBchPrbs::PrbS as input
226 Sets a specific problem
235 Removes a specific problem
244 convert module name to ros,drawer
247 part_dict = {
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4}
248 partname = str(module[0:3])
249 ros = part_dict[partname]
250 drawer = int(module[3:])-1
253 if drawer<0
or drawer>63:
254 self.log().critical(
"Invalid module name %s" % module )
262 Get TileBchStatus for a given ADC.
270 Set TileBchStatus for a given ADC.
278 Returns a dictionary with { problemEnum : 'Description'}
283 if not status.isGood():
284 prbs = status.getPrbs()
292 Expects a list of TileBchPrbs::PrbS as input
303 Sets a specific problem
313 Removes a specific problem
323 Print a formatted list of all ADCs with problems.
325 self.log().info(
"==============================================================")
326 self.log().info(
" Current list of affected ADCs " )
327 self.log().info(
"==============================================================")
328 for ros
in range(rosBeg,rosEnd):
332 chnName =
"channel %2i" % chn
338 for prbCode
in sorted(prbs.keys()):
339 prbDesc = prbs[prbCode]
340 msg =
"%s %s %s %2i (%s)" % (modName,chnName,gainName,prbCode,prbDesc)
341 self.log().info( msg )
345 self.log().info(
"==============================================================")
351 - if nothing changed : 0
352 - if something changed and complete drawer is now good : -1
353 - if something changed but drawer is not completely good: >0
365 if not newStatus.isGood():
367 if diffCnt>0
and allGood:
374 Updates the internal bad channel cache with the content
375 found in the file. The layout of the file has to follow the
376 TileConditions ASCII file layout.
378 NGO: change this at some point. In a file, not the status word (which
379 depends on the bit pattern version) should be encoded, but the individual problems (enums).
380 For this we need one line per ADC... this requires some modification in the reader.
382 parser = TileASCIIParser(fileName,
'Bch')
383 dict = parser.getDict()
384 self.log().info(
"Updating dictionary from file with %i entries", len(dict))
385 self.log().info(
"... filename: %s", fileName )
386 for key, stat
in list(dict.items()):
394 statInt = int(stat[adc])
401 status += TileBchPrbs.IgnoredInHlt
403 status += int(stat[adc])
407 def commitToDb(self, db, folderPath, tag, bitPatVer, author, comment,
408 since, moduleList=[]):
410 Commits the differences compared to the set of bad channels read in with the
411 initialze function to the provided database.
412 - author : author name (string)
413 - comment : a comment (string)
414 - sinceRun, sinceLbk : start of IOV for which bad channels are valid
417 writer = TileBlobWriterCrest(db,folderPath,
'Bch')
418 if len(comment)
or isinstance(author,tuple):
419 writer.setComment(author, comment)
423 if moduleList!=[
'CMT']:
424 if since != (MINRUN,MINLBK):
425 justBefore = list(since)
426 if justBefore[1]>MINLBK:
427 justBefore[1] = justBefore[1]-1
429 justBefore[0] = justBefore[0]-1
430 justBefore[1] = MAXLBK
431 justBefore = tuple(justBefore)
433 self.log().info(
"Reading db state just before %s, i.e. at %s", since,justBefore)
436 self.log().info(
"Using previous bad channel list from input DB")
437 self.log().info(
"And comparing it with new list of bad channels")
439 self.log().info(
"Filling db from %s, resetting old status cache", list(since))
443 self.log().info(
"Committing changes to DB \'%s\'", db)
444 self.log().info(
"... using tag \'%s\' and [run,lumi] [%i,%i]",
445 tag,since[0],since[1])
446 if isinstance(author,tuple)
and len(author)==3:
447 self.log().info(
"... author : \'%s\'", author[0] )
448 self.log().info(
"... comment: \'%s\'", author[1] )
450 self.log().info(
"... author : \'%s\'", author )
451 self.log().info(
"... comment: \'%s\'", comment )
454 loGainDefVec = cppyy.gbl.std.vector(
'unsigned int')()
455 loGainDefVec.push_back(0)
456 hiGainDefVec = cppyy.gbl.std.vector(
'unsigned int')()
457 hiGainDefVec.push_back(0)
458 comChnDefVec = cppyy.gbl.std.vector(
'unsigned int')()
459 comChnDefVec.push_back(0)
460 defVec = cppyy.gbl.std.vector(
'std::vector<unsigned int>')()
461 defVec.push_back(loGainDefVec)
462 defVec.push_back(hiGainDefVec)
463 defVec.push_back(comChnDefVec)
472 if (modName
in moduleList
or 'ALL' in moduleList):
474 drawerR = self.
__reader.getDrawer(ros, mod,
None,
False,
False)
476 writer.getDrawer(ros,mod,drawerR)
478 writer.zeroBlob(ros,mod)
482 self.log().info(
"Drawer %s reset to GOOD", modName)
483 if modName
not in comment
and (
"ONL" not in folderPath
or "syncALL" not in comment):
485 self.log().
error(
"Comment string - '%s' - doesn't contain drawer %s", comment,modName)
486 writer.zeroBlob(ros,mod)
489 self.log().info(
"Applying %2i changes to drawer %s", nChange,modName)
490 if modName
not in comment
and (
"ONL" not in folderPath
or "syncALL" not in comment):
492 self.log().
error(
"Comment string - '%s' - doesn't contain drawer %s", comment,modName)
493 drawer = writer.getDrawer(ros,mod)
497 wordsLo = bchDecoder.encode(self.
getAdcStatus(ros,mod,chn,0))
501 wordsHi = bchDecoder.encode(self.
getAdcStatus(ros,mod,chn,1))
502 chBits = wordsHi[0] | chBits
505 drawer.setData(chn,0,0, loBits)
506 drawer.setData(chn,1,0, hiBits)
507 drawer.setData(chn,2,0, chBits)
509 if wordsLo[0] != chBits:
510 self.log().info(
"Drawer %s ch %2d - sync LG status with HG ", modName,chn)
513 if wordsHi[0] != chBits:
514 self.log().info(
"Drawer %s ch %2d - sync HG status with LG ", modName,chn)
519 if nUpdates>0
or moduleList==[
'CMT']:
521 self.log().info(
"Attempting to register %i modified drawers..." , nUpdates)
522 writer.register(since,tag)
524 self.log().
error(
"Aborting update due to errors in comment string")
526 self.log().warning(
"No drawer modifications detected, ignoring commit request")
532 Returns bad status definition
538 Returns bad time status definition
Class providing the association between TileCal problems and status word bits.
static std::string getDescription(const Prb &prb)
Get description of problem.
Class holding bad channel problems.
static void defineBadTiming(const TileBchStatus &status)
static void defineBad(const TileBchStatus &status)
static unsigned int getAdcIdx(unsigned int ros, unsigned int drawer, unsigned int channel, unsigned int adc)
Returns an ADC hash.
static unsigned int max_gain()
Python compatibility function.
static unsigned int badtiming_definition_chan()
Python compatibility function.
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static unsigned int max_chan()
Python compatibility function.
static unsigned int max_ros()
Python compatibility function.
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
static unsigned int definitions_draweridx()
Python compatibility function.
static unsigned int bad_definition_chan()
Python compatibility function.
setAdcProblems(self, ros, drawer, channel, adc, problems)
getBadTimingDefinition(self)
setADCStatus(self, module, channel, adc, status)
setADCProblems(self, module, channel, adc, problems)
updateFromFile(self, fileName)
decodeModule(self, module)
__getAdcIdx(self, ros, drawer, channel, adc)
getAdcProblems(self, ros, drawer, channel, adc)
addAdcProblem(self, ros, drawer, channel, adc, problem)
listBadAdcs(self, rosBeg=0, modBeg=0, rosEnd=5, modEnd=64)
checkModuleForChanges(self, ros, drawer)
delADCProblem(self, module, channel, adc, problem)
delAdcProblem(self, ros, drawer, channel, adc, problem)
addADCProblem(self, module, channel, adc, problem)
getADCProblems(self, module, channel, adc)
updateFromDb(self, db, folderPath, tag, runLumi, fillTable=1, mode=None, ros=-1, module=-1)
getADCStatus(self, module, channel, adc)
__updateFromDb(self, db, folderPath, tag, runLumi, fillTable=1, ros=-1, module=-1)
commitToDb(self, db, folderPath, tag, bitPatVer, author, comment, since, moduleList=[])
getAdcStatus(self, ros, drawer, channel, adc)
setAdcStatus(self, ros, drawer, channel, adc, status)