#include <DaqToOStream.h>
Inheritance diagram for DybDaq::DaqToOStream:
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 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 | |
DaqToOStream (const FileTraits &traits) | |
Suppress default. | |
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. | |
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. | |
DaqToOStream & | operator= (DaqToOStream &rhs) |
Suppress default. | |
void | setFileBase (const std::string &fileBase) |
Sets the file base used by this object. | |
Private Attributes | |
const FileTraits * | m_traits |
The FileTraits to use to create file based opjects. | |
std::ostream * | m_ostream |
The stream being written to. | |
DaqBuffer::OutputBufferList * | m_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. |
Definition at line 33 of file DaqToOStream.h.
DaqToOStream::~DaqToOStream | ( | ) | [virtual] |
Destroy this instance of the class.
Definition at line 53 of file DaqToOStream.cc.
00053 { 00054 if (0 != m_fileBase) { 00055 delete m_fileBase; 00056 } 00057 if (0 != m_buffers) { 00058 delete m_buffers; 00059 } 00060 if (0 != m_ostream) { 00061 delete m_ostream; 00062 } 00063 }
DaqToOStream::DaqToOStream | ( | const FileTraits & | traits | ) | [protected] |
Suppress default.
Definition at line 37 of file DaqToOStream.cc.
00037 : 00038 m_traits(&traits), 00039 m_ostream(0), 00040 m_buffers(new DaqBuffer::OutputBufferList()), 00041 m_fileBase(0), 00042 m_filePayloadLength(0), 00043 m_payloadLengthTotal(0), 00044 m_lastRecord(FileTraits::kFileEndRecord), 00045 m_dataBlockLimit(0), 00046 m_megabyteLimit(0), 00047 m_fileCount(0), 00048 m_sequenceBlockCount(0), 00049 m_fileBlockCount(0), 00050 m_blockCountTotal(0) { 00051 }
DybDaq::DaqToOStream::DaqToOStream | ( | ) | [private] |
Suppress default.
DybDaq::DaqToOStream::DaqToOStream | ( | DaqToOStream & | rhs | ) | [private] |
Suppress default.
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.
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 | |||
) |
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 | ) |
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 | ) |
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 | ) |
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 = "" | |||
) |
Saves the supplied data in a file_name_strings.
bool DaqToOStream::saveMetadataStrings | ( | const MetadataStrings & | record | ) |
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 | ) |
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 | ) |
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 | |||
) |
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 | ) |
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 | |||
) |
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 | ) |
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 | ) |
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 | ) |
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 | ) |
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 | |||
) |
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] |
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 }
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.
00089 { 00090 if (0 == m_ostream) { 00091 return; 00092 } 00093 closeStream(*m_ostream); 00094 delete m_ostream; 00095 m_ostream = openStream(); 00096 }
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 317 of file DaqToOStream.cc.
00317 { 00318 ++m_fileBlockCount; 00319 ++m_sequenceBlockCount; 00320 m_filePayloadLength += bytesSaved; 00321 }
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.
00065 { 00066 return *m_fileBase; 00067 }
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.
00069 { 00070 return m_fileBlockCount; 00071 }
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.
00073 { 00074 return m_fileCount; 00075 }
unsigned int DaqToOStream::getLastRecord | ( | ) | const [protected] |
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] |
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] |
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] |
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 }
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 172 of file DaqToOStream.cc.
00172 { 00173 if (0 != m_fileBase) { 00174 delete m_fileBase; 00175 } 00176 m_fileBase = new string(fileBase); 00177 }
const FileTraits* DybDaq::DaqToOStream::m_traits [private] |
std::ostream* DybDaq::DaqToOStream::m_ostream [private] |
List of output buffers used to collect FileBuffer to be output.
Definition at line 266 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 271 of file DaqToOStream.h.
unsigned long DybDaq::DaqToOStream::m_filePayloadLength [private] |
The number of payload bytes saved in the current file.
Definition at line 276 of file DaqToOStream.h.
unsigned long DybDaq::DaqToOStream::m_payloadLengthTotal [private] |
unsigned int DybDaq::DaqToOStream::m_lastRecord [private] |
unsigned int DybDaq::DaqToOStream::m_dataBlockLimit [private] |
The maximum number of data blocks that should be written to a file.
Definition at line 291 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 296 of file DaqToOStream.h.
unsigned int DybDaq::DaqToOStream::m_fileCount [private] |
unsigned int DybDaq::DaqToOStream::m_sequenceBlockCount [private] |
The count of the data blocks saved in the current file sequence.
Definition at line 306 of file DaqToOStream.h.
unsigned int DybDaq::DaqToOStream::m_fileBlockCount [private] |
The count of the data blocks saved in the current file.
Definition at line 311 of file DaqToOStream.h.
unsigned int DybDaq::DaqToOStream::m_blockCountTotal [private] |