def listBadAdcs(self, rosBeg=0, modBeg=0, rosEnd=5, modEnd=64): """ Print a formatted list of all ADCs with problems. """ self.log().info( "==============================================================") self.log().info( " Current list of affected ADCs ") self.log().info( "==============================================================") for ros in range(rosBeg, rosEnd): for mod in range(modBeg, min(modEnd, TileCalibUtils.getMaxDrawer(ros))): modName = TileCalibUtils.getDrawerString(ros, mod) for chn in range(TileCalibUtils.max_chan()): chnName = "channel %2i" % chn for adc in range(TileCalibUtils.max_gain()): gainName = "LG:" if adc: gainName = "HG:" prbs = self.getAdcProblems(ros, mod, chn, adc) for prbCode in sorted(prbs.keys()): prbDesc = prbs[prbCode] msg = "%s %s %s %2i (%s)" % ( modName, chnName, gainName, prbCode, prbDesc) self.log().info(msg) modName = " " * 5 chnName = " " * 10 gainName = " " * 3 self.log().info( "==============================================================")
outfolderTag = TileCalibTools.getFolderTag(dbr, outfolderPath, outtag) log.info("Initializing folder %s with tag %s", folderPath, folderTag) iovAll = [] iovList = [] iovUntil = [] iovListMOD = [] iovListCMT = [] iovUntilCMT = [] blobReader = TileCalibTools.TileBlobReader(dbr, folderPath, folderTag) if iov: #=== filling the iovList log.info("Looking for IOVs") if moduleList != ['CMT']: for ros in range(rosmin, 5): for mod in range(min(64, TileCalibUtils.getMaxDrawer(ros))): modName = TileCalibUtils.getDrawerString(ros, mod) if len( moduleList ) > 0 and modName not in moduleList and 'ALL' not in moduleList: iovAll += [[]] else: iovMod = blobReader.getIOVsWithinRange(ros, mod) iovAll += [iovMod] iovList += iovMod if 'ALL' in moduleList: moduleList.remove('ALL') else: for ros in range(rosmin, 5): iovAll += [[]] * min(64, TileCalibUtils.getMaxDrawer(ros)) if 'CMT' in moduleList:
pref = "" for iovs in iovList: if iov: pref = "(%i,%i) " % (iovs[0][0], iovs[0][1]) if comment: log.info(pref + blobReader.getComment(iovs[0])) modOk = False miss = 0 good = 0 aff = 0 bad = 0 nMod = 0 for ros in range(rosmin, rosmax): for mod in range(modmin, min(modmax, TileCalibUtils.getMaxDrawer(ros))): nMod += 1 mgr.updateFromDb(db, folderPath, folderTag, iovs[0], 1, warn, ros, mod) if hexid: modName = "0x%x" % ((ros << 8) + mod) else: modName = TileCalibUtils.getDrawerString(ros, mod) if warn < 0: bch = blobReader.getDrawer(ros, mod, iovs[0], False, False) if bch is None: modOk = False miss += 1 #print ("%s is missing in DB" % modName) else: modOk = True
"Initializing for run1 %d lumi %d run2 %d lumi2 %d maxdiff %f maxdiffpercent %f", run, lumi, run2, lumi2, maxdiff, maxdiffpercent) log.info("Comment1: %s", blobReader.getComment((run, lumi))) log.info("Comment2: %s", blobReader2.getComment((run2, lumi2))) flt = None r = 5 d = 0 while not flt: d -= 1 if d < 0: r -= 1 if r < 0: log.error("No valid drawers in first database") sys.exit() d = TileCalibUtils.getMaxDrawer(r) - 1 flt = blobReader.getDrawer(r, d, (run, lumi), False, False) #flt.dump() ot = flt.getObjType() ov = flt.getObjVersion() os = flt.getObjSizeByte() // 4 no = flt.getNObjs() nc = flt.getNChans() ng = flt.getNGains() flt2 = None r = 5 d = 0 while not flt2: d -= 1 if d < 0:
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")
def fillPed(filePed, tag, comment, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folder = TileCalibTools.getTilePrefix(True,True)+"NOISE/SAMPLE" #=== get full folder tag folderTag = TileCalibUtils.getFullTag(folder, tag) #=== create default (ADC counts) pedDef = [30.,50.] loGainDef = 0.8 hiGainDef = 1.6 defaultLo = cppyy.gbl.std.vector('float')() defaultLo.push_back(pedDef[0]) # pedestal mean value defaultLo.push_back(loGainDef) # pedestal rms defaultLo.push_back(0.0) # pedestal low frequency noise defaultLo.push_back(loGainDef) # pedestal HFN1 defaultLo.push_back(0.0) # pedestal HFN2 defaultLo.push_back(0.0) # pedestal HFN2/HFN1 ratio defaultHi = cppyy.gbl.std.vector('float')() defaultHi.push_back(pedDef[1]) # pedestal mean value defaultHi.push_back(hiGainDef) # pedestal rms defaultHi.push_back(0.0) # pedestal low frequency noise defaultHi.push_back(hiGainDef) # pedestal HFN1 defaultHi.push_back(0.0) # pedestal HFN2 defaultHi.push_back(0.0) # pedestal HFN2/HFN1 ratio defVec = cppyy.gbl.std.vector('std::vector<float>')() defVec.push_back(defaultLo) defVec.push_back(defaultHi) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db,folder,'Flt') writer.setComment(os.getlogin(),comment) parser = TileCalibTools.TileASCIIParser2(filePed,"") #=== loop over whole detector for ros in range(0,5): #for mod in range(64): for mod in range(0, min(64,TileCalibUtils.getMaxDrawer(ros))): #=== need to invalidate previous blob in DB when reading from ASCII file writer.zeroBlob(ros,mod) #=== init drawer with defaults for first entry calibDrawer = writer.getDrawer(ros,mod) if not calibDrawer.getNObjs(): log.info("Initializing drawer %i/%2i\t%i", ros,mod,calibDrawer.getNObjs()) calibDrawer.init(defVec,48,0) for chn in range(48): #=== loop over gains for adc in range(2): calibDrawer.setData(chn,adc,0,pedDef[adc]+(chn+1)/48.) values = parser.getData(ros,mod,chn,adc) if not len(values): log.warning("%i/%2i/%2i/%i: No value found in file", ros,mod,chn,adc) values = parser.getData(0,ros*4,chn,adc) if not len(values): log.warning("No default per partition available") values = parser.getData(0,0,chn,adc) if not len(values): log.warning("No global default available - give up") continue else: log.warning("Using global default") else: log.warning("Using default per partition") #=== the order of columns in the ASCII file is different to the order in DB lvl = float(values[0]) # pedestal level hfn = float(values[1]) # high frequency noise lfn = float(values[2]) # low frequency noise hfn1= float(values[3]) # hfn1 hfn2= float(values[4]) # hfn2 norm= float(values[5]) # hfn2/hfn1 log.debug("%i/%2i/%2i/%i: pedLvl=%f\thfn=%f\tlfn=%f\thfn1=%f\thfn2=%f\tnorm=%f", ros,mod,chn,adc, lvl,hfn,lfn,hfn1,hfn2,norm) calibDrawer.setData(chn,adc,0,lvl) calibDrawer.setData(chn,adc,1,hfn) calibDrawer.setData(chn,adc,2,lfn) calibDrawer.setData(chn,adc,3,hfn1) calibDrawer.setData(chn,adc,4,hfn2) calibDrawer.setData(chn,adc,5,norm) #=== register in DB writer.register(since, until, folderTag)
folderPath = folderPath.split(",") folderTag = [] for fp in folderPath: ft = TileCalibTools.getFolderTag(schema, fp, tag) log.info("Initializing folder %s with tag %s", fp, ft) folderTag += [ft] multi = (len(folderPath) > 1) if multi and many: print("Can not calculate product of " + " ".join(folderPath) + " in multi-channel mode") sys.exit(2) #=== Get list of IOVs for given drawer or for comments record if ros != -1: 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)
#=== resolve folder tag from global tag folderTag = TileCalibTools.getFolderTag(db, folder, globalTag) #--- or the folderTag can be specified like this: #folderTag = TileCalibUtils.getFullTag(folder, "COM-00") #=== get a blob reader blobReader = TileCalibTools.TileBlobReader(db, folder, folderTag) #=== write out the comment associated to current values in DB comment = blobReader.getComment(pointInTime) print("Comment: \"%s\"" % comment) #=== Loop over the whole detector #--- including default drawers with ros = [0,...,19] for ros in range(TileCalibUtils.max_ros()): for mod in range(TileCalibUtils.getMaxDrawer(ros)): #=== get the TileCalibDrawerFlt correcponding to module drawer = blobReader.getDrawer(ros, mod, pointInTime) #=== loop over all the channels for chn in range(TileCalibUtils.max_chan()): for adc in range(TileCalibUtils.max_gain()): ped = drawer.getData(chn, adc, 0) hfn = drawer.getData(chn, adc, 1) #=== currently lfn is not filled, but should be in the future lfn = 0. if drawer.getObjSizeUint32() > 2: lfn = drawer.getData(chn, adc, 2)