Esempio n. 1
0
 def getLumiMuCache(self, since, until):
     "Return a lumicache (pairs of inst lumi, eventsbx) for given range"
     lumicache = IOVCache()
     folderLUMI = self.cooldblumi.getFolder(self.lumifoldername)
     if (not folderLUMI.existsChannel(self.lumimethod)):
         if self.lumimethod != 'EXTERNAL':
             raise Error('This luminosity method is not supported by %s' %
                         self.lumifoldername)
         chid = cool.ChannelSelection(998)
     else:
         chid = cool.ChannelSelection(folderLUMI.channelId(self.lumimethod))
     itr = folderLUMI.browseObjects(since, until - 1, chid, self.lumitag)
     while (itr.goToNext()):
         obj = itr.currentRef()
         # OnlineLumiDel is the integrated luminosity in the block
         # in units of ub^-1/s (1e30 cm-2 s-1)
         payload = obj.payload()
         instlumi = payload['LBAvInstLumi']
         if (instlumi > 0):
             evtsbx = payload['LBAvEvtsPerBX']
         else:
             evtsbx = 0
             pass
         lumicache.add(obj.since(), obj.until(), (instlumi, evtsbx))
         pass
     itr.close()
     return lumicache
Esempio n. 2
0
def lumi(run, lbr):
    if tuple(lbr) in lumicache:
        return lumicache[tuple(lbr)]

    lblbdb = dbSvc.openDatabase('COOLONL_TRIGGER/CONDBR2', True)
    lblb = lblbdb.getFolder('/TRIGGER/LUMI/LBLB')
    lblestonl = lblbdb.getFolder('/TRIGGER/LUMI/LBLESTONL')

    lbs = lblb.browseObjects((run << 32) + lbr[0], (run << 32) + lbr[1] - 1,
                             cool.ChannelSelection(0))
    inf = {}
    for obj in lbs:
        lbpy = obj.payload()
        #print ((lbpy['EndTime']-lbpy['StartTime'])/1e9)
        inf[(run, obj.since()
             & 0xFFFFFFFF)] = (lbpy['EndTime'] - lbpy['StartTime']) / 1e9
    if obj.since() & 0xFFFFFFFF == lbr[1]:
        print('Oops: this should not happen, appears to be off-by-one error')
    lbls = lblestonl = lblestonl.browseObjects((run << 32) + lbr[0],
                                               (run << 32) + lbr[1] - 1,
                                               cool.ChannelSelection(0))
    infl = {}
    for obj in lbls:
        lblpy = obj.payload()
        infl[(run, obj.since() & 0xFFFFFFFF)] = lblpy['LBAvInstLumi']

    #print (sorted(infl.keys()))
    totlum = 0
    for lb in inf:
        if lb in infl:
            totlum += inf[lb] * infl[lb]
        else:
            print('Missing run %d, LB %d' % lb)
    lumicache[tuple(lbr)] = totlum
    return totlum
Esempio n. 3
0
def statusCutsToRange(dbconn, foldername, since, until, tag, statusreq):
    """Return a RangeList giving the good IOV range corresponding to the
    specified set of daetector status cuts, using the given DB and folder"""
    range = RangeList(since, until)
    reqs = DetStatusReq()
    reqs.setFromString(statusreq)
    folder = dbconn.getFolder(foldername)
    # loop over all requested status cuts
    for (ichan, req) in reqs.getDict().items():
        itr = folder.browseObjects(since, until, cool.ChannelSelection(ichan),
                                   tag)
        lastiov = since
        while itr.goToNext():
            obj = itr.currentRef()
            status = obj.payload()['Code']
            if (lastiov < obj.since()):
                # veto gaps where no status data was provided - assume bad
                range.vetoRange(lastiov, obj.since())
            if (status < req):
                range.vetoRange(obj.since(), obj.until())
            lastiov = obj.until()
        # veto final gap (if any)
        range.vetoRange(lastiov, until)
        itr.close()
    return range
Esempio n. 4
0
class OracleGainReader:

  def __init__(self):

    self.reference_gains={}
    self.UNIX2COOL = 1000000000

    # get database service and open database
    dbSvc = cool.DatabaseSvcFactory.databaseService()

    dbString = 'oracle://ATLAS_COOLPROD;schema=ATLAS_COOLONL_TRIGGER;dbname=COMP200'
    try:
      db = dbSvc.openDatabase(dbString, False)        
    except Exception, e:
      print 'Error: Problem opening database', e
      sys.exit(1)

    folder_name = "/TRIGGER/Receivers/Factors/CalibGains"
    folder=db.getFolder(folder_name)
    ch = folder.listChannels()
       
    startUtime = int(time.time())
    endUtime = int(time.time())
    startValKey = startUtime * self.UNIX2COOL
    endValKey = endUtime * self.UNIX2COOL
    chsel = cool.ChannelSelection(0,sys.maxint)

    try:
      itr=folder.browseObjects(startValKey, endValKey, chsel)
    except Exception, e:
      print e
      sys.exit(1)
