/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 | Private Member Functions | Private Attributes
DybDaq::DaqToOStream Class Reference

#include <DaqToOStream.h>

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

List of all members.

Public Member Functions

virtual ~DaqToOStream ()
 Destroy this instance of the class.
bool openSequence (const std::string &fileBase, const FileStartRecord &record)
 Opens the first element in a new sequence, writing the file_start_record into it.
const FileStartRecordopenSequence (const std::string &fileBase, const FileTraits::FileDateTime &dateTime, const unsigned int dataBlockLimit, const unsigned int megabyteLimit)
 Opens the first element in a new sequence, creating and writing the file_start_record into it.
bool open (const FileStartRecord &record)
 Opens a new element in a sequence, writing the file_start_record into it.
const FileStartRecordopenNext (const FileTraits::FileDateTime &dateTime)
 Opens a new element in a sequence, creating and then writing a file_start_record into it.
bool saveFileNameStrings (const FileNameStrings &record)
 Saves the supplied file_name_strings.
const FileNameStringssaveFileNameStrings (const std::string &application, const std::string &fileBase="")
 Saves the supplied data in a file_name_strings.
bool saveMetadataStrings (const MetadataStrings &record)
 Saves the supplied metadata_strings.
const MetadataStringssaveMetadataStrings (const MetadataStrings::MetadataStringPtrList &metadataStrings)
 Saves the supplied data in a metadata_strings.
bool saveRunParametersRecord (const RunParametersRecord &record)
 Saves the supplied run_parameters_record.
const RunParametersRecordsaveRunParametersRecord (const unsigned int runNumber, const bool recordEnabled, const unsigned int triggerType, const unsigned int detectorMask)
 Saves the supplied data in a run_parameters_record.
bool saveCalibrationParametersRecord (const CalibrationParametersRecord &record)
 Saves the supplied calibration_parameters_record.
const CalibrationParametersRecordsaveCalibrationParametersRecord (const unsigned int detector, const unsigned int adNumber, const unsigned int sourceA, const unsigned int zPositionA, const unsigned int sourceB, const unsigned int zPositionB, const unsigned int sourceC, const unsigned int zPositionC, const unsigned int led1, const unsigned int led2, const unsigned int led1Voltage, const unsigned int led2Voltage, const unsigned int duration, const unsigned int ledFrequency, const unsigned int ledPulseSeparation, const unsigned int ltbMode, const unsigned int motorPower, const unsigned int cameraPower, const unsigned int ledFlashing)
 Saves the supplied data in a calibration_parameters_record.
bool saveDataSeparatorRecord (const DataSeparatorRecord &record)
 Saves the supplied data_separator_record and its payload.
const DataSeparatorRecordsaveEvent (const EventReadout &event)
 Saves the supplied event after a data_separator_record.
const DataSeparatorRecordsaveEvent (const EventReadout &event, int dataBlockNumber)
 Saves the supplied event after a data_separator_record.
bool close (const FileEndRecord &record)
 Closes a sequence, saving the supplied file_end_record at the end of the last element.
const FileEndRecordclose (const FileTraits::FileDateTime &dateTime)
 Saves the supplied date in a file_end_record and closes the last stream in a sequence.
const FileEndRecordclose (const FileTraits::FileDateTime &dateTime, const unsigned int blockCountBeforeFile, const unsigned long payloadLengthBeforeFile, const unsigned int status)
 Closes a sequence, saving the supplied data in an file_end_record at the end of the last element.

Protected Member Functions

 DaqToOStream (const FileTraits &traits)
 Suppress default.
const FileStartRecordopenElement (const unsigned int fileNumber, const FileTraits::FileDateTime &dateTime, const unsigned int dataBlockLimit, const unsigned int megabyteLimit)
 Opens a isolated element in a sequence, creating and writing the file_start_record into it.
virtual std::ostream * openStream ()=0
 Used to open a new stream that is used as the backing of this class.
virtual void prepareNext ()=0
 Used to prepare for the next element in the sequence.
virtual void closeStream (std::ostream &stream)=0
 Used to close the ostream that is backing this class.
void splitStream ()
 Splits the output stream, closing the current one opening a new one but not changing any of the bookkeeping.
void eventSaved (unsigned int bytesSaved)
 Informs this object that the event has been saved by an outside mechanism.
const std::string & getFileBase () const
 Returns the name used as the base of all files written.
unsigned int getFileBlockCount () const
 The count of the data blocks saved in the current file.
unsigned int getFileCount () const
 Returns the number of files that have been opened so far.
unsigned int getLastRecord () const
 Returns the type of record last 'saved'.
