Go to the documentation of this file.00001 #include "IOPool/Streamer/src/StreamerFileWriter.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00003
00004 namespace edm {
00005 StreamerFileWriter::StreamerFileWriter(edm::ParameterSet const& ps) :
00006 stream_writer_(new StreamerOutputFile(
00007 ps.getUntrackedParameter<std::string>("fileName"))),
00008 hltCount_(0),
00009 stream_eof_size_(0) {
00010 }
00011
00012 StreamerFileWriter::StreamerFileWriter(std::string const& fileName) :
00013 stream_writer_(new StreamerOutputFile(fileName)),
00014 hltCount_(0),
00015 stream_eof_size_(0) {
00016 }
00017
00018 StreamerFileWriter::~StreamerFileWriter() {
00019 }
00020
00021 void StreamerFileWriter::stop() {
00022
00023
00024
00025 uint32 const dummyStatusCode = 1234;
00026
00027 stream_eof_size_ = stream_writer_->writeEOF(dummyStatusCode, hltStats_);
00028 }
00029
00030 void StreamerFileWriter::doOutputHeader(InitMsgBuilder const& init_message) {
00031
00032 InitMsgView view(init_message.startAddress());
00033 doOutputHeader(view);
00034 }
00035
00036 void StreamerFileWriter::doOutputHeader(InitMsgView const& init_message) {
00037
00038 stream_writer_->write(init_message);
00039
00040
00041 hltCount_ = init_message.get_hlt_bit_cnt();
00042
00043
00044 for(uint32 i = 0; i != hltCount_; ++i) {
00045 hltStats_.push_back(0);
00046 }
00047 }
00048
00049 void StreamerFileWriter::doOutputHeaderFragment(StreamerFileWriterHeaderParams const& hdrParams) {
00050
00051 stream_writer_->writeInitFragment(hdrParams.fragmentIndex,
00052 hdrParams.fragmentCount,
00053 hdrParams.dataPtr,
00054 hdrParams.dataSize);
00055 if (hdrParams.fragmentIndex == 0) {
00056
00057 hltCount_ = hdrParams.hltCount;
00058
00059
00060 for(uint32 i = 0; i != hltCount_; ++i) {
00061 hltStats_.push_back(0);
00062 }
00063 }
00064 }
00065
00066 void StreamerFileWriter::doOutputEvent(EventMsgView const& msg) {
00067
00068 stream_writer_->write(msg);
00069
00070
00071
00072
00073
00074 std::vector<uint8> packedHlt;
00075 uint32 const hlt_sz = (hltCount_ != 0 ? 1 + ((hltCount_ - 1) / 4) : 0);
00076 packedHlt.resize(hlt_sz);
00077 msg.hltTriggerBits(&packedHlt[0]);
00078 updateHLTStats(packedHlt);
00079 }
00080
00081 void StreamerFileWriter::doOutputEvent(EventMsgBuilder const& msg) {
00082 EventMsgView eview(msg.startAddress());
00083 doOutputEvent(eview);
00084 }
00085
00086 void StreamerFileWriter::doOutputEventFragment(StreamerFileWriterEventParams const& evtParams) {
00087
00088 stream_writer_->writeEventFragment(evtParams.fragmentIndex,
00089 evtParams.fragmentCount,
00090 evtParams.dataPtr,
00091 evtParams.dataSize);
00092 if (evtParams.fragmentIndex == 0) {
00093
00094
00095 updateHLTStats(evtParams.hltBits);
00096 }
00097 }
00098
00099 void StreamerFileWriter::updateHLTStats(std::vector<uint8> const& packedHlt) {
00100 unsigned int const packInOneByte = 4;
00101 unsigned char const testAgaint = 0x01;
00102 for(unsigned int i = 0; i != hltCount_; ++i) {
00103 unsigned int const whichByte = i/packInOneByte;
00104 unsigned int const indxWithinByte = i % packInOneByte;
00105 if ((testAgaint << (2 * indxWithinByte)) & (packedHlt.at(whichByte))) {
00106 ++hltStats_[i];
00107 }
00108
00109 }
00110 }
00111
00112 void StreamerFileWriter::fillDescription(ParameterSetDescription& desc) {
00113 desc.setComment("Writes events into a streamer output file.");
00114 desc.addUntracked<std::string>("fileName", "teststreamfile.dat")->setComment("Name of output file.");
00115 }
00116 }