Exemplo n.º 1
0
 def listBadAdcs(self, rosBeg=0, modBeg=0, rosEnd=5, modEnd=64):
     """
     Print a formatted list of all ADCs with problems.
     """
     self.log().info(
         "==============================================================")
     self.log().info(
         "                 Current list of affected ADCs               ")
     self.log().info(
         "==============================================================")
     for ros in range(rosBeg, rosEnd):
         for mod in range(modBeg,
                          min(modEnd, TileCalibUtils.getMaxDrawer(ros))):
             modName = TileCalibUtils.getDrawerString(ros, mod)
             for chn in range(TileCalibUtils.max_chan()):
                 chnName = "channel %2i" % chn
                 for adc in range(TileCalibUtils.max_gain()):
                     gainName = "LG:"
                     if adc:
                         gainName = "HG:"
                     prbs = self.getAdcProblems(ros, mod, chn, adc)
                     for prbCode in sorted(prbs.keys()):
                         prbDesc = prbs[prbCode]
                         msg = "%s %s %s %2i (%s)" % (
                             modName, chnName, gainName, prbCode, prbDesc)
                         self.log().info(msg)
                         modName = " " * 5
                         chnName = " " * 10
                         gainName = " " * 3
     self.log().info(
         "==============================================================")
Exemplo n.º 2
0
def decode_status(chan, calib_blob):
    """
    Given a module number `chan` and a `calib_blob` string, return the number
    of bad, good and affected channels in this module.
    
    It also returns a dictionary `prob` containing as keys the problem identifier
    and values the number of channels affected by that problem.
    """

    if chan == 1000 or len(calib_blob) <= 24:
        # chan 1000 is a comment, and calib_blobs less than 24 in length cause
        # a crash.
        return None

    # Decode a Coral BLOB into a string
    b = make_blob(calib_blob)
    bch = TileCalibDrawerBch.getInstance(b)

    bad, good, affected = [], [], []

    probs = {}

    decoder = TileBchDecoder(bch.getBitPatternVersion())
    chn_adcs = product(xrange(TileCalibUtils.max_chan()),
                       xrange(TileCalibUtils.max_gain()))
    # Stolen from near
    # http://alxr.usatlas.bnl.gov/lxr/source/atlas/TileCalorimeter/TileCalib/
    #     TileCalibBlobPython/python/TileBchTools.py#072
    for chn, adc in chn_adcs:
        adcBits, chnBits = bch.getData(chn, adc, 0), bch.getData(chn, 2, 0)
        status = TileBchStatus(decoder.decode(chnBits, adcBits))
        if status.isBad(): bad.append((chn, adc))
        if status.isGood(): good.append((chn, adc))
        if status.isAffected(): affected.append((chn, adc))

        if not status.isGood():
            prbs = status.getPrbs()
            # Build a dictionary
            for prb in prbs:
                key = prb, TileBchPrbs.getDescription(prb)
                probs[key] = probs.get(key, 0) + 1

    return len(bad), len(good), len(affected), probs
Exemplo n.º 3
0
 def checkModuleForChanges(self, ros, drawer):
     """
     Returns:
     - if nothing changed                                    :  0
     - if something changed and complete drawer is now good  : -1
     - if something changed but drawer is not completely good: >0
     """
     diffCnt = 0
     allGood = True
     for chn in range(TileCalibUtils.max_chan()):
         for adc in range(TileCalibUtils.max_gain()):
             idx = self.__getAdcIdx(ros, drawer, chn, adc)
             newStatus = self.__newStat[idx]
             #=== count differences between old and new
             if newStatus != self.__oldStat[idx]:
                 diffCnt += 1
             #=== invalidate allGood if one ADC is not good
             if not newStatus.isGood():
                 allGood = False
     if diffCnt > 0 and allGood:
         return -1
     return diffCnt
