CMS 3D CMS Logo

StreamerFileWriter.cc

Go to the documentation of this file.
00001 // $Id: StreamerFileWriter.cc,v 1.17 2007/11/07 06:51:52 wmtan Exp $
00002 
00003 #include "IOPool/Streamer/src/StreamerFileWriter.h"
00004 
00005 namespace edm
00006 {
00007 StreamerFileWriter::StreamerFileWriter(edm::ParameterSet const& ps):
00008   stream_writer_(new StreamerOutputFile(
00009                     ps.getUntrackedParameter<std::string>("fileName","teststreamfile.dat"))),
00010   index_writer_(new StreamerOutputIndexFile(
00011                     ps.getUntrackedParameter<std::string>("indexFileName","testindexfile.ind"))),
00012   hltCount_(0),
00013   index_eof_size_(0),
00014   stream_eof_size_(0)
00015   {
00016   }
00017 
00018 
00019 StreamerFileWriter::StreamerFileWriter(std::string const& fileName, std::string const& indexFileName):
00020   stream_writer_(new StreamerOutputFile(fileName)),
00021   index_writer_(new StreamerOutputIndexFile(indexFileName)),
00022   hltCount_(0),
00023   index_eof_size_(0),
00024   stream_eof_size_(0)
00025   {
00026   }
00027 
00028 
00029 StreamerFileWriter::~StreamerFileWriter()
00030   {
00031   }
00032 
00033 void StreamerFileWriter::stop() 
00034   {
00035 
00036     // User code of this class MUST call method
00037 
00038     //Write the EOF Record Both at the end of Streamer file and Index file
00039     uint32 dummyStatusCode = 1234;
00040     
00041     index_eof_size_ = index_writer_->writeEOF(dummyStatusCode, hltStats_);
00042     stream_eof_size_ = stream_writer_->writeEOF(dummyStatusCode, hltStats_);
00043     
00044   }
00045 
00046 void StreamerFileWriter::doOutputHeader(InitMsgBuilder const& init_message)
00047   {
00048 
00049     //Let us turn it into a View
00050     InitMsgView view(init_message.startAddress());
00051     doOutputHeader(view);
00052 
00053   }
00054 void StreamerFileWriter::doOutputHeader(InitMsgView const& init_message)
00055   {
00056 
00057     //Write the Init Message to Streamer file
00058     stream_writer_->write(init_message);
00059 
00060     uint32 magic = 22;
00061     uint64 reserved = 666;
00062     index_writer_->writeIndexFileHeader(magic, reserved);
00063     index_writer_->write(init_message);
00064 
00065     //HLT Count
00066     hltCount_ = init_message.get_hlt_bit_cnt();
00067 
00068     //Initialize the HLT Stat vector with all ZEROs
00069     for(uint32 i = 0; i != hltCount_; ++i)
00070        hltStats_.push_back(0);
00071   }
00072 
00073 
00074 void StreamerFileWriter::doOutputEvent(EventMsgView const& msg)
00075   {
00076     //Write the Event Message to Streamer file
00077     uint64 event_offset = stream_writer_->write(msg);
00078     
00079     index_writer_->write(msg, event_offset);
00080     
00081     // Lets update HLT Stat, know how many 
00082     // Events for which Trigger are being written
00083     
00084     //get the HLT Packed bytes
00085     std::vector<uint8> packedHlt;
00086     uint32 hlt_sz = 0;
00087     if (hltCount_ != 0) hlt_sz = 1 + ((hltCount_-1)/4); 
00088     packedHlt.resize(hlt_sz);
00089     msg.hltTriggerBits(&packedHlt[0]);
00090     updateHLTStats(packedHlt); 
00091   }
00092 
00093 
00094 void StreamerFileWriter::doOutputEvent(EventMsgBuilder const& msg)
00095   {
00096 
00097     EventMsgView eview(msg.startAddress());
00098     doOutputEvent(eview);
00099  
00100   }
00101 
00102 
00103 void StreamerFileWriter::updateHLTStats(std::vector<uint8> const& packedHlt)
00104    {
00105     unsigned int packInOneByte = 4;
00106     unsigned char testAgaint = 0x01;
00107     for(unsigned int i = 0; i != hltCount_; ++i)
00108     {
00109        unsigned int whichByte = i/packInOneByte;
00110        unsigned int indxWithinByte = i % packInOneByte;
00111        if ((testAgaint << (2 * indxWithinByte)) & (packedHlt.at(whichByte))) {
00112            ++hltStats_[i];
00113        }
00114        //else  std::cout <<"Bit "<<i<<" is not set"<< std::endl;
00115     }
00116    }
00117 } //namespace edm
00118 
00119 
00120 

Generated on Tue Jun 9 17:39:18 2009 for CMSSW by  doxygen 1.5.4