Esempio n. 5
0
	def processQuery(self,rateBundle):
		result = {}
		result[rateBundle.alias] = {}

		#Get first result
		firstResult = {}
		folder = self.getFolder(rateBundle.folderName)
		folder.setPrefetchAll(False)
		folderIterator = folder.browseObjects(rateBundle.IoVStart,rateBundle.IoVEnd,rateBundle.channelSelection)
		while folderIterator.goToNext():
			currentSlice = folderIterator.currentRef()
			firstResult[currentSlice.since()]=float(currentSlice.payloadValue(rateBundle.payloadName))
		folderIterator.close()
		
		#Get second result (if counts based)
		if rateBundle.turnCountFolderName is not None:
			secondResult = {}
			folder = self.getFolder(rateBundle.turnCountFolderName)
			folder.setPrefetchAll(False)
			folderIterator = folder.browseObjects(rateBundle.IoVStart,rateBundle.IoVEnd,cool.ChannelSelection())
			while folderIterator.goToNext():
				currentSlice = folderIterator.currentRef()
				secondResult[currentSlice.since()]=float(currentSlice.payloadValue(rateBundle.turnCountPayloadName))
			folderIterator.close()
			result[rateBundle.alias].update(dict((key,11246.0*firstResult.get(key)/secondResult.get(key)) for key in commonKeys([firstResult,secondResult])))		
		else: 
			result[rateBundle.alias].update(firstResult)
		return result
Esempio n. 6
0
    def getLBs(self):
        "Get the number of lumiblocks in each run, using the LBLB folder"
        lbdata = {}
        tdaqdbname = 'COOLONL_TRIGGER/COMP200'
        tdaqdb = AtlCoolLib.indirectOpen(tdaqdbname, True, True)
        if tdaqdb is None:
            print "ERROR - cannot access %s for run/LB mapping lookup" % tdaqdbname
        try:
            lbfolder = tdaqdb.getFolder('/TRIGGER/LUMI/LBLB')
            objs = lbfolder.browseObjects(self.since, self.until,
                                          cool.ChannelSelection(0))
            oldrun = 0
            maxlb = 0
            while objs.goToNext():
                obj = objs.currentRef()
                iovsince = obj.since()
                run = int(iovsince >> 32)
                lb = int(iovsince & 0xFFFFFFFF)
                if (run != oldrun):
                    if oldrun != 0:
                        lbdata[oldrun] = maxlb
                    maxlb = 0
                    oldrun = run
                if lb > maxlb: maxlb = lb
            if oldrun != 0: lbdata[oldrun] = maxlb

        except Exception, e:
            print e
            print "ERROR accessing data for run/LB mapping"
Esempio n. 7
0
def PrintHVInfo(hvline, tmstmp, folderName):

    from PyCool import cool
    outputList["voltage"] = []
    outputList["current"] = []
    outputList["status"] = []
    outputList["time"] = []

    dbSvc = cool.DatabaseSvcFactory.databaseService()
    #The "COMP200" DB contains information from prior to 2014
    #db=dbSvc.openDatabase("oracle://ATLAS_COOLPROD;schema=ATLAS_COOLOFL_DCS;dbname=COMP200")
    db = dbSvc.openDatabase(
        "oracle://ATLAS_COOLPROD;schema=ATLAS_COOLOFL_DCS;dbname=CONDBR2")
    folder = db.getFolder(folderName)

    range = 3 * 60 * 60 * 1e9  # 1 day in ns
    t1 = long(tmstmp - range)
    t2 = long(tmstmp + range)

    itr = folder.browseObjects(t1, t2, cool.ChannelSelection(hvline))
    while itr.goToNext():
        obj = itr.currentRef()
        pl = obj.payload()
        time_out = time.strftime("%Y-%m-%d:%H:%M:%S",
                                 localtime(obj.since() / 1e9))
        outputList["voltage"].append(pl["R_VMEAS"])
        outputList["current"].append(pl["R_IMEAS"])
        outputList["status"].append(pl["R_STAT"])
        outputList["time"].append(time_out)

    itr.close()
    db.closeDatabase()
    return
Esempio n. 8
0
def fetch_busy_runs(folder,
                    since=runlumi(0),
                    until=runlumi(2**63 - 1),
                    cs=cool.ChannelSelection(),
                    ntop=5):
    """
    `folder` to query
    `since` start time (defaults to 0)
    `until` until (defaults to iovmax)
    `cs` channelselection (defaults to all)
    `ntop` number of the busyiest runs to retrieve (defaults to 5)
    """

    result = []

    print "Fetching iovs.."
    iovs = split_by_channel(fetch_iovs(folder, since, until, cs, loud=True))

    print "Tallying by channel.."
    run_counts = {}
    for channel, iovs in iovs.iteritems():
        run_counts[channel] = iov_count_per_run(iovs)

    print "Getting busiest.."
    for channel, runs_iov_counts in run_counts.iteritems():
        run_counts[channel] = sorted(runs_iov_counts.items(),
                                     key=lambda (run, count): (count, -run),
                                     reverse=True)[:ntop]

    return sorted(run_counts.iteritems())