Exemplo n.º 4
0
 ]:
     modSpec = 'EBMBTS'
 else:
     modSpec = modName
 newDrawer = True
 flt1 = blobReader.getDrawer(ros, mod, since, False, False)
 if flt1:
     oldNchan = flt1.getNChans()
     oldNgain = flt1.getNGains()
     oldVsize = flt1.getObjSizeUint32()
 else:
     oldNchan = 0
     oldNgain = 0
     oldVsize = 0
 nchan = nchanDef if nchanDef > 0 else (
     flt1.getNChans() if flt1 else TileCalibUtils.max_chan())
 ngain = ngainDef if ngainDef > 0 else (
     flt1.getNGains() if flt1 else TileCalibUtils.max_gain())
 for chn in range(nchan):
     #=== loop over gains
     for adc in range(ngain):
         data = blobParser.getData(ros, mod, chn, adc, since)
         if not len(data) and allzero:
             continue
         if not len(data) and (not all or
                               (not flt1 and not rosmin)):
             if not rosmin:
                 log.warning(
                     "%i/%2i/%2i/%i: No value found in file",
                     ros, mod, chn, adc)
             continue
Exemplo n.º 5
0
part_dict = {'AUX': 0, 'LBA': 1, 'LBC': 2, 'EBA': 3, 'EBC': 4}
if partname in part_dict:
    ros = part_dict[partname]
    rosmin = ros
    rosmax = ros + 1
else:
    ros = -1

if mod >= 0:
    modmin = mod
    modmax = mod + 1
elif mod < -1:
    modmax = modmin

if chan_n >= 0 and chan_n < TileCalibUtils.max_chan():
    chanmin = chan_n
    chanmax = chan_n + 1
else:
    if chanmin < 0:
        chanmin = 0
    if chanmax < 0:
        chanmax = TileCalibUtils.max_chan()
    else:
        chanmax += 1

if gain_n >= 0 and gain_n < TileCalibUtils.max_gain():
    gainmin = gain_n
    gainmax = gain_n + 1
else:
    gainmin = 0
Exemplo n.º 6
0
                    log.warning(
                        "Object sizes are different for last drawer in DB (%s) and default drawer %s (%s)",
                        os, modName, osc)
                else:
                    log.error(
                        "Object sizes are different for last drawer in DB (%s and %s) and drawer %s (%s and %s)",
                        os, os2, modName, osc, os2c)
                    answ = input(' continue anyway? (y/n)')
                    if (answ != 'y'):
                        sys.exit()
                    else:
                        for ind in range(0, oscMax):
                            v.append(0)
                            v2.append(0)

            for chn in range(TileCalibUtils.max_chan()):
                chnName = " %2i" % chn
                for adc in range(ng):
                    for ind in range(0, oscMax):
                        if (ind < osc):
                            v[ind] = flt.getData(chn, adc, ind)
                        if (ind < os2c):
                            v2[ind] = flt2.getData(chn, adc, ind)
                        dv12 = v[ind] - v2[ind]
                        if v2[ind] == 0:
                            dv12percent = 0
                        else:
                            dv12percent = dv12 * 100. / v2[ind]
                        #print ( modName, ' chann ',  repr(chn),  ' adc ',  repr(adc),  ' ind ',  repr(ind),  ' val1 ',  repr(v[ind]),' val2 ',  repr(v2[ind]), ' diff ',  repr(dv12), 'percent ', repr(dv12percent))
                        if abs(dv12) > maxdiff and abs(
                                dv12percent) > maxdiffpercent:
Exemplo n.º 7
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
Exemplo n.º 8
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")
Exemplo n.º 9
0
db = TileCalibTools.openDbConn(schema, 'READONLY')
folderTag = TileCalibTools.getFolderTag(
    schema if 'COMP200' in schema or 'OFLP200' in schema else db, folderPath,
    tag)
log.info("Initializing folder %s with tag %s", folderPath, folderTag)

#=== initialize blob reader
blobReader = TileCalibTools.TileBlobReader(db, folderPath, folderTag)
#blobReader.log().setLevel(logging.DEBUG)

#=== get drawer with status at given run
log.info("Initializing for run %d, lumiblock %d", run, lumi)
flt = None
r = 5
d = 0
nchan = TileCalibUtils.max_chan()
ngain = TileCalibUtils.max_gain()
while not flt:
    d -= 1
    if d < 0:
        r -= 1
        if r < 0:
            break
        d = TileCalibUtils.getMaxDrawer(r) - 1
    flt = blobReader.getDrawer(r, d, (run, lumi), False, False)
if flt:
    blobT = flt.getObjType()
    blobV = flt.getObjVersion()
    mchan = flt.getNChans()
    mgain = flt.getNGains()
    mval = flt.getObjSizeUint32()