def setup(self, args): # set values of non-optional parameters self.isdata = False self.comments = False self.numbers = False self.foldername = '' self.fversion = cool.FolderVersioning.MULTI_VERSION if (len(args) > 0): self.tag = str(args[0]) self.det = str(args[1]) self.light = str(args[2]) self.isdata = True else: self.det = 'ALL' self.deadfrac = 0. self.deadthrust = 1. self.commstr = '' self.nconfig = 0 self.nworking = 0 self.newtag = False if len(args) > 3: self.deadfrac = float(args[3]) if len(args) > 4: self.deadthrust = float(args[4]) if len(args) == 6: self.commstr = str(args[5]) self.comments = True if len(args) == 7: self.nconfig = int(args[5]) self.nworking = int(args[6]) self.numbers = True # access to name encoding self.namelookup = DetStatusLib.DetStatusNames()
def setup(self, args): # set values of non-optional parameters self.destdbstr = str(args[0]) # access to name encoding self.namelookup = DetStatusLib.DetStatusNames() self.folderinfo = [] self.destfolder = '/GLOBAL/DETSTATUS/LBSUMM' self.tag = '' self.truncate = False self.numbers = False
def setup(self, args): # set values of non-optional parameters self.filename = str(args[0]) self.tag = str(args[1]) self.detlist = args[2:] self.foldername = '' self.flag = '' self.newtag = False # access to name encoding self.namelookup = DetStatusLib.DetStatusNames()
def setup(self, args): # set values of non-optional parameters self.foldername = '' self.tag = str(args[0]) self.dets = args[1:] self.summ = False self.graphics = False self.pictfile = "" # access to name encoding self.namelookup = DetStatusLib.DetStatusNames()
def setup(self, args): # set values of non-optional parameters self.isdata = False self.det = 'ALL' if len(args) > 0: self.det = str(args[0]) self.nbuilt = int(args[1]) self.isdata = True self.foldername = '/GLOBAL/DETSTATUS/ASBUILT' # access to name encoding self.namelookup = DetStatusLib.DetStatusNames()
def execute(self): # print "Name is %s" AtlCoolLib.getHostname() # prepare an empty StatusList for each channel statuslists = {} for chan in self.namelookup.allNums(): statuslists[chan] = DetStatusLib.StatusList() # deduce the source database instance name, looking for xyzP200 idx = self.conn.find('P200') if (idx >= 3): dbinst = self.conn[idx - 3:idx + 4] print "Working with database instance %s" % dbinst else: print "Cannot deduce database instance name, assume COMP200" dbinst = 'COMP200' # Extract timestamp information for mapping to run/LB tsconvdb = AtlCoolLib.indirectOpen('COOLONL_TRIGGER/' + dbinst, oracle=self.oracle) # initialize the converter tsToRLB = AtlCoolLib.TimeStampToRLB(tsconvdb, self.since, self.until) tsconvdb.closeDatabase() StartTime = tsToRLB.StartTime EndTime = tsToRLB.EndTime # open auxillary databases for online and DCS info onlinedb = AtlCoolLib.indirectOpen('COOLONL_GLOBAL/' + dbinst, oracle=self.oracle) dcsdb = AtlCoolLib.indirectOpen('COOLOFL_GLOBAL/' + dbinst, oracle=self.oracle) # loop over all 'AND' folders and merge information ngood = 0 nbad = 0 for (afolder, atag, override) in self.folderinfo: print "Process folder %s tag %s override %d" % (afolder, atag, override) try: atsindexed = 0 isonline = 0 if (afolder.find("ONL") != -1): isonline = 1 isdcs = 0 if (afolder.find("DCS") != -1): isdcs = 1 tostart = self.since toend = self.until ifolder = None if (isonline): ifolder = onlinedb.getFolder(afolder) elif (isdcs): ifolder = dcsdb.getFolder(afolder) else: ifolder = self.db.getFolder(afolder) descr = ifolder.description() if (descr.find("<timeStamp>time") != -1): atsindexed = 1 tostart = StartTime toend = EndTime objs = None if (isonline | isdcs): objs = ifolder.browseObjects(tostart, toend, cool.ChannelSelection.all()) else: objs = ifolder.browseObjects(tostart, toend, cool.ChannelSelection.all(), atag) while objs.goToNext(): obj = objs.currentRef() chan = obj.channelId() if (chan in statuslists.keys()): start = obj.since() stop = obj.until() payload = obj.payload() code = payload['Code'] deadfrac = payload['deadFrac'] thrust = payload['Thrust'] if ('NConfig' in payload.keys()): nconfig = payload['NConfig'] nworking = payload['NWorking'] else: nconfig = -1 nworking = -1 if ('Comment' in payload.keys()): comment = payload['Comment'] else: comment = '' #override=False if (atsindexed): start = tsToRLB.getRLB(start, True) stop = tsToRLB.getRLB(stop, False) + 1 statuslists[chan].merge( DetStatusLib.StatusObj(start, stop, code, deadfrac, thrust, nconfig, nworking, comment), override) ngood += 1 else: print "Data found for unexpected channel %i" % chan nbad += 1 except Exception, e: print e print "Problem accessing folder %s" % afolder nbad += 1
def execute(self): # check if flag given on command line, if not will get from each file # input line if (self.flag != ''): status = DetStatusLib.colourVal(self.flag) if (status is None): sys.exit(1) chanlist = self.getchans() if len(chanlist) == 0: sys.exit(1) # folder name depends on choice of run-lumi or timestamp, or explicit if (self.foldername == ''): folder = DetStatusLib.folderName(self.runLumi) else: folder = self.foldername print ">== Store object in folder", folder hascomment = (folder == '/GLOBAL/DETSTATUS/SHIFTOFL' or folder == '/GLOBAL/DETSTATUS/SHIFTONL') # now do update - setup folder specification and create if needed spec = cool.RecordSpecification() spec.extend("Code", cool.StorageType.Int32) spec.extend("deadFrac", cool.StorageType.Float) spec.extend("Thrust", cool.StorageType.Float) if (hascomment): spec.extend("Comment", cool.StorageType.String255) cfolder = AtlCoolLib.ensureFolder( self.db, folder, spec, AtlCoolLib.athenaDesc(self.runLumi, 'CondAttrListCollection') + '<named/>', cool.FolderVersioning.MULTI_VERSION) if (cfolder is None): sys.exit(1) # check if tag exists if self.tag != 'HEAD': taglist = cfolder.listTags() if self.tag not in taglist: if self.newtag: print ">== Tag %s will be created" % self.tag else: print ">== ERROR: Tag %s does not exist (use --newtag if you really want to create it)" % self.tag sys.exit(1) # now write data according to list in file datafile = open(self.filename, 'r') # setup storage buffer ready for input cfolder.setupStorageBuffer() nobj = 0 print "Reading data from file %s to insert in tag %s" % (self.filename, self.tag) for line in datafile.readlines(): tokens = line[:-1].split() if (len(tokens) > 0 and tokens[0][0] != '#'): # if no flag value specified on command line, take from first # argument on line if (self.flag == ''): status = DetStatusLib.colourVal(tokens[0]) if (status is None): print "Cannot define status from line %s" % line sys.exit(-1) del tokens[0] run1 = int(tokens[0]) run2 = run1 if len(tokens) == 2: run2 = int(tokens[1]) if len(tokens) < 3: lb1 = 0 lb2 = (1 << 32) - 1 else: lb1 = int(tokens[1]) lb2 = int(tokens[2]) if len(tokens) > 3: # take the rest of the line from where the comment starts comment = line[line.find(tokens[3]):-1] else: comment = "" if (comment != "" and not hascomment): print "Comment %s specified for folder type without comments" % comment sys.exit(-1) if comment == "": commstr = "" else: commstr = ' comment "%s"' % comment print "Update status for [%i,%i] to [%i,%i] to %s%s" % ( run1, lb1, run2, lb2, DetStatusLib.colour(status), commstr) payload = cool.Record(spec) payload['Code'] = status payload['deadFrac'] = 0. payload['Thrust'] = 0. if (hascomment): payload['Comment'] = comment since = (run1 << 32) + lb1 until = (run2 << 32) + lb2 + 1 for chan in chanlist: if (self.tag == "HEAD"): cfolder.storeObject(since, until, payload, chan) else: cfolder.storeObject(since, until, payload, chan, self.tag, True) nobj += 1 datafile.close() if (nobj > 0): chk = raw_input("Execute upload of %i objects (y/n)" % nobj) if (chk.upper() == "Y"): try: cfolder.flushStorageBuffer() print "Data written to COOL" except Exception, e: print "Error during bulk upload", e else: print "Upload ABORTED - not done"
def execute(self): # find folder name from timestamp options if (self.foldername == ''): folder = DetStatusLib.folderName(self.runLumi) else: folder = self.foldername # setup channel object (chanlist, chansel) = self.getChannels(self.dets) if (self.summ): # prepare for summary - get number of LBs in each folder lumiblocks = self.getLBs() runlist = lumiblocks.keys() runlist.sort() lbtot = 0 lboffset = {} for run in runlist: lb = lumiblocks[run] lboffset[run] = lbtot lbtot += lb statusbychan = {} chanindex = {} index = 0 for chan in chanlist: # statusbychan gives [nBLACK,nUNKNOWN,nRED,nYELLOW,nGREEN] statusbychan[chan] = [0, 0, 0, 0, 0] chanindex[chan] = index index += 1 if (self.graphics): hist, canvas = self.initGraphics(len(chanlist), lbtot) print ">== Reading status from folder %s tag %s" % (folder, self.tag) try: cfolder = self.db.getFolder(folder) tag = self.tag if (tag == "HEAD"): tag = "" objs = cfolder.browseObjects(self.since, self.until, chansel, tag) while objs.goToNext(): obj = objs.currentRef() chan = obj.channelId() if chan not in chanlist: continue name = self.namelookup.name(obj.channelId()) since = obj.since() until = obj.until() sincerun = since >> 32 untilrun = until >> 32 payload = obj.payload() code = payload['Code'] if (code >= 0): code = code & 3 deadFrac = payload['deadFrac'] deadThrust = payload['Thrust'] if (self.summ): # increment the counts of all appropriate runs for (run, lbn) in lumiblocks.iteritems(): # slice represents IOV of LBs in this run startslice = 1 + (run << 32) endslice = 1 + (run << 32) + lbn comstart = max(startslice, since) comend = min(endslice, until) nlb = comend - comstart if nlb > 0: #print "Overlap %i LB for db [%i %i] [%i %i] in run %i with %i LB status %i %i" % (nlb,since >> 32, since & 0xFFFFFFFF, until >> 32, until & 0xFFFFFFFF, run,lbn,code,chan) ((statusbychan[chan])[code + 1]) += nlb if (self.graphics): for i in range(0, nlb): ixfill = i + lboffset[run] + (comstart & 0xFFFFFFFF) hist.Fill(chanindex[chan] + 1, ixfill, [7, 4, 41, 30, 45][code + 1]) else: # printout data print name, ":", if (self.runLumi): print '[', (since >> 32), ',', ( since % (1 << 32)), '] - [', (until >> 32), ',', ( until % (1 << 32)), ' ]', else: print '{', AtlCoolLib.timeString( since), ',', AtlCoolLib.timeString(until), '} ', print '%s %5.3f %5.3f' % (DetStatusLib.colour(code), deadFrac, deadThrust), if ('Comment' in payload.keys()): print payload['Comment'], if ('NConfig' in payload.keys()): print "(%i/%i)" % (payload['NConfig'], payload['NWorking']), print except Exception, e: print e print 'Problem accessing COOL data' sys.exit(1)
# should not normally be needed, unless have to restart the DB import sys from CoolConvUtilities import AtlCoolLib from DetectorStatus import DetStatusLib if len(sys.argv) < 2: print "usage", sys.argv[0], "<dbname> {<foldername>}" print "Adds channel names to detector status folder (default /GLOBAL/DETSTATUS/LBSUMM)" sys.exit(-1) dbname = sys.argv[1] foldername = "/GLOBAL/DETSTATUS/LBSUMM" if len(sys.argv) > 2: foldername = sys.argv[2] mynames = DetStatusLib.DetStatusNames() print "Opening database", dbname db = AtlCoolLib.forceOpen(dbname) print "Access folder", foldername folder = db.getFolder(foldername) chanlist = mynames.allNums() for ichan in chanlist: channame = mynames.name(ichan) print "Channel ", ichan, " name ", channame, if (folder.existsChannel(ichan)): folder.setChannelName(ichan, channame) print "... Name set for existing channel" else: folder.createChannel(ichan, channame) print "... Created" # check we have <named/> in the metadata
def execute(self): chanlist = self.getchans() if len(chanlist) == 0: sys.exit(1) # now do update - setup folder specification and create if needed spec = cool.RecordSpecification() spec.extend("Code", cool.StorageType.Int32) spec.extend("deadFrac", cool.StorageType.Float) spec.extend("Thrust", cool.StorageType.Float) if (self.numbers): spec.extend("NConfig", cool.StorageType.Int32) spec.extend("NWorking", cool.StorageType.Int32) if (self.comments): spec.extend("Comment", cool.StorageType.String255) # folder name depends on choice of run-lumi or timestamp if (self.foldername == ''): folder = DetStatusLib.folderName(self.runLumi) else: folder = self.foldername print ">== Store object in folder", folder cfolder = AtlCoolLib.ensureFolder( self.db, folder, spec, AtlCoolLib.athenaDesc(self.runLumi, 'CondAttrListCollection') + '<named/>', self.fversion) if (cfolder is None): sys.exit(1) # if we do not have data to add - finish here if (not self.isdata): return # translate detector to COOL channel status = DetStatusLib.colourVal(self.light) if (status is None): print "Cannot define status from value", self.light sys.exit(1) # check if tag exists if self.tag != 'HEAD': taglist = cfolder.listTags() if self.tag not in taglist: if self.newtag: print ">== Tag %s will be created" % self.tag else: print ">== ERROR: Tag %s does not exist (use --newtag if you really want to create it)" % self.tag sys.exit(1) # now write data payload = cool.Record(spec) payload['Code'] = status payload['deadFrac'] = self.deadfrac payload['Thrust'] = self.deadthrust if (self.comments): payload['Comment'] = self.commstr if (self.numbers): payload['NConfig'] = self.nconfig payload['NWorking'] = self.nworking for channel in chanlist: print '>== Store object with IOV [', self.since, ',', self.until, '] channel', channel, 'and tag', self.tag, 'status info', status, self.deadfrac, self.deadthrust try: if (self.tag == "HEAD"): cfolder.storeObject(self.since, self.until, payload, channel) else: cfolder.storeObject(self.since, self.until, payload, channel, self.tag, True) except Exception, e: print e print 'Exception thrown when storing for channel', channel print '>== Storing COOL object FAILED' sys.exit(1)