Esempio n. 9
0
def test_refcounting():
    record = namedtuple("coracool_record", "since until channel elements")
    element = namedtuple("element", "group id")

    from time import time
    start = time()

    objects = None

    before_objects = map(id, gc.get_objects())
    gc.collect()

    try:
        raise RuntimeError
    except:
        pass

    print "Objects alive before call:", len(gc.get_objects())

    try:
        #raise RuntimeError
        objects = browse_coracool(database, folder_path, since, until,
                                  cool.ChannelSelection(), "", ["group", "id"],
                                  record, element)

    except Exception, e:
        del e
Esempio n. 10
0
 def _retrieve(self, iovmin, iovmax, f, sortedRanges):
     chansel = None
     for ch1,ch2 in sortedRanges:
         if chansel==None: chansel = cool.ChannelSelection(ch1,ch2,cool.ChannelSelection.sinceBeforeChannel)
         else:             chansel.addRange(ch1,ch2)
     print (self.name,"browsing objects with tag",self.tagname)
     return coolgen(f.browseObjects( iovmin, iovmax, chansel, self.tagname))
Esempio n. 11
0
def getPerBunchLumiAll(run, lb, mask):
    channel = 147

    if (run, lb) not in cond_dict["lumi"].keys():
        lbInfo = getRunLbInfo(run, lb)
        (iovstart, iovend) = (lbInfo[lb][0], lbInfo[lb][1])

        citr = dbfolderTdaqBunchLumi.browseObjects(
            iovstart, iovend, cool.ChannelSelection(channel))

        for cobj in citr:
            if int(cobj.payload()['RunLB'] & 0xFFFFFFF) != lb:
                continue
            blob = cobj.payload()['BunchRawInstLum']
            if len(blob) != 1 + 3564 * 4:
                print "BAD info in COOL!"
                return 0
            head1 = unpack('B', blob.read(1))[0]
            cond_dict["lumi"][(run, lb)] = np.array(
                [unpack('f', blob.read(4))[0] for i in range(0, 3564)])

    data = cond_dict["lumi"][(run, lb)][mask]
    if np.any(data > 1.0):
        print "====== Out of range data in run", run, " and lb", lb
    calibdata = -np.log(1 - data) * 80000. / 6890.4
    caliberr = 1.0 / (1 - data) * numpy.sqrt(
        data * (1 - data) / 100000.) * 80000. / 6890.4

    return (calibdata, caliberr)
Esempio n. 12
0
def runLumiToTimeStamp(runnumber):
    run=long(runnumber)
    dbSvc = cool.DatabaseSvcFactory.databaseService()
    db=dbSvc.openDatabase("COOLONL_TRIGGER/"+dbname)
    f=db.getFolder("/TRIGGER/LUMI/LBLB")

    t1=run<<32
    t2=(run<<32) + 0xFFFFFFFFL

    runstart=None
    runstop=None
    lbtimes=[]
    itr=f.browseObjects(cool.ValidityKey(t1),cool.ValidityKey(t2),cool.ChannelSelection(0))
    while itr.goToNext():
        obj=itr.currentRef()
        pl=obj.payload()
        lbstart=pl["StartTime"]
        if runstart is None:
            runstart=lbstart
        runstop=pl["EndTime"]
        lbtimes+=[(obj.since()&0xFFFFFFFF,runstop),]
    itr.close()
    db.closeDatabase()
    #print lbtimes
    return (runstart, runstop, lbtimes)
Esempio n. 13
0
def fillNumberToRunLbRange(fillNumbers):
	minFill = min(fillNumbers)-1
	worker = COOLQueryWorker()
	result = {}
	folder = worker.getFolder('/LHC/DCS/FILLSTATE')
	folder.setPrefetchAll(False)
	timeEnd = int(time.mktime(time.localtime()))*10**9
	channelSelection = cool.ChannelSelection()
	for i in range(25):
		timeStart = timeEnd-259200000000000
		#load information in 3 day chunks until lowest fill is less than or equal to minFill (break after loading full year)
		folderIterator = folder.browseObjects(timeStart,timeEnd,channelSelection)
		while folderIterator.goToNext():
			currentSlice = folderIterator.currentRef()
			fillNumber = currentSlice.payloadValue('FillNumber')
			if not fillNumber.isdigit(): continue
			fillNumber = int(fillNumber)
			if fillNumber not in result: result[fillNumber]=[]
			result[fillNumber].append(currentSlice.since())
			result[fillNumber].append(currentSlice.until())
		folderIterator.close()
		timeEnd = timeStart	
		if not len(result): continue
		if min(result.keys())<=minFill: break
	nanoTimeRanges = []
	for fillNumber in list(set(fillNumbers)&set(result.keys())):
		nanoTimes = result[fillNumber]
		nanoTimeRanges.append((min(nanoTimes),max(nanoTimes)))
	worker.close()
	return nanoTimeRangesToRunLbRanges(nanoTimeRanges)
