CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/IOPool/Streamer/src/StreamerOutputFile.cc

Go to the documentation of this file.
00001 #include "IOPool/Streamer/interface/StreamerOutputFile.h"
00002 #include "IOPool/Streamer/interface/EOFRecordBuilder.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 
00005   StreamerOutputFile::~StreamerOutputFile() {
00006   }
00007 
00008   StreamerOutputFile::StreamerOutputFile(const std::string& name):
00009   streamerfile_(new OutputFile(name))
00010   {
00011     streamerfile_->set_do_adler(1);
00012   }
00013 
00014   uint64 StreamerOutputFile::write(const EventMsgBuilder& ineview)
00015   {
00016     EventMsgView tmpView(ineview.startAddress());
00017     return write(tmpView);
00018   }
00019 
00020   uint64 StreamerOutputFile::write(const EventMsgView& ineview)
00021   {
00023     uint64 offset_to_return = streamerfile_->current_offset();
00024 
00026     streamerfile_->set_last_event_offset(streamerfile_->current_offset());
00027 
00028     writeEventHeader(ineview);
00029     bool ret = streamerfile_->write((const char*) ineview.eventData(),
00030                                     ineview.size() - ineview.headerSize());
00031     if (ret) {
00032       throw cms::Exception("OutputFile", "write(EventMsgView)")
00033         << "Error writing streamer event data to "
00034         << streamerfile_->fileName() << ".  Possibly the output disk "
00035         << "is full?" << std::endl;
00036     }
00037 
00038     streamerfile_->inc_events();
00039 
00040     return offset_to_return;
00041   }
00042 
00043   uint64 StreamerOutputFile::
00044   writeEventFragment(uint32 fragIndex, uint32 fragCount,
00045                      const char *dataPtr, uint32 dataSize)
00046   {
00048     uint64 offset_to_return = streamerfile_->current_offset();
00049 
00050     if (fragIndex == 0) {
00052       streamerfile_->set_last_event_offset(streamerfile_->current_offset());
00053     }
00054 
00055     bool ret = streamerfile_->write(dataPtr, dataSize);
00056     if (ret) {
00057       throw cms::Exception("OutputFile", "writeEventFragment()")
00058         << "Error writing streamer event data to "
00059         << streamerfile_->fileName() << ".  Possibly the output disk "
00060         << "is full?" << std::endl;
00061     }
00062 
00063     if (fragIndex == fragCount-1) {streamerfile_->inc_events();}
00064 
00065     return offset_to_return;
00066   }
00067 
00068   void StreamerOutputFile::writeEventHeader(const EventMsgView& ineview)
00069   {
00070     bool ret = streamerfile_->write((const char*)
00071                                     ineview.startAddress(),
00072                                     ineview.headerSize()) ;
00073     if (ret) {
00074       throw cms::Exception("OutputFile", "writeEventHeader")
00075         << "Error writing streamer event data to "
00076         << streamerfile_->fileName() << ".  Possibly the output disk "
00077         << "is full?" << std::endl;
00078     }
00079   }
00080 
00081   void StreamerOutputFile::write(const InitMsgBuilder& inview)
00082   {
00083     InitMsgView tmpView(inview.startAddress());
00084     return write(tmpView);
00085   }
00086 
00087   void StreamerOutputFile::write(const InitMsgView& inview)
00088   {
00089     writeStart(inview);
00090     bool ret = streamerfile_->write((const char*) inview.descData(),
00091                                     inview.size() - inview.headerSize());
00092     if (ret) {
00093       throw cms::Exception("OutputFile", "write(InitMsgView)")
00094         << "Error writing streamer header data to "
00095         << streamerfile_->fileName() << ".  Possibly the output disk "
00096         << "is full?" << std::endl;
00097     }
00098 
00100     streamerfile_->set_first_event_offset(streamerfile_->current_offset());
00101   }
00102 
00103   void StreamerOutputFile::
00104   writeInitFragment(uint32 fragIndex, uint32 fragCount,
00105                     const char *dataPtr, uint32 dataSize)
00106   {
00107     bool ret = streamerfile_->write((const char*) dataPtr, dataSize);
00108     if (ret) {
00109       throw cms::Exception("OutputFile", "writeInitFragment()")
00110         << "Error writing streamer header data to "
00111         << streamerfile_->fileName() << ".  Possibly the output disk "
00112         << "is full?" << std::endl;
00113     }
00114 
00115     if (fragIndex == fragCount-1) {
00117       streamerfile_->set_first_event_offset(streamerfile_->current_offset());
00118     }
00119   }
00120 
00121   void StreamerOutputFile::writeStart(const InitMsgView& inview)
00122   {
00123     bool ret = streamerfile_->write((const char*)
00124                                     inview.startAddress(),
00125                                     inview.headerSize()) ;
00126     if (ret) {
00127       throw cms::Exception("OutputFile", "writeStart")
00128         << "Error writing streamer header data to "
00129         << streamerfile_->fileName() << ".  Possibly the output disk "
00130         << "is full?" << std::endl;
00131     }
00132     streamerfile_->set_run(inview.run()); 
00133   }
00134  
00135   uint32 StreamerOutputFile::writeEOF(uint32 statusCode, 
00136                                       const std::vector<uint32>& hltStats) 
00137   {
00138     EOFRecordBuilder eof(streamerfile_->run(), 
00139                          streamerfile_->events(),
00140                          statusCode,
00141                          hltStats,
00142                          streamerfile_->first_event_offset(),
00143                          streamerfile_->last_event_offset());
00144 
00145     bool ret = streamerfile_->write((const char*) 
00146                                     eof.recAddress(), 
00147                                     eof.size());  
00148     if (ret) {
00149       throw cms::Exception("OutputFile", "writeEOF")
00150         << "Error writing streamer end-of-file to "
00151         << streamerfile_->fileName() << ".  Possibly the output disk "
00152         << "is full?" << std::endl;
00153     }
00154     return eof.size();  
00155   }