CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StreamerFileWriter.cc
Go to the documentation of this file.
3 
4 namespace edm {
6  stream_writer_(new StreamerOutputFile(
7  ps.getUntrackedParameter<std::string>("fileName"))),
8  hltCount_(0),
9  stream_eof_size_(0) {
10  }
11 
13  stream_writer_(new StreamerOutputFile(fileName)),
14  hltCount_(0),
15  stream_eof_size_(0) {
16  }
17 
19  }
20 
22  // User code of this class MUST call method
23 
24  //Write the EOF Record Both at the end of Streamer file
25  uint32 const dummyStatusCode = 1234;
26 
27  stream_eof_size_ = stream_writer_->writeEOF(dummyStatusCode, hltStats_);
28  }
29 
31  //Let us turn it into a View
32  InitMsgView view(init_message.startAddress());
33  doOutputHeader(view);
34  }
35 
36  void StreamerFileWriter::doOutputHeader(InitMsgView const& init_message) {
37  //Write the Init Message to Streamer file
38  stream_writer_->write(init_message);
39 
40  //HLT Count
41  hltCount_ = init_message.get_hlt_bit_cnt();
42 
43  //Initialize the HLT Stat vector with all ZEROs
44  for(uint32 i = 0; i != hltCount_; ++i) {
45  hltStats_.push_back(0);
46  }
47  }
48 
50  //Write the Init Message to Streamer file
51  stream_writer_->writeInitFragment(hdrParams.fragmentIndex,
52  hdrParams.fragmentCount,
53  hdrParams.dataPtr,
54  hdrParams.dataSize);
55  if (hdrParams.fragmentIndex == 0) {
56  //HLT Count
57  hltCount_ = hdrParams.hltCount;
58 
59  //Initialize the HLT Stat vector with all ZEROs
60  for(uint32 i = 0; i != hltCount_; ++i) {
61  hltStats_.push_back(0);
62  }
63  }
64  }
65 
67  //Write the Event Message to Streamer file
68  stream_writer_->write(msg);
69 
70  // Lets update HLT Stat, know how many
71  // Events for which Trigger are being written
72 
73  //get the HLT Packed bytes
74  std::vector<uint8> packedHlt;
75  uint32 const hlt_sz = (hltCount_ != 0 ? 1 + ((hltCount_ - 1) / 4) : 0);
76  packedHlt.resize(hlt_sz);
77  msg.hltTriggerBits(&packedHlt[0]);
78  updateHLTStats(packedHlt);
79  }
80 
82  EventMsgView eview(msg.startAddress());
83  doOutputEvent(eview);
84  }
85 
87  //Write the Event Message to Streamer file
88  stream_writer_->writeEventFragment(evtParams.fragmentIndex,
89  evtParams.fragmentCount,
90  evtParams.dataPtr,
91  evtParams.dataSize);
92  if (evtParams.fragmentIndex == 0) {
93  // Lets update HLT Stat, know how many
94  // Events for which Trigger are being written
95  updateHLTStats(evtParams.hltBits);
96  }
97  }
98 
99  void StreamerFileWriter::updateHLTStats(std::vector<uint8> const& packedHlt) {
100  unsigned int const packInOneByte = 4;
101  unsigned char const testAgaint = 0x01;
102  for(unsigned int i = 0; i != hltCount_; ++i) {
103  unsigned int const whichByte = i/packInOneByte;
104  unsigned int const indxWithinByte = i % packInOneByte;
105  if ((testAgaint << (2 * indxWithinByte)) & (packedHlt.at(whichByte))) {
106  ++hltStats_[i];
107  }
108  //else std::cout <<"Bit "<<i<<" is not set"<< std::endl;
109  }
110  }
111 
113  desc.setComment("Writes events into a streamer output file.");
114  desc.addUntracked<std::string>("fileName", "teststreamfile.dat")->setComment("Name of output file.");
115  }
116 } //namespace edm
int i
Definition: DBlmapReader.cc:9
std::vector< unsigned char > hltBits
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void hltTriggerBits(uint8 *put_here) const
void doOutputHeaderFragment(StreamerFileWriterHeaderParams const &)
uint8 * startAddress() const
std::vector< uint32 > hltStats_
StreamerFileWriter(edm::ParameterSet const &ps)
void setComment(std::string const &value)
void doOutputHeader(InitMsgBuilder const &init_message)
unsigned int uint32
Definition: MsgTools.h:13
static void fillDescription(ParameterSetDescription &desc)
uint32 get_hlt_bit_cnt() const
Definition: InitMessage.h:82
uint8 * startAddress() const
void doOutputEvent(EventMsgBuilder const &msg)
void doOutputEventFragment(StreamerFileWriterEventParams const &)
void updateHLTStats(std::vector< uint8 > const &packedHlt)
std::auto_ptr< StreamerOutputFile > stream_writer_