Esempio n. 14
0
def readLvl1Counters(run, itemList, label):
    """ Read LVL1 item rates from COOL for the whole run, return dict indexed by item name, value is a list of rates per LB """

    # first get item names mapped to CTP IDs
    itemNames = readLvl1ItemNames(run)
    itemIDs = []
    id = 0
    for name in itemNames:
        if name in itemList:
            itemIDs.append(id)
        id += 1

    payloadName = ''
    if label == 'TBP': payloadName = 'BeforePrescale'
    if label == 'TAP': payloadName = 'AfterPrescale'
    if label == 'TAV': payloadName = 'L1Accept'
    if not payloadName:
        print "Invalid label", label, " / valid values are 'TBP','TAP','TAV'"
        sys.exit(-1)

    # now construct channels we want to read
    channels = cool.ChannelSelection(cool.ChannelSelection.channelBeforeSince)
    for id in itemIDs:
        channels.addChannel(id)

    TBPCounts = {}
    #    LBs = []

    db = openDb()

    lvl1counters_foldername = '/TRIGGER/LUMI/LVL1COUNTERS'
    if not db.existsFolder(lvl1counters_foldername):
        print "Folder", lvl1counters_foldername, "not found"
        db.closeDatabase()
        sys.exit(-1)

    folder = db.getFolder(lvl1counters_foldername)
    try:
        itr = folder.browseObjects(run << 32, (run + 1) << 32, channels)
        while itr.goToNext():
            obj = itr.currentRef()
            lb = int(obj.since() & 0xffff)
            itemNo = obj.channelId()
            #            if not lb in LBs : LBs.append(lb)
            if not itemNo in itemIDs: continue
            payload = obj.payload()
            try:
                TBPCounts[itemNames[itemNo]][lb] = int(payload[payloadName])
            except KeyError:
                newDict = {}
                TBPCounts[itemNames[itemNo]] = newDict
                TBPCounts[itemNames[itemNo]][lb] = int(payload[payloadName])

        itr.close()
        return TBPCounts

    except Exception, e:
        print "Reading data from", lvl1lbdata_foldername, "failed:", e
Esempio n. 15
0
class HVRefUpdator:

     def __init__(self):
       
         self.reference_HV = {}
         self.reference_AffectedCells = {}
         self.forced_HV    = {}
         self.NLayers      = {}
         self.LayerName    = {}
         self.NCells       = {}
         self.UNIX2COOL = 1000000000

     def read_forced_list(self,forced_file_name):
         print " Loading forced file", forced_file_name

         new_hv = []
         myfile = open(forced_file_name,'r')
         for line in myfile.readlines():
           line.rstrip()
           line.lstrip()
           line_cont  = line.split(' ')
           line_cont  = [iii for iii in line_cont if not iii == ''] 
           rec_chan   = line_cont[0]

           new_hv      = [float(line_cont[iii]) for iii in range(2,6)]
         
           self.forced_HV[rec_chan]=new_hv
           print "updating channel ", rec_chan, " to HV  ", new_hv 

         return

     def read_HV_reference(self,ref_file_name):
         print " Loading reference HV file", ref_file_name
      # get database service and open database
         dbSvc = cool.DatabaseSvcFactory.databaseService()

         dbString='sqlite://;schema='+ref_file_name+';dbname=L1CALO'
         try:
           db = dbSvc.openDatabase(dbString, False)        
         except Exception, e:
           print 'Error: Problem opening database', e
           sys.exit(1)

         folder_name = '/TRIGGER/L1Calo/V1/Results/HVCorrections'
         folder=db.getFolder(folder_name)
         ch = folder.listChannels()
       
         startUtime = int(time.time())
         endUtime = int(time.time())
         startValKey = startUtime * self.UNIX2COOL
         endValKey = endUtime * self.UNIX2COOL
         chsel = cool.ChannelSelection(0,sys.maxint)

         try:
           itr=folder.browseObjects(startValKey, endValKey, chsel)
         except Exception, e:
           print e
           sys.exit(1)
