/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 | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
DybOutputHeaderSvc Class Reference

A service that maintains a reverse-inputHeaders mapping. More...

#include <DybOutputHeaderSvc.h>

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

List of all members.

Public Types

typedef std::vector< const
DayaBay::IHeader * > 
OutputHeaders

Public Member Functions

 DybOutputHeaderSvc (const std::string &name, ISvcLocator *svc)
virtual ~DybOutputHeaderSvc ()
StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual void handle (const Incident &incident)
virtual OutputHeaders get (const DayaBay::IHeader &header)
 Get known "output headers" of given header.
std::string path (const DayaBay::IHeader &header)
 Last known path.
virtual void clear ()
 Clear all (expert use only)
virtual void erase (const DayaBay::IHeader &header)
 Erase one (expert use only)
virtual void add (const DayaBay::IHeader &header)
 Add a header (expert use only)

Static Public Member Functions

static const InterfaceID & interfaceID ()

Private Types

typedef std::map< const
DayaBay::IHeader
*, OutputHeaders
OutputHeaderMap
typedef std::map< const
DayaBay::IHeader
*, std::string > 
OutputHeaderNameMap

Private Member Functions

std::string hostr (const DayaBay::HeaderObject &ho)
void addHeaderName (const DayaBay::HeaderObject &ho)
void removeHeaderName (const DayaBay::HeaderObject &ho)
OutputHeaderMap::iterator find (const DayaBay::IHeader &header)
bool in (OutputHeaders &oh, const DayaBay::IHeader &header)

Private Attributes

OutputHeaderMap m_ohmap
OutputHeaderNameMap m_names
IIncidentSvc * m_incsvc

Detailed Description

A service that maintains a reverse-inputHeaders mapping.

bv@bnl.gov Wed Aug 10 10:40:00 2011

Definition at line 26 of file DybOutputHeaderSvc.h.


Member Typedef Documentation

Definition at line 66 of file DybOutputHeaderSvc.h.

typedef std::map<const DayaBay::IHeader*,std::string> DybOutputHeaderSvc::OutputHeaderNameMap [private]

Definition at line 68 of file DybOutputHeaderSvc.h.


Constructor & Destructor Documentation

DybOutputHeaderSvc::DybOutputHeaderSvc ( const std::string &  name,
ISvcLocator *  svc 
)

Definition at line 11 of file DybOutputHeaderSvc.cpp.

    : Service(name,svc)
    , m_incsvc(0)
{
}
DybOutputHeaderSvc::~DybOutputHeaderSvc ( ) [virtual]

Definition at line 17 of file DybOutputHeaderSvc.cpp.

{
    this->clear();
}

Member Function Documentation

StatusCode DybOutputHeaderSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvInterface 
)

Definition at line 22 of file DybOutputHeaderSvc.cpp.

{
    if ( riid == IID_IOutputHeaderSvc )  {
        *ppvInterface = (IOutputHeaderSvc*)this;
    }
    else  {
        return Service::queryInterface(riid, ppvInterface);
    }
    addRef();
    return StatusCode::SUCCESS;
}
StatusCode DybOutputHeaderSvc::initialize ( ) [virtual]

Definition at line 34 of file DybOutputHeaderSvc.cpp.

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

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

    sc = this->service("IncidentSvc",m_incsvc,true);
    if (sc.isFailure()) {
        log << MSG::ERROR
            << "Failed to get IncidentSvc" << endreq;
        return sc;
    }
    m_incsvc->addListener(this,"EventStoreIncident");

    return sc;
}
StatusCode DybOutputHeaderSvc::finalize ( ) [virtual]

Definition at line 52 of file DybOutputHeaderSvc.cpp.

{
    m_incsvc->removeListener(this,"EventStoreIncident");
    m_incsvc->release();
    m_incsvc = 0;

    return Service::finalize();
}
void DybOutputHeaderSvc::handle ( const Incident &  incident) [virtual]

Definition at line 79 of file DybOutputHeaderSvc.cpp.

