| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

RawRecord.cc

Go to the documentation of this file.
00001 #include "RawData/RawRecord.h"
00002 #include "RawData/RawRecordFormat.h"
00003 #include "RawData/RawData.h"
00004 #include <string.h>
00005 #include <sstream>
00006 
00007 using namespace DayaBay::RawRecord_v06;
00008 
00009 DayaBay::RawRecord::RawRecord(unsigned int* buffer/*=0*/,
00010                               unsigned int version/*=0*/,
00011                               bool isOwner/*=false*/)
00012   : RawBuffer(buffer,isOwner),
00013     m_version(version)
00014 {
00015   // Default constructor
00016 }
00017 
00018 DayaBay::RawRecord::RawRecord(DayaBay::RawRecord& record,
00019                               bool adopt/*=false*/)
00020   : RawBuffer(record,adopt)
00021 {
00022   // Construct from another RawRecord
00023   // If adopt==true, then take over ownership of the 
00024   // memory buffer (if the input record is the current owner)
00025   m_version = record.version();
00026 }
00027 
00028 DayaBay::RawRecord::~RawRecord()
00029 {
00030   // Destructor
00031   m_version=0;
00032 }
00033 
00034 unsigned int DayaBay::RawRecord::minimumSize()
00035 {
00036   // Minimum size for all raw records.
00037   return RecordFormat::Record::minimumSize;
00038 }
00039 
00040 unsigned int DayaBay::RawRecord::type() const
00041 {
00042   // Return the type of this RawRecord
00043   return this->getValue(RecordFormat::Record::typeLine);
00044 }
00045 
00046 unsigned int DayaBay::RawRecord::size() const
00047 {
00048   // Return the size of this record, in integer segments
00049   return this->getValue(RecordFormat::Record::sizeLine);
00050 }
00051 
00052 unsigned int DayaBay::RawRecord::version() const
00053 {
00054   // Version of this record
00055   return m_version;
00056 }
00057 
00058 bool DayaBay::RawRecord::isFileStart() const
00059 {
00060   // Is this a file start record?
00061   return (this->type()==RecordFormat::FileStart::type);
00062 }
00063 
00064 bool DayaBay::RawRecord::isFileName() const
00065 {
00066   // Is this a file name record?
00067   return (this->type()==RecordFormat::FileName::type);
00068 }
00069 
00070 bool DayaBay::RawRecord::isMetadata() const
00071 {
00072   // Is this a metadata record?
00073   return (this->type()==RecordFormat::Metadata::type);
00074 }
00075 
00076 bool DayaBay::RawRecord::isRunParameters() const
00077 {
00078   // Is this a run parameters record?
00079   return (this->type()==RecordFormat::RunParameters::type);
00080 }
00081 
00082 bool DayaBay::RawRecord::isCalibrationParameters() const
00083 {
00084   // Is this a calibration parameters record?
00085   return (this->type()==RecordFormat::CalibrationParameters::type);
00086 }
00087 
00088 bool DayaBay::RawRecord::isDataSeparator() const
00089 {
00090   // Is this a data separator record?
00091   return (this->type()==RecordFormat::DataSeparator::type);
00092 }
00093 
00094 bool DayaBay::RawRecord::isFileEnd() const
00095 {
00096   // Is this a file end record?
00097   return (this->type()==RecordFormat::FileEnd::type);
00098 }
00099 
00100 DayaBay::RawRecord* DayaBay::RawRecord::clone() const
00101 {
00102   // Make a full copy of this record
00103   unsigned int* newBuffer = 0;
00104   if(this->buffer()){
00105     unsigned int size = this->size();
00106     if( this->isDataSeparator() ){ 
00107       // Add additional lines for data block contents
00108       DayaBay::RawDataSeparator dataSeparator(this->buffer(), this->version());
00109       size += (dataSeparator.blockSize() + sizeof(unsigned int)-1)
00110               / sizeof(unsigned int);
00111     }
00112     if( size>0 ){
00113       memcpy( newBuffer, this->buffer(), size*sizeof(unsigned int) );
00114       if(!newBuffer) return 0;
00115     }
00116   }
00117   return DayaBay::RawRecord::makeNewRecord(newBuffer, m_version, 
00118                                            true /*isOwner*/);
00119 }
00120 
00121 std::ostream& DayaBay::RawRecord::dump(std::ostream& str){
00122   // Print the record information
00123   return str << "Record {type: 0x" << std::hex << this->type() << std::dec 
00124              << ", "
00125              << "size: " << this->size() << ", "
00126              << "version: " << this->version() << "}" << std::endl;
00127 }
00128 
00129 DayaBay::RawRecord* DayaBay::RawRecord::makeNewRecord(
00130                                                      unsigned int* buffer/*=0*/,
00131                                                      unsigned int version/*=0*/,
00132                                                      bool isOwner/*=false*/){
00133   // Make a new record.  Automatically set the correct class type
00134   // using the type() defined in the raw record.
00135   // 
00136   // The caller is responsible for deleting the returned record.
00137   
00138   DayaBay::RawRecord* newRecord = 0;
00139   // Convert to the proper record type
00140   DayaBay::RawRecord rawRecord(buffer,version);
00141   if( rawRecord.isFileStart() ){
00142     newRecord = new DayaBay::RawFileStart(buffer, version, isOwner);
00143   }else if( rawRecord.isFileName() ){
00144     newRecord = new DayaBay::RawFileName(buffer, version, isOwner);
00145   }else if( rawRecord.isMetadata() ){
00146     newRecord = new DayaBay::RawMetadata(buffer, version, isOwner);
00147   }else if( rawRecord.isRunParameters() ){
00148     newRecord = new DayaBay::RawRunParameters(buffer, version, isOwner);
00149   }else if( rawRecord.isCalibrationParameters() ){
00150     newRecord = new DayaBay::RawCalibrationParameters(buffer, version, isOwner);
00151   }else if( rawRecord.isDataSeparator() ){
00152     newRecord = new DayaBay::RawDataSeparator(buffer, version, isOwner);
00153   }else if( rawRecord.isFileEnd() ){
00154     newRecord = new DayaBay::RawFileEnd(buffer, version, isOwner);
00155   }else{
00156     newRecord = new DayaBay::RawRecord(buffer, version, isOwner);
00157   }
00158   return newRecord;
00159 }
00160 
00162 
00163 DayaBay::RawFileStart::RawFileStart(unsigned int* buffer/*=0*/,
00164                                     unsigned int version/*=0*/,
00165                                     bool isOwner/*=false*/)
00166   : RawRecord(buffer,version,isOwner)
00167 {
00168   // Default constructor
00169 }
00170 
00171 DayaBay::RawFileStart::RawFileStart(DayaBay::RawRecord& record,
00172                                     bool adopt/*=false*/)
00173   : RawRecord(record,adopt)
00174 {
00175   // Construct from another RawRecord
00176   // If adopt==true, then take over ownership of the 
00177   // memory buffer (if the input record is the current owner)
00178 }
00179 
00180 DayaBay::RawFileStart::~RawFileStart()
00181 {
00182   // Destructor
00183 }
00184 
00185 unsigned int DayaBay::RawFileStart::fileVersion() const
00186 {
00187   return this->getValue(RecordFormat::FileStart::fileVersionLine);
00188 }
00189 
00190 unsigned int DayaBay::RawFileStart::fileNumber() const
00191 {
00192   return this->getValue(RecordFormat::FileStart::fileNumberLine);
00193 }
00194 
00195 unsigned int DayaBay::RawFileStart::date() const
00196 {
00197   return this->getValue(RecordFormat::FileStart::dateLine);
00198 }
00199 
00200 unsigned int DayaBay::RawFileStart::time() const
00201 {
00202   return this->getValue(RecordFormat::FileStart::timeLine);
00203 }
00204 
00205 unsigned int DayaBay::RawFileStart::sizeLimitDataBlocks() const
00206 {
00207   return this->getValue(RecordFormat::FileStart::sizeLimitDataBlocksLine);
00208 }
00209 
00210 unsigned int DayaBay::RawFileStart::sizeLimitMB() const
00211 {
00212   return this->getValue(RecordFormat::FileStart::sizeLimitMBLine);
00213 }
00214 
00215 std::ostream& DayaBay::RawFileStart::dump(std::ostream& str){
00216   // Print the record information
00217   str << "RawFileStart {" << std::endl << "  ";
00218   this->RawRecord::dump(str);
00219   return str << "  fileVersion: " << this->fileVersion() << std::endl
00220              << "  fileNumber: " << this->fileNumber() << std::endl
00221              << "  date: " << this->date() << std::endl
00222              << "  time: " << this->time() << std::endl
00223              << "  sizeLimitDataBlocks: " << this->sizeLimitDataBlocks() 
00224              << std::endl
00225              << "  sizeLimitMB: " << this->sizeLimitMB() << " }" << std::endl;
00226 }
00227 
00229 
00230 
00231 DayaBay::RawFileName::RawFileName(unsigned int* buffer/*=0*/,
00232                                   unsigned int version/*=0*/,
00233                                   bool isOwner/*=false*/)
00234   : RawRecord(buffer,version,isOwner)
00235 {
00236   // Default constructor
00237 }
00238 
00239 DayaBay::RawFileName::RawFileName(DayaBay::RawRecord& record,
00240                                   bool adopt/*=false*/)
00241   : RawRecord(record,adopt)
00242 {
00243   // Construct from another RawRecord
00244   // If adopt==true, then take over ownership of the 
00245   // memory buffer (if the input record is the current owner)
00246 }
00247 
00248 DayaBay::RawFileName::~RawFileName()
00249 {
00250   // Destructor
00251 }
00252 
00253 char* DayaBay::RawFileName::appName() const
00254 {
00255   return this->getString(RecordFormat::FileName::appNameLine);
00256 }
00257 
00258 unsigned int DayaBay::RawFileName::appNameLength() const
00259 {
00260   return this->getValue(RecordFormat::FileName::appNameLengthLine);
00261 }
00262 
00263 char* DayaBay::RawFileName::fileName() const
00264 {
00265   // Add enough integer lines to account for app name string size
00266   unsigned int stringLineLength = this->appNameLength()*sizeof(char)
00267     +sizeof(unsigned int) - 1;
00268   stringLineLength /= sizeof(unsigned int);
00269   return this->getString(RecordFormat::FileName::appNameLine
00270                          +stringLineLength+1);
00271 }
00272 
00273 unsigned int DayaBay::RawFileName::fileNameLength() const
00274 {
00275   // Add enough integer lines to account for app name string size
00276   unsigned int stringLineLength = this->appNameLength()*sizeof(char)
00277     +sizeof(unsigned int) - 1;
00278   stringLineLength /= sizeof(unsigned int);
00279   return this->getValue(RecordFormat::FileName::appNameLine
00280                         +stringLineLength);
00281 }
00282 
00283 std::ostream& DayaBay::RawFileName::dump(std::ostream& str){
00284   // Print the record information
00285   str << "RawFileName {" << std::endl << "  ";
00286   this->RawRecord::dump(str);
00287   return str << "  appNameLength: " << this->appNameLength() << std::endl
00288              << "  appName: " << std::string(this->appName(),
00289                                              this->appNameLength()) << std::endl
00290              << "  fileNameLength: " << this->fileNameLength() << std::endl
00291              << "  fileName: " << std::string(this->fileName(),
00292                                               this->fileNameLength()) << " }" 
00293              << std::endl;
00294 }
00295 
00297 
00298 DayaBay::RawMetadata::RawMetadata(unsigned int* buffer/*=0*/,
00299                                   unsigned int version/*=0*/,
00300                                   bool isOwner/*=false*/)
00301   : RawRecord(buffer,version,isOwner)
00302 {
00303   // Default constructor
00304 }
00305 
00306 DayaBay::RawMetadata::RawMetadata(DayaBay::RawRecord& record,
00307                                   bool adopt/*=false*/)
00308   : RawRecord(record,adopt)
00309 {
00310   // Construct from another RawRecord
00311   // If adopt==true, then take over ownership of the 
00312   // memory buffer (if the input record is the current owner)
00313 }
00314 
00315 DayaBay::RawMetadata::~RawMetadata()
00316 {
00317   // Destructor
00318 }
00319 
00320 unsigned int DayaBay::RawMetadata::entries() const
00321 {
00322   return this->getValue(RecordFormat::Metadata::entriesLine);
00323 }
00324 
00325 char* DayaBay::RawMetadata::string(unsigned int index) const
00326 {
00327   if(index >= this->entries()) return 0;
00328   unsigned int currentLine = RecordFormat::Metadata::entriesLine + 1;
00329   for(unsigned int i = 0; i<index; i++){
00330     // add offset from each string
00331     unsigned int stringLength = this->getValue(currentLine)*sizeof(char);
00332     stringLength += (sizeof(unsigned int) / sizeof(char)) - 1;
00333     stringLength /= sizeof(unsigned int);
00334     currentLine += 1 + stringLength;
00335   }
00336   return this->getString(currentLine + 1);
00337 }
00338 
00339 unsigned int DayaBay::RawMetadata::stringLength(unsigned int index) const
00340 {
00341   if(index >= this->entries()) return 0;
00342   unsigned int currentLine = RecordFormat::Metadata::entriesLine + 1;
00343   for(unsigned int i = 0; i<index; i++){
00344     // add offset from each string
00345     unsigned int stringLength = this->getValue(currentLine)*sizeof(char);
00346     stringLength += (sizeof(unsigned int) / sizeof(char)) - 1;
00347     stringLength /= sizeof(unsigned int);
00348     currentLine += 1 + stringLength;
00349   }
00350   return this->getValue(currentLine);
00351 }
00352 
00353 std::ostream& DayaBay::RawMetadata::dump(std::ostream& str){
00354   // Print the record information
00355   str << "Metadata {" << std::endl << "  ";
00356   this->RawRecord::dump(str);
00357   str << "  entries: " << this->entries() << std::endl;
00358   for(unsigned int idx=0; idx < this->entries(); idx++){
00359     str << "  stringLength: " << this->stringLength(idx) << std::endl
00360         << "  string: " << std::string(this->string(idx),
00361                                        this->stringLength(idx)) << std::endl;
00362   }
00363   return str << "}" << std::endl;
00364 }
00365 
00367 
00368 
00369 DayaBay::RawRunParameters::RawRunParameters(unsigned int* buffer/*=0*/,
00370                                             unsigned int version/*=0*/,
00371                                             bool isOwner/*=false*/)
00372   : RawRecord(buffer,version,isOwner)
00373 {
00374   // Default constructor
00375 }
00376 
00377 DayaBay::RawRunParameters::RawRunParameters(DayaBay::RawRecord& record,
00378                                             bool adopt/*=false*/)
00379   : RawRecord(record,adopt)
00380 {
00381   // Construct from another RawRecord
00382   // If adopt==true, then take over ownership of the 
00383   // memory buffer (if the input record is the current owner)
00384 }
00385 
00386 DayaBay::RawRunParameters::~RawRunParameters()
00387 {
00388   // Destructor
00389 }
00390 
00391 unsigned int DayaBay::RawRunParameters::runNumber() const
00392 {
00393   return this->getValue(RecordFormat::RunParameters::runNumberLine);
00394 }
00395 
00396 unsigned int DayaBay::RawRunParameters::reconstructionEnabled() const
00397 {
00398   return this->getValue(RecordFormat::RunParameters::reconstructionEnabledLine);
00399 }
00400 
00401 unsigned int DayaBay::RawRunParameters::triggerType() const
00402 {
00403   return this->getValue(RecordFormat::RunParameters::triggerTypeLine);
00404 }
00405 
00406 unsigned int DayaBay::RawRunParameters::detectorMask() const
00407 {
00408   return this->getValue(RecordFormat::RunParameters::detectorMaskLine);
00409 }
00410 
00411 std::ostream& DayaBay::RawRunParameters::dump(std::ostream& str){
00412   // Print the record information
00413   str << "RunParameters {" << std::endl << "  ";
00414   this->RawRecord::dump(str);
00415   return str << "  runNumber: " << this->runNumber() << std::endl
00416              << "  reconstructionEnabled: " << this->reconstructionEnabled() 
00417              << std::endl
00418              << "  triggerType: " << this->triggerType() << std::endl
00419              << "  detectorMask: " << this->detectorMask() << " }" << std::endl;
00420 }
00421 
00423 
00424 
00425 DayaBay::RawCalibrationParameters::RawCalibrationParameters(
00426                                                      unsigned int* buffer/*=0*/,
00427                                                      unsigned int version/*=0*/,
00428                                                      bool isOwner/*=false*/)
00429   : RawRecord(buffer,version,isOwner)
00430 {
00431   // Default constructor
00432 }
00433 
00434 DayaBay::RawCalibrationParameters::RawCalibrationParameters(
00435                                                      DayaBay::RawRecord& record,
00436                                                      bool adopt/*=false*/)
00437   : RawRecord(record,adopt)
00438 {
00439   // Construct from another RawRecord
00440   // If adopt==true, then take over ownership of the 
00441   // memory buffer (if the input record is the current owner)
00442 }
00443 
00444 DayaBay::RawCalibrationParameters::~RawCalibrationParameters()
00445 {
00446   // Destructor
00447 }
00448 
00449 unsigned int DayaBay::RawCalibrationParameters::detectorId() const
00450 {
00451   return this->getValue(RecordFormat::CalibrationParameters::detectorIdLine);
00452 }
00453 
00454 unsigned int DayaBay::RawCalibrationParameters::axis() const
00455 {
00456   return this->getValue(RecordFormat::CalibrationParameters::axisLine);
00457 }
00458 
00459 unsigned int DayaBay::RawCalibrationParameters::sourceId() const
00460 {
00461   return this->getValue(RecordFormat::CalibrationParameters::sourceIdLine);
00462 }
00463 
00464 unsigned int DayaBay::RawCalibrationParameters::zPosition() const
00465 {
00466   return this->getValue(RecordFormat::CalibrationParameters::zPositionLine);
00467 }
00468 
00469 unsigned int DayaBay::RawCalibrationParameters::duration() const
00470 {
00471   return this->getValue(RecordFormat::CalibrationParameters::durationLine);
00472 }
00473 
00474 unsigned int DayaBay::RawCalibrationParameters::ledFrequency() const
00475 {
00476   return this->getValue(RecordFormat::CalibrationParameters::ledFrequencyLine);
00477 }
00478 
00479 unsigned int DayaBay::RawCalibrationParameters::ltbMode() const
00480 {
00481   return this->getValue(RecordFormat::CalibrationParameters::ltbModeLine);
00482 }
00483 
00484 std::ostream& DayaBay::RawCalibrationParameters::dump(std::ostream& str){
00485   // Print the record information
00486   str << "CalibrationParameters {" << std::endl << "  ";
00487   this->RawRecord::dump(str);
00488   return str << "  detectorId: " << this->detectorId() << std::endl
00489              << "  axis: " << this->axis() << std::endl
00490              << "  sourceId: " << this->sourceId() << std::endl
00491              << "  zPosition: " << this->zPosition() << " mm"<< std::endl
00492              << "  duration: " << this->duration() << std::endl
00493              << "  ledFrequency: " << this->ledFrequency() << std::endl
00494              << "  ltbMode: " << this->ltbMode() << " }" << std::endl;
00495 }
00496 
00498 
00499 DayaBay::RawDataSeparator::RawDataSeparator(unsigned int* buffer/*=0*/,
00500                                             unsigned int version/*=0*/,
00501                                             bool isOwner/*=false*/)
00502   : RawRecord(buffer,version,isOwner)
00503 {
00504   // Default constructor
00505 }
00506 
00507 DayaBay::RawDataSeparator::RawDataSeparator(DayaBay::RawRecord& record,
00508                                             bool adopt/*=false*/)
00509   : RawRecord(record,adopt)
00510 {
00511   // Construct from another RawRecord
00512   // If adopt==true, then take over ownership of the 
00513   // memory buffer (if the input record is the current owner)
00514 }
00515 
00516 DayaBay::RawDataSeparator::~RawDataSeparator()
00517 {
00518   // Destructor
00519 }
00520 
00521 unsigned int DayaBay::RawDataSeparator::blockNumber() const
00522 {
00523   return this->getValue(RecordFormat::DataSeparator::blockNumberLine);
00524 }
00525 
00526 unsigned int DayaBay::RawDataSeparator::blockSize() const
00527 {
00528   return this->getValue(RecordFormat::DataSeparator::blockSizeLine);
00529 }
00530 
00531 DayaBay::RawData* DayaBay::RawDataSeparator::data() const
00532 {
00533   return DayaBay::RawData::makeNewData(
00534                this->getPointer(RecordFormat::DataSeparator::dataLine));
00535 }
00536 
00537 std::ostream& DayaBay::RawDataSeparator::dump(std::ostream& str){
00538   // Print the record information
00539   str << "DataSeparator {" << std::endl << "  ";
00540   this->RawRecord::dump(str);
00541   return str << "  blockNumber: " << this->blockNumber() << std::endl
00542              << "  blockSize: " << this->blockSize() << " }" << std::endl;
00543 }
00544 
00546 
00547 
00548 DayaBay::RawFileEnd::RawFileEnd(unsigned int* buffer/*=0*/,
00549                                 unsigned int version/*=0*/,
00550                                 bool isOwner/*=false*/)
00551   : RawRecord(buffer,version,isOwner)
00552 {
00553   // Default constructor
00554 }
00555 
00556 DayaBay::RawFileEnd::RawFileEnd(DayaBay::RawRecord& record,
00557                                 bool adopt/*=false*/)
00558   : RawRecord(record,adopt)
00559 {
00560   // Construct from another RawRecord
00561   // If adopt==true, then take over ownership of the 
00562   // memory buffer (if the input record is the current owner)
00563 }
00564 
00565 DayaBay::RawFileEnd::~RawFileEnd()
00566 {
00567   // Destructor
00568 }
00569 
00570 unsigned int DayaBay::RawFileEnd::date() const
00571 {
00572   return this->getValue(RecordFormat::FileEnd::dateLine);
00573 }
00574 
00575 unsigned int DayaBay::RawFileEnd::time() const
00576 {
00577   return this->getValue(RecordFormat::FileEnd::timeLine);
00578 }
00579 
00580 unsigned int DayaBay::RawFileEnd::eventsInFile() const
00581 {
00582   return this->getValue(RecordFormat::FileEnd::eventsInFileLine);
00583 }
00584 
00585 unsigned int DayaBay::RawFileEnd::dataInFile() const
00586 {
00587   return this->getValue(RecordFormat::FileEnd::dataInFileLine);
00588 }
00589 
00590 unsigned int DayaBay::RawFileEnd::eventsInRun() const
00591 {
00592   return this->getValue(RecordFormat::FileEnd::eventsInRunLine);
00593 }
00594 
00595 unsigned int DayaBay::RawFileEnd::dataInRun() const
00596 {
00597   return this->getValue(RecordFormat::FileEnd::dataInRunLine);
00598 }
00599 
00600 unsigned int DayaBay::RawFileEnd::status() const
00601 {
00602   return this->getValue(RecordFormat::FileEnd::statusLine);
00603 }
00604 
00605 unsigned int DayaBay::RawFileEnd::end() const
00606 {
00607   return this->getValue(RecordFormat::FileEnd::endLine);
00608 }
00609 
00610 std::ostream& DayaBay::RawFileEnd::dump(std::ostream& str){
00611   // Print the record information
00612   str << "FileEnd {" << std::endl << "  ";
00613   this->RawRecord::dump(str);
00614   return str << "  date: " << this->date() << std::endl
00615              << "  time: " << this->time() << std::endl
00616              << "  eventsInFile: " << this->eventsInFile() << std::endl
00617              << "  dataInFile: " << this->dataInFile() << std::endl
00618              << "  eventsInRun: " << this->eventsInRun() << std::endl
00619              << "  dataInRun: " << this->dataInRun() << std::endl
00620              << "  status: " << this->status() << std::endl
00621              << "  end: " << std::hex << this->end() << std::dec << " }" 
00622              << std::endl;
00623 }
00624 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:07:27 2011 for RawData by doxygen 1.4.7