Esempio n. 16
0
    def read_HV_geometry(self, ref_file_name):
        print(" Reading HV geometry from file", ref_file_name)
        # get database service and open database
        dbSvc = cool.DatabaseSvcFactory.databaseService()

        dbString = 'sqlite://;schema=' + ref_file_name + ';dbname=L1CALO'
        try:
            db = dbSvc.openDatabase(dbString, False)
        except Exception as e:
            print('Error: Problem opening database', e)
            sys.exit(1)

        folder_name = '/TRIGGER/L1Calo/V1/Results/RxLayers'
        folder = db.getFolder(folder_name)
        ch = folder.listChannels()

        startUtime = int(time.time())
        endUtime = int(time.time())
        startValKey = startUtime * self.UNIX2COOL
        endValKey = endUtime * self.UNIX2COOL
        chsel = cool.ChannelSelection(0, sys.maxint)

        try:
            itr = folder.browseObjects(startValKey, endValKey, chsel)
        except Exception as e:
            print(e)
            sys.exit(1)

        for row in itr:
            HV_layer_names = 4 * [0]
            HV_Ncells = 4 * [0]

            CoolId = hex(int(row.channelId()))
            payload = row.payload()

            self.NLayers[CoolId] = struct.unpack('B', payload['NLayers'])[0]

            HV_layer_names[0] = struct.unpack('B', payload['Name1'])[0]
            HV_layer_names[1] = struct.unpack('B', payload['Name2'])[0]
            HV_layer_names[2] = struct.unpack('B', payload['Name3'])[0]
            HV_layer_names[3] = struct.unpack('B', payload['Name4'])[0]

            HV_Ncells[0] = struct.unpack('B', payload['NCells1'])[0]
            HV_Ncells[1] = struct.unpack('B', payload['NCells2'])[0]
            HV_Ncells[2] = struct.unpack('B', payload['NCells3'])[0]
            HV_Ncells[3] = struct.unpack('B', payload['NCells4'])[0]

            self.LayerName[CoolId] = HV_layer_names
            self.NCells[CoolId] = HV_Ncells

#         for iii in self.NLayers.keys():
# 	   print (iii," NLayers: ",self.NLayers[iii], " Names: ",self.LayerName[iii], "  NCells: ",self.NCells[iii])

# close database
        db.closeDatabase()

        return 0
Esempio n. 17
0
	def __init__(self,IoVStart,IoVEnd,alias,folderName,payloadName,turnCountFolderName,turnCountPayloadName,channel):
		self.IoVStart = IoVStart
		self.IoVEnd = IoVEnd
		self.alias = alias
		self.folderName = folderName
		self.payloadName = payloadName
		self.turnCountFolderName = turnCountFolderName
		self.turnCountPayloadName = turnCountPayloadName
		self.channelSelection = cool.ChannelSelection(channel)
Esempio n. 18
0
	def rateNameWorker(queueIn,queueOut):
		worker = COOLQueryWorker()
		while(1):
			try: run = queueIn.get(False,0.001)
			except Empty:
				sleep(.001)
				continue
			if run is True:
				break
			runLbStart=run<<32
			runLbEnd=runLbStart+1
			nameToChannel={}
			nameToFolder={}
			#L1 Triggers
			folder = worker.getFolder("/TRIGGER/LVL1/Menu")
			folder.setPrefetchAll(False)
			folderIterator = folder.browseObjects(runLbStart,runLbEnd,cool.ChannelSelection())
			while folderIterator.goToNext():
				currentSlice = folderIterator.currentRef()
				nameToChannel[currentSlice.payloadValue('ItemName')] = currentSlice.channelId()
				nameToFolder[currentSlice.payloadValue('ItemName')] = 0
			folderIterator.close()			
			#HLT Triggers
			folder = worker.getFolder("/TRIGGER/HLT/Menu")
			folder.setPrefetchAll(False)
			folderIterator = folder.browseObjects(runLbStart,runLbEnd,cool.ChannelSelection())
			while folderIterator.goToNext():
				currentSlice = folderIterator.currentRef()
				if currentSlice.payloadValue('ChainName').startswith('L2'):
					nameToChannel[currentSlice.payloadValue('ChainName')] = int(currentSlice.payloadValue('ChainCounter'))
					nameToFolder[currentSlice.payloadValue('ChainName')] = 1
				elif currentSlice.payloadValue('ChainName').startswith('EF'):
					nameToChannel[currentSlice.payloadValue('ChainName')] = int(currentSlice.payloadValue('ChainCounter'))
					nameToFolder[currentSlice.payloadValue('ChainName')] = 2
			folderIterator.close()			
			#Totals/Streams
			folder = worker.getFolder("/TRIGGER/HLT/TotalRates")
			folder.setPrefetchAll(False)
			for channel in folder.listChannels():
				nameToChannel[folder.channelName(channel)] = channel
				nameToFolder[folder.channelName(channel)] = 3
			queueOut.put(({run:nameToChannel},{run:nameToFolder}))
		queueOut.put(True)
		return	
