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

#include <DybIODaqSvc.h>

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

List of all members.

Public Member Functions

 DybIODaqSvc (const std::string &name, ISvcLocator *svc)
 Creates an instance of this class.
virtual StatusCode queryInterface (const InterfaceID &id, void **interface)
 Resolve what interface is supported by this implementation.
virtual StatusCode finalize ()
 Cleans up before this instance is destroyed.
virtual StatusCode setEventEntry (const unsigned int entry)
 Sets the entry number within the ROOT stream of the incoming Event.

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Retrieve interface ID.

Private Member Functions

DayaBay::DaqBlockHeaderreadDaqBlockHeader ()
 Reads the next DaqBlock in the ROOT file.
StatusCode findDaqReadoutSvc ()
 Finds the DaqReadoutSvc to hold the DAQ context.
StatusCode findInputStream ()
 Finds the RootInputStream containing the DaqBlock tree, if it has not already been found.
StatusCode findConverter ()
 Finds the Converter used to convert DaqBlocks to and from ROOT, if it has not already been found.
StatusCode parseDaqBlock (const DayaBay::DaqBlock &block)
 Parse out the contents of a DaqBlock into its File Records.

Private Attributes

std::string m_daqBlockLocation
 Location in file where DAQ block will be saved.
IRootIOSvcm_rioSvc
 The ROOT service.
RootInputStreamm_input
 The RootInputStream containing the DaqBlock tree.
IConversionSvc * m_convSvc
 The conversion service.
DaqReadoutSvcm_daqSvc
 The DAQ service that contains the current DAQ content.
RootIOTypedCnv
< PerDaqBlockHeader,
DayaBay::DaqBlockHeader > * 
m_daqBlockCnv
 The Converter used to convert DaqBlocks to and from ROOT.
unsigned int m_nextInsertion
 The entry number in the ROOT stream of wheere the next DaqBlock should be inserted.
unsigned int m_entry
 The entry in the RootInputStream.
DayaBay::DaqBlockHeaderm_pendingHeader
 The DaqBlockHeader containing the next DaqBlock to be inserted.

Detailed Description

Definition at line 31 of file DybIODaqSvc.h.


Constructor & Destructor Documentation

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

Creates an instance of this class.

Definition at line 35 of file DybIODaqSvc.cc.

                                             :
    Service(name,
            svc),
    m_rioSvc(0),
    m_input(0),
    m_convSvc(0),
    m_daqSvc(0),
    m_daqBlockCnv(0),
    m_nextInsertion(0),
    m_entry(0),
    m_pendingHeader(0) {
    declareProperty("DaqBlockLocation",
                    m_daqBlockLocation=DayaBay::DaqBlockHeaderLocation::Default,
                    "Location in file where DAQ block will be saved.");
}

Member Function Documentation

StatusCode DybIODaqSvc::queryInterface ( const InterfaceID &  id,
void **  interface 
) [virtual]

Resolve what interface is supported by this implementation.

Definition at line 52 of file DybIODaqSvc.cc.

                                                          {
    if (IDybIODaqSvc::interfaceID().versionMatch(id)) {
        // Good enough. Return this object
        *interface = dynamic_cast<IDybIODaqSvc*>(this);
        addRef();
        return StatusCode::SUCCESS;
    }
    // Try base class
    return Service::queryInterface(id,
                                   interface);
}
StatusCode DybIODaqSvc::finalize ( ) [virtual]

Cleans up before this instance is destroyed.

Definition at line 65 of file DybIODaqSvc.cc.

                                 {
    if (0 != m_pendingHeader) {
        delete m_pendingHeader;
    }
    if (0 != m_daqSvc) {
      m_daqSvc->release();
    }
    if (0 != m_convSvc) {
      m_convSvc->release();
    }
    if (0 != m_rioSvc) {
      m_rioSvc->release();
    }
    return Service::finalize();
}
StatusCode DybIODaqSvc::setEventEntry ( const unsigned int  entry) [virtual]

Sets the entry number within the ROOT stream of the incoming Event.

Implements IDybIODaqSvc.

