def fillTileMuId(file, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folder = TileCalibTools.getTilePrefix(False)+"MUID" #=== common TileMuId defaults default = cppyy.gbl.std.vector('float')() for i in xrange(20): default.push_back(150.) default.push_back(5000.) defVec = cppyy.gbl.std.vector('std::vector<float>')() defVec.push_back(default) defVec.push_back(default) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db,folder,'Flt',False) writer.setComment(os.getlogin(),"Arantxa's values, april 2009.") parser = TileCalibTools.TileASCIIParser(file,"TileMuId"); #=== initialize all channels and write global default util = cppyy.gbl.TileCalibUtils() for ros in xrange(util.max_ros()): for drawer in xrange(util.getMaxDrawer(ros)): flt = writer.zeroBlob(ros,drawer) calibDrawer = writer.getDrawer(0,0) calibDrawer.init(defVec,1,1) #=== loop over whole detector for ros in xrange(1,5): for mod in xrange(64): #=== need to invalidate previous blob in DB when reading from ASCII file writer.zeroBlob(ros,mod) #=== we write 40 numbers (thresholds for 20 cells) only to channel 0 in each drawer chn = 0 values = parser.getData(ros,mod,chn) if not len(values): log.warning("%i/%2i/%2i/x: No value found in file" % (ros,mod,chn)) continue #=== 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,1) #=== fill in realistic values (just for the low gain index, store 40 values) adc = 0 line = "%i/%2i/%2i/%i: " % (ros,mod,chn,adc) for i in xrange(40): value = float(values[i]) calibDrawer.setData(chn,adc,i,value) line += "%f " % (value,) log.debug(line) #=== register in DB writer.register(since, until, "")
def fillTimingTc(fileTclas, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folderTclas = TileCalibTools.getTilePrefix(True,True)+"TIME/CHANNELOFFSET/LAS" #=== create default: one number #--- per ADC for Tclas default = cppyy.gbl.std.vector('float')() default.push_back(0.) #===================================================== #=== fill Tclas #===================================================== tclasWriter = TileCalibTools.TileBlobWriter(db,folderTclas,'Flt') tclasWriter.setComment(os.getlogin(),fileTclas) parserTclas = TileCalibTools.TileASCIIParser(fileTclas,"Tclas"); defTclas = cppyy.gbl.std.vector('std::vector<float>')() defTclas.push_back(default) # low gain defTclas.push_back(default) # high gain #=== initialize defaults ros = 0 for mod in xrange(20): flt = tclasWriter.zeroBlob(ros,mod) flt = tclasWriter.getDrawer(0, 0) flt.init(defTclas,1,0) #=== loop over whole detector for ros in xrange(1,5): for mod in xrange(64): #=== need to invalidate previous blob in DB when reading from ASCII file tclasWriter.zeroBlob(ros,mod) for chn in xrange(48): tclas = parserTclas.getData(ros,mod,chn) if not len(tclas): log.warning("%i/%2i/%2i/x: No value found in file" % (ros,mod,chn)) continue #=== init drawer for first entry calibDrawer = tclasWriter.getDrawer(ros,mod) if not calibDrawer.getNObjs(): log.info("Initializing drawer %i/%2i\t%i" % (ros,mod,calibDrawer.getNObjs())) calibDrawer.init(defTclas,48,0) #=== loop over gainsa for adc in xrange(2): val = float(tclas[adc]) log.debug("%i/%2i/%2i/%i: tclas = %f" % (ros,mod,chn,adc, val)) calibDrawer.setData(chn,adc,0,val) folderTag = TileCalibUtils.getFullTag(folderTclas, tag) tclasWriter.setComment(os.getlogin(),"Timing update for all partitions") tclasWriter.register(since, until, folderTag)
def fillTripsProbs(fileTrips, folderPath, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== get full folder tag folderTag = TileCalibUtils.getFullTag(folderPath, tag) util = cppyy.gbl.TileCalibUtils() default = cppyy.gbl.std.vector('unsigned int')() for i in xrange(util.max_drawer() + 1): default.push_back(0) defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')() defVec.push_back(default) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db, folderPath, 'Bch') precisions = [[0 for drawer in xrange(util.max_drawer())] for ros in xrange(util.max_ros())] trips = [[0 for drawer in xrange(util.max_drawer())] for ros in xrange(util.max_ros())] parser = TileCalibTools.TileASCIIParser3(fileTrips, "Trip") dict = parser.getDict() log.info("Updating dictionary from file with %i entries" % len(dict)) log.info("... filename: %s" % fileTrips) for key, trip in dict.iteritems(): ros = key[0] mod = key[1] precisions[ros][mod] = len(trip[0]) - 2 trips[ros][mod] = float(trip[0]) tripsCalibDrawer = writer.getDrawer(util.trips_ros(), util.trips_drawer()) tripsCalibDrawer.init(defVec, util.max_ros(), 1) for ros in xrange(util.max_ros()): denominator = 10**max(precisions[ros]) for mod in xrange(util.max_drawer()): trip = int(trips[ros][mod] * denominator) tripsCalibDrawer.setData(ros, 0, mod, trip) tripsCalibDrawer.setData(ros, 0, util.max_drawer(), denominator) #=== register in DB writer.register(since, until, folderTag)
def updateFromFile(self, fileName): """ Updates the internal bad channel cache with the content found in the file. The layout of the file has to follow the TileConditions ASCII file layout. NGO: change this at some point. In a file, not the status word (which depends on the bit pattern version) should be encoded, but the individual problems (enums). For this we need one line per ADC... this requires some modification in the reader. """ parser = TileCalibTools.TileASCIIParser(fileName, 'Bch') dict = parser.getDict() self.log().info("Updating dictionary from file with %i entries" % len(dict)) self.log().info("... filename: %s" % fileName) for key, stat in dict.iteritems(): ros = key[0] mod = key[1] chn = key[2] for adc in xrange(2): status = TileBchStatus() status += self.getAdcStatus(ros, mod, chn, adc) if adc < len(stat): statInt = int(stat[adc]) else: statInt = 0 #=== temporary convention if statInt == 0: pass elif statInt == 1: status += TileBchPrbs.IgnoredInHlt else: status += int(stat[adc]) self.setAdcStatus(ros, mod, chn, adc, status)
def fillTimingTd(fileTdlas, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folderTdlas = TileCalibTools.getTilePrefix(True,True)+"TIME/DRAWEROFFSET/LAS" #=== create default: one number #--- per drawer for Tdlas default = cppyy.gbl.std.vector('float')() default.push_back(0.) #===================================================== #=== fill Tdlas #===================================================== tdlasWriter = TileCalibTools.TileBlobWriter(db,folderTdlas,'Flt') tdlasWriter.setComment(os.getlogin(),fileTdlas) parserTdlas = TileCalibTools.TileASCIIParser(fileTdlas,"Tdlas"); defTdlas = cppyy.gbl.std.vector('std::vector<float>')() defTdlas.push_back(default) #=== initialize defaults ros = 0 for mod in xrange(20): flt = tdlasWriter.zeroBlob(ros,mod) flt = tdlasWriter.getDrawer(0, 0) flt.init(defTdlas,1,0) #=== loop over whole detector for ros in xrange(1,5): for mod in xrange(64): #=== need to invalidate previous blob in DB when reading from ASCII file tdlasWriter.zeroBlob(ros,mod) tdlas = parserTdlas.getData(ros,mod,0) if not len(tdlas): log.warning("(ros,mod)=(%i,%2i): No value found in file" % (ros,mod)) continue defTdlas[0][0] = float(tdlas[0]) log.debug("(ros,mod)=(%i,%2i): tdlas = %f" % (ros,mod,defTdlas[0][0])) calibDrawer = tdlasWriter.getDrawer(ros,mod) calibDrawer.init(defTdlas,1,0) folderTag = TileCalibUtils.getFullTag(folderTdlas, tag) tdlasWriter.setComment(os.getlogin(),"Timing update for all partitions") tdlasWriter.register(since, until, folderTag)
# What it does: offline problems are set, online problems are set and finally the ONL01 folder is synchronized with OFL02 from TileCalibBlobPython import TileCalibTools from TileCalibBlobPython import TileBchTools from TileCalibBlobObjs.Classes import TileCalibUtils, TileBchDecoder, \ TileBchPrbs from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("writeBch") import logging log.setLevel(logging.DEBUG) #=================================================================== #====================== FILL DB BELOW ============================== #=================================================================== db = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'UPDATE') #=== ADC status folder folder = TileCalibTools.getTilePrefix(True, True) + "STATUS/ADC" #=== specify folder and tag folderTag = TileCalibUtils.getFullTag(folder, "RUN2-HLT-UPD1-00") #=== create bad channel manager mgr = TileBchTools.TileBchMgr() mgr.setLogLvl(logging.DEBUG) #=== always initialize with no bad channels log.info("Initializing with no bad channels at tag=%s and time=%s", folderTag, (0, 0)) mgr.initialize(db, folder, folderTag, (0, 0))
run = None if len(sys.argv) < 3 else int(sys.argv[2].rpartition("=")[2]) from TileCalibBlobPython import TileCalibTools from TileCalibBlobPython import TileBchTools from TileCalibBlobPython.TileCalibTools import MAXRUN from TileCalibBlobObjs.Classes import TileCalibUtils, TileBchPrbs, \ TileBchDecoder from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("SyncOnlWithOfl") import logging log.setLevel(logging.DEBUG) if run is None or run < 0: badrun = run run = TileCalibTools.getLastRunNumber() if badrun is None: log.info("Run number was not specified, using current run number %d", run) else: log.warning("Bad run number %d was set, using current run number %d", badrun, run) if run is None or run < 0: log.error("Still bad run number") sys.exit(2) #=================================================================== #====================== FILL DB BELOW ============================== #=================================================================== #--- run number and folder to synchronize to
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 xrange(0, 5): #for mod in xrange(64): for mod in xrange(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 xrange(48): #=== loop over gains for adc in xrange(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)
if schema == 'COOLOFL_TILE/COMP200' or schema == 'COOLOFL_TILE/CONDBR2': if not '/TILE/OFL02' in folderPath: print "Folder %s doesn't exist in schema %s " % (folderPath, schema) sys.exit(2) 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")
def fillIntegrator(fileInt, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folder = TileCalibTools.getTilePrefix(True, True) + "INTEGRATOR" #=== get full folder tag folderTag = TileCalibUtils.getFullTag(folder, tag) #=== create default values for each of the six gains 1 to 6 # for each gain there is: # gain, error of the gain, chi2 of the fit, pedestal # DAC for pedestal, sigma of pedestal distribution # RMS of pedestal distribution, sigma of the RMS dv = [] dv.append((2.814, 0.023, -1, -1, 80, -1, -1, -1)) dv.append((26.010, 0.230, -1, -1, 80, -1, -1, -1)) dv.append((28.810, 0.240, -1, -1, 80, -1, -1, -1)) dv.append((54.810, 0.480, -1, -1, 70, -1, -1, -1)) dv.append((75.790, 0.677, -1, -1, 70, -1, -1, -1)) dv.append((101.800, 0.900, -1, -1, 70, -1, -1, -1)) #=== number of integrator gains and value per gain ngain = 6 nperg = 8 defVec = cppyy.gbl.std.vector('std::vector<float>')() for i in range(ngain): defaultGain = cppyy.gbl.std.vector('float')() for v in dv[i]: defaultGain.push_back(v) defVec.push_back(defaultGain) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db, folder, 'Flt') writer.setComment(os.getlogin(), "Jalal's values with non-zero defaults, 2008-12-05") parser = TileCalibTools.TileASCIIParser(fileInt, "IntGain") #=== initialize all channels and write global default util = cppyy.gbl.TileCalibUtils() for ros in range(util.max_ros()): for drawer in range(util.getMaxDrawer(ros)): writer.zeroBlob(ros, drawer) calibDrawer = writer.getDrawer(0, 0) calibDrawer.init(defVec, 1, 1) #=== loop over whole detector for ros in range(1, 5): for mod in range(64): #=== need to invalidate previous blob in DB when reading from ASCII file writer.zeroBlob(ros, mod) for chn in range(48): values = parser.getData(ros, mod, chn) if not len(values): log.warning("%i/%2i/%2i/x: No value found in file", ros, mod, chn) continue #=== 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, 1) #=== loop over gains for adc in range(ngain): line = "%i/%2i/%2i/%i: " % (ros, mod, chn, adc) for v in range(nperg): value = float(values[adc * nperg + v]) calibDrawer.setData(chn, adc, v, value) line += "%f " % (value, ) log.debug(line) #=== register in DB writer.register(since, until, folderTag)
log.info("Copying only BAD statuses from %s to %s" % (tag1, tag2)) if run1 is None or run1 < 0: badrun = run1 run1 = MAXRUN if badrun is None: log.info( "First run number was not specified, using maximal possible run number %d for input DB" % run1) else: log.warning( "First run number %d is bad, using maximal possible run number %d for input DB" % (badrun, run1)) if run2 is None or run2 < 0: badrun = run2 run2 = TileCalibTools.getLastRunNumber() if badrun is None: log.info( "Second run number was not specified, using current run number %d for output DB" % run2) else: log.warning( "Second run number %d is bad, using current run number %d for output DB" % (badrun, run2)) if run2 is None or run2 < 0: log.error("Still bad run number") sys.exit(2) log.info("") #=================================================================== #====================== FILL DB BELOW ==============================
def fillAutoCr(filePed, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folder = TileCalibTools.getTilePrefix(True, True) + "NOISE/AUTOCR" #=== get full folder tag folderTag = TileCalibUtils.getFullTag(folder, tag) #=== common noise autocr defaults (no correlation) default = cppyy.gbl.std.vector('float')() for i in range(6): default.push_back(0.) defVec = cppyy.gbl.std.vector('std::vector<float>')() defVec.push_back(default) defVec.push_back(default) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db, folder, 'Flt') writer.setComment(os.getlogin(), "Giulio's file for LBC test n.0, 2009-02-27") parser = TileCalibTools.TileASCIIParser(filePed, "AutoCr") #=== initialize all channels and write global default util = cppyy.gbl.TileCalibUtils() for ros in range(util.max_ros()): for drawer in range(util.getMaxDrawer(ros)): writer.zeroBlob(ros, drawer) calibDrawer = writer.getDrawer(0, 0) calibDrawer.init(defVec, 1, 1) #=== loop over whole detector for ros in range(1, 5): for mod in range(64): #=== need to invalidate previous blob in DB when reading from ASCII file writer.zeroBlob(ros, mod) for chn in range(48): values = parser.getData(ros, mod, chn) if not len(values): log.warning("%i/%2i/%2i/x: No value found in file", ros, mod, chn) continue #=== 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, 1) #=== fill in realistic values for adc in range(2): line = "%i/%2i/%2i/%i: " % (ros, mod, chn, adc) for i in range(6): value = float(values[adc * 6 + i]) calibDrawer.setData(chn, adc, i, value) line += "%f " % (value, ) log.debug(line) #=== register in DB writer.register(since, until, folderTag)
usage = "Usage: integrator_readDb.py [\"yyyy-mm-dd hh:mm:ss\"]" if (len(sys.argv) > 2) or ("-h" in sys.argv) or ("--help" in sys.argv): print(usage) 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
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")
comment = "OFC weights (7 samples) imported from TileDSPofc v4r1p4" #================================================== #=== #=== Code starts below here #=== #================================================== #=== set shortcut g = cppyy.gbl #=== get a logger log = TileCalibLogger.getLogger("WriteOfc") #=== (re-)create the database db = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'UPDATE') #=== creating folder specifications spec = cool.RecordSpecification() #=== Note special name '*Ofc' and 16M instead of 64k for OFCs spec.extend( 'TileCalibBlobOfc', cool.StorageType.Blob16M ) folderMode = cool.FolderVersioning.SINGLE_VERSION folderSpec = cool.FolderSpecification(folderMode, spec) #=== loop over all input files for fileName in [ofcFiles[0]]: log.info( "Reading file: %s" % fileName ) #=== determine COOL folder from input file name fileNameParts = re_fileName.search(fileName).groups() ofMethod = fileNameParts[0]
elif arg == "-c" and len(sys.argv) > 0: comment = sys.argv.pop(0) elif arg == "-from" and len(sys.argv) > 0: regFrom = sys.argv.pop(0) else: #=== check if file exists if os.path.exists(arg): fileList.append(arg) else: log.error("File \"%s\" does not exist, ignoring input!", arg) import cppyy from TileCalibBlobPython import TileCalibTools #=== open the database db = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'UPDATE') #=== get a blob writer blobWriter = TileCalibTools.TileBlobWriter(db, "/TILE/ONL01/INTEGRATOR", True, False) #=== declare default vector default = cppyy.gbl.std.vector('float')() default.push_back(0.) # gain 0 default.push_back(0.) # sigma(gain) 1 default.push_back(0.) # chi2 2 default.push_back(0.) # DAC 3 default.push_back(0.) # pedestal 4 default.push_back(0.) # sigma(pedestal) 5 default.push_back(0.) # rms 6 default.push_back(0.) # sigma(rms) 7
if iov and end >= TileCalibTools.MAXRUN: end = TileCalibTools.MAXRUN lumi2 = TileCalibTools.MAXLBK until = (TileCalibTools.MAXRUN, TileCalibTools.MAXLBK) from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("WriteCalibToCool") import logging if iov: log.setLevel(logging.INFO) else: log.setLevel(logging.DEBUG) #=== set database dbr = TileCalibTools.openDbConn(inSchema, 'READONLY') dbw = TileCalibTools.openDbConn(outSchema, ('UPDATE' if update else 'RECREATE')) if tag == 'UPD5': tag = 'UPD4' outtag = 'UPD4' outfolderPath = folderPath folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag) tag2 = folderTag.split('-') tag2[len(tag2) - 1] = "%02d" % (int(tag2[len(tag2) - 1]) + 1) outfolderTag = "-".join(tag2) else: folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag) if outfolderPath == folderPath and outtag == tag: outfolderTag = folderTag else:
from TileCalibBlobPython import TileCalibTools from TileCalibBlobObjs.Classes import * import os, sys, getopt #------------------------- from Misha #sys.path.append('/afs/cern.ch/user/a/atlcond/utils/python/ [cern.ch]') sys.path.append('/afs/cern.ch/user/a/atlcond/utils/python/') from AtlCoolBKLib import resolveAlias current = resolveAlias.getCurrent() next = resolveAlias.getNext() #-------------------------------- from TileCalibBlobPython.TileCalibLogger import TileCalibLogger, getLogger log = getLogger("resolve_Tag") import logging log.setLevel(logging.DEBUG) if instance == 'CONDBR2': log.info("alias CURRENT = %s alias NEXT = %s" % (current, next)) if folder == '': sys.exit() #================================================= connStr = 'COOLOFL_TILE/' + instance #=== open the database db = TileCalibTools.openDbConn(connStr, 'READONLY') #=== resolve folder tag from global tag foldertag = TileCalibTools.getFolderTag(db, folder, globaltag) # log.info("leaf TAG %s" % foldertag)
oraSchema = oraSchema.replace("COOLOFL", "COOLONL") if not len(outSchema): outSchema = schema else: schema = outSchema if not len(inSchema): inSchema = schema update = update or (inSchema == outSchema) from TileCalibBlobPython import TileCalibTools from TileCalibBlobPython import TileBchTools from TileCalibBlobObjs.Classes import * from TileCalibBlobPython.TileCalibLogger import TileCalibLogger, getLogger log = getLogger("WriteBchToCool") import logging log.setLevel(logging.DEBUG) dbr = TileCalibTools.openDbConn(inSchema, 'READONLY') folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag) if run < 0: since = (TileCalibTools.MAXRUN, TileCalibTools.MAXLBK - 1) else: since = (run, lumi) until = (TileCalibTools.MAXRUN, TileCalibTools.MAXLBK) if mode == 0: if inSchema == outSchema: mode = 1 else: mode = 2 elif mode != 1 and mode != 2: log.error("Bad mode %d" % mode) sys.exit(2) #=== create bad channel manager log.info("")
# # PlotPulseshapeFromCool.py # Nils Gollub <*****@*****.**>, 2008-06-05 from TileCalibBlobPython import TileCalibTools from TileCalibBlobObjs.Classes import * import ROOT pointInTime = (999999999,0) #=== get a logger from TileCalibBlobPython.TileCalibLogger import TileCalibLogger, getLogger log = getLogger("ps_readDb") #=== open the database db = TileCalibTools.openDb('ORACLE', 'CONDBR2', 'READONLY', 'COOLOFL_TILE') #=== specify folder and tag folder = "/TILE/OFL02/PULSESHAPE/PHY" folderTag = TileCalibUtils.getFullTag(folder, "RUN2-HLT-UPD1-00") #folder = "/TILE/OFL01/PULSESHAPE/LAS" #folderTag = TileCalibUtils.getFullTag(folder, "RUN2-HLT-UPD1-01") #=== get a blob reader print folder print folderTag blobReader = TileCalibTools.TileBlobReader(db,folder,folderTag) #=== write out the comment comment = blobReader.getComment(pointInTime)
) print( '\npython ReadFromCoolCompare.py --folder=/TILE/ONL01/FRAG1 --schema=COOLONL_TILE --tag= --maxdiffpercent=5.5 --run=160000 --run2=999999999' ) sys.exit() connStr = schema + '/' + instance connStr2 = schema2 + '/' + instance2 #=================================================================== #====================== FILL DB parameters BELOW =================== #=================================================================== #--- Read from COOL server or from local sqlite file: if sqlfn == 'none': db = TileCalibTools.openDbConn(connStr, 'READONLY') else: db = TileCalibTools.openDb('SQLITE', instance, 'READONLY', schema, sqlfn) if sqlfn2 == 'none': db2 = TileCalibTools.openDbConn(connStr2, 'READONLY') else: db2 = TileCalibTools.openDb('SQLITE', instance2, 'READONLY', schema2, sqlfn2) #if tag: # folderTag = TileCalibUtils.getFullTag(folderPath, tag) #else: # folderTag = "" #if tag2: # folderTag2 = TileCalibUtils.getFullTag(folderPath2, tag2) #else:
sys.exit(2) else: assert False, "unhandeled option" from TileCalibBlobPython import TileCalibTools from TileCalibBlobObjs.Classes import * from TileCalibBlobPython.TileCalibLogger import TileCalibLogger, getLogger log = getLogger("ReadOfc") import logging log.setLevel(logging.DEBUG) #=== set database db = TileCalibTools.openDbConn(schema, 'READONLY') folderTag = TileCalibTools.getFolderTag( schema if 'COMP200' in schema or 'OFLP200' in schema else db, folderPath, tag) #=== required OF2 folder if len(tag) > 0: log.info("Initializing folder %s with tag %s" % (folderPath, folderTag)) else: log.info("Initializing folder %s" % (folderPath)) 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))
cabling = 'RUN2a' elif run<222222 or 'COMP200' in ischema: cabling = 'RUN1' 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)
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) #=================================================================== #====================== FILL DB BELOW ============================== #=================================================================== #=== open the database db = TileCalibTools.openDb('SQLITE', 'OFLP200', 'UPDATE') tag = "TwoGauss-19" file = "TileDefault.ped" run = 222222 comment = "Intial tag with 2G noise for RUN2, all modules are identical, 2014-07-11" #=== read ascii file and put it in DB fillPed(file, tag, comment, (run, 0)) #=== close the database connection db.closeDatabase()
tag = 'IOVDEP-02' # change default to tag used in DC14 if run < 222222 or 'COMP200' in schema: cabling = 'RUN1' else: if ('OFLP200' in schema and run >= 310000) or run >= 343000: cabling = 'RUN2a' else: cabling = 'RUN2' hashMgr = TileCellTools.TileCellHashMgr(cabling=cabling) db = CaloCondTools.openDbConn(schema, "READONLY") if folderPath.startswith( '/TILE') or tag == 'UPD1' or tag == 'UPD4' or 'COND' in tag: folderTag = TileCalibTools.getFolderTag(db, folderPath, tag) elif folderPath.startswith('/CALO/Ofl'): folderTag = 'CaloOflNoiseCellnoise-' + tag elif folderPath.startswith('/CALO'): folderTag = 'CaloNoiseCellnoise-' + tag elif folderPath.startswith('/LAR'): folderTag = 'LARNoiseOflCellNoise-' + tag #=== Read from COOL server 2: if schema2 == 'ONL': # shortcut for COOLONL_CALO/COMP200 schema2 = 'COOLONL_CALO/COMP200' folderPath2 = '/CALO/Noise/CellNoise' if tag2 == 'UPD4': tag2 = 'UPD1-00' # change default to latest RUN1 tag elif schema2 == 'ONL2': # shortcut for COOLONL_CALO/CONDBR2 schema2 = 'COOLONL_CALO/CONDBR2'
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])) self.log().info("... author : \'%s\'" % author) self.log().info("... comment: \'%s\'" % comment) #=== default for drawer initialization loGainDefVec = cppyy.gbl.std.vector('unsigned int')()
from TileCalibBlobPython import TileCalibTools from TileCalibBlobPython import TileCellTools from TileCalibBlobObjs.Classes import * from TileCalibBlobPython.TileCalibLogger import TileCalibLogger, getLogger log = getLogger("PlotCalibFromCool") import logging logLevel=logging.DEBUG log.setLevel(logLevel) log1 = getLogger("PlotCalibFromCool") log1.setLevel(logLevel) 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) #=== 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
#!/bin/env python # Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration # # TileCalibBlobPython_writeDefaults.py # Nils Gollub <*****@*****.**>, 2007-11-26 # Andrei Artamonov 2011-05-26 # Yuri Smirnov 2014-12-24 from TileCalibBlobPython import TileCalibTools, TileCalibDefaultWriter from TileCalibBlobObjs.Classes import * #=== open database db = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'UPDATE') tag = "" #=== create default writer defaultWriter = TileCalibDefaultWriter.TileCalibDefaultWriter(db) #=== increase TileCalibTools log level import logging defaultWriter.setLogLvl(logging.DEBUG) #=== write noise defaults defaultWriter.writeNoiseOnl(tag) #=== close the database connection db.closeDatabase()
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