{
    // Through this incident handler the service is notified of
    // new header objects to add and obsolete ones to remove.

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

    if (incident.type() != "EventStoreIncident") { 
        log << MSG::DEBUG 
            << "Got unknown incident: \"" << incident.type() << "\""
            << endreq;
        return; 
    }

    const EventStoreIncident* esi = dynamic_cast<const EventStoreIncident*>(&incident);
    if (!esi) { 
        log << MSG::DEBUG 
            << "Got right incident (" << incident.type() << ") but does not dynamic cast"
            << endreq;
        return; 
    }
    log << MSG::DEBUG
        << "Handling incident of type " << incident.type()
        << " stored=" << esi->stored()
        << endreq;


    const DataObject* dobj = esi->object();
    if (!dobj) { 
        log << MSG::DEBUG << incident.type() << ": object is null" << endreq;
        return; 
    }

    const HeaderObject* ho = dynamic_cast<const HeaderObject*>(dobj);
    if (!ho) { 
        log << MSG::DEBUG 
            << incident.type() << ": object is not HeaderObject" << endreq;
        return; 
    }

    if (esi->stored()) {
        log << MSG::DEBUG 
            << incident.type() << ": adding: " << hostr(*ho) << endreq;
        size_t siz = ho->inputHeaders().size();
        for (size_t ind = 0; ind < siz; ++ind) {
            const HeaderObject* other_ho = dynamic_cast<const HeaderObject*>(ho->inputHeaders()[ind]);
            log << MSG::DEBUG << "\t" << hostr(*other_ho) << endreq;
        }
        this->add(*ho);
    }
    else {
        log << MSG::DEBUG 
            << incident.type() << ": erasing: " << hostr(*ho) << endreq;
        this->erase(*ho);
    }
}
IOutputHeaderSvc::OutputHeaders DybOutputHeaderSvc::get ( const DayaBay::IHeader header) [virtual]

Get known "output headers" of given header.

Implements IOutputHeaderSvc.

Definition at line 137 of file DybOutputHeaderSvc.cpp.

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

    OutputHeaderMap::iterator it = find(header);
    return it->second;          // find can not fail
}
std::string DybOutputHeaderSvc::path ( const DayaBay::IHeader header) [virtual]

Last known path.

Implements IOutputHeaderSvc.

Definition at line 225 of file DybOutputHeaderSvc.cpp.

{
    OutputHeaderNameMap::iterator it = m_names.find(&header);
    if (it == m_names.end()) {
        return "UnknownHeader";
    }
    return it->second;
}
void DybOutputHeaderSvc::clear ( ) [virtual]

Clear all (expert use only)

Implements IOutputHeaderSvc.

Definition at line 278 of file DybOutputHeaderSvc.cpp.

{
    MsgStream log(msgSvc(), name());
    m_ohmap.clear();
}
void DybOutputHeaderSvc::erase ( const DayaBay::IHeader header) [virtual]

Erase one (expert use only)

Implements IOutputHeaderSvc.

Definition at line 234 of file DybOutputHeaderSvc.cpp.

{
    MsgStream log(msgSvc(), name());
    HeaderObject* ho = dynamic_cast<HeaderObject*>(const_cast<IHeader*>(&header));

    OutputHeaderMap::iterator it = m_ohmap.find(&header), done = m_ohmap.end();
    if (it == done) {
        log << MSG::DEBUG
            << "Given an IHeader to erase which is not in my map: " << hostr(*ho)
            << endreq;
        return;
    }

    log << MSG::DEBUG
        << "Erasing from output headers map:  " << hostr(*ho) 
        << " " << path(header)
        << endreq;
    m_ohmap.erase(it);

    done = m_ohmap.end();
    for (it = m_ohmap.begin(); it != done; ++it) {
        IOutputHeaderSvc::OutputHeaders newone, &ohs = it->second;
        size_t nohs = ohs.size();
        for (size_t ind = 0; ind < nohs; ++ind) {
            const IHeader* thisone = ohs[ind];
            if (thisone == &header) {
                log << MSG::DEBUG
                    << "Found as output header: " << hostr(*ho)
                    << endreq;
                continue;
            }
            newone.push_back(thisone);
        }
        if (newone.size() < nohs) {
            it->second = newone;
        }
    }


    log << MSG::DEBUG << "Releasing: " << hostr(*ho) << endreq;
    ho->release();
    removeHeaderName(*ho);
}
void DybOutputHeaderSvc::add ( const DayaBay::IHeader header) [virtual]