Definition at line 81 of file DybIODaqSvc.cc.

                                                              {
    findDaqReadoutSvc();
    if (0 != m_daqSvc) {
        m_daqSvc->setFileRecord((const FileEndRecord*)0);
    }
    while (m_nextInsertion == entry) {
        if (0 != m_pendingHeader) {
            parseDaqBlock(*(m_pendingHeader->daqBlock()));
            delete m_pendingHeader;
        }
        m_pendingHeader = readDaqBlockHeader();
        if (0 == m_pendingHeader) {
            return StatusCode::FAILURE;
        }
        m_nextInsertion += m_pendingHeader->deltaEvents();
    }
    return StatusCode::SUCCESS;
}
DaqBlockHeader * DybIODaqSvc::readDaqBlockHeader ( ) [private]

Reads the next DaqBlock in the ROOT file.

Definition at line 243 of file DybIODaqSvc.cc.

                                                {
    MsgStream log(msgSvc(),
                  "DybIODaqSvc");

    StatusCode sc = findInputStream();
    if (sc.isFailure()) {
        return 0;
    }
    sc = findConverter();
    if (sc.isFailure()) {
        return 0;
    }

    m_input->setEntry(m_entry);
    log << MSG::DEBUG
        << "Return status of read: "
        << m_input->read()
        << "\t" 
        << m_input->obj()
        << endreq;
    PerDaqBlockHeader* perDaqBlockHeader = (PerDaqBlockHeader*)(m_input->obj());
    if(0 == perDaqBlockHeader){
        log << MSG::ERROR
            << "Failed to get persistent DaqBlockHeader"
            << endreq;
        return 0;
    }

    DaqBlockHeader* result = new DaqBlockHeader;
    sc = m_daqBlockCnv->PerToTran(*perDaqBlockHeader,
                                  *result);
    if (sc.isFailure()) {
        log << MSG::ERROR
            << "Failed to translate persistent DaqBlockHeader" 
            << endreq;
        return 0;
    } else {
        ++m_entry;
    }
    return result;
}
StatusCode DybIODaqSvc::findDaqReadoutSvc ( ) [private]

Finds the DaqReadoutSvc to hold the DAQ context.

Definition at line 128 of file DybIODaqSvc.cc.

                                          {
    if (0 != m_daqSvc) {
      return StatusCode::SUCCESS;
    }
    MsgStream log(msgSvc(),
                  "DybIODaqSvc");
    IService* isvc = 0; 
    StatusCode status = service("DaqReadoutSvc",
                                "DaqReadoutSvc",
                                isvc);
    if (status.isFailure() ) {
        log << MSG::ERROR
            << "Failed to get IDaqReadoutSvc as IService"
            << endreq;
        return status;
    }
    IDaqReadoutSvc* daqSvc = 0;
    status = isvc->queryInterface(IDaqReadoutSvc::interfaceID(),
                                  (void**)&daqSvc);
    if (status.isFailure()) {
        log << MSG::ERROR
            << "Service does not implement IDaqReadoutSvc interface"
            << endreq;
        return status;
    }
    m_daqSvc = dynamic_cast<DaqReadoutSvc*>(daqSvc);
    return StatusCode::SUCCESS;
}
StatusCode DybIODaqSvc::findInputStream ( ) [private]

Finds the RootInputStream containing the DaqBlock tree, if it has not already been found.

Definition at line 157 of file DybIODaqSvc.cc.

                                        {
    if (0 != m_input) {
      return StatusCode::SUCCESS;
    }
    MsgStream log(msgSvc(),
                  "DybIODaqSvc");
    IService* isvc = 0; 
    StatusCode sc = service("RootIOCnvSvc",
                            isvc,
                            true);
    if(sc.isFailure()){
        log << MSG::ERROR
            << "Failed to get RootIOCnvSvc as IService"
            << endreq;
        return sc;
    }
    sc = isvc->queryInterface(IRootIOSvc::interfaceID(),
                              (void**)&m_rioSvc);
    if (sc.isFailure()) {
        log << MSG::ERROR
            << "Conversion service RootIOCnvSvc"
            << " does not implement IRootIOCnvSvc"
            << endreq;
        return sc;
    }

    IRootIOSvc::InputStreamMap& ism = m_rioSvc->inputStreams();
    const IRootIOSvc::InputStreamMap::iterator finished = ism.end();
    for (IRootIOSvc::InputStreamMap::iterator it = ism.begin();
         finished != it;
         ++it) {
        log << MSG::DEBUG
            << "checking input stream: "
            << it->first << endreq;
        if( it->first == m_daqBlockLocation ){
            m_input = it->second;
            return StatusCode::SUCCESS;
        }
    }
    return StatusCode::FAILURE;
}
StatusCode DybIODaqSvc::findConverter ( ) [private]