Esempio n. 19
0
    def LoadGainsSqlite(self, name):

        # get database service and open database
        dbSvc = cool.DatabaseSvcFactory.databaseService()

        dbString = 'sqlite://;schema=' + name + ';dbname=L1CALO'
        try:
            db = dbSvc.openDatabase(dbString, False)
        except Exception as e:
            print('Error: Problem opening database', e)
            sys.exit(1)

        folder_name = '/TRIGGER/L1Calo/V1/Results/EnergyScanResults'
        folder = db.getFolder(folder_name)
        ch = folder.listChannels()

        startUtime = int(time.time())
        endUtime = int(time.time())
        startValKey = startUtime * self.UNIX2COOL
        endValKey = endUtime * self.UNIX2COOL
        chsel = cool.ChannelSelection(0, sys.maxint)

        try:
            itr = folder.browseObjects(startValKey, endValKey, chsel)
        except Exception as e:
            print(e)
            sys.exit(1)

        for row in itr:
            CoolId = hex(int(row.channelId()))
            payload = row.payload()
            self.measured_gains[CoolId] = payload['Slope']
            self.measured_chi2[CoolId] = payload['Chi2']
            self.measured_offset[CoolId] = payload['Offset']

#       print (self.measured_gains)

        folder_gen_name = '/TRIGGER/L1Calo/V1/Results/EnergyScanRunInfo'
        folder_gen = db.getFolder(folder_gen_name)

        try:
            itr = folder_gen.browseObjects(startValKey, endValKey, chsel)
            for row in itr:
                payload = row.payload()
                self.run_nr = payload['RunNumber']
                self.strategy = payload['GainStrategy']
            print("Run nr. = ", self.run_nr, " Strategy = ", self.strategy)

        except:  # Doesn't seem to catch C++ exceptions :-(
            print(
                "Warning, in LoadGainsSqlite can't get runtype info! Hope this is not serious!"
            )

        # close database
        db.closeDatabase()
def make_channelselection(cs, mapping=None):
    """
    Helper function which can convert a channel id, name, or list of either into
    a cool.ChannelSelection. Includes protections for invalid channels.
    """
    from PyCool import cool
    if mapping == None:
        mapping = channel_mapping
    if cs is None or cs == []:
        return cool.ChannelSelection()
    elif isinstance(cs, (int, str)):
        channel_id = convert_channel(cs, channel_mapping=mapping)
        return cool.ChannelSelection(channel_id, channel_id)
    elif hasattr(cs, "__iter__"):
        cc = lambda cs: convert_channel(cs, channel_mapping=mapping)
        return list_to_channelselection(cs, convert_channel=cc)
    elif isinstance(cs, cool.ChannelSelection):
        return cs
    raise RuntimeError, ("I don't know how to convert %r into a "
                         "ChannelSelection" % cs)
Esempio n. 21
0
def _getCountsInFolder(run, lb, chainCounters, folder, lbinfo):
    """
    returns a list of Run/LB indexed CountRec objects
    if lb<0 then the list contains the entire run, otherwise it has just one entry for the given run/lb
    """

    with timer("access COOL"):
        if lb >= 0:
            runlb = (run << 32) + lb
            objs = [folder.findObject(runlb, 0)]
        else:
            start = run << 32
            end = ((run + 1) << 32) - 1
            objs = folder.browseObjects(
                start, end,
                cool.ChannelSelection(
                    0, 0, cool.ChannelSelection.sinceBeforeChannel))

    res = defaultdict(TriggerRate)
    pos = None
    nocounts = []

    with timer("read the blob for run %i" % run):
        sl = [(o.since(), o.payload()['Data'].read()) for o in objs]

    with timer("unpack"):
        for (runlb, s) in sl:
            #run = runlb>>32
            lb = runlb & 0xFFFFFFFF

            lbinfo_thislb = lbinfo[lb]
            if lbinfo_thislb.lb != lb:
                print "LBInfo", lbinfo_thislb, "is at the wrong place in the array", lb
                sys.exit(1)

            if len(s) == 0:
                nocounts += [Rate(lbinfo_thislb, None)]
            else:
                if len(s) % 20 != 0:
                    raise RuntimeError, "the length of the data vector %i is not a multiple of 20" % len(
                        s)

                #__printCounts(s)
                if pos == None:
                    counterpositions = __findPos(chainCounters, s)

                for counter, pos in counterpositions:
                    res[counter].add(
                        Rate(lbinfo_thislb, __decodeCounts(pos, s)))

        for trigrates in res.values():
            for r in nocounts:
                trigrates.add(r)
    return res
