/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 Attributes
DybDaq::DaqFormatWriter Class Reference

#include <DaqFormatWriter.h>

Inheritance diagram for DybDaq::DaqFormatWriter:
Inheritance graph
[legend]
Collaboration diagram for DybDaq::DaqFormatWriter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DaqFormatWriter (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~DaqFormatWriter ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()
DayaBay::ReadoutHeaderGetCurrentHeaderObject () const
virtual StatusCode sysInitialize ()
virtual StatusCode sysExecute ()
virtual StatusCode preExecute ()
virtual StatusCode postExecute ()
virtual StatusCode sysFinalize ()
IDataProviderSvc * arcSvc () const
void putTES (DataObject *obj, std::string location) const
TYPE * getTES (std::string location) const
TYPE * getAES (std::string location, int index) const
std::vector< DataObject * > getAEScollection (std::string location) const
int getExecNum ()
std::string Location () const

Protected Member Functions

virtual DaqToOStreamcreateDaqToOStream (const FileTraits &traits)=0
 Creates the DaqToOStream into which the DAQ bytes wiull be written.
virtual StatusCode writeFileHead (const DayaBay::DaqCrate *daqCrate)
 Writes the file header records.
virtual StatusCode writeData (const DayaBay::DaqCrate *daqCrate)
 Writes the data block.
virtual StatusCode writeFileFoot ()
 Writes the file footer records.
virtual void wroteFileHead ()=0
 Called when the file header records have all been written.
virtual void wroteData ()=0
 Called when a file data record has all been written.
virtual void wroteFileFoot ()=0
 Called when the file footer records have all been written.
DayaBay::ReadoutHeaderMakeHeaderObject ()
void InitializeHeader (DayaBay::HeaderObject *header)
TYPE * MakeHeader ()
TYPE * MakeHeader (std::vector< const DayaBay::IHeader * > &inputHeaders)
TYPE * MakeHeader (const DayaBay::IHeader *referenceHeader)
void AppendInputHeader (const DayaBay::HeaderObject *header) const

Protected Attributes

DayaBay::HeaderObjectm_headerObject
bool m_pullMode
std::string m_location

Private Attributes

const DybDaq::FileTraitsm_traits
 The FileTriats used to format the DAQ data.
unsigned int m_firstDataBlock
 The number of the first data block to write.
IDaqReadoutSvcm_daqSvc
 The service managing DAQ formatted data generation.
DybDaq::DaqToOStreamm_daqToOStream
 The DaqToOStream instance that writes of the DAQ formated files.
std::string m_outputBase
 The base from which to construct the output file names.
unsigned long m_fileByteCount
 The bytes of payload written to the file.
unsigned long m_fileByteLimit
 The maximum number of megabytes of payload that should be written to a file.
unsigned int m_fileBlockCount
 The number of data blocks written to the file.
unsigned int m_fileBlockLimit
 The maximum number of data blocks that should be written to a file.

Detailed Description

Definition at line 28 of file DaqFormatWriter.h.


Constructor & Destructor Documentation

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

Definition at line 46 of file DaqFormatWriter.cc.

                                                   :
DybAlgorithm<DayaBay::ReadoutHeader>(name,
                                     svc),
    m_traits(0),
    m_daqSvc(0),
    m_daqToOStream(0),
    m_fileByteCount(0),
    m_fileByteLimit(0),
    m_fileBlockCount(0),
    m_fileBlockLimit(0) {
    declareProperty("OutputBase",
                    m_outputBase,
                    "The base from which to construct the output file names");
    declareProperty("FirstDataBlock",
                    m_firstDataBlock=1,
                    "The number of the first data block to write.");
}
DaqFormatWriter::~DaqFormatWriter ( ) [virtual]

Definition at line 65 of file DaqFormatWriter.cc.

                                  {
    if (0 != m_daqToOStream) {
        delete m_daqToOStream;
    }
}

Member Function Documentation

StatusCode DaqFormatWriter::initialize ( ) [virtual]

Definition at line 71 of file DaqFormatWriter.cc.

                                       {
    m_traits = &(FileTraits::defaultTraits());
    StatusCode status = service("DaqReadoutSvc",
                                "DaqReadoutSvc",
                                m_daqSvc);
    if (status.isFailure() ) {
        return status;
    }
    if (0 != m_daqSvc) {
        m_daqSvc->setFirstDataBlockNumber(m_firstDataBlock);
    }
    return StatusCode::SUCCESS;
}
StatusCode DaqFormatWriter::execute ( ) [virtual]

Definition at line 85 of file DaqFormatWriter.cc.

                                    {
    const ReadoutHeader* readoutHeader = get<ReadoutHeader>("/Event/Readout/ReadoutHeader");
    if (0 == readoutHeader) {
        error() << "Failed to get readout header." << endreq;
        return StatusCode::FAILURE;
    }
    
    const DaqCrate* daqCrate = readoutHeader->daqCrate();
    if (0 == daqCrate) {
        error() << "Failed to get crate readout from header" << endreq;
        return StatusCode::FAILURE;
    }
    StatusCode status = writeFileHead(daqCrate);
    if (status.isFailure() ) {
      return status;
    }
    return writeData(daqCrate);
}
StatusCode DaqFormatWriter::finalize ( ) [virtual]

Definition at line 104 of file DaqFormatWriter.cc.

                                     {
    const StatusCode status = writeFileFoot();
    if (status.isFailure()) {
        return status;
    }
    return StatusCode::SUCCESS;
}
virtual DaqToOStream* DybDaq::DaqFormatWriter::createDaqToOStream ( const FileTraits traits) [protected, pure virtual]

Creates the DaqToOStream into which the DAQ bytes wiull be written.

Implemented in DybDaq::DaqFileWriter.

StatusCode DaqFormatWriter::writeFileHead ( const DayaBay::DaqCrate daqCrate) [protected, virtual]

Writes the file header records.

Definition at line 112 of file DaqFormatWriter.cc.

                                                                  {
    bool freshFile = false;
    if (0 == m_daqToOStream) {
        if (m_daqSvc->hasFileStartRecord()) {
            const FileStartRecord& record = m_daqSvc->fileStartRecord();
            m_daqToOStream = createDaqToOStream(record.fileTraits());
            if (!(m_daqToOStream->openSequence(m_outputBase,
                                               record))) {
                return StatusCode::FAILURE;
            }
        } else {
            m_daqToOStream = createDaqToOStream(*m_traits);
            const FileTraits::FileDateTime* dateTime = m_traits->makeDateTime(time(0));
            const FileStartRecord* record = m_daqToOStream->openSequence(m_outputBase,
                                                                         *dateTime,
                                                                         m_fileBlockLimit,
                                                                         (m_fileByteLimit / kBytesInMegabyte));
            delete dateTime;
            if (0 == record) {
                return StatusCode::FAILURE;
            }
            delete record;
        }
    } else {
        if (m_daqSvc->hasFileEndRecord()) {
            if (m_daqSvc->hasFileStartRecord()) {
                if (!m_daqToOStream->close(m_daqSvc->fileEndRecord())) {
                    return StatusCode::FAILURE;
                }
                wroteFileFoot();
                if (!m_daqToOStream->open(m_daqSvc->fileStartRecord())) {
                  return StatusCode::FAILURE;
                }
            } else {
                if (!(m_daqToOStream->close(m_daqSvc->fileEndRecord()))) {
                    return StatusCode::FAILURE;
                }
                wroteFileFoot();
                delete m_daqToOStream;
                m_daqToOStream = 0;
                return StatusCode::SUCCESS;
            }
        } else {
            const EventReadout& eventReadout = daqCrate->eventReadout();
            const EventHeader& eventHeader = eventReadout.header();
            ++m_fileBlockCount;
            m_fileByteCount += eventHeader.totalSize() * kBytesInInt;
            if (((0 != m_fileBlockLimit) && (0 == (m_fileBlockCount > m_fileBlockLimit))) ||
                ((0 != m_fileByteLimit) && (0 == (m_fileByteCount > m_fileByteLimit)))) {
                const FileTraits::FileDateTime* dateTime = m_traits->makeDateTime(time(0));
                const FileStartRecord* record = m_daqToOStream->openNext(*dateTime);
                delete dateTime;
                if (0 == record) {
                    return StatusCode::FAILURE;
                }
                delete record;
                m_fileBlockCount = 1;
                m_fileByteCount = eventHeader.totalSize() * kBytesInInt;
                freshFile = true;
            } else {
                return StatusCode::SUCCESS;
            }
        }
    }
    if (m_daqSvc->hasFileNameStrings()) {
        if (!(m_daqToOStream->saveFileNameStrings(m_daqSvc->fileNameStrings()))) {
            return StatusCode::FAILURE;
        }
    } else {
        const FileNameStrings* record = m_daqToOStream->saveFileNameStrings("DaqFormatWriter");
        if (0 == record) {
            return StatusCode::FAILURE;
        }
        delete record;
    }
    if (m_daqSvc->hasMetadataStrings()) {
        if (!(m_daqToOStream->saveMetadataStrings(m_daqSvc->metadataStrings()))) {
            return StatusCode::FAILURE;
        }
    } else {
        MetadataStrings::MetadataStringPtrList* metadataStrings = new MetadataStrings::MetadataStringPtrList();
        MetadataStrings::MetadataString metaString("type","MC");
        metadataStrings->push_back(&metaString);
        const MetadataStrings* record = m_daqToOStream->saveMetadataStrings(*metadataStrings);
        if (0 == record) {
            return StatusCode::FAILURE;
        }
        delete record;
    }
    if (m_daqSvc->hasRunParametersRecord()) {
        if (!(m_daqToOStream->saveRunParametersRecord(m_daqSvc->runParametersRecord()))) {
            return StatusCode::FAILURE;
        }
    } else {
        const RunParametersRecord* record = m_daqToOStream->saveRunParametersRecord(m_daqSvc->runNumber(daqCrate->detector()),
                                                                              true,
                                                                              0,
                                                                              0);
        if (0 == record) {
            return StatusCode::FAILURE;
        }
        delete record;
    }
    const int finished = m_daqSvc->calibrationParametersRecordCount();
    for (int count = 0;
         finished != count;
         ++count) {
        if (!(m_daqToOStream->saveCalibrationParametersRecord(m_daqSvc->calibrationParametersRecord(count)))) {
            return StatusCode::FAILURE;
        }
    }
    wroteFileHead();
    return StatusCode::SUCCESS;
}
StatusCode DaqFormatWriter::writeData ( const DayaBay::DaqCrate daqCrate) [protected, virtual]

Writes the data block.

Definition at line 227 of file DaqFormatWriter.cc.

                                                              {
    if (0 == m_daqToOStream) {
      return StatusCode::FAILURE;
    }
    const DataSeparatorRecord* record = m_daqToOStream->saveEvent(daqCrate->eventReadout(),
                                                                  m_daqSvc->nextDataBlockNumber());
    if (0 == record) {
        return StatusCode::FAILURE;
    }
    delete record;
    wroteData();
    return StatusCode::SUCCESS;
}
StatusCode DaqFormatWriter::writeFileFoot ( ) [protected, virtual]

Writes the file footer records.

Definition at line 241 of file DaqFormatWriter.cc.

                                          {
    if (0 == m_daqToOStream) {
        return StatusCode::SUCCESS;
    }
    if (m_daqSvc->hasFileEndRecord()) {
        if (!(m_daqToOStream->close(m_daqSvc->fileEndRecord()))) {
            return StatusCode::FAILURE;
        }
    } else {
        const FileTraits::FileDateTime* dateTime = m_traits->makeDateTime(time(0));
        const FileEndRecord* record = m_daqToOStream->close(*dateTime);
        delete dateTime;
        if (0 == record) {
            return StatusCode::FAILURE;
        }
        delete const_cast<FileEndRecord*>(record);
    }
    wroteFileFoot();
    delete m_daqToOStream;
    m_daqToOStream = 0;
    return StatusCode::SUCCESS;
}
virtual void DybDaq::DaqFormatWriter::wroteFileHead ( ) [protected, pure virtual]

Called when the file header records have all been written.

Implemented in DybDaq::DaqFileWriter.

virtual void DybDaq::DaqFormatWriter::wroteData ( ) [protected, pure virtual]

Called when a file data record has all been written.

Implemented in DybDaq::DaqFileWriter.

virtual void DybDaq::DaqFormatWriter::wroteFileFoot ( ) [protected, pure virtual]

Called when the file footer records have all been written.

Implemented in DybDaq::DaqFileWriter.

DayaBay::ReadoutHeader * DybAlgorithm< DayaBay::ReadoutHeader >::GetCurrentHeaderObject ( ) const [inherited]
virtual StatusCode DybAlgorithm< DayaBay::ReadoutHeader >::sysInitialize ( ) [virtual, inherited]

Reimplemented from DybBaseAlg.

virtual StatusCode DybAlgorithm< DayaBay::ReadoutHeader >::sysExecute ( ) [virtual, inherited]

Reimplemented from DybBaseAlg.

virtual StatusCode DybAlgorithm< DayaBay::ReadoutHeader >::preExecute ( ) [virtual, inherited]

Reimplemented from DybBaseAlg.

virtual StatusCode DybAlgorithm< DayaBay::ReadoutHeader >::postExecute ( ) [virtual, inherited]

Reimplemented from DybBaseAlg.

virtual StatusCode DybAlgorithm< DayaBay::ReadoutHeader >::sysFinalize ( ) [virtual, inherited]

Reimplemented from DybBaseAlg.

IDataProviderSvc * DybAlgorithm< DayaBay::ReadoutHeader >::arcSvc ( ) const [inherited]

Reimplemented from DybBaseAlg.

void DybAlgorithm< DayaBay::ReadoutHeader >::putTES ( DataObject *  obj,
std::string  location 
) const [inherited]

Reimplemented from DybBaseAlg.

TYPE * DybAlgorithm< DayaBay::ReadoutHeader >::getTES ( std::string  location) const [inherited]

Reimplemented from DybBaseAlg.

TYPE * DybAlgorithm< DayaBay::ReadoutHeader >::getAES ( std::string  location,
int  index 
) const [inherited]

Reimplemented from DybBaseAlg.

std::vector< DataObject * > DybAlgorithm< DayaBay::ReadoutHeader >::getAEScollection ( std::string  location) const [inherited]

Reimplemented from DybBaseAlg.

int DybAlgorithm< DayaBay::ReadoutHeader >::getExecNum ( ) [inherited]

Reimplemented from DybBaseAlg.

std::string DybAlgorithm< DayaBay::ReadoutHeader >::Location ( ) const [inherited]

Reimplemented from DybBaseAlg.

DayaBay::ReadoutHeader * DybAlgorithm< DayaBay::ReadoutHeader >::MakeHeaderObject ( ) [protected, inherited]
void DybAlgorithm< DayaBay::ReadoutHeader >::InitializeHeader ( DayaBay::HeaderObject header) [protected, inherited]

Reimplemented from DybBaseAlg.

TYPE * DybAlgorithm< DayaBay::ReadoutHeader >::MakeHeader ( ) [protected, inherited]

Reimplemented from DybBaseAlg.

TYPE * DybAlgorithm< DayaBay::ReadoutHeader >::MakeHeader ( std::vector< const DayaBay::IHeader * > &  inputHeaders) [protected, inherited]

Reimplemented from DybBaseAlg.

TYPE * DybAlgorithm< DayaBay::ReadoutHeader >::MakeHeader ( const DayaBay::IHeader referenceHeader) [protected, inherited]

Reimplemented from DybBaseAlg.

void DybAlgorithm< DayaBay::ReadoutHeader >::AppendInputHeader ( const DayaBay::HeaderObject header) const [protected, inherited]

Reimplemented from DybBaseAlg.


Member Data Documentation

The FileTriats used to format the DAQ data.

Definition at line 85 of file DaqFormatWriter.h.

The number of the first data block to write.

Definition at line 90 of file DaqFormatWriter.h.

The service managing DAQ formatted data generation.

Definition at line 95 of file DaqFormatWriter.h.

The DaqToOStream instance that writes of the DAQ formated files.

Definition at line 100 of file DaqFormatWriter.h.

The base from which to construct the output file names.

Definition at line 105 of file DaqFormatWriter.h.

The bytes of payload written to the file.

Definition at line 110 of file DaqFormatWriter.h.

The maximum number of megabytes of payload that should be written to a file.

Definition at line 115 of file DaqFormatWriter.h.

The number of data blocks written to the file.

Definition at line 120 of file DaqFormatWriter.h.

The maximum number of data blocks that should be written to a file.

Definition at line 125 of file DaqFormatWriter.h.

Reimplemented from DybBaseAlg.

bool DybAlgorithm< DayaBay::ReadoutHeader >::m_pullMode [protected, inherited]

Reimplemented from DybBaseAlg.

std::string DybAlgorithm< DayaBay::ReadoutHeader >::m_location [protected, inherited]

Reimplemented from DybBaseAlg.


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:32 for DaqFormatModules by doxygen 1.7.4