Finds the Converter used to convert DaqBlocks to and from ROOT, if it has not already been found.

Definition at line 199 of file DybIODaqSvc.cc.

                                      {
    if (0 != m_daqBlockCnv) {
      return StatusCode::SUCCESS;
    }
    MsgStream log(msgSvc(),
                  "DybIODaqSvc");
    IService* isvc = 0; 
    StatusCode sc = service("RootIOCnvSvc",
                            isvc,
                            true);
    if(sc.isFailure()){
        log << MSG::ERROR
            << "Failed to get RootIOCnvSvc as IService"
            << endreq;
        return sc;
    }
    sc = isvc->queryInterface(IConversionSvc::interfaceID(),
                              (void**)&m_convSvc);
    if (sc.isFailure()) {
        log << MSG::ERROR
            << "Conversion service RootIOCnvSvc"
            << " does not implement IConversionSvc"
            << endreq;
        return sc;
    }

    DaqBlockHeader daqBlockHeader;
    IConverter* converter = m_convSvc->converter(daqBlockHeader.classID());
    if (0 == converter) {
        log << MSG::ERROR
            << "Failed to get DaqBlockHeader converter"
            << endreq;
        return StatusCode::FAILURE;
    }
    m_daqBlockCnv = dynamic_cast< RootIOTypedCnv<PerDaqBlockHeader, DaqBlockHeader>* >(converter);
    if (0 == m_daqBlockCnv) {
        log << MSG::ERROR
            << "Failed to cast DaqBlockHeader converter"
            << endreq;
        return StatusCode::FAILURE;
    }
    return StatusCode::SUCCESS;
}
StatusCode DybIODaqSvc::parseDaqBlock ( const DayaBay::DaqBlock block) [private]

Parse out the contents of a DaqBlock into its File Records.

Definition at line 100 of file DybIODaqSvc.cc.

                                                              {
    string content((const char*)(&((*(daqBlock.bytes()))[0])),
                   daqBlock.size() * ByteBuffer::BYTES_IN_INT);
    DaqFromStrStream reader;
    reader.openWithString(content);
    const FileBuffer* record = reader.nextRecord();
    while (0 != record) {
        if(record->isMarked(FileTraits::kDataSeparatorRecord)) {
            return StatusCode::FAILURE;
        } else {
            if (0 != m_daqSvc) {
                m_daqSvc->setFileRecord(record);
            }
            std::stringstream message;
            message << '\n';
            DaqXmlStream xmlStream(message,
                                   kTwoSpaces,
                                   true);
            xmlStream.dumpElement(*record);
            MsgStream log(msgSvc(),
                          "DaqFormatContext");
            log << MSG::INFO << message.str() << endreq;        
        }
        record = reader.nextRecord();
    }
    return StatusCode::SUCCESS;
}
static const InterfaceID& IDybIODaqSvc::interfaceID ( ) [inline, static, inherited]

Retrieve interface ID.

Definition at line 19 of file IDybIODaqSvc.h.

                                            {
        return IID_IDybIODaqSvc;
    }

Member Data Documentation

std::string DybIODaqSvc::m_daqBlockLocation [private]

Location in file where DAQ block will be saved.

Definition at line 89 of file DybIODaqSvc.h.

The ROOT service.

This is held to ensure it does not vanish while the RootInputStream is in use.

Definition at line 94 of file DybIODaqSvc.h.

The RootInputStream containing the DaqBlock tree.

Definition at line 99 of file DybIODaqSvc.h.

IConversionSvc* DybIODaqSvc::m_convSvc [private]

The conversion service.

This is held to ensure it does not vanish while the Converter is in use.

Definition at line 104 of file DybIODaqSvc.h.

The DAQ service that contains the current DAQ content.

Definition at line 109 of file DybIODaqSvc.h.

The Converter used to convert DaqBlocks to and from ROOT.

Definition at line 114 of file DybIODaqSvc.h.

unsigned int DybIODaqSvc::m_nextInsertion [private]

The entry number in the ROOT stream of wheere the next DaqBlock should be inserted.

Definition at line 119 of file DybIODaqSvc.h.

unsigned int DybIODaqSvc::m_entry [private]

The entry in the RootInputStream.

Definition at line 124 of file DybIODaqSvc.h.

The DaqBlockHeader containing the next DaqBlock to be inserted.

Definition at line 129 of file DybIODaqSvc.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:15:57 for DybIO by doxygen 1.7.4