Esempio n. 22
0
    def read_corrections(self, file_name):

        # get database service and open database
        dbSvc = cool.DatabaseSvcFactory.databaseService()

        dbString = 'sqlite://;schema=' + file_name + ';dbname=L1CALO'
        try:
            db = dbSvc.openDatabase(dbString, False)
        except Exception as e:
            print('Error: Problem opening database', e)
            sys.exit(1)

        folder_name = '/TRIGGER/L1Calo/V1/Results/HVCorrections'
        folder = db.getFolder(folder_name)
        ch = folder.listChannels()

        startUtime = int(time.time())
        endUtime = int(time.time())
        startValKey = startUtime * self.UNIX2COOL
        endValKey = endUtime * self.UNIX2COOL
        chsel = cool.ChannelSelection(0, sys.maxint)

        try:
            itr = folder.browseObjects(startValKey, endValKey, chsel)
        except Exception as e:
            print(e)
            sys.exit(1)

        for row in itr:
            CoolId = hex(int(row.channelId()))
            payload = row.payload()

            self.MeanCorr[CoolId] = payload['RxMean']

            self.CorrLayer1[CoolId] = payload['LayerMean1']
            self.CorrLayer2[CoolId] = payload['LayerMean2']
            self.CorrLayer3[CoolId] = payload['LayerMean3']
            self.CorrLayer4[CoolId] = payload['LayerMean4']

            self.AffectedCells1[CoolId] = struct.unpack(
                'B', payload['AffectedCells1'])[0]
            self.AffectedCells2[CoolId] = struct.unpack(
                'B', payload['AffectedCells2'])[0]
            self.AffectedCells3[CoolId] = struct.unpack(
                'B', payload['AffectedCells3'])[0]
            self.AffectedCells4[CoolId] = struct.unpack(
                'B', payload['AffectedCells4'])[0]


#	 print ( " CoolId", CoolId ,"AffectedCells",  struct.unpack('B',self.AffectedCells1[CoolId])[0])

# close database
        db.closeDatabase()
Esempio n. 23
0
    def readData(self):

        self.data = []

        # Open the DB connection here if needed
        if self.folder == None:
            dbHandler = LumiDBHandler()
            self.folder = dbHandler.getFolder(self.dbstr, self.folderstr)
            
            if self.folder == None:
                print "Can't access DB", self.dbstr, 'folder', self.folderstr, '!'
                return self.data

        # Create the channel list
        if len(self.channelIdList) == 0:
            channels = cool.ChannelSelection.all()
            self.readChannelList(channels)

        else:
            # Build the channel list here
            self.channelIdList.sort()  # Must be sorted!

            # Must read channels 50 at a time due to COOL limit...
            ichan = 0
            while (ichan < len(self.channelIdList)) :

                jchan = 0
                channels = None
                firstChan = True
            
                for channelId in self.channelIdList[ichan:]:
                    jchan += 1
                    if firstChan:
                        firstChan = False
                        channels = cool.ChannelSelection(channelId)
                    else:
                        channels.addChannel(channelId)
                    if jchan == 50: break 

                # Remeber how many we have read for next time
                if self.verbose:
                    print 'CoolDataReader.readData() - loaded %d channels from %d' % (jchan, ichan)
                ichan += jchan

                if self.verbose:
                    print 'CoolDataReader.readData() - browsing', self.iovstart, self.iovend, 'with channel', channels, 'and tag', self.tag

                self.readChannelList(channels)

            # End of loop building channel list and reading

        # End of if statement reading data
        return self.data
Esempio n. 24
0
def getLumi(run, lb):
    iovstart = (run << 32) + lb
    iovend = (run << 32) + lb

    citr = dbfolderLumi.browseObjects(iovstart, iovend,
                                      cool.ChannelSelection(0))

    data = dict()
    for cobj in citr:
        data[int(cobj.since() & 0xFFFFFFF)] = cobj.payload()['LBAvInstLumi']

    return data[lb]
Esempio n. 25
0
def list_to_channelselection(list_,
                             convert_channel=convert_channel,
                             as_list=False):
    """
    Given a list, return a channelselection.
    
    Does the hard work of merging together adjacent channel numbers. Will also
    convert channel names to numbers (if the folder is using DQ channels,
    otherwise will give an incorrect result or fail to convert the strings to
    channelids.)
    """
    from PyCool import cool
    if not list_ and as_list: return []
    if not list_: return cool.ChannelSelection()
    if set(map(type, list_)) != set([int]) and convert_channel:
        list_ = map(convert_channel, list_)

    list_.sort()

    start = None
    ranges = []
    for this, next in zip(list_, list_[1:] + [-1]):
        if start is None:
            start = this
        if next - this != 1:
            ranges.append((start, this))
            start = None

    if as_list:
        return ranges

    assert len(ranges) < 50, (
        "Cool has a 50 channel selection limit (%s selected)" % ranges)

    selection = cool.ChannelSelection(*ranges.pop(0))
    for start, end in ranges:
        selection.addRange(start, end)

    return selection