bool hasFileBase () const
 Returns true when this object has a valid file base.
bool hasOStream () const
 Returns true when this object has a valid ostream.
void saveBuffer (const FileBuffer &daqBuffer)
 Saves the supplied buffer to the output file.

Private Member Functions

 DaqToOStream ()
 Suppress default.
 DaqToOStream (DaqToOStream &rhs)
 Suppress default.
DaqToOStreamoperator= (DaqToOStream &rhs)
 Suppress default.
void setFileBase (const std::string &fileBase)
 Sets the file base used by this object.

Private Attributes

const FileTraitsm_traits
 The FileTraits to use to create file based opjects.
std::ostream * m_ostream
 The stream being written to.
DaqBuffer::OutputBufferListm_buffers
 List of output buffers used to collect FileBuffer to be output.
std::string * m_fileBase
 The base from which to build a sequence of file names.
unsigned long m_filePayloadLength
 The number of payload bytes saved in the current file.
unsigned long m_payloadLengthTotal
 The number of payload bytes saved in total.
unsigned int m_lastRecord
 The type of the last record saved.
unsigned int m_dataBlockLimit
 The maximum number of data blocks that should be written to a file.
unsigned int m_megabyteLimit
 The maximum number of megabytes of payload that should be written to a file.
unsigned int m_fileCount
 The number of files that this object has opened.
unsigned int m_sequenceBlockCount
 The count of the data blocks saved in the current file sequence.
unsigned int m_fileBlockCount
 The count of the data blocks saved in the current file.
unsigned int m_blockCountTotal
 The count of the data blocks saved in total.

Detailed Description

Definition at line 33 of file DaqToOStream.h.


Constructor & Destructor Documentation

DaqToOStream::~DaqToOStream ( ) [virtual]

Destroy this instance of the class.

Definition at line 53 of file DaqToOStream.cc.

                            {
    if (0 != m_fileBase) {
        delete m_fileBase;
    }
    if (0 != m_buffers) {
        delete m_buffers;
    }
    if (0 != m_ostream) {
        delete m_ostream;
    }
}
DaqToOStream::DaqToOStream ( const FileTraits traits) [protected]
DybDaq::DaqToOStream::DaqToOStream ( ) [private]

Suppress default.

DybDaq::DaqToOStream::DaqToOStream ( DaqToOStream rhs) [private]

Suppress default.


Member Function Documentation

bool DaqToOStream::openSequence ( const std::string &  fileBase,
const FileStartRecord record 
)

Opens the first element in a new sequence, writing the file_start_record into it.

Definition at line 143 of file DaqToOStream.cc.

                                                              {
    setFileBase(fileBase);
    m_fileCount = record.fileNumber() - 1;
    m_dataBlockLimit = record.dataBlockLimit(),
    m_megabyteLimit = record.megabyteLimit();
    return open(record);
}    
const FileStartRecord * DaqToOStream::openSequence ( const std::string &  fileBase,
const FileTraits::FileDateTime dateTime,
const unsigned int  dataBlockLimit,
const unsigned int  megabyteLimit 
)

Opens the first element in a new sequence, creating and writing the file_start_record into it.

Definition at line 152 of file DaqToOStream.cc.

                                                                                   {
    setFileBase(fileBase);
    m_dataBlockLimit = dataBlockLimit,
    m_megabyteLimit = megabyteLimit;
    return openNext(dateTime);
}    
bool DaqToOStream::open ( const FileStartRecord record)

Opens a new element in a sequence, writing the file_start_record into it.

Definition at line 98 of file DaqToOStream.cc.

const FileStartRecord * DaqToOStream::openNext ( const FileTraits::FileDateTime dateTime)

Opens a new element in a sequence, creating and then writing a file_start_record into it.

Definition at line 126 of file DaqToOStream.cc.

                                                                                    {
    if (hasOStream()) {
        return 0;
    }
    prepareNext();
    FileStartRecord* record = new FileStartRecord(++m_fileCount,
                                                  dateTime,
                                                  m_dataBlockLimit,
                                                  m_megabyteLimit,
                                                  *m_traits);
    if (open(*record)) {
        return record;
    }
    delete record;
    return 0;
}
bool DaqToOStream::saveFileNameStrings ( const FileNameStrings record)

Saves the supplied file_name_strings.

Definition at line 180 of file DaqToOStream.cc.

                                                                    {
    if (FileTraits::kFileStartRecord != m_lastRecord) {
        return false;
    }
    saveBuffer(record);
    m_lastRecord = FileTraits::kFileNameStrings;
    return true;
}
const FileNameStrings* DybDaq::DaqToOStream::saveFileNameStrings ( const std::string &  application,
const std::string &  fileBase = "" 
)