Add a header (expert use only)

Implements IOutputHeaderSvc.

Definition at line 183 of file DybOutputHeaderSvc.cpp.

{
    MsgStream log(msgSvc(), name());
    HeaderObject* ho = dynamic_cast<HeaderObject*>(const_cast<IHeader*>(&header));

    if (!ho) {
        log << MSG::ERROR
            << "Failed to cast IHeader @ " << (void*)&header << endreq;
        return;
    }

    addHeaderName(*ho);

    const std::vector<const IHeader*>& inputHeaders = header.inputHeaders();
    if (!inputHeaders.size()) {
        log << MSG::DEBUG << "No input headers: " << hostr(*ho) << endreq;
        return;                 // origin header
    }

    // if (m_ohmap.find(&header) != m_ohmap.end()) {
    //     return;                 // already mapped
    // }

    
    for (size_t ind=0; ind<inputHeaders.size(); ++ind) {
        const IHeader* inhead = inputHeaders[ind];
        OutputHeaderMap::iterator it = find(*inhead);

        if (!in(it->second,header)) {
            it->second.push_back(&header);

            HeaderObject* other_ho = 
                dynamic_cast<HeaderObject*>(const_cast<IHeader*>(it->first));
            addHeaderName(*other_ho);

            log << MSG::DEBUG << "Setting as OutputHeader for: " << hostr(*other_ho) << endreq;
            ho->addRef();
        }
        add(*inhead);           // recurse
    }
}
std::string DybOutputHeaderSvc::hostr ( const DayaBay::HeaderObject ho) [private]

Definition at line 66 of file DybOutputHeaderSvc.cpp.

{
    std::stringstream ss;
    ss << "HeaderObject: @" << (void*)&ho 
       << " name=\"" << ho.name() << "\""
       << " path=\"" << path(ho) << "\""
       << " execNum=" << ho.execNumber()
       << " refCount=" << ho.refCount() 
       << " #inputHeaders=" << ho.inputHeaders().size()
       << " context=\"" << ho.context().AsString() << "\"";
    return ss.str();
}
void DybOutputHeaderSvc::addHeaderName ( const DayaBay::HeaderObject ho) [private]

Definition at line 173 of file DybOutputHeaderSvc.cpp.

{
    IRegistry* registry = ho.registry();
    if (!registry) {
        return;
    }
    std::string hname = registry->identifier();
    m_names[&ho] = hname;
}
void DybOutputHeaderSvc::removeHeaderName ( const DayaBay::HeaderObject ho) [private]

Definition at line 165 of file DybOutputHeaderSvc.cpp.

{
    OutputHeaderNameMap::iterator nit = m_names.find(&ho);
    if (nit != m_names.end()) {
        m_names.erase(nit);
    }
}
DybOutputHeaderSvc::OutputHeaderMap::iterator DybOutputHeaderSvc::find ( const DayaBay::IHeader header) [private]

Definition at line 145 of file DybOutputHeaderSvc.cpp.

{
    OutputHeaderMap::iterator it = m_ohmap.find(&header);
    if (it != m_ohmap.end()) {
        return it;
    }

    m_ohmap[&header] = IOutputHeaderSvc::OutputHeaders();
    return m_ohmap.find(&header); // what we just added
}
bool DybOutputHeaderSvc::in ( OutputHeaders oh,
const DayaBay::IHeader header 
) [private]

Definition at line 156 of file DybOutputHeaderSvc.cpp.

{
    size_t size = oh.size();
    for (size_t ind=0; ind<size; ++ind) {
        if (oh[ind] == &header) return true;
    }
    return false;
}

Member Data Documentation

Definition at line 67 of file DybOutputHeaderSvc.h.

Definition at line 69 of file DybOutputHeaderSvc.h.

IIncidentSvc* DybOutputHeaderSvc::m_incsvc [private]

Definition at line 76 of file DybOutputHeaderSvc.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