/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::DaqToStrStream Class Reference

#include <DaqToStrStream.h>

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

List of all members.

Public Member Functions

 DaqToStrStream (const FileTraits &traits)
 Creates an instance of this class.
virtual ~DaqToStrStream ()
 Destroy this instance of the class.
void eventSaved (unsigned int bytesSaved)
 Informs this object that the event has been saved by an outside mechanism.
unsigned int getFileBlockCount () const
 The count of the data blocks saved in the current file.
std::string str () const
 Return the current contents of the string that is being filled.
void splitStream ()
 Splits the output stream, closing the current one opening a new one but not changing any of the bookkeeping.
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

virtual std::ostream * openStream ()
 Used to open a new stream that is used as the backing of this class.
virtual void prepareNext ()
 Used to prepare for the next element in the sequence.
virtual void closeStream (std::ostream &stream)
 Used to close the ostream that is backing this class.
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.
const std::string & getFileBase () const
 Returns the name used as the base of all files written.
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

 DaqToStrStream ()
 Suppress default.
 DaqToStrStream (DaqToStrStream &rhs)
 Suppress default.
DaqToStrStreamoperator= (DaqToStrStream &rhs)
 Suppress default.

Private Attributes

std::ostringstream * m_stringStream
 The string stream into which the DAQ data is being written.
std::string * m_lastString
 The last string in the stream when it was closed.

Detailed Description

Definition at line 21 of file DaqToStrStream.h.


Constructor & Destructor Documentation

DaqToStrStream::DaqToStrStream ( const FileTraits traits)

Creates an instance of this class.

Definition at line 25 of file DaqToStrStream.cc.

                                                       :
    DaqToOStream(traits),
    m_stringStream(0),
    m_lastString(0) {
}
DaqToStrStream::~DaqToStrStream ( ) [virtual]

Destroy this instance of the class.

Definition at line 31 of file DaqToStrStream.cc.

                                {
    // deleting m_stringStream taken care by superclass.
    if (0 != m_lastString) {
        delete m_lastString;
    }
}
DybDaq::DaqToStrStream::DaqToStrStream ( ) [private]

Suppress default.

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

Suppress default.


Member Function Documentation

void DaqToStrStream::eventSaved ( unsigned int  bytesSaved)

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

Reimplemented from DybDaq::DaqToOStream.

Definition at line 56 of file DaqToStrStream.cc.

                                                       {
    DaqToOStream::eventSaved(bytesSaved);
}
unsigned int DaqToStrStream::getFileBlockCount ( ) const

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

Reimplemented from DybDaq::DaqToOStream.

Definition at line 60 of file DaqToStrStream.cc.

string DaqToStrStream::str ( ) const

Return the current contents of the string that is being filled.

Definition at line 64 of file DaqToStrStream.cc.

                                 {
    if (0 != m_stringStream) {
        return m_stringStream->str();
    }
    return *m_lastString;
}
void DaqToStrStream::splitStream ( )

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

Reimplemented from DybDaq::DaqToOStream.

Definition at line 71 of file DaqToStrStream.cc.

ostream * DaqToStrStream::openStream ( ) [protected, virtual]

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

Implements DybDaq::DaqToOStream.

Definition at line 41 of file DaqToStrStream.cc.

                                    {
    if (0 != m_lastString) {
        delete m_lastString;
        m_lastString = 0;
    }
    m_stringStream = new ostringstream();
    return m_stringStream;
}
void DaqToStrStream::prepareNext ( ) [protected, virtual]

Used to prepare for the next element in the sequence.

Implements DybDaq::DaqToOStream.

Definition at line 38 of file DaqToStrStream.cc.

                                 {
}
void DaqToStrStream::closeStream ( std::ostream &  stream) [protected, virtual]

Used to close the ostream that is backing this class.

Implements DybDaq::DaqToOStream.

Definition at line 50 of file DaqToStrStream.cc.

                                              {
    m_lastString = new string(m_stringStream->str());
    // deleting m_stringStream taken care by superclass.
    m_stringStream = 0;
}
DaqToStrStream& DybDaq::DaqToStrStream::operator= ( DaqToStrStream rhs) [private]

Suppress default.

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

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 
) [inherited]

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) [inherited]

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) [inherited]

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) [inherited]

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 = "" 
) [inherited]

Saves the supplied data in a file_name_strings.

bool DaqToOStream::saveMetadataStrings ( const MetadataStrings record) [inherited]

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) [inherited]

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) [inherited]

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 
) [inherited]

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) [inherited]

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 
) [inherited]

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) [inherited]

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) [inherited]

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 
) [inherited]

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) [inherited]

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) [inherited]

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 
) [inherited]

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, inherited]

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);
}    
const string & DaqToOStream::getFileBase ( ) const [protected, inherited]

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::getFileCount ( ) const [protected, inherited]

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, inherited]

Returns the type of record last 'saved'.

Definition at line 77 of file DaqToOStream.cc.

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

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, inherited]

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, inherited]

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();
}

Member Data Documentation

std::ostringstream* DybDaq::DaqToStrStream::m_stringStream [private]

The string stream into which the DAQ data is being written.

Definition at line 92 of file DaqToStrStream.h.

std::string* DybDaq::DaqToStrStream::m_lastString [private]

The last string in the stream when it was closed.

Definition at line 97 of file DaqToStrStream.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