/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
EventBuilderAlg Class Reference

Build events. More...

#include <EventBuilderAlg.h>

List of all members.

Public Member Functions

 EventBuilderAlg (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~EventBuilderAlg ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()

Private Types

typedef std::pair
< DayaBay::HeaderObject
*, std::string > 
LocatedObject_t
typedef std::list
< LocatedObject_t
ObjectList_t

Private Member Functions

void switch_mode ()
void collect_frames (DayaBay::HeaderObject &framesTag)
DayaBay::HeaderObjectcollect_headers ()
std::string locate (DayaBay::HeaderObject &ho, const std::string &path)
void build_event (DayaBay::HeaderObject &frameTag)
void build_events (DayaBay::HeaderObject &framesTag)
StatusCode execute_event ()
StatusCode execute_readout ()
ObjectList_t::iterator objects_find (DayaBay::HeaderObject &ho)
LocatedObject_t objects_pop (DayaBay::HeaderObject &ho)
void objects_push (DayaBay::HeaderObject &ho, std::string loc)
bool objects_in (DayaBay::HeaderObject &ho)
void add_to_event (ObjectList_t &event, DayaBay::HeaderObject &ho)
void build_derived (ObjectList_t &event, DayaBay::HeaderObject &ho)
void dump_vecho (std::vector< DayaBay::HeaderObject * > &hos)
void dump_objects ()

Private Attributes

std::string m_location
int m_firstEvent
IIncidentSvc * m_incsvc
int m_eventNumber
int m_branch
ObjectList_t m_objects
std::list< ObjectList_tm_events

Detailed Description

Build events.

This is a C++ reimplementation of the Python class HybridLoop.EventBuilderAlg

bv@bnl.gov Wed Sep 28 16:04:07 2011

Definition at line 26 of file EventBuilderAlg.h.


Member Typedef Documentation

typedef std::pair<DayaBay::HeaderObject*,std::string> EventBuilderAlg::LocatedObject_t [private]

Definition at line 49 of file EventBuilderAlg.h.

typedef std::list<LocatedObject_t> EventBuilderAlg::ObjectList_t [private]

Definition at line 52 of file EventBuilderAlg.h.


Constructor & Destructor Documentation

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

Definition at line 11 of file EventBuilderAlg.cpp.

  : GaudiAlgorithm(name,pSvcLocator)
  , m_incsvc(0)
  , m_branch(1)                 // start in readout mode
{
    declareProperty("Location",m_location="/Event/EventBuilder/Frames",
                    "TES Location for frames collection");
    
    declareProperty("FirstEvent", m_firstEvent = 0,
                    "Starting event number");
}
EventBuilderAlg::~EventBuilderAlg ( ) [virtual]

Definition at line 23 of file EventBuilderAlg.cpp.

{
}

Member Function Documentation

StatusCode EventBuilderAlg::initialize ( ) [virtual]

Definition at line 27 of file EventBuilderAlg.cpp.

{
    StatusCode status = GaudiAlgorithm::initialize();
    if (status.isFailure()) {
        error() << "Failed initialize base class GaudiAlgorithm" << endmsg;
        return status;
    }

    m_eventNumber = m_firstEvent;

    status = service("IncidentSvc", m_incsvc, true);
    if (status.isFailure()) {
        error() << "Failed to get IncidentSvc" << endmsg;
        return status;
    }
    info () << "C++ version initialized" << endreq;
    return status;
}
StatusCode EventBuilderAlg::execute ( ) [virtual]

Definition at line 92 of file EventBuilderAlg.cpp.

{
    // handle switching between readout/event modes and delegate the
    // work to a per-mode execute_*() method

    if (m_branch == 1) {        // readout mode
        return this->execute_readout();
    }

    // event mode

    StatusCode sc = this->execute_event();
    ++m_eventNumber;

    if (!m_events.size()) {
        switch_mode();
    }
    return sc;
}
StatusCode EventBuilderAlg::finalize ( ) [virtual]

Definition at line 112 of file EventBuilderAlg.cpp.

void EventBuilderAlg::switch_mode ( ) [private]

Definition at line 119 of file EventBuilderAlg.cpp.

{
    // switch between modes, notify the world

    m_branch = (m_branch % 2) + 1; // 1<-->2
    debug () << "Switching to " <<  (m_branch==1 ? "READOUT" : "EVENT") << endreq;
    m_incsvc->fireIncident(HybridExecutionIncident(m_branch,name()));
}
void EventBuilderAlg::collect_frames ( DayaBay::HeaderObject framesTag) [private]

Definition at line 145 of file EventBuilderAlg.cpp.

{
    std::vector<const IHeader*> framesVec = framesTag.inputHeaders();
    std::vector<DayaBay::HeaderObject*> frames = bustsomehos(framesVec);
    size_t nframes = frames.size();
    for (size_t iframe=0; iframe<nframes; ++iframe) {
        HeaderObject* frame = frames[iframe];
        std::vector<const IHeader*> frameVec = frame->inputHeaders();
        std::vector<DayaBay::HeaderObject*> rohs = bustsomehos(frameVec);
        size_t nrohs = rohs.size();
        for (size_t iroh=0; iroh<nrohs; ++iroh) {
            HeaderObject* ho = rohs[iroh];
            objects_push(*ho,ho->defLoc());
        }
    }

    debug() << "Collected " << frames.size() << " frames" << endreq;
}
HeaderObject * EventBuilderAlg::collect_headers ( ) [private]

Definition at line 166 of file EventBuilderAlg.cpp.

{
    RegistrationSequence* rs = get<RegistrationSequence>("/Event/RegistrationSequence");
    if (!rs) return 0;

    HeaderObject* frames = 0;

    std::vector<ObjectReg> regs = rs->registrations();
    size_t nregs = regs.size();
    for (size_t ireg=0; ireg<nregs; ++ireg) {
        ObjectReg objreg = regs[ireg];
        std::string path = objreg.path();
        if (path == m_location) {
            frames = dynamic_cast<HeaderObject*>(objreg.object());
            //collect_frames(*frames);
            continue;
        }
        if (path.find("/Chunk") != std::string::npos) {
            continue;
        }
        HeaderObject* ho = dynamic_cast<HeaderObject*>(objreg.object());
        objects_push(*ho,path);
    }

    debug() << "Have now collected " << m_objects.size() << " header objects" << endreq;
    return frames;
}
std::string EventBuilderAlg::locate ( DayaBay::HeaderObject ho,
const std::string &  path 
) [private]

Definition at line 256 of file EventBuilderAlg.cpp.

{
    std::string cname = classname(ho);
    std::string dname = DetectorId::AsString(ho.context().GetDetId());

    const char* tmp1[] = {"RecHeader","UserDataHeader","HeaderObject"};
    std::vector<std::string> needname = arr2vec(3, tmp1);
    const char* tmp2[] = {"Rec","Data","Tags"};
    std::vector<std::string> wantname = arr2vec(3, tmp2);

    size_t ind = index(needname,cname);

    if (ind != needname.size()) {
        std::string name = basename((char*)path.c_str());
        return "/Event/" + wantname[ind] + "/" + name + "/" + dname;
    }

    cname = replace(cname,"Header");

    return "/Event/" + cname + "/" + dname;
}
void EventBuilderAlg::build_event ( DayaBay::HeaderObject frameTag) [private]

Definition at line 384 of file EventBuilderAlg.cpp.

{
    ObjectList_t event;
    
    std::vector<const IHeader*> frameVec = frameTag.inputHeaders();
    std::vector<DayaBay::HeaderObject*> rohs = bustsomehos(frameVec);

    size_t nrohs = rohs.size();
    debug() << "Building event" << endreq;
    dump_vecho(rohs);
    for (size_t iroh=0; iroh<nrohs; ++iroh) {
        HeaderObject* ho = rohs[iroh];
        add_to_event(event,*ho);
        build_derived(event,*ho);
    }

    m_events.push_back(event);

    debug() << "Built event #" << m_events.size() 
            << " with " << nrohs << " ReadoutHeaders and "
            << event.size() << " HeaderObjects total."
            << endreq;
}
void EventBuilderAlg::build_events ( DayaBay::HeaderObject framesTag) [private]

Definition at line 432 of file EventBuilderAlg.cpp.

{
    std::vector<const IHeader*> framesVec = framesTag.inputHeaders();
    std::vector<DayaBay::HeaderObject*> frames = bustsomehos(framesVec);
    debug() << "Building events" << endreq;
    dump_vecho(frames);
    size_t nframes = frames.size();
    for (size_t iframe=0; iframe<nframes; ++iframe) {
        HeaderObject* ho = frames[iframe];
        build_event(*ho);
    }
}
StatusCode EventBuilderAlg::execute_event ( ) [private]

Definition at line 445 of file EventBuilderAlg.cpp.

{
    ObjectList_t event = *m_events.begin();
    m_events.pop_front();

    ObjectList_t::iterator it, done = event.end();
    for (it = event.begin(); it != done; ++it) {
        LocatedObject_t lo = *it;
        HeaderObject* ho = lo.first;
        ho->setExecNumber(m_eventNumber);
        put(ho,lo.second);
        ho->release();
    }
    event.clear();

    return SUCCESS;
}
StatusCode EventBuilderAlg::execute_readout ( ) [private]

Definition at line 463 of file EventBuilderAlg.cpp.

{
    HeaderObject* framesTag = this->collect_headers();
    if (!framesTag) return SUCCESS;

    this->build_events(*framesTag);
    this->switch_mode();
    return SUCCESS;
}
EventBuilderAlg::ObjectList_t::iterator EventBuilderAlg::objects_find ( DayaBay::HeaderObject ho) [private]

Definition at line 280 of file EventBuilderAlg.cpp.

{
    ObjectList_t::iterator it, done = m_objects.end();
    for (it=m_objects.begin(); it != done; ++it) {
        if (it->first == &ho) { 
            return it;
        }
    }
    return done;
}
EventBuilderAlg::LocatedObject_t EventBuilderAlg::objects_pop ( DayaBay::HeaderObject ho) [private]

Definition at line 290 of file EventBuilderAlg.cpp.

{
    ObjectList_t::iterator it = objects_find(ho);
    if (it == m_objects.end()) {
        return LocatedObject_t(0,"");
    }
    LocatedObject_t ret = *it;
    m_objects.erase(it);
    return ret;
}
void EventBuilderAlg::objects_push ( DayaBay::HeaderObject ho,
std::string  loc 
) [private]

Definition at line 300 of file EventBuilderAlg.cpp.

{
    if (objects_in(ho)) {
        debug() << "Already have this ho: " << hostr(ho) << endreq;
        return;
    }
    debug() << "Accepting ho: " << hostr(ho) << endreq;
    ho.addRef();                // this should be released after it has been added to the TES
    if (loc == "") {
        loc = classname(ho);
    }
    loc = locate(ho,loc);
    m_objects.push_back(LocatedObject_t(&ho,loc));
}
bool EventBuilderAlg::objects_in ( DayaBay::HeaderObject ho) [private]

Definition at line 314 of file EventBuilderAlg.cpp.

{
    ObjectList_t::iterator it, done = m_objects.end();
    for (it = m_objects.begin(); it != done; ++it) {
        if (it->first == &ho) return true;
    }
    return false;    
}
void EventBuilderAlg::add_to_event ( ObjectList_t event,
DayaBay::HeaderObject ho 
) [private]

Definition at line 323 of file EventBuilderAlg.cpp.

{
    LocatedObject_t lo = this->objects_pop(ho);
    if (lo.first) {
        event.push_back(lo);
    }
    else {
        warning() << "Asked to add HeaderObject to event that is unknown: " << hostr(ho) << endreq;
    }
}
void EventBuilderAlg::build_derived ( ObjectList_t event,
DayaBay::HeaderObject ho 
) [private]

Definition at line 352 of file EventBuilderAlg.cpp.

{
    debug() << "Building derived based on " << hostr(ho) << " and " << m_objects.size() << " objects" << endreq;
    dump_objects();
    ObjectList_t tokeep;
    ObjectList_t::iterator it, done = m_objects.end();
    int count = 0;
    for (it = m_objects.begin(); it != done; ++it, ++count) {

        HeaderObject* head = it->first;
        if (!head) {
            warning() << "Found a null object at " << count << " loc=" << it->second << endreq;
        }

        debug() << "\tchecking: " << (void*)head << endreq;

        LocatedObject_t lo = (*it);

        if (pointsto(*head,ho)) {
            debug() << "\tsaving to event: " << hostr(*lo.first) << endreq;
            event.push_back(lo);
        }
        else {
            debug() << "\tsaving for later: " << hostr(*lo.first) << endreq;
            tokeep.push_back(lo);
        }
    }
    m_objects.clear();
    m_objects = tokeep;
}
void EventBuilderAlg::dump_vecho ( std::vector< DayaBay::HeaderObject * > &  hos) [private]

Definition at line 421 of file EventBuilderAlg.cpp.

{
    size_t nhos = hos.size();
    debug() << "Dumping " << nhos << " HeaderObjects:" << endreq;
    for (size_t iho=0; iho < nhos; ++iho) {
        HeaderObject* ho = hos[iho];
        debug() << "\t" << hostr(*ho) << endreq;
    }
}
void EventBuilderAlg::dump_objects ( ) [private]

Definition at line 408 of file EventBuilderAlg.cpp.

{
    debug() << "Dumping " << m_objects.size() << " objects:" << endreq;

    ObjectList_t::iterator it, done = m_objects.end();
    for (it=m_objects.begin(); it != done; ++it) {
        LocatedObject_t lo = *it;
        HeaderObject* ho = lo.first;
        debug() << "\t" << lo.second << ": " << hostr(*ho) << endreq;
    }
}

Member Data Documentation

std::string EventBuilderAlg::m_location [private]

Definition at line 40 of file EventBuilderAlg.h.

Definition at line 46 of file EventBuilderAlg.h.

IIncidentSvc* EventBuilderAlg::m_incsvc [private]

Definition at line 54 of file EventBuilderAlg.h.

Definition at line 55 of file EventBuilderAlg.h.

Definition at line 56 of file EventBuilderAlg.h.

Definition at line 57 of file EventBuilderAlg.h.

Definition at line 58 of file EventBuilderAlg.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