Example #1
0
    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):
        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)