/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 | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
DybDualEventLoopMgr Class Reference

#include <DybDualEventLoopMgr.h>

Inheritance diagram for DybDualEventLoopMgr:
Inheritance graph
[legend]
Collaboration diagram for DybDualEventLoopMgr:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DybDualEventLoopMgr (const std::string &nam, ISvcLocator *svcLoc)
virtual ~DybDualEventLoopMgr ()
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode reinitialize ()
virtual StatusCode nextEvent (int maxevt)
virtual StatusCode executeRun (int maxevt)
virtual StatusCode executeEvent (void *par)

Protected Member Functions

StatusCode getEventRoot (IOpaqueAddress *&refpAddr)
 Create event address using event selector.

Protected Attributes

IDataManagerSvc * m_evtDataMgrSvc
IDataProviderSvc * m_evtDataSvc
IEvtSelector * m_evtSelector
IEvtSelector::Context * m_evtContext

Private Member Functions

bool switch_state (bool force=false)
void union_alg_list ()
StatusCode initialize_algs ()
StatusCode decodeTopAlgs ()

Private Attributes

ELMStatem_theState
ELMStatem_theLastState
ELMStatem_state1
ELMStatem_state2
std::string m_eventBuilderAlgName
 Property: EventBuilderAlg: name of the algorithm that builds events.
IIncidentSvc * m_incsvc
IAesFeederm_aesfeed
HEIHandlerm_heiHandler

Detailed Description

Definition at line 15 of file DybDualEventLoopMgr.h.


Constructor & Destructor Documentation

DybDualEventLoopMgr::DybDualEventLoopMgr ( const std::string &  nam,
ISvcLocator *  svcLoc 
)

Definition at line 37 of file DybDualEventLoopMgr.cpp.

  : DybEventLoopMgr(nam, svcLoc)
  , m_theState(0)
  , m_state1(new ELMState)
  , m_state2(new ELMState)
  , m_incsvc(0)
  , m_heiHandler(0)
{
    // My additional properties
    declareProperty("EventBuilderAlg",m_eventBuilderAlgName = "EventBuilderAlg",
                    "Name of the algorithm responsible for building events (def: EventBuilderAlg)");
}
DybDualEventLoopMgr::~DybDualEventLoopMgr ( ) [virtual]

Definition at line 50 of file DybDualEventLoopMgr.cpp.

{
}

Member Function Documentation

StatusCode DybDualEventLoopMgr::initialize ( ) [virtual]

Reimplemented from DybEventLoopMgr.

Definition at line 54 of file DybDualEventLoopMgr.cpp.

{
    MsgStream log(msgSvc(), name());

    log << MSG::DEBUG
        << "calling DybEventLoopMgr::intialize(),"
        << " state = " << FSMState() 
        << " targeting " << targetFSMState()
        << endreq;

    StatusCode sc = DybEventLoopMgr::initialize();
    if (sc.isFailure()) {
        log << MSG::ERROR << "Failed to initialize DybEventLoopMgr base class" << endreq;
        return sc;
    }
    log << MSG::DEBUG
        << "returned from DybEventLoopMgr::intialize()"
        << " state = " << FSMState() 
        << " targeting " << targetFSMState()
        << endreq;


    sc = m_evtDataSvc->queryInterface(IAesFeeder::interfaceID(),(void**)&m_aesfeed);
    if (sc.isFailure()) {
        log << MSG::ERROR
            << "Failed to get interface IAesFeeder from event data service."
            << endreq;
        return sc;
    }

    sc = this->initialize_algs();
    if (sc.isFailure()) {
        log << MSG::ERROR << "Failed to initialize algorithms" << endreq;
        return sc;
    }

    // Connect to "HybridExecutionIncident"
    sc = this->service("IncidentSvc",m_incsvc,true);
    if (sc.isFailure()) {
        log << MSG::ERROR
            << "Failed to get IncidentSvc" << endreq;
        return sc;
    }
    
    m_heiHandler = new HEIHandler(m_theState, m_state1, m_state2);
    m_incsvc->addListener(m_heiHandler,"HybridExecutionIncident");

    return StatusCode::SUCCESS;
}
StatusCode DybDualEventLoopMgr::finalize ( ) [virtual]

Reimplemented from DybEventLoopMgr.

Definition at line 200 of file DybDualEventLoopMgr.cpp.

{
    MsgStream log(msgSvc(), name());
    log << MSG::INFO << "A useless message about me finalizing" << endreq;

    m_incsvc->removeListener(m_heiHandler,"HybridExecutionIncident");
    delete m_heiHandler; m_heiHandler = 0;
    m_incsvc->release();
    m_incsvc = 0;

    union_alg_list();
    return DybEventLoopMgr::finalize();    
}
StatusCode DybDualEventLoopMgr::reinitialize ( ) [virtual]

Reimplemented from DybEventLoopMgr.

Definition at line 215 of file DybDualEventLoopMgr.cpp.