Saves the supplied data in a file_name_strings.

bool DaqToOStream::saveMetadataStrings ( const MetadataStrings record)

Saves the supplied metadata_strings.

Definition at line 207 of file DaqToOStream.cc.

                                                                    {
    if (FileTraits::kFileNameStrings != m_lastRecord) {
        return false;
    }
    saveBuffer(record);
    m_lastRecord = FileTraits::kMetadataStrings;
    return true;
}
const MetadataStrings * DaqToOStream::saveMetadataStrings ( const MetadataStrings::MetadataStringPtrList metadataStrings)

Saves the supplied data in a metadata_strings.

Definition at line 216 of file DaqToOStream.cc.

                                                                                                                    {
    MetadataStrings* record = new MetadataStrings(metadataStrings,
                                                  *m_traits);
    if (saveMetadataStrings(*record)) {
        return record;
    }
    delete record;
    return 0;
}
bool DaqToOStream::saveRunParametersRecord ( const RunParametersRecord record)

Saves the supplied run_parameters_record.

Definition at line 226 of file DaqToOStream.cc.

const RunParametersRecord * DaqToOStream::saveRunParametersRecord ( const unsigned int  runNumber,
const bool  recordEnabled,
const unsigned int  triggerType,
const unsigned int  detectorMask 
)

Saves the supplied data in a run_parameters_record.

Definition at line 236 of file DaqToOStream.cc.

                                                                                                 {
    RunParametersRecord* record = new RunParametersRecord(runNumber,
                                                          recordEnabled,
                                                          triggerType,
                                                          detectorMask,
                                                          *m_traits);
    if (saveRunParametersRecord(*record)) {
        return record;
    }
    delete record;
    return 0;
}
bool DaqToOStream::saveCalibrationParametersRecord ( const CalibrationParametersRecord record)

Saves the supplied calibration_parameters_record.

Definition at line 252 of file DaqToOStream.cc.

const CalibrationParametersRecord * DaqToOStream::saveCalibrationParametersRecord ( const unsigned int  detector,
const unsigned int  adNumber,
const unsigned int  sourceA,
const unsigned int  zPositionA,
const unsigned int  sourceB,
const unsigned int  zPositionB,
const unsigned int  sourceC,
const unsigned int  zPositionC,
const unsigned int  led1,
const unsigned int  led2,
const unsigned int  led1Voltage,
const unsigned int  led2Voltage,
const unsigned int  duration,
const unsigned int  ledFrequency,
const unsigned int  ledPulseSeparation,
const unsigned int  ltbMode,
const unsigned int  motorPower,
const unsigned int  cameraPower,
const unsigned int  ledFlashing 
)

Saves the supplied data in a calibration_parameters_record.

Definition at line 261 of file DaqToOStream.cc.

                                                                                                                {
    CalibrationParametersRecord* record = new CalibrationParametersRecord(detector,
                                                                          adNumber,
                                                                          sourceA,
                                                                          zPositionA,
                                                                          sourceB,
                                                                          zPositionB,
                                                                          sourceC,
                                                                          zPositionC,
                                                                          led1,
                                                                          led2,
                                                                          led1Voltage,
                                                                          led2Voltage,
                                                                          duration,
                                                                          ledFrequency,
                                                                          ledPulseSeparation,
                                                                          ltbMode,
                                                                          motorPower,
                                                                          cameraPower,
                                                                          ledFlashing,
                                                                          *m_traits);
    if (saveCalibrationParametersRecord(*record)) {
        return record;
    }
    delete record;
    return 0;
}
bool DaqToOStream::saveDataSeparatorRecord ( const DataSeparatorRecord record)

Saves the supplied data_separator_record and its payload.

Definition at line 307 of file DaqToOStream.cc.

                                                                            {
    if (FileTraits::FileTraits::kRunParametersRecord != m_lastRecord
        && FileTraits::kCalibrationParametersRecord != m_lastRecord
        && FileTraits::kDataSeparatorRecord != m_lastRecord) {
        return false;
    }
    saveBuffer(record);
    m_lastRecord = FileTraits::kDataSeparatorRecord;
    return true;
}
const DataSeparatorRecord * DaqToOStream::saveEvent ( const EventReadout event)

Saves the supplied event after a data_separator_record.

