from TileCalibBlobPython import TileCalibTools from TileCalibBlobObjs.Classes import * from TileCalibBlobPython.TileCalibLogger import TileCalibLogger, getLogger log = getLogger("ReadLUT") import logging log.setLevel(logging.DEBUG) #=== set database db = TileCalibTools.openDbConn(schema, 'READONLY') folderTag = TileCalibTools.getFolderTag(db, folderPath, tag) log.info("Initializing folder %s with tag %s" % (folderPath, folderTag)) #=== initialize blob reader blobReader = TileCalibTools.TileBlobReader(db, folderPath, folderTag) #blobReader.log().setLevel(logging.DEBUG) #=== get drawer with status at given run log.info("Initializing ros %d, drawer %d for run %d, lumiblock %d" % (ros, drawer, run, lumi)) log.info("... %s" % blobReader.getComment((run, lumi))) flt = blobReader.getDrawer(ros, drawer, (run, lumi)) maxidx = flt.getObjSizeUint32() log.info("Maxidx = %d" % maxidx) log.info("\n") #=== get float for a given ADC modName = TileCalibUtils.getDrawerString(ros, drawer) print("%s ch %i gn %i :" % (modName, channel, adc)) for idx in xrange(0, maxidx):
else: if ('OFLP200' in ischema and run>=310000) or run>=343000: cabling = 'RUN2a' else: cabling = 'RUN2' hashMgr=None hashMgrDef=TileCellTools.TileCellHashMgr(cabling=cabling) hashMgrA=TileCellTools.TileCellHashMgr("UpgradeA") hashMgrBC=TileCellTools.TileCellHashMgr("UpgradeBC") hashMgrABC=TileCellTools.TileCellHashMgr("UpgradeABC") #=== Get list of IOVs by tricking TileCalibTools to read a Calo blob idb = TileCalibTools.openDbConn(ischema,'READONLY') iovList = [] try: blobReader = TileCalibTools.TileBlobReader(idb,folderPath, inTag) dbobjs = blobReader.getDBobjsWithinRange(-1, chan) if (dbobjs == None): raise Exception("No DB objects retrieved when building IOV list!") while dbobjs.goToNext(): obj = dbobjs.currentRef() objsince = obj.since() sinceRun = objsince >> 32 sinceLum = objsince & 0xFFFFFFFF since = (sinceRun, sinceLum) objuntil = obj.until() untilRun = objuntil >> 32 untilLum = objuntil & 0xFFFFFFFF until = (untilRun, untilLum) iov = (since, until) iovList.append(iov)
class TileBchMgr(TileCalibLogger): """ This class manages updates to the Tile Calorimeter bad channel database. The usual mode of operation should start with initializing this manager with a current set of bad channels from an existing database. The status of individual ADCs can then be modified using the setAdcStatus, updateFromFile or updateFromDb methods. In a final step, the changes are commited to the database using the commit method. """ #____________________________________________________________________ def __init__(self): #=== initialize base class TileCalibLogger.__init__(self, "TileBchMgr") #=== initialize all channel status to "good" self.__newStat = [ TileBchStatus() for _ in range(self.__getAdcIdx(4, 63, 47, 1) + 1) ] self.__oldStat = [ TileBchStatus() for _ in range(self.__getAdcIdx(4, 63, 47, 1) + 1) ] self.__comment = "" self.__mode = 1 self.__runLumi = (MAXRUN, MAXLBK - 1) self.__multiVersion = True #____________________________________________________________________ def __getAdcIdx(self, ros, drawer, channel, adc): """ Private function, calculating the index of a given ADC for the internal cache. """ return TileCalibUtils.getAdcIdx(ros, drawer, channel, adc) #____________________________________________________________________ def __updateFromDb(self, db, folderPath, tag, runLumi, fillTable=1, ros=-1, module=-1): """ Updates the internal bad channel cache with the content found in the database. An open database instance (db) has to be provided. Tag and runNum are used to locate the set of bad channels to be read from the database. """ #=== try to open the db try: if not db.isOpen(): raise "DB not open: ", db.databaseId() except Exception, e: self.log().critical(e) return #=== print status information reader = TileCalibTools.TileBlobReader(db, folderPath, tag) if ros == -2: ros = 0 module = TileCalibUtils.definitions_draweridx() self.log().info("Updating dictionary from \'%s\'" % db.databaseName()) self.log().info("... using tag \'%s\', run-lumi=%s" % (tag, runLumi)) self.__multiVersion = reader.folderIsMultiVersion() self.__comment = reader.getComment(runLumi) self.log().info("... comment: %s" % self.__comment) #=== loop over the whole detector rosmin = ros if ros >= 0 else 0 rosmax = ros + 1 if ros >= 0 else TileCalibUtils.max_ros() for ros in xrange(rosmin, rosmax): modmin = module if module >= 0 else 0 modmax = module + 1 if module >= 0 else TileCalibUtils.getMaxDrawer( ros) for mod in xrange(modmin, modmax): bch = reader.getDrawer(ros, mod, runLumi, False) if bch is None: if fillTable >= 0: self.log().warning( "Missing IOV in condDB: ros=%i mod=%i runLumi=%s" % (ros, mod, runLumi)) continue bchDecoder = TileBchDecoder(bch.getBitPatternVersion()) for chn in xrange(TileCalibUtils.max_chan()): for adc in xrange(TileCalibUtils.max_gain()): #=== adc bits adcBits = bch.getData(chn, adc, 0) #=== channel bits (works always due to default policy) chnBits = bch.getData(chn, 2, 0) #=== build status from both adc and channel bits status = TileBchStatus( bchDecoder.decode(chnBits, adcBits)) if fillTable == 0: self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status elif fillTable == 1 or fillTable == -1: self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status elif fillTable == 2 or fillTable == -2: self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status else: self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status status1 = TileBchStatus( bchDecoder.decode(chnBits, adcBits)) self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status1
#====================== Write new bad channel list ================= #=== commit changes dbw = TileCalibTools.openDbConn(outSchema, ('UPDATE' if update else 'RECREATE')) mgr.commitToDb( dbw, folderPath, folderTag, (TileBchDecoder.BitPat_onl01 if onl else TileBchDecoder.BitPat_ofl01), os.getlogin(), comment, since, until) else: dbw = None if len(curSuffix) and not onl and "sqlite" in outSchema: if len(comment) == 0: reader = TileCalibTools.TileBlobReader(dbr, folderPath, folderTag) comment = reader.getComment(since) if comment.find("): ") > -1: comment = comment[(comment.find("): ")) + 3:] log.info("") log.info("============================================================== ") log.info("") log.info("creating DB with CURRENT UPD4 tag") folderTagUPD4 = TileCalibTools.getFolderTag(dbr, folderPath, "UPD4") if folderTagUPD4 == folderTag: log.warning( "CURRENT UPD4 tag %s is identical to the tag in DB which was created already" % folderTagUPD4) folderTagUPD4 = TileCalibTools.getFolderTag(dbr, folderPath, "UPD1")
sys.exit(0) sys.argv.pop(0) pointInTime = -1 if len(sys.argv) > 0: pointInTime = sys.argv.pop(0) #=== get a logger from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("int_readDb") #=== open the database from TileCalibBlobPython import TileCalibTools db = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'READONLY') #=== get a blob writer blobReader = TileCalibTools.TileBlobReader(db, "/TILE/ONL01/INTEGRATOR") #=== write out the comment comment = blobReader.getComment(pointInTime) log.info("Comment: \"%s\"", comment) #=== write out all values for ros in range(1, 5): for mod in range(64): #=== get the drawer cd = blobReader.getDrawer(ros, mod, pointInTime) #=== check if data is avialable and continue if not if not cd: continue
def __updateFromDb(self, db, folderPath, tag, runLumi, fillTable=1, ros=-1, module=-1): """ Updates the internal bad channel cache with the content found in the database. An open database instance (db) has to be provided. Tag and runNum are used to locate the set of bad channels to be read from the database. """ #=== try to open the db try: if not db.isOpen(): raise Exception("DB not open: ", db.databaseId()) except Exception as e: self.log().critical(e) return #=== print status information reader = TileCalibTools.TileBlobReader(db, folderPath, tag) if ros == -2: ros = 0 module = TileCalibUtils.definitions_draweridx() self.log().info("Updating dictionary from \'%s\'", db.databaseName()) self.log().info("... using tag \'%s\', run-lumi=%s", tag, runLumi) self.__multiVersion = reader.folderIsMultiVersion() self.__comment = reader.getComment(runLumi) self.log().info("... comment: %s", self.__comment) #=== loop over the whole detector rosmin = ros if ros >= 0 else 0 rosmax = ros + 1 if ros >= 0 else TileCalibUtils.max_ros() for ros in range(rosmin, rosmax): modmin = module if module >= 0 else 0 modmax = module + 1 if module >= 0 else TileCalibUtils.getMaxDrawer( ros) for mod in range(modmin, modmax): bch = reader.getDrawer(ros, mod, runLumi, False) if bch is None: if fillTable >= 0: self.log().warning( "Missing IOV in condDB: ros=%i mod=%i runLumi=%s", ros, mod, runLumi) continue bchDecoder = TileBchDecoder(bch.getBitPatternVersion()) for chn in range(TileCalibUtils.max_chan()): for adc in range(TileCalibUtils.max_gain()): #=== adc bits adcBits = bch.getData(chn, adc, 0) #=== channel bits (works always due to default policy) chnBits = bch.getData(chn, 2, 0) #=== build status from both adc and channel bits status = TileBchStatus( bchDecoder.decode(chnBits, adcBits)) if fillTable == 0: self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status elif fillTable == 1 or fillTable == -1: self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status elif fillTable == 2 or fillTable == -2: self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status else: self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status status1 = TileBchStatus( bchDecoder.decode(chnBits, adcBits)) self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status1
def commitToDb(self, db, folderPath, tag, bitPatVer, author, comment, since, until=(MAXRUN, MAXLBK), untilCmt=None, moduleList=[]): """ Commits the differences compared to the set of bad channels read in with the initialze function to the provided database. - author : author name (string) - comment : a comment (string) - sinceRun, sinceLbk : start of IOV for which bad channels are valid - untilRun, untilLbk : end of IOV for which bad channels are valid """ #=== check db status try: if not db.isOpen(): raise Exception("DB not open: ", db.databaseId()) except Exception as e: raise (e) multiVersion = self.__multiVersion writer = TileCalibTools.TileBlobWriter(db, folderPath, 'Bch', multiVersion) if len(comment) or isinstance(author, tuple): writer.setComment(author, comment) nUpdates = 0 goodComment = True #=== get latest state from db if moduleList != ['CMT']: if since != (MINRUN, MINLBK): justBefore = list(since) if justBefore[1] > MINLBK: justBefore[1] = justBefore[1] - 1 else: justBefore[0] = justBefore[0] - 1 justBefore[1] = MAXLBK justBefore = tuple(justBefore) if self.__mode != 2: self.log().info( "Reading db state just before %s, i.e. at %s", since, justBefore) self.__updateFromDb(db, folderPath, tag, justBefore, 0) else: self.log().info( "Using previous bad channel list from input DB") self.log().info( "And comparing it with new list of bad channels") else: if self.__mode != 2: reader = TileCalibTools.TileBlobReader(db, folderPath, tag) multiVersion = reader.folderIsMultiVersion() self.log().info( "Filling db from %s, resetting old status cache", list(since)) self.__oldStat = len(self.__oldStat) * [TileBchStatus()] #=== print status information self.log().info("Committing changes to DB \'%s\'", db.databaseId()) self.log().info( "... using tag \'%s\' and [run,lumi] range: [%i,%i] - [%i,%i]", tag, since[0], since[1], until[0], until[1]) if isinstance(author, tuple) and len(author) == 3: self.log().info("... author : \'%s\'", author[0]) self.log().info("... comment: \'%s\'", author[1]) else: self.log().info("... author : \'%s\'", author) self.log().info("... comment: \'%s\'", comment) #=== default for drawer initialization loGainDefVec = cppyy.gbl.std.vector('unsigned int')() loGainDefVec.push_back(0) hiGainDefVec = cppyy.gbl.std.vector('unsigned int')() hiGainDefVec.push_back(0) comChnDefVec = cppyy.gbl.std.vector('unsigned int')() comChnDefVec.push_back(0) cppyy.makeClass('std::vector<unsigned int>') defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')() defVec.push_back(loGainDefVec) defVec.push_back(hiGainDefVec) defVec.push_back(comChnDefVec) #=== loop over the whole detector bchDecoder = TileBchDecoder(bitPatVer) for ros in range(0, TileCalibUtils.max_ros()): for mod in range(TileCalibUtils.getMaxDrawer(ros)): modName = TileCalibUtils.getDrawerString(ros, mod) nChange = self.checkModuleForChanges(ros, mod) if nChange == 0 and (len(moduleList) == 0 or modName not in moduleList or 'ALL' not in moduleList): #=== do nothing if nothing changed continue if nChange == -1: nUpdates += 1 self.log().info("Drawer %s reset to GOOD", modName) if modName not in comment and not ( "ONL" not in folderPath or "syncALL" not in comment): goodComment = False self.log().error( "Comment string - '%s' - doesn't contain drawer %s", comment, modName) writer.zeroBlob(ros, mod) else: nUpdates += 1 self.log().info("Applying %2i changes to drawer %s", nChange, modName) if modName not in comment and ("ONL" not in folderPath or "syncALL" not in comment): goodComment = False self.log().error( "Comment string - '%s' - doesn't contain drawer %s", comment, modName) drawer = writer.getDrawer(ros, mod) drawer.init(defVec, TileCalibUtils.max_chan(), bitPatVer) for chn in range(TileCalibUtils.max_chan()): #=== get low gain bit words wordsLo = bchDecoder.encode( self.getAdcStatus(ros, mod, chn, 0)) chBits = wordsLo[0] loBits = wordsLo[1] #=== get high gain bit words wordsHi = bchDecoder.encode( self.getAdcStatus(ros, mod, chn, 1)) chBits = wordsHi[0] | chBits hiBits = wordsHi[1] #=== set low, high and common channel word in calibDrawer drawer.setData(chn, 0, 0, loBits) drawer.setData(chn, 1, 0, hiBits) drawer.setData(chn, 2, 0, chBits) #=== synchronizing channel status in low and high gain if wordsLo[0] != chBits: self.log().info( "Drawer %s ch %2d - sync LG status with HG ", modName, chn) status = TileBchStatus( bchDecoder.decode(chBits, loBits)) self.setAdcStatus(ros, mod, chn, 0, status) if wordsHi[0] != chBits: self.log().info( "Drawer %s ch %2d - sync HG status with LG ", modName, chn) status = TileBchStatus( bchDecoder.decode(chBits, hiBits)) self.setAdcStatus(ros, mod, chn, 1, status) #=== register if nUpdates > 0 or moduleList == ['CMT']: if goodComment: self.log().info( "Attempting to register %i modified drawers...", nUpdates) if untilCmt is not None and untilCmt != until: if moduleList != ['CMT'] and until > since: writer.register(since, until, tag, 1) if untilCmt > since: writer.register(since, untilCmt, tag, -1) else: writer.register(since, until, tag) else: self.log().error( "Aborting update due to errors in comment string") else: self.log().warning( "No drawer modifications detected, ignoring commit request")
modmax=min(modmax,TileCalibUtils.getMaxDrawer(ros)) if ros!=-1 and modmin==modmax: COOL_part = ros COOL_chan = modmin-1 elif ros==0 and modmin==1: COOL_part = ros COOL_chan = modmin-1 else: COOL_part = -1 COOL_chan = 1000 idb = TileCalibTools.openDbConn(schema,'READONLY') iovList = [] blobReader = [] for (fp,ft) in zip(folderPath,folderTag): try: br = TileCalibTools.TileBlobReader(idb,fp, ft) blobReader += [br] dbobjs = br.getDBobjsWithinRange(COOL_part, COOL_chan) if (dbobjs == None): raise Exception("No DB objects retrieved when building IOV list!") while dbobjs.goToNext(): obj = dbobjs.currentRef() objsince = obj.since() sinceRun = objsince >> 32 sinceLum = objsince & 0xFFFFFFFF since = (sinceRun, sinceLum) objuntil = obj.until() untilRun = objuntil >> 32 untilLum = objuntil & 0xFFFFFFFF until = (untilRun, untilLum) if multi: