/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
DybChanQualCache Class Reference

Cache the info from the tables involved. More...

#include <DybChannelQualitySvc.h>

Collaboration diagram for DybChanQualCache:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::map
< DayaBay::FeeChannelId, float > 
HvValMap_t
typedef std::map
< DayaBay::FeeChannelId, bool > 
DqCpMap_t

Public Member Functions

 DybChanQualCache (const ServiceMode &sm, bool usehv, bool usenoisy)
bool update (const TimeStamp &ts)
bool empty ()
HvValMap_tsetted_hv ()
HvValMap_tgetted_hv ()
HvValMap_tnoise ()
bool covers (const TimeStamp &start, const TimeStamp &stop)
DqCpMap_tchannel_quality ()

Private Types

typedef std::list< int > ChList_t
typedef std::map< std::string,
DayaBay::HvChannelId
Loc2hv_t
typedef std::map
< DayaBay::HvChannelId,
DayaBay::FeeChannelId
Hv2fee_t

Private Member Functions

void check_hvchid (DayaBay::HvChannelId hvch, const std::string &who)
int feechid (int hvb, int hvc)
bool update_hvloc (Context &ctx)
bool update_hvfee (Context &ctx)
bool update_hvset (Context &ctx, bool force)
bool update_hvget (Context &ctx, bool force)
bool update_cmap (Context &ctx)
bool update_dqcp (Context &ctx)
bool update_noise (Context &ctx, bool force)
DayaBay::FeeChannelId hv2fee (DayaBay::HvChannelId hvch)

Private Attributes

ServiceMode m_timelessSM
TimeStamp m_lastTS
HvValMap_t m_hvset
HvValMap_t m_hvget
HvValMap_t m_noise
DqCpMap_t m_dqcp
ChList_t m_chlist
DbiResultKeym_hvlocKey
DbiResultKeym_hvfeeKey
DbiResultKeym_hvgetKey
DbiResultKeym_hvsetKey
DbiResultKeym_dqcpKey
DbiResultKeym_cmapKey
Loc2hv_t m_loc2hv
Hv2fee_t m_hv2fee
bool m_useHV
bool m_useNoisy

Detailed Description

Cache the info from the tables involved.

The two map channels are cached in essentially the same form as they are in the DB. The requested and measured HV tables are cached with these maps applied.

Definition at line 36 of file DybChannelQualitySvc.h.


Member Typedef Documentation

Definition at line 51 of file DybChannelQualitySvc.h.

Definition at line 60 of file DybChannelQualitySvc.h.

typedef std::list<int> DybChanQualCache::ChList_t [private]

Definition at line 95 of file DybChannelQualitySvc.h.

typedef std::map< std::string, DayaBay::HvChannelId > DybChanQualCache::Loc2hv_t [private]

Definition at line 106 of file DybChannelQualitySvc.h.

Definition at line 110 of file DybChannelQualitySvc.h.


Constructor & Destructor Documentation

DybChanQualCache::DybChanQualCache ( const ServiceMode sm,
bool  usehv,
bool  usenoisy 
)

Definition at line 46 of file DybChannelQualitySvc.cc.

    : m_timelessSM(Context(sm.context().GetSite(), 
                           sm.context().GetSimFlag(),
                               TimeStamp(0,0),
                               sm.context().GetDetId()),
                       sm.task())
    , m_hvlocKey(0)
    , m_hvfeeKey(0)
    , m_hvgetKey(0)
    , m_hvsetKey(0)
    , m_dqcpKey(0)
    , m_cmapKey(0)
    , m_useHV(usehv)
    , m_useNoisy(usenoisy)
{
    this->update(sm.context().GetTimeStamp());
}

Member Function Documentation

bool DybChanQualCache::update ( const TimeStamp ts)

Definition at line 329 of file DybChannelQualitySvc.cc.

{
    // Progressively check more expensively if this timestamp is "new"

    if (ts.GetSec() == m_lastTS.GetSec() && ts.GetNanoSec() == m_lastTS.GetNanoSec()) {
        //cerr << "Cache clean on timestamp value: " << ts.AsString() << endl;
        return false;
    }
    m_lastTS = ts;
    
    Context ctx = m_timelessSM.context();
    ctx.SetTimeStamp(ts);

    //cerr << "Checking cache for " << ctx.AsString("E") << endl;

    bool updated_hv = false;
    if (m_useHV) {
        bool updated_hvloc = update_hvloc(ctx);
        bool updated_hvfee = update_hvfee(ctx);
        bool updated_hvset = update_hvset(ctx, updated_hvfee);
        bool updated_hvget = update_hvget(ctx, updated_hvfee|updated_hvloc);
        updated_hv = updated_hvset || updated_hvget;
    }

    /*bool updated_cmap =*/ update_cmap(ctx);
    bool updated_dqcp = update_dqcp(ctx);

    if (m_useNoisy) {
        update_noise(ctx, true);
    }

    return updated_hv || updated_dqcp;
}
bool DybChanQualCache::empty ( )

Definition at line 98 of file DybChannelQualitySvc.cc.

{
    bool full = m_dqcp.size()>0 && m_chlist.size()>0;
    if (m_useHV) {
        full = full && m_hvset.size()>0 && m_hvget.size()>0;
    }
    return !full;
}
HvValMap_t& DybChanQualCache::setted_hv ( ) [inline]

Definition at line 52 of file DybChannelQualitySvc.h.

{ return m_hvset; }
HvValMap_t& DybChanQualCache::getted_hv ( ) [inline]

Definition at line 53 of file DybChannelQualitySvc.h.

{ return m_hvget; }
HvValMap_t& DybChanQualCache::noise ( ) [inline]

Definition at line 54 of file DybChannelQualitySvc.h.

{ return m_noise;}
bool DybChanQualCache::covers ( const TimeStamp start,
const TimeStamp stop 
)

Definition at line 364 of file DybChannelQualitySvc.cc.

{
    return start <= m_lastTS && m_lastTS < stop;
}
DqCpMap_t& DybChanQualCache::channel_quality ( ) [inline]

Definition at line 61 of file DybChannelQualitySvc.h.

{ return m_dqcp; }
void DybChanQualCache::check_hvchid ( DayaBay::HvChannelId  hvch,
const std::string &  who 
) [private]

Definition at line 107 of file DybChannelQualitySvc.cc.

{
    if (!hvch.bogus()) { return; }

    stringstream ss;
    ss << " bogus HvChannelId: " << hvch.asString();
    throw GaudiException(ss.str().c_str(), who, StatusCode::FAILURE);
}
int DybChanQualCache::feechid ( int  hvb,
int  hvc 
) [private]
bool DybChanQualCache::update_hvloc ( Context ctx) [private]

Definition at line 116 of file DybChannelQualitySvc.cc.

{
    DbiResultPtr<GAdWpHvMap>* res = 0;
    bool updated = update_table<GAdWpHvMap>("AdWpHvMap",
                                            ctx, m_timelessSM.task(), m_hvlocKey, res);
    if (updated) { 
        m_loc2hv.clear();
        unsigned int ind, nrows = res->GetNumRows();
        //cerr << "Updating from AdWpHvMap with " << nrows << " rows @ " << ctx.AsString("E") << endl;
        if (!nrows) {
            throw GaudiException("DybChannelQualitySvc no AdWpHvMap entries",
                                 "DybChanQualCache",StatusCode::FAILURE);
        }

        for (ind=0; ind < nrows; ++ind) {
            const GAdWpHvMap* row = res->GetRowByIndex(ind);
            DayaBay::HvChannelId hvch = row->GetHvChannelId();
            check_hvchid(hvch,"AdWpHvMap");
            std::string loc = row->GetLocationId();
            m_loc2hv[loc] = hvch;
        }
    }

    delete res;
    return updated;
}
bool DybChanQualCache::update_hvfee ( Context ctx) [private]

Definition at line 143 of file DybChannelQualitySvc.cc.

{
    DbiResultPtr<GAdWpHvToFee>* res = 0;
    bool updated = update_table<GAdWpHvToFee>("AdWpHvToFee",
                                              ctx, m_timelessSM.task(), m_hvfeeKey, res);
    if (updated) {
        m_hv2fee.clear();
        unsigned int ind, nrows = res->GetNumRows();
        //cerr << "Updating from AdWpHvToFee with " << nrows << " rows @ " << ctx.AsString("E") << endl;
        if (!nrows) {
            throw GaudiException("DybChannelQualitySvc no AdWpHvToFee entries",
                                 "DybChanQualCache",StatusCode::FAILURE);
        }

        for (ind=0; ind < nrows; ++ind) {
            const GAdWpHvToFee* row = res->GetRowByIndex(ind);
            DayaBay::HvChannelId hvch = row->GetHvChannelId();
            check_hvchid(hvch,"AdWpHvToFee");
            DayaBay::FeeChannelId chid = row->GetFeeChannelId();
            m_hv2fee[hvch] = chid;
        }
    }
    delete res;
    return updated;
}
bool DybChanQualCache::update_hvset ( Context ctx,
bool  force 
) [private]

