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 range(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 range(util.max_drawer())] for ros in range(util.max_ros())] trips = [[0 for drawer in range(util.max_drawer())] for ros in range(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 list(dict.items()): 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 range(util.max_ros()): denominator = 10**max(precisions[ros]) for mod in range(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 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)
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)) #=== Tuples of empty channels emptyChannelLongBarrel = (30, 31, 43) emptyChannelExtendedBarrel = (18, 19, 24, 25, 26, 27, 28, 29, 33, 34, 42, 43, 44, 45, 46, 47) #=== Add problems with mgr.addAdcProblem(ros, drawer, channel, adc, problem)
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: # folderTag2 = "" if tag.startswith('TileO'): folderTag = tag elif tag: folderTag = TileCalibUtils.getFullTag(folderPath, tag) else: folderTag = "" if tag2.startswith('TileO'): folderTag2 = tag2 elif tag2: folderTag2 = TileCalibUtils.getFullTag(folderPath2, tag2) else: folderTag2 = "" #================================================== from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("readFromCool") import logging
if ros < 1 or ros > 4: raise Exception("Invalid ros=%i" % ros) if mod < 0 or mod > 63: raise Exception("Invalid module=%i" % mod) if run1 < run: raise Exception("Invalid validity range: %i < %i" % (run1, run)) log.info("ros=%i mod=%i since=%s until=%s comment=%s", ros, mod, since, until, comment) #=================================================================== #====================== FILL DB BELOW ============================== #=================================================================== db = TileCalibTools.openDb('SQLITE', 'OFLP200', 'UPDATE') #=== specify folder and tag folderTag = TileCalibUtils.getFullTag(folder, tag) #=== create bad channel manager mgr = TileBchTools.TileBchMgr() mgr.setLogLvl(logging.DEBUG) #=== initialize bch mgr with conditions from DB log.info("Initializing with conditions from tag=%s and time=%s", folderTag, since) mgr.initialize(db, folder, folderTag, since) #=== Tuples of empty channels emptyChannelLongBarrel = (30, 31, 43) emptyChannelExtendedBarrel = (18, 19, 24, 25, 26, 27, 28, 29, 33, 34, 42, 43, 44, 45, 46, 47) #=== Add problems with mgr.addAdcProblem(ros, drawer, channel, adc, problem)
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)
from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("writeBch") import logging log.setLevel(logging.DEBUG) #=================================================================== #====================== FILL DB BELOW ============================== #=================================================================== db = TileCalibTools.openDb('SQLITE', 'COMP200', 'UPDATE') #=== ADC status folder folder = TileCalibTools.getTilePrefix(True,True)+"STATUS/ADC" #=== specify folder and tag folderTag = TileCalibUtils.getFullTag(folder, "COM-04") #=== 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)) #=== Define TileBchStatus.isBad() #=== Currently all channels with any problem are considered as bad and masked #=== ADC problems mgr.addAdcProblem(0, 1, 0, 0, TileBchPrbs.GeneralMaskAdc) mgr.addAdcProblem(0, 1, 0, 0, TileBchPrbs.AdcDead)
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)