{
    MsgStream log(msgSvc(), name());
    log << MSG::WARNING << "Why am I being reinitialized?" << endreq;
    return StatusCode::SUCCESS;
}
StatusCode DybDualEventLoopMgr::nextEvent ( int  maxevt) [virtual]

Reimplemented from DybEventLoopMgr.

Definition at line 246 of file DybDualEventLoopMgr.cpp.

{
    StatusCode        sc = StatusCode::SUCCESS;
    MsgStream         log( msgSvc(), name() );

    log << MSG::DEBUG
        << "nextEvent(" << maxevt << ")"
        << endreq;

    ListAlg save_topAlgList = m_topAlgList;

    // force starting at state 1
    m_theState = m_state1;
    switch_state(true);

    // loop over events if the maxevt (received as input) if different from -1. 
    // if evtmax is -1 it means infinite loop
    int nevt = 0;
    bool been_here = false;
    while (true) {

        switch_state();

        log << MSG::DEBUG
            << "Event #" << nevt 
            << " in state " << (m_theState == m_state1 ? "one" : "two")
            << " with " << m_theState->topAlgList.size() << " algorithms"
            << endreq;
        dump_algs(log,m_theState->topAlgList);

        if (m_theState == m_state2) {
            if (maxevt != -1 && nevt >= maxevt) {
                break;
            }
            ++nevt;
        }

        log << MSG::DEBUG
            << "Executing event loop #" << nevt << endreq;

        // Check if there is a scheduled stop issued by some algorithm/sevice
        if (m_scheduledStop) {
            m_scheduledStop = false;
            log << MSG::ALWAYS
                << "Terminating event processing loop due to scheduled stop" << endreq;
            m_topAlgList = save_topAlgList;
            return StatusCode::SUCCESS;
        }

        if (true) {             // this block is for debugging and can be turned off

            // Want to avoid getting readout-phase objects tangled up
            // in AES and OHS.
            if (m_theState == m_state1) {
                log << MSG::DEBUG << "Inhibiting AES feeding" << endreq;
                m_aesfeed->inhibit();
            }
            else {
                log << MSG::DEBUG << "Enabling AES feeding" << endreq;
                m_aesfeed->enable();
            }

            dump_tes(m_evtDataMgrSvc,log);
        }

        if (been_here) {
            sc = m_evtDataMgrSvc->clearStore();
            if (sc.isFailure()) {
                log << MSG::WARNING << "Clear of Event data store failed" << endreq;
            }
            log << MSG::DEBUG << "Cleared event store" << endreq;
            dump_tes(m_evtDataMgrSvc,log);
        }
        else {
            been_here = true;
        }
        // Setup event in the event store only in state1
        if (m_theState == m_state1 && m_evtContext) {
            IOpaqueAddress* addr = 0;
            // Only if there is a EventSelector
            sc = getEventRoot(addr);
            if (sc.isFailure())  {
                log << MSG::INFO << "No more events in event selection " << endreq;
                m_topAlgList = save_topAlgList;
                return StatusCode::SUCCESS;
            }

            // Set root clears the event data store first
            sc = m_evtDataMgrSvc->setRoot("/Event", addr);
            if (sc.isFailure())  {
                log << MSG::WARNING << "Error declaring event root address." << endreq;
                continue; // not failure?
            }
            DataObject* pObject = 0;
            sc = m_evtDataSvc->retrieveObject("/Event", pObject);
            if( sc.isFailure() ) {
                log << MSG::WARNING << "Unable to retrieve Event root object" << endreq;
                m_topAlgList = save_topAlgList;
                return StatusCode::FAILURE;
            }
        }
        else {
            sc = m_evtDataMgrSvc->setRoot ("/Event", new DataObject());
            if (sc.isFailure() )  {
                log << MSG::WARNING << "Error declaring event root DataObject" << endreq;
            } 
        }
        // Execute event for all required algorithms
        sc = executeEvent(NULL);
        if (sc.isFailure()){
            log << MSG::ERROR << "Terminating event processing loop due to errors" << endreq;
            m_topAlgList = save_topAlgList;
            return StatusCode::FAILURE;
        }
    }
    m_topAlgList = save_topAlgList;
    return StatusCode::SUCCESS;
}
StatusCode DybDualEventLoopMgr::executeRun ( int  maxevt) [virtual]

Definition at line 365 of file DybDualEventLoopMgr.cpp.

bool DybDualEventLoopMgr::switch_state ( bool  force = false) [private]

Definition at line 161 of file DybDualEventLoopMgr.cpp.

{
    MsgStream log(msgSvc(), name());

    if (!force && m_theLastState == m_theState) {
        log << MSG::DEBUG
            << "switch_state("<<force<<") keeping state " 
            << (m_theState == m_state1 ? "one" : "two")
            << endreq;
        return false;
    }

    // Set MinimalEventLoopMgr's TopAlg list
    m_theLastState = m_theState;
    m_topAlgList = m_theState->topAlgList;

    log << MSG::DEBUG
        << "switch_state("<<force<<") switched state to " 
        << (m_theState == m_state1 ? "one" : "two")
        << " with algs:"
        << endreq;
    dump_algs(log,m_topAlgList);
    return true;
}
void DybDualEventLoopMgr::union_alg_list ( ) [private]