Definition at line 186 of file DybChannelQualitySvc.cc.

{
    DbiResultPtr<GAdWpHvSetting>* res = 0;
    bool updated = update_table<GAdWpHvSetting>("AdWpHvSetting", 
                                                ctx, m_timelessSM.task(), m_hvsetKey, res);
    if (!updated) { updated = force; }
    if (updated) {
        m_hvset.clear();
        unsigned int ind, nrows = res->GetNumRows();
        //cerr << "Updating from AdWpHvToSetting with " << nrows << " rows @ " << ctx.AsString("E") << endl;
        if (!nrows) {
            throw GaudiException("DybChannelQualitySvc no AdWpHvSetting entries",
                                 "DybChanQualCache",StatusCode::FAILURE);
        }

        for (ind=0; ind < nrows; ++ind) {
            const GAdWpHvSetting* row = res->GetRowByIndex(ind);
            DayaBay::HvChannelId hvch = row->GetHvChannelId();
            check_hvchid(hvch,"AdWpHvSetting");
            DayaBay::FeeChannelId feech = hv2fee(hvch);
            m_hvset[feech] = row->GetHvSetting();
        }
    }
    delete res;
    return updated;
}
bool DybChanQualCache::update_hvget ( Context ctx,
bool  force 
) [private]

Definition at line 213 of file DybChannelQualitySvc.cc.

{
    DbiResultPtr<GDcsAdWpHv>* res = 0;
    bool updated = update_table<GDcsAdWpHv>("DcsAdWpHv", 
                                            ctx, m_timelessSM.task(), m_hvgetKey, res);
    if (!updated) { updated = force; }
    if (updated) {
        m_hvget.clear();
        unsigned int ind, nrows = res->GetNumRows();
        //cerr << "Updating from DcsAdWpHv with " << nrows << " rows @ " << ctx.AsString("E") << endl;
        if (!nrows) {
            throw GaudiException("DybChannelQualitySvc no DcsAdWpHv entries",
                                 "DybChanQualCache",StatusCode::FAILURE);
        }

        for (ind=0; ind < nrows; ++ind) {
            const GDcsAdWpHv* row = res->GetRowByIndex(ind);
            std::string loc = row->GetLocationId();
            DayaBay::HvChannelId hvch = m_loc2hv[loc];
            check_hvchid(hvch,loc);
            DayaBay::FeeChannelId feech = hv2fee(hvch);
            m_hvget[feech] = row->GetVoltage();
        }
    }
    delete res;
    return updated;
}
bool DybChanQualCache::update_cmap ( Context ctx) [private]

Definition at line 241 of file DybChannelQualitySvc.cc.

{
    DbiResultPtr<GCableMap>* res = 0;
    bool updated = update_table<GCableMap>("CableMap",
                                           ctx, m_timelessSM.task(), m_cmapKey, res);
    if (updated) {
        m_chlist.clear();
        unsigned int ind=0, nrows = res->GetNumRows();
        if (!nrows) {
            throw GaudiException("DybChannelQualitySvc no CableMap entries",
                                 "DybChanQualCache",StatusCode::FAILURE);
        }
        
        for (ind=0; ind<nrows; ++ind) {
            const GCableMap* row = res->GetRowByIndex(ind);
            DayaBay::AdPmtSensor pmt(row->GetSensorId().fullPackedData());
            if (! pmt.is8inch()) {
                continue;
            }
            m_chlist.push_back(row->GetChannelId().fullPackedData());
        }
        m_chlist.sort();
    }
    delete res;
    return updated;
}
bool DybChanQualCache::update_dqcp ( Context ctx) [private]

Definition at line 267 of file DybChannelQualitySvc.cc.

{
    DbiResultPtr<GDqChannelPacked>* res = 0;
    bool updated = update_table<GDqChannelPacked>("DqChannelPacked",
                                                  ctx, m_timelessSM.task(), m_dqcpKey, res);
    if (updated) {
        unsigned int nrows = res->GetNumRows();
        if (!nrows) {
            throw GaudiException("DybChannelQualitySvc no DqChannelPacked entries",
                                 "DybChanQualCache",StatusCode::FAILURE);
        }
        
        if (nrows > 1) {
            cerr << "Got ignoring additional ("<<nrows-1<<") DqChannelPacked results for " << ctx.AsString() << endl;
        }
        const GDqChannelPacked* row = res->GetRowByIndex(0);
        ChannelPacked::CQpacked packed;
        packed.push_back(row->GetMask0());
        packed.push_back(row->GetMask1());
        packed.push_back(row->GetMask2());
        packed.push_back(row->GetMask3());
        packed.push_back(row->GetMask4());
        packed.push_back(row->GetMask5());
        packed.push_back(row->GetMask6());
        
        ChannelPacked::CQbits channel_quality = ChannelPacked::unpack(packed);

        ChList_t::iterator it, done = m_chlist.end();
        int cqind = 0;
        m_dqcp.clear();
        for (it=m_chlist.begin(); it != done; ++it, ++cqind) {
            DayaBay::FeeChannelId chid(*it);
            m_dqcp[chid] = channel_quality[cqind]; // whew
        }
    }
    delete res;
    return updated;
    
}
bool DybChanQualCache::update_noise ( Context ctx,
bool  force 
) [private]

Definition at line 309 of file DybChannelQualitySvc.cc.

{
    //cerr << "update_noise("<<ctx.AsString("E")<<") clearing " << m_noise.size() << " channels" << endl;
    m_noise.clear();

    for (int ind=0; Dyb::noisy_channels[ind].channel.fullPackedData(); ++ind) {
        Dyb::NoisyChannel& nc = Dyb::noisy_channels[ind];
        //cerr << "update_noise() checking: " << nc.channel << " from " << nc.start.AsString("E") << " to " << nc.stop.AsString("E") << endl;

        if (! nc.covered(ctx)) { continue; }
        //cerr << "Caching based on " << ctx.AsString("E") << endl;
        m_noise[nc.channel] = nc.noise;
    }

    //cerr << "update_noise(): cached " << m_noise.size() << " noisy channels" << endl;
    return true;
}
DayaBay::FeeChannelId DybChanQualCache::hv2fee ( DayaBay::HvChannelId  hvch) [private]

Definition at line 169 of file DybChannelQualitySvc.cc.

{
    DayaBay::FeeChannelId feech = m_hv2fee[hvch];
    if (feech.bogus()) {
        stringstream ss;
        // ss << "Got bogus FeeChannelId out of " << m_hv2fee.size() 
        //    << " from HvChannelId=" << hvch
        //    << ", crate=" << hvch.crate()
        //    << ", board=" << hvch.slot()
        //    << ", channel=" << hvch.channel();
        throw GaudiException(ss.str().c_str(),
                             "DybChanQualCache",StatusCode::FAILURE);
    }
    return feech;
}

Member Data Documentation

Definition at line 84 of file DybChannelQualitySvc.h.

Definition at line 86 of file DybChannelQualitySvc.h.

Definition at line 89 of file DybChannelQualitySvc.h.

Definition at line 90 of file DybChannelQualitySvc.h.

Definition at line 91 of file DybChannelQualitySvc.h.

DqCpMap_t DybChanQualCache::m_dqcp [mutable, private]

Definition at line 92 of file DybChannelQualitySvc.h.

Definition at line 96 of file DybChannelQualitySvc.h.

Definition at line 98 of file DybChannelQualitySvc.h.

Definition at line 99 of file DybChannelQualitySvc.h.

Definition at line 100 of file DybChannelQualitySvc.h.

Definition at line 101 of file DybChannelQualitySvc.h.

Definition at line 102 of file DybChannelQualitySvc.h.

Definition at line 103 of file DybChannelQualitySvc.h.

Definition at line 107 of file DybChannelQualitySvc.h.

Definition at line 111 of file DybChannelQualitySvc.h.

bool DybChanQualCache::m_useHV [private]

Definition at line 114 of file DybChannelQualitySvc.h.

Definition at line 114 of file DybChannelQualitySvc.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:00:00 for DybMetaDataSvc by doxygen 1.7.4