#include <DaqToStrStream.h>
Inheritance diagram for DybDaq::DaqToStrStream:
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 FileStartRecord * | 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. | |
bool | open (const FileStartRecord &record) |
Opens a new element in a sequence, writing the file_start_record into it. | |
const FileStartRecord * | openNext (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 FileNameStrings * | saveFileNameStrings (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 MetadataStrings * | saveMetadataStrings (const MetadataStrings::MetadataStringPtrList &metadataStrings) |
Saves the supplied data in a metadata_strings. | |
bool | saveRunParametersRecord (const RunParametersRecord &record) |
Saves the supplied run_parameters_record. | |
const RunParametersRecord * | 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. | |
bool | saveCalibrationParametersRecord (const CalibrationParametersRecord &record) |
Saves the supplied calibration_parameters_record. | |
const CalibrationParametersRecord * | 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. | |
bool | saveDataSeparatorRecord (const DataSeparatorRecord &record) |
Saves the supplied data_separator_record and its payload. | |
const DataSeparatorRecord * | saveEvent (const EventReadout &event) |
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 FileEndRecord * | close (const FileTraits::FileDateTime &dateTime) |
Saves the supplied date in a file_end_record and closes the last stream in a sequence. | |
const FileEndRecord * | 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. | |
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 FileStartRecord * | openElement (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. | |
DaqToStrStream & | operator= (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. |
Definition at line 21 of file DaqToStrStream.h.
DaqToStrStream::DaqToStrStream | ( | const FileTraits & | traits | ) |
Creates an instance of this class.
Definition at line 25 of file DaqToStrStream.cc.
00025 : 00026 DaqToOStream(traits), 00027 m_stringStream(0), 00028 m_lastString(0) { 00029 }
DaqToStrStream::~DaqToStrStream | ( | ) | [virtual] |
Destroy this instance of the class.
Definition at line 31 of file DaqToStrStream.cc.
00031 { 00032 // deleting m_stringStream taken care by superclass. 00033 if (0 != m_lastString) { 00034 delete m_lastString; 00035 } 00036 }
DybDaq::DaqToStrStream::DaqToStrStream | ( | ) | [private] |
Suppress default.
DybDaq::DaqToStrStream::DaqToStrStream | ( | DaqToStrStream & | rhs | ) | [private] |
Suppress default.
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.
00056 { 00057 DaqToOStream::eventSaved(bytesSaved); 00058 }
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.
00060 { 00061 return DaqToOStream::getFileBlockCount(); 00062 }
string DaqToStrStream::str | ( | ) | const |
Return the current contents of the string that is being filled.
Definition at line 64 of file DaqToStrStream.cc.
00064 { 00065 if (0 != m_stringStream) { 00066 return m_stringStream->str(); 00067 } 00068 return *m_lastString; 00069 }
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.
00071 { 00072 return DaqToOStream::splitStream(); 00073 }
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.
00041 { 00042 if (0 != m_lastString) { 00043 delete m_lastString; 00044 m_lastString = 0; 00045 } 00046 m_stringStream = new ostringstream(); 00047 return m_stringStream; 00048 }
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.
00050 { 00051 m_lastString = new string(m_stringStream->str()); 00052 // deleting m_stringStream taken care by superclass. 00053 m_stringStream = 0; 00054 }
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.
00144 { 00145 setFileBase(fileBase); 00146 m_dataBlockLimit = record.dataBlockLimit(), 00147 m_megabyteLimit = record.megabyteLimit(); 00148 return open(record); 00149 }
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 151 of file DaqToOStream.cc.
00154 { 00155 setFileBase(fileBase); 00156 m_dataBlockLimit = dataBlockLimit, 00157 m_megabyteLimit = megabyteLimit; 00158 return openNext(dateTime); 00159 }
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.
00098 { 00099 if (hasOStream()) { 00100 return false; 00101 } 00102 if (FileTraits::kFileEndRecord != getLastRecord()) { 00103 return false; 00104 } 00105 m_ostream = openStream(); 00106 m_dataBlockLimit = record.dataBlockLimit(), 00107 m_megabyteLimit = record.megabyteLimit(); 00108 m_filePayloadLength = 0; 00109 m_fileBlockCount = 0; 00110 00111 saveBuffer(record); 00112 m_lastRecord = FileTraits::kFileStartRecord; 00113 return true; 00114 }
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.
00126 { 00127 if (hasOStream()) { 00128 return 0; 00129 } 00130 prepareNext(); 00131 FileStartRecord* record = new FileStartRecord(++m_fileCount, 00132 dateTime, 00133 m_dataBlockLimit, 00134 m_megabyteLimit, 00135 *m_traits); 00136 if (open(*record)) { 00137 return record; 00138 } 00139 delete record; 00140 return 0; 00141 }
bool DaqToOStream::saveFileNameStrings | ( | const FileNameStrings & | record | ) | [inherited] |
Saves the supplied file_name_strings.
Definition at line 179 of file DaqToOStream.cc.
00179 { 00180 if (FileTraits::kFileStartRecord != m_lastRecord) { 00181 return false; 00182 } 00183 saveBuffer(record); 00184 m_lastRecord = FileTraits::kFileNameStrings; 00185 return true; 00186 }
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 206 of file DaqToOStream.cc.
00206 { 00207 if (FileTraits::kFileNameStrings != m_lastRecord) { 00208 return false; 00209 } 00210 saveBuffer(record); 00211 m_lastRecord = FileTraits::kMetadataStrings; 00212 return true; 00213 }
const MetadataStrings * DaqToOStream::saveMetadataStrings | ( | const MetadataStrings::MetadataStringPtrList & | metadataStrings | ) | [inherited] |
Saves the supplied data in a metadata_strings.
Definition at line 215 of file DaqToOStream.cc.
00215 { 00216 MetadataStrings* record = new MetadataStrings(metadataStrings, 00217 *m_traits); 00218 if (saveMetadataStrings(*record)) { 00219 return record; 00220 } 00221 delete record; 00222 return 0; 00223 }
bool DaqToOStream::saveRunParametersRecord | ( | const RunParametersRecord & | record | ) | [inherited] |
Saves the supplied run_parameters_record.
Definition at line 225 of file DaqToOStream.cc.
00225 { 00226 if (FileTraits::kFileNameStrings != m_lastRecord 00227 && FileTraits::kMetadataStrings != m_lastRecord) { 00228 return false; 00229 } 00230 saveBuffer(record); 00231 m_lastRecord = FileTraits::kRunParametersRecord; 00232 return true; 00233 }
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 235 of file DaqToOStream.cc.
00238 { 00239 RunParametersRecord* record = new RunParametersRecord(runNumber, 00240 recordEnabled, 00241 triggerType, 00242 detectorMask, 00243 *m_traits); 00244 if (saveRunParametersRecord(*record)) { 00245 return record; 00246 } 00247 delete record; 00248 return 0; 00249 }
bool DaqToOStream::saveCalibrationParametersRecord | ( | const CalibrationParametersRecord & | record | ) | [inherited] |
Saves the supplied calibration_parameters_record.
Definition at line 251 of file DaqToOStream.cc.
00251 { 00252 if (FileTraits::kRunParametersRecord != m_lastRecord) { 00253 return false; 00254 } 00255 saveBuffer(record); 00256 m_lastRecord = FileTraits::kCalibrationParametersRecord; 00257 return true; 00258 }
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 260 of file DaqToOStream.cc.
00278 { 00279 CalibrationParametersRecord* record = new CalibrationParametersRecord(detector, 00280 adNumber, 00281 sourceA, 00282 zPositionA, 00283 sourceB, 00284 zPositionB, 00285 sourceC, 00286 zPositionC, 00287 led1, 00288 led2, 00289 led1Voltage, 00290 led2Voltage, 00291 duration, 00292 ledFrequency, 00293 ledPulseSeparation, 00294 ltbMode, 00295 motorPower, 00296 cameraPower, 00297 ledFlashing, 00298 *m_traits); 00299 if (saveCalibrationParametersRecord(*record)) { 00300 return record; 00301 } 00302 delete record; 00303 return 0; 00304 }
bool DaqToOStream::saveDataSeparatorRecord | ( | const DataSeparatorRecord & | record | ) | [inherited] |
Saves the supplied data_separator_record and its payload.
Definition at line 306 of file DaqToOStream.cc.
00306 { 00307 if (FileTraits::FileTraits::kRunParametersRecord != m_lastRecord 00308 && FileTraits::kCalibrationParametersRecord != m_lastRecord 00309 && FileTraits::kDataSeparatorRecord != m_lastRecord) { 00310 return false; 00311 } 00312 saveBuffer(record); 00313 m_lastRecord = FileTraits::kDataSeparatorRecord; 00314 return true; 00315 }
const DataSeparatorRecord * DaqToOStream::saveEvent | ( | const EventReadout & | event | ) | [inherited] |
Saves the supplied event after a data_separator_record.
Definition at line 323 of file DaqToOStream.cc.
00323 { 00324 const unsigned int bytesSaved = event.header().totalSize() * DaqBuffer::kBytesInInt; 00325 eventSaved(bytesSaved); 00326 const DataSeparatorRecord* record = new DataSeparatorRecord(event, 00327 m_sequenceBlockCount, 00328 *m_traits); 00329 if (saveDataSeparatorRecord(*record)) { 00330 return record; 00331 } 00332 m_filePayloadLength -= bytesSaved; 00333 --m_sequenceBlockCount; 00334 --m_fileBlockCount; 00335 delete record; 00336 return 0; 00337 }
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 339 of file DaqToOStream.cc.
00339 { 00340 if (FileTraits::FileTraits::kRunParametersRecord != m_lastRecord 00341 && FileTraits::kCalibrationParametersRecord != m_lastRecord 00342 && FileTraits::kDataSeparatorRecord != m_lastRecord) { 00343 return false; 00344 } 00345 saveBuffer(record); 00346 if (0 != m_ostream) { 00347 closeStream(*m_ostream); 00348 delete m_ostream; 00349 m_ostream = 0; 00350 } 00351 m_lastRecord = FileTraits::kFileEndRecord; 00352 return true; 00353 }
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 355 of file DaqToOStream.cc.
00355 { 00356 return close(dateTime, 00357 m_blockCountTotal, 00358 m_payloadLengthTotal, 00359 0x01); 00360 }
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 362 of file DaqToOStream.cc.
00365 { 00366 unsigned int runBlockCount = blockCountBeforeFile + m_fileBlockCount; 00367 unsigned long payloadLengthTotal = payloadLengthBeforeFile + m_filePayloadLength; 00368 const FileEndRecord* record = new FileEndRecord(dateTime, 00369 m_fileBlockCount, 00370 (unsigned int)(m_filePayloadLength / kBytesInMegabyte), 00371 runBlockCount, 00372 (unsigned int)(payloadLengthTotal / kBytesInMegabyte), 00373 status, 00374 *m_traits); 00375 if (close(*record)) { 00376 m_blockCountTotal = runBlockCount; 00377 m_payloadLengthTotal = payloadLengthTotal; 00378 return record; 00379 } 00380 delete record; 00381 return 0; 00382 }
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.
00119 { 00120 m_fileCount = fileCount - 1; 00121 m_dataBlockLimit = dataBlockLimit, 00122 m_megabyteLimit = megabyteLimit; 00123 return openNext(dateTime); 00124 }
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.
00065 { 00066 return *m_fileBase; 00067 }
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.
00073 { 00074 return m_fileCount; 00075 }
unsigned int DaqToOStream::getLastRecord | ( | ) | const [protected, inherited] |
Returns the type of record last 'saved'.
Definition at line 77 of file DaqToOStream.cc.
00077 { 00078 return m_lastRecord; 00079 }
bool DaqToOStream::hasFileBase | ( | ) | const [protected, inherited] |
Returns true when this object has a valid file base.
Definition at line 81 of file DaqToOStream.cc.
00081 { 00082 return 0 != m_fileBase; 00083 }
bool DaqToOStream::hasOStream | ( | ) | const [protected, inherited] |
Returns true when this object has a valid ostream.
Definition at line 85 of file DaqToOStream.cc.
00085 { 00086 return 0 != m_ostream; 00087 }
void DaqToOStream::saveBuffer | ( | const FileBuffer & | daqBuffer | ) | [protected, inherited] |
Saves the supplied buffer to the output file.
Definition at line 161 of file DaqToOStream.cc.
00161 { 00162 daqBuffer.gather(*m_buffers); 00163 DaqBuffer::OutputBufferList::const_iterator buffer; 00164 for (buffer = m_buffers->begin(); 00165 buffer != m_buffers->end(); 00166 ++buffer) { 00167 m_ostream->write((*buffer).first, (*buffer).second); 00168 } 00169 m_buffers->clear(); 00170 }
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] |