Definition at line 324 of file DaqToOStream.cc.

                                                                            {
    const unsigned int bytesSaved = event.header().totalSize() * DaqBuffer::kBytesInInt;
    eventSaved(bytesSaved);
    const DataSeparatorRecord* record = new DataSeparatorRecord(event,
                                                                m_sequenceBlockCount,
                                                                *m_traits);
    if (saveDataSeparatorRecord(*record)) {
        return record;
    }
    m_filePayloadLength -= bytesSaved;
    --m_sequenceBlockCount;
    --m_fileBlockCount;
    delete record;
    return 0;
}
const DataSeparatorRecord * DaqToOStream::saveEvent ( const EventReadout event,
int  dataBlockNumber 
)

Saves the supplied event after a data_separator_record.

Definition at line 340 of file DaqToOStream.cc.

                                                                       {
    const unsigned int bytesSaved = event.header().totalSize() * DaqBuffer::kBytesInInt;
    eventSaved(bytesSaved);
    const DataSeparatorRecord* record = new DataSeparatorRecord(event,
                                                                dataBlockCount,
                                                                *m_traits);
    if (saveDataSeparatorRecord(*record)) {
        return record;
    }
    m_filePayloadLength -= bytesSaved;
    --m_fileBlockCount;
    delete record;
    return 0;
}
bool DaqToOStream::close ( const FileEndRecord record)

Closes a sequence, saving the supplied file_end_record at the end of the last element.

Definition at line 356 of file DaqToOStream.cc.

                                                    {
    if (FileTraits::FileTraits::kRunParametersRecord != m_lastRecord
        && FileTraits::kCalibrationParametersRecord != m_lastRecord
        && FileTraits::kDataSeparatorRecord != m_lastRecord) {
        return false;
    }
    saveBuffer(record);
    if (0 != m_ostream) {
        closeStream(*m_ostream);
        delete m_ostream;
        m_ostream = 0;
    }
    m_lastRecord = FileTraits::kFileEndRecord;
    return true;
}
const FileEndRecord * DaqToOStream::close ( const FileTraits::FileDateTime dateTime)

Saves the supplied date in a file_end_record and closes the last stream in a sequence.

Definition at line 372 of file DaqToOStream.cc.

                                                                               {
    return close(dateTime,
                 m_blockCountTotal,
                 m_payloadLengthTotal,
                 0x01);
}
const FileEndRecord * DaqToOStream::close ( const FileTraits::FileDateTime dateTime,
const unsigned int  blockCountBeforeFile,
const unsigned long  payloadLengthBeforeFile,
const unsigned int  status 
)

Closes a sequence, saving the supplied data in an file_end_record at the end of the last element.

Definition at line 379 of file DaqToOStream.cc.

                                                                   {
    unsigned int runBlockCount = blockCountBeforeFile + m_fileBlockCount;
    unsigned long payloadLengthTotal = payloadLengthBeforeFile + m_filePayloadLength;
    const FileEndRecord* record = new FileEndRecord(dateTime,
                                                    m_fileBlockCount,
                                                    (unsigned int)(m_filePayloadLength / kBytesInMegabyte),
                                                    runBlockCount,
                                                    (unsigned int)(payloadLengthTotal / kBytesInMegabyte),
                                                    status,
                                                    *m_traits);
    if (close(*record)) {
        m_blockCountTotal = runBlockCount;
        m_payloadLengthTotal = payloadLengthTotal;
        return record;
    }
    delete record;
    return 0;
}
const FileStartRecord * DaqToOStream::openElement ( const unsigned int  fileNumber,
const FileTraits::FileDateTime dateTime,
const unsigned int  dataBlockLimit,
const unsigned int  megabyteLimit 
) [protected]

Opens a isolated element in a sequence, creating and writing the file_start_record into it.

Definition at line 116 of file DaqToOStream.cc.

                                                                                  {
    m_fileCount = fileCount - 1;
    m_dataBlockLimit = dataBlockLimit,
    m_megabyteLimit = megabyteLimit;
    return openNext(dateTime);
}    
virtual std::ostream* DybDaq::DaqToOStream::openStream ( ) [protected, pure virtual]

Used to open a new stream that is used as the backing of this class.

Implemented in DybDaq::DaqToFStream, and DybDaq::DaqToStrStream.

virtual void DybDaq::DaqToOStream::prepareNext ( ) [protected, pure virtual]

Used to prepare for the next element in the sequence.

Implemented in DybDaq::DaqToFStream, and DybDaq::DaqToStrStream.

virtual void DybDaq::DaqToOStream::closeStream ( std::ostream &  stream) [protected, pure virtual]

Used to close the ostream that is backing this class.

