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

#include <DaqToFStream.h>

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

List of all members.

Public Member Functions

 DaqToFStream (const FileTraits &traits)
 Creates an instance of this class.
 DaqToFStream (const FileTraits &traits, std::string &fileDir)
 Creates an instance of this class.
virtual ~DaqToFStream ()
 Destroy this instance of the class.
bool openFile (const std::string &fileName, const FileStartRecord &record)
 Opens a new file and writes the File Start Record into it.
const FileStartRecordopenFile (const std::string &fileName, const unsigned int fileNumber, const FileTraits::FileDateTime &dateTime, const unsigned int dataBlockLimit, const unsigned int megabyteLimit)
 Saves the supplied data in a file_start_record in a new file.
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.
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

 DaqToFStream ()
 Suppress default.
 DaqToFStream (DaqToFStream &rhs)
 Suppress default.
DaqToFStreamoperator= (DaqToFStream &rhs)
 Suppress default.
void createNextFileName ()
 Creates the next file name in the sequence.
const FileStartRecordopenFile (const std::string &fileName, const FileTraits::FileDateTime &dateTime)
 Opens a new file, creating and then writing a File Start Record into it.

Private Attributes

std::ofstream * m_ofstream
 The file being read.
std::string * m_fileDir
 The directory into which to write the files.
std::string * m_fileName
 The name of the file to open.

Detailed Description

Definition at line 25 of file DaqToFStream.h.


Constructor & Destructor Documentation

DaqToFStream::DaqToFStream ( const FileTraits traits)

Creates an instance of this class.

Definition at line 26 of file DaqToFStream.cc.

                                                   :
    DaqToOStream(traits),
    m_ofstream(0),
    m_fileDir(0),
    m_fileName(0) {
}
DaqToFStream::DaqToFStream ( const FileTraits traits,
std::string &  fileDir 
)

Creates an instance of this class.

Definition at line 33 of file DaqToFStream.cc.

                                           :
    DaqToOStream(traits),
    m_ofstream(0),
    m_fileDir(0),
    m_fileName(0) {
    if (0 != &fileDir) {
        m_fileDir = new string(".");
    }
}
DaqToFStream::~DaqToFStream ( ) [virtual]

Destroy this instance of the class.

Definition at line 44 of file DaqToFStream.cc.

                            {
    if (0 != m_fileDir) {
        delete m_fileDir;
    }
    if (0 != m_fileName) {
        delete m_fileName;
    }
    if (hasOStream()) {
        if (m_ofstream->is_open()) {
            m_ofstream->close();
        }
    }
}
DybDaq::DaqToFStream::DaqToFStream ( ) [private]

Suppress default.

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

Suppress default.


Member Function Documentation

bool DybDaq::DaqToFStream::openFile ( const std::string &  fileName,
const FileStartRecord record 
)

Opens a new file and writes the File Start Record into it.

const FileStartRecord* DybDaq::DaqToFStream::openFile ( const std::string &  fileName,
const unsigned int  fileNumber,
const FileTraits::FileDateTime dateTime,
const unsigned int  dataBlockLimit,
const unsigned int  megabyteLimit 
)

Saves the supplied data in a file_start_record in a new file.

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

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

Implements DybDaq::DaqToOStream.

Definition at line 112 of file DaqToFStream.cc.

                                  {
    if (0 == m_fileName) {
        prepareNext();
    }
    m_ofstream = new std::ofstream(m_fileName->c_str(),
                                   fstream::binary | fstream::out | fstream::trunc);
    if (0 != m_fileName) {
        delete m_fileName;
    }
    m_fileName = 0;
    return m_ofstream;
}
void DaqToFStream::prepareNext ( ) [protected, virtual]

Used to prepare for the next element in the sequence.

Implements DybDaq::DaqToOStream.

Definition at line 88 of file DaqToFStream.cc.

                               {
    // If file base is not set used provided name.
    const string& fileBase = getFileBase();
    if (0 == &fileBase) {
      return;
    }

    unsigned int segmentCount = getFileCount() + 1;
    char* segmentSuffix = new char[11];
    sprintf(segmentSuffix,
            "_%.4d.data",
            segmentCount);
    segmentSuffix[10] = 0;
    string fileName = getFileBase() + segmentSuffix;
    delete[] segmentSuffix;
    if (0 != m_fileDir) {
        fileName = *m_fileDir + "/" + fileName;
    }
    if (0 != m_fileName) {
        delete m_fileName;
    }
    m_fileName = new string(fileName);
}
void DaqToFStream::closeStream ( std::ostream &  stream) [protected, virtual]

Used to close the ostream that is backing this class.

Implements DybDaq::DaqToOStream.

Definition at line 125 of file DaqToFStream.cc.

                                                 {
    ofstream& fileStream = dynamic_cast<ofstream&> (stream);
    fileStream.close();
    m_ofstream = 0;
}
DaqToFStream& DybDaq::DaqToFStream::operator= ( DaqToFStream rhs) [private]

Suppress default.

void DybDaq::DaqToFStream::createNextFileName ( ) [private]

Creates the next file name in the sequence.

const FileStartRecord* DybDaq::DaqToFStream::openFile ( const std::string &  fileName,
const FileTraits::FileDateTime dateTime 
) [private]

Opens a new file, creating and then writing a File Start Record into it.

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);
}    
void DaqToOStream::splitStream ( ) [protected, inherited]

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

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

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, 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::ofstream* DybDaq::DaqToFStream::m_ofstream [private]

The file being read.

Definition at line 99 of file DaqToFStream.h.

std::string* DybDaq::DaqToFStream::m_fileDir [private]

The directory into which to write the files.

Definition at line 104 of file DaqToFStream.h.

std::string* DybDaq::DaqToFStream::m_fileName [private]

The name of the file to open.

Definition at line 109 of file DaqToFStream.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:22 for FileReadoutFormat by doxygen 1.7.4