Esempio n. 26
0
	def __init__(self,IoVStart,IoVEnd,payloadRequests,folderName,channelSelection=cool.ChannelSelection(),timeBased=False,payloadRequirements={},timeConverter={}):
		self.IoVStart = IoVStart
		self.IoVEnd = IoVEnd
		for request in payloadRequests:
			if not len(request)==3:
				print(payloadRequests)
				sys.exit(0)
		self.payloadRequests = payloadRequests
		self.payloadRequirements = payloadRequirements
		self.folderName = folderName
		self.timeBased=timeBased
		self.timeConverter=timeConverter
		self.channelSelection = channelSelection
Esempio n. 27
0
 def getChannels(self, dets):
     "Return a list of the channels to be selected, and COOL selector"
     # COOL selector may give more channels
     chanlist = []
     for det in dets:
         updet = det.upper()
         if updet in ['ALL', 'A']:
             chanlist += self.namelookup.allNums()
         else:
             chanlist += self.namelookup.nums(updet)
     chanlist.sort()
     chansel = cool.ChannelSelection(min(chanlist), max(chanlist))
     return (chanlist, chansel)
def generate_table(folder, channel, since, until):

    cool_folder = Databases.get_folder(folder)

    channelid = cool_folder.channelId(channel)
    cs = cool.ChannelSelection(channelid, channelid)

    print "Totals for channel '%s' in folder '%s'" % (channel, folder)

    iovs, info_runs = fetch_fixedup_folder_information(folder, since, until,
                                                       cs)
    table = generate_lb_count_table(folder, iovs, info_runs)
    pprint_table(table, header_loc=2)
Esempio n. 29
0
def test_coracool():

    folder_path = "/SCT/DAQ/Configuration/Module"

    database = Databases.get_instance("COOLONL_SCT/COMP200")
    folder = database.getFolder(folder_path)

    #print "Total:", folder.countObjects(0, 2**63-1, cool.ChannelSelection())

    if not "<coracool>" in folder.description():
        print "%s is not a coracool folder" % folder.fullPath()
        return

    #x = fetch_objects("LBLB", (142391,0), (142391,0xFFFF), what=[], with_channel=False)
    #print "Expected count:", len(x)

    # Run 142391 timestamps
    #since, until = 1260878894897166135, 1260879303912307635
    run = 142391
    #run = 90415

    since, until, dummy = fetch_lb_timestamps((run, 0), (run, 2**32 - 1))

    #since, until = 0, 2**63-1
    since, until = 1221973544491128285, 1221995264779751560

    variables = ["group", "id"]

    record = namedtuple("coracool_record", "since until channel elements")
    element = namedtuple("element", " ".join(variables))

    start = time()

    objects = browse_coracool(database, folder_path, since, until,
                              cool.ChannelSelection(), "", variables, record,
                              element)

    elapsed = time() - start
    print "Took %.2f to browse_coracool" % elapsed

    print len(objects)
    #pprint(objects[:10])

    bad = [x for x in objects if any(el.group == -1 for el in x.elements)]
    print len(bad)

    #pprint(bad)

    ip()

    return
Esempio n. 30
0
    def LoadReferenceOracle(self, mapping_tool):

        # get database service and open database
        dbSvc = cool.DatabaseSvcFactory.databaseService()

        dbString = 'oracle://ATLAS_COOLPROD;schema=ATLAS_COOLONL_TRIGGER;dbname=COMP200'
        try:
            db = dbSvc.openDatabase(dbString, False)
        except Exception as e:
            print('Error: Problem opening database', e)
            sys.exit(1)

        folder_name = "/TRIGGER/Receivers/Factors/CalibGains"
        folder = db.getFolder(folder_name)
        ch = folder.listChannels()

        startUtime = int(time.time())
        endUtime = int(time.time())
        startValKey = startUtime * self.UNIX2COOL
        endValKey = endUtime * self.UNIX2COOL
        chsel = cool.ChannelSelection(0, sys.maxint)

        try:
            itr = folder.browseObjects(startValKey, endValKey, chsel)
        except Exception as e:
            print(e)
            sys.exit(1)

        for row in itr:
            ReceiverId = hex(int(row.channelId()))
            PPMId = mapping_tool.getPPMfromReceiver(ReceiverId)
            payload = row.payload()
            gain = payload['factor']

            if not PPMId == None:
                if self.strategy == None:  #run type not known
                    self.reference_gains[PPMId] = gain
                else:
                    if mapping_tool.getReceiverfromPPM(
                            PPMId,
                            self.strategy) == ReceiverId:  # correct receiver?
                        #               print ("Using receiver nr.", ReceiverId, "for PPM nr.",PPMId)
                        self.reference_gains[PPMId] = gain


#             else:
#               print ("Skipping receiver nr.", ReceiverId, "for PPM nr.",PPMId)

#      print (self.reference_gains)
# close database
        db.closeDatabase()