Implemented in DybDaq::DaqToFStream, and DybDaq::DaqToStrStream.

void DaqToOStream::splitStream ( ) [protected]

Splits the output stream, closing the current one opening a new one but not changing any of the bookkeeping.

Reimplemented in DybDaq::DaqToStrStream.

Definition at line 89 of file DaqToOStream.cc.

                               {
    if (0 == m_ostream) {
        return;
    }
    closeStream(*m_ostream);
    delete m_ostream;
    m_ostream = openStream();
}
void DaqToOStream::eventSaved ( unsigned int  bytesSaved) [protected]

Informs this object that the event has been saved by an outside mechanism.

Reimplemented in DybDaq::DaqToStrStream.

Definition at line 318 of file DaqToOStream.cc.

const string & DaqToOStream::getFileBase ( ) const [protected]

Returns the name used as the base of all files written.

Definition at line 65 of file DaqToOStream.cc.

                                              {
    return *m_fileBase;
}
unsigned int DaqToOStream::getFileBlockCount ( ) const [protected]

The count of the data blocks saved in the current file.

Reimplemented in DybDaq::DaqToStrStream.

Definition at line 69 of file DaqToOStream.cc.

                                                   {
    return m_fileBlockCount;
}
unsigned int DaqToOStream::getFileCount ( ) const [protected]

Returns the number of files that have been opened so far.

Definition at line 73 of file DaqToOStream.cc.

                                              {
    return m_fileCount;
}
unsigned int DaqToOStream::getLastRecord ( ) const [protected]

Returns the type of record last 'saved'.

Definition at line 77 of file DaqToOStream.cc.

                                               {
    return m_lastRecord;
}
bool DaqToOStream::hasFileBase ( ) const [protected]

Returns true when this object has a valid file base.

Definition at line 81 of file DaqToOStream.cc.

                                     {
    return 0 != m_fileBase;
}
bool DaqToOStream::hasOStream ( ) const [protected]

Returns true when this object has a valid ostream.

Definition at line 85 of file DaqToOStream.cc.

                                    {
    return 0 != m_ostream;
}
void DaqToOStream::saveBuffer ( const FileBuffer daqBuffer) [protected]

Saves the supplied buffer to the output file.

Definition at line 162 of file DaqToOStream.cc.

                                                         {
    daqBuffer.gather(*m_buffers);
    DaqBuffer::OutputBufferList::const_iterator buffer;
    for (buffer = m_buffers->begin();
         buffer != m_buffers->end();
         ++buffer) {
        m_ostream->write((*buffer).first, (*buffer).second);
    }
    m_buffers->clear();
}
DaqToOStream& DybDaq::DaqToOStream::operator= ( DaqToOStream rhs) [private]

Suppress default.

void DaqToOStream::setFileBase ( const std::string &  fileBase) [private]

Sets the file base used by this object.

Definition at line 173 of file DaqToOStream.cc.

                                                        {
    if (0 != m_fileBase) {
        delete m_fileBase;
    }
    m_fileBase = new string(fileBase);
}

Member Data Documentation

The FileTraits to use to create file based opjects.

Definition at line 262 of file DaqToOStream.h.

std::ostream* DybDaq::DaqToOStream::m_ostream [private]

The stream being written to.

Definition at line 267 of file DaqToOStream.h.

List of output buffers used to collect FileBuffer to be output.

Definition at line 272 of file DaqToOStream.h.

std::string* DybDaq::DaqToOStream::m_fileBase [private]

The base from which to build a sequence of file names.

Definition at line 277 of file DaqToOStream.h.

The number of payload bytes saved in the current file.

Definition at line 282 of file DaqToOStream.h.

The number of payload bytes saved in total.

Definition at line 287 of file DaqToOStream.h.

unsigned int DybDaq::DaqToOStream::m_lastRecord [private]

The type of the last record saved.

Definition at line 292 of file DaqToOStream.h.

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

Definition at line 297 of file DaqToOStream.h.

unsigned int DybDaq::DaqToOStream::m_megabyteLimit [private]

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

Definition at line 302 of file DaqToOStream.h.

unsigned int DybDaq::DaqToOStream::m_fileCount [private]

The number of files that this object has opened.

Definition at line 307 of file DaqToOStream.h.

The count of the data blocks saved in the current file sequence.

Definition at line 312 of file DaqToOStream.h.

The count of the data blocks saved in the current file.

Definition at line 317 of file DaqToOStream.h.

The count of the data blocks saved in total.

Definition at line 322 of file DaqToOStream.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 09:53:23 for FileReadoutFormat by doxygen 1.7.4