Definition at line 187 of file DybDualEventLoopMgr.cpp.

{
    m_topAlgList.clear();
    m_topAlgList.insert(m_topAlgList.end(), 
                        m_state1->topAlgList.begin(), 
                        m_state1->topAlgList.end()); 
    if (m_state2->topAlgList.size()) {
        m_topAlgList.insert(m_topAlgList.end(), 
                            ++m_state2->topAlgList.begin(), 
                            m_state2->topAlgList.end()); 
    }
}
StatusCode DybDualEventLoopMgr::initialize_algs ( ) [private]

Definition at line 105 of file DybDualEventLoopMgr.cpp.

{
    MsgStream log(msgSvc(), name());
    StatusCode sc = StatusCode::SUCCESS;

    log << MSG::DEBUG
        << "initializing top alg lists with "
        << m_topAlgList.size()
        << " algorithms."
        << endreq;

    ELMState* theState = m_state1;
    ListAlg::iterator it, done = m_topAlgList.end();
    for (it = m_topAlgList.begin(); it != done; ++it) {
        IAlgorithm* ialg = *it;
        SmartIF<IStateful> istate(IID_IStateful,ialg);
        
        std::string name = ialg->name();

        log << MSG::DEBUG
            << "Algorithm \"" << name << "\"" 
            << " in state " << istate->FSMState() 
            << " targetting " << istate->targetFSMState() 
            << endreq;
        
        theState->topAlgList.push_back(ialg);
        if (name == m_eventBuilderAlgName) {
            theState = m_state2; // switch to second list
            theState->topAlgList.push_back(ialg); // event builder goes in both
        }            
    }

    if (!m_state2->topAlgList.size()) {
        log << MSG::WARNING
            << "Did not find event builder algorithm: \"" 
            << m_eventBuilderAlgName << "\""
            << endreq;
        //return StatusCode::FAILURE;
    }

    // Start with list #1
    m_theState = m_state1;
    switch_state(true);
    return sc;
}
StatusCode DybDualEventLoopMgr::decodeTopAlgs ( ) [inline, private]

Definition at line 48 of file DybDualEventLoopMgr.h.

{ return SUCCESS; }
StatusCode DybEventLoopMgr::executeEvent ( void *  par) [virtual, inherited]

Definition at line 113 of file DybEventLoopMgr.cpp.

{
    MsgStream log(msgSvc(), name());

    if (m_scheduledStop) {
        log << MSG::ALWAYS 
            << "Terminating event processing loop due to a stop scheduled by an incident listener"
            << endreq;
        return StatusCode::SUCCESS;
    }

    // Execute Algorithms
    StatusCode sc = MinimalEventLoopMgr::executeEvent(par);
    if (sc.isFailure()) {
        log << MSG::ERROR << "Terminating event processing loop due to errors" << endreq;
    }

    return sc;
}
StatusCode DybEventLoopMgr::getEventRoot ( IOpaqueAddress *&  refpAddr) [protected, inherited]

Create event address using event selector.

Definition at line 198 of file DybEventLoopMgr.cpp.

{
    refpAddr = 0;
    StatusCode sc = m_evtSelector->next(*m_evtContext);
    if (sc.isFailure())  {
        return sc;
    }

    // Create root address and assign address to data service
    sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
    if (sc.isFailure()) {
        sc = m_evtSelector->next(*m_evtContext);
        if (sc.isSuccess()) {
            sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
            if (sc.isFailure())  {
                MsgStream log( msgSvc(), name() );
                log << MSG::WARNING << "Error creating IOpaqueAddress." << endreq;
            }
        }
    }
    return sc;
}

Member Data Documentation

Definition at line 33 of file DybDualEventLoopMgr.h.

Definition at line 33 of file DybDualEventLoopMgr.h.

Definition at line 33 of file DybDualEventLoopMgr.h.

Definition at line 33 of file DybDualEventLoopMgr.h.

Property: EventBuilderAlg: name of the algorithm that builds events.

Definition at line 38 of file DybDualEventLoopMgr.h.

IIncidentSvc* DybDualEventLoopMgr::m_incsvc [private]

Definition at line 40 of file DybDualEventLoopMgr.h.

Definition at line 41 of file DybDualEventLoopMgr.h.

Definition at line 43 of file DybDualEventLoopMgr.h.

IDataManagerSvc* DybEventLoopMgr::m_evtDataMgrSvc [protected, inherited]

Definition at line 62 of file DybEventLoopMgr.h.

IDataProviderSvc* DybEventLoopMgr::m_evtDataSvc [protected, inherited]

Definition at line 63 of file DybEventLoopMgr.h.

IEvtSelector* DybEventLoopMgr::m_evtSelector [protected, inherited]

Definition at line 64 of file DybEventLoopMgr.h.

IEvtSelector::Context* DybEventLoopMgr::m_evtContext [protected, inherited]

Definition at line 65 of file DybEventLoopMgr.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:08 for DybEventMgr by doxygen 1.7.4