示例#1
0
    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")
示例#2
0
    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
示例#3
0
#=== resolve folder tag from global tag
folderTag = TileCalibTools.getFolderTag(db, folder, globalTag)
#--- or the folderTag can be specified like this:
#folderTag = TileCalibUtils.getFullTag(folder, "COM-00")

#=== get a blob reader
blobReader = TileCalibTools.TileBlobReader(db, folder, folderTag)

#=== write out the comment associated to current values in DB
comment = blobReader.getComment(pointInTime)
print("Comment: \"%s\"" % comment)

#=== Loop over the whole detector
#--- including default drawers with ros = [0,...,19]
for ros in range(TileCalibUtils.max_ros()):
    for mod in range(TileCalibUtils.getMaxDrawer(ros)):

        #=== get the TileCalibDrawerFlt correcponding to module
        drawer = blobReader.getDrawer(ros, mod, pointInTime)

        #=== loop over all the channels
        for chn in range(TileCalibUtils.max_chan()):
            for adc in range(TileCalibUtils.max_gain()):

                ped = drawer.getData(chn, adc, 0)
                hfn = drawer.getData(chn, adc, 1)

                #=== currently lfn is not filled, but should be in the future
                lfn = 0.
                if drawer.getObjSizeUint32() > 2: