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

In This Package:

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

Drive output and AES trimming. More...

#include <DybArchiveOutput.h>

Collaboration diagram for DybArchiveOutput:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DybArchiveOutput (const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize ()
StatusCode execute ()
StatusCode finalize ()
StatusCode stop ()

Private Types

typedef std::map< std::string,
DybArchiveList * > 
AESListMap_t

Private Member Functions

DayaBay::RegistrationSequencecondemned ()
StatusCode erase (const DataObject *object, const std::string &path)
StatusCode store (DayaBay::RegistrationSequence *rs)
StatusCode trim (DayaBay::RegistrationSequence *rs)
StatusCode process (DayaBay::RegistrationSequence *rs)
StatusCode sweep_up ()
DybArchiveListaes_list (const std::string &location)
DybArchiveList::iterator find_in_archive (DybArchiveList *aeslist, const DataObject *object)

Private Attributes

double m_window
bool m_saveFlag
std::string m_regSeqLocation
std::string m_aesName
IDataProviderSvc * m_aes
std::string m_dybStorageSvcName
IDybStorageSvcm_store
IIncidentSvc * m_incsvc
AESListMap_t m_aesListMap

Detailed Description

Drive output and AES trimming.

This is a drop in replacement for DybTrimIO

bv@bnl.gov Thu Oct 13 17:39:13 2011

Definition at line 26 of file DybArchiveOutput.h.


Member Typedef Documentation

typedef std::map<std::string,DybArchiveList*> DybArchiveOutput::AESListMap_t [private]

Definition at line 63 of file DybArchiveOutput.h.


Constructor & Destructor Documentation

DybArchiveOutput::DybArchiveOutput ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 13 of file DybArchiveOutput.cc.

 : GaudiAlgorithm(name, pSvcLocator)
 , m_aes(0)
 , m_store(0)
 , m_incsvc(0)
{
    declareProperty("WindowSeconds", m_window = 0.0, "Time window to apply to the AES");    
    declareProperty("SaveOutput", m_saveFlag = false, "Set to true to save ouput, default is false");
    declareProperty("RegSeqLocation",
                    m_regSeqLocation = DayaBay::RegistrationSequenceLocation::Default,
                    "Location to RegistrationSequence");
    declareProperty("ArchiveSvc",
                    m_aesName = "EventDataArchiveSvc",
                    "Name of Archive Event Store");
    declareProperty("DybStorageSvc",
                    m_dybStorageSvcName = "DybStorageSvc",
                    "Name of an IDybStorageSvc");
}

Member Function Documentation

StatusCode DybArchiveOutput::initialize ( )

Definition at line 32 of file DybArchiveOutput.cc.

{
    StatusCode sc = GaudiAlgorithm::initialize();
    if (sc.isFailure()) return sc;

    sc = service(m_aesName,m_aes);
    if (sc.isFailure()) return sc;

    if (m_saveFlag) {
        sc = service(m_dybStorageSvcName, m_store);
        if (sc.isFailure()) return sc;    
    }

    sc = service("IncidentSvc",m_incsvc,true);
    if (sc.isFailure()) return sc;

    debug() << "initialized" << endreq;

    return StatusCode::SUCCESS;
}
StatusCode DybArchiveOutput::execute ( )

Definition at line 220 of file DybArchiveOutput.cc.

{
    // save and trim until no more 
    while (true) {
        RegistrationSequence* rs = condemned();
        if (!rs) { 
            return StatusCode::SUCCESS;
        }

        StatusCode sc = process(rs);
        if (sc.isFailure()) {
            // fixme: error msg
            return sc;
        }
    }
    
    // actually, should never reach here.
    return StatusCode::SUCCESS;
}
StatusCode DybArchiveOutput::finalize ( )

Definition at line 269 of file DybArchiveOutput.cc.

{
    debug() << "finalize" << endreq;

    StatusCode sc = sweep_up();
    if (sc.isFailure()) {
        return sc;
    }

    return GaudiAlgorithm::finalize();
}
StatusCode DybArchiveOutput::stop ( )

Definition at line 263 of file DybArchiveOutput.cc.

{
    debug() << "stop called" << endreq;

    return GaudiAlgorithm::stop();
}
RegistrationSequence * DybArchiveOutput::condemned ( ) [private]

Definition at line 172 of file DybArchiveOutput.cc.

{
    // Try to return the next RS if it is out of the window

    DybArchiveList* rslist = aes_list(m_regSeqLocation);
    if (! rslist) return 0;
    if (rslist->size() <= 1) return 0;

    // newest objects are push_front'ed, so we must check the back for oldest.
    DybArchiveList::reverse_iterator rit_old = rslist->rbegin();
    DybArchiveList::iterator rit_new = rslist->begin();
    RegistrationSequence* rs_old = dynamic_cast<RegistrationSequence*>(*rit_old);
    RegistrationSequence* rs_new = dynamic_cast<RegistrationSequence*>(*rit_new);

    if (!rs_old || !rs_new) {
        error() << "Not a RegistrationSequence at " << m_regSeqLocation << endreq;
        return 0;
    }

    TimeStamp threshold = rs_new->earliest();
    threshold.Add(-1.0 * m_window);

    if (rs_old->earliest() > threshold) {
        return 0;
    }

    return rs_old;              // I salute you.
}
StatusCode DybArchiveOutput::erase ( const DataObject *  object,
const std::string &  path 
) [private]

Definition at line 121 of file DybArchiveOutput.cc.

{
    DybArchiveList* lst = aes_list(path);
    if (!lst) {
        error() << "No AES list for " << path << endreq;
        return StatusCode::FAILURE;
    }

    DybArchiveList::iterator todie = find_in_archive(lst,object);
    if (todie == lst->end()) {
        error() << "Failed to find object for " << path
                << " object:" << dostr(object)
                << endreq;
        return StatusCode::FAILURE;
    }

    m_incsvc->fireIncident(EventStoreIncident(object, false, "TrimmingAgent"));

    debug() << "Erasing object from " << path
            << " object:" << dostr(object)
            << endreq;

    lst->erase(todie);  // when Registration is dtor'ed, object.release() is called

    return StatusCode::SUCCESS;
}
StatusCode DybArchiveOutput::store ( DayaBay::RegistrationSequence rs) [private]

Definition at line 96 of file DybArchiveOutput.cc.

{
    if (! m_store) {            // not configure to store data
        return StatusCode::SUCCESS;
    }

    debug() << "Storing RegistrationSequence with "
            << rs->size() << " registrations spanning " 
            << rs->earliest() << " --> " << rs->latest()
            << endreq;
    return m_store->store(*rs);
}
StatusCode DybArchiveOutput::trim ( DayaBay::RegistrationSequence rs) [private]

Definition at line 147 of file DybArchiveOutput.cc.

{
    const IRegistrationSequence::Registrations& regs = rs->registrations();
    IRegistrationSequence::Registrations::const_iterator regit, regend = regs.end();

    // First remove all registrations from their AES lists
    for (regit = regs.begin(); regit != regend; ++regit) {
        const ObjectReg& reg = (*regit);
        StatusCode sc = erase(reg.object(),reg.path());
        if (sc.isFailure()) {
            return StatusCode::FAILURE;
        }

    }

    // Finally, trim the RegistrationSequence itself.
    StatusCode sc = erase(rs,m_regSeqLocation);
    if (sc.isFailure()) {
        return StatusCode::FAILURE;
    }

    return StatusCode::SUCCESS;
}    
StatusCode DybArchiveOutput::process ( DayaBay::RegistrationSequence rs) [private]

Definition at line 201 of file DybArchiveOutput.cc.

{
    // Process one RS, maybe store and then trim

    StatusCode sc = store(rs);
    if (sc.isFailure()) {
        error() << "Failed to store RegistrationSequence: " << dostr(rs) << endreq;
        return sc;
    }

    sc = trim(rs);
    if (sc.isFailure()) {
        error() << "Failed to trim RegistrationSequence: " << dostr(rs) << endreq;
        return sc;
    }

    return StatusCode::SUCCESS;
 }
StatusCode DybArchiveOutput::sweep_up ( ) [private]

Definition at line 240 of file DybArchiveOutput.cc.

{
    // process any remaining data left in the AES.

    DybArchiveList* rslist = aes_list(m_regSeqLocation);

    debug() << "sweeping up with " << rslist->size() << " RegistrationSequences to process" << endreq;

    // be careful iterating over this list because it is being erased as we go
    while (true) {              
        if (!rslist->size()) {
            break;
        }

        DybArchiveList::reverse_iterator rit = rslist->rbegin();
        RegistrationSequence* rs = dynamic_cast<RegistrationSequence*>(*rit);
        StatusCode sc = process(rs);
        if (sc.isFailure()) {
            return sc;
        }
    }
    return StatusCode::SUCCESS;
}
DybArchiveList * DybArchiveOutput::aes_list ( const std::string &  location) [private]

Definition at line 70 of file DybArchiveOutput.cc.

{
    // return the list at the given location or null if it d.n.e.  use
    // local cache to avoid somewhat expensive calls to
    // aes->retrieveObject().

    AESListMap_t::iterator it = m_aesListMap.find(location);
    if (it != m_aesListMap.end()) { // cache hit
        return it->second;
    }

    DataObject* object = 0;
    StatusCode sc = m_aes->retrieveObject(location,object);
    if (sc.isFailure()) {       // not here now but maybe later.
        return 0;
    }
    DybArchiveList* aesList = dynamic_cast<DybArchiveList*>(object);
    if (!aesList) {
        // fixme: add warning msg
        return 0;
    }
    
    m_aesListMap[location] = aesList;
    return aesList;
}
DybArchiveList::iterator DybArchiveOutput::find_in_archive ( DybArchiveList aeslist,
const DataObject *  object 
) [private]

Definition at line 109 of file DybArchiveOutput.cc.

{
    DybArchiveList::iterator it, done = aeslist->end();
    for (it = aeslist->begin(); it != done; ++it) {
        if (object == *it) {
            return it;
        }
    }
    return done;
}

Member Data Documentation

double DybArchiveOutput::m_window [private]

Definition at line 38 of file DybArchiveOutput.h.

Definition at line 41 of file DybArchiveOutput.h.

std::string DybArchiveOutput::m_regSeqLocation [private]

Definition at line 44 of file DybArchiveOutput.h.

std::string DybArchiveOutput::m_aesName [private]

Definition at line 47 of file DybArchiveOutput.h.

IDataProviderSvc* DybArchiveOutput::m_aes [private]

Definition at line 48 of file DybArchiveOutput.h.

Definition at line 51 of file DybArchiveOutput.h.

Definition at line 52 of file DybArchiveOutput.h.

IIncidentSvc* DybArchiveOutput::m_incsvc [private]

Definition at line 54 of file DybArchiveOutput.h.

Definition at line 64 of file DybArchiveOutput.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:09:44 for DybAlg by doxygen 1.7.4