CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RawEventOutputModuleForBU.h
Go to the documentation of this file.
1 #ifndef IOPool_Streamer_RawEventOutputModuleForBU_h
2 #define IOPool_Streamer_RawEventOutputModuleForBU_h
3 
12 
13 #include "EvFDaqDirector.h"
14 #include "EvFBuildingThrottle.h"
15 
16 #include "boost/shared_array.hpp"
17 
18 class FRDEventMsgView;
19 template <class Consumer>
21 {
22  typedef unsigned int uint32;
30  public:
31  explicit RawEventOutputModuleForBU(edm::ParameterSet const& ps);
33 
34  private:
35  virtual void write(edm::EventPrincipal const& e, edm::ModuleCallingContext const*);
36  virtual void beginRun(edm::RunPrincipal const&, edm::ModuleCallingContext const*);
37  virtual void endRun(edm::RunPrincipal const&, edm::ModuleCallingContext const*);
38  virtual void writeRun(const edm::RunPrincipal&, edm::ModuleCallingContext const*){}
40 
43 
44  std::auto_ptr<Consumer> templateConsumer_;
47  unsigned int numEventsPerFile_;
48  unsigned long long totsize;
49  unsigned long long writtensize;
50  unsigned long long writtenSizeLast;
51  unsigned int totevents;
52  unsigned int index_;
53  timeval startOfLastLumi;
54  bool firstLumi_;
55 };
56 
57 template <class Consumer>
59  edm::OutputModule(ps),
60  templateConsumer_(new Consumer(ps)),
61  label_(ps.getUntrackedParameter<std::string>("ProductLabel","source")),
62  instance_(ps.getUntrackedParameter<std::string>("ProductInstance","")),
63  numEventsPerFile_(ps.getUntrackedParameter<unsigned int>("numEventsPerFile",100)),
64  totsize(0LL),
65  writtensize(0LL),
66  writtenSizeLast(0LL),
67  totevents(0),
68  index_(0),
69  firstLumi_(true)
70 {
71 }
72 
73 template <class Consumer>
75 
76 template <class Consumer>
78 {
79  unsigned int ls = e.luminosityBlock();
80  if(totevents>0 && totevents%numEventsPerFile_==0){
81  index_++;
82  std::string filename = edm::Service<evf::EvFDaqDirector>()->getOpenRawFilePath( ls,index_);
83  std::string destinationDir = edm::Service<evf::EvFDaqDirector>()->buBaseDir();
84  templateConsumer_->initialize(destinationDir,filename,ls);
85  }
86  totevents++;
87  // serialize the FEDRawDataCollection into the format that we expect for
88  // FRDEventMsgView objects (may be better ways to do this)
89  edm::Event event(const_cast<edm::EventPrincipal&>(e), description(),mcc);
91  event.getByLabel(label_, instance_, fedBuffers);
92 
93  // determine the expected size of the FRDEvent IN BYTES !!!!!
94  int expectedSize = (4 + 1024) * sizeof(uint32);
95  for (int idx = 0; idx < 1024; ++idx) {
96  FEDRawData singleFED = fedBuffers->FEDData(idx);
97  expectedSize += singleFED.size();
98  //if (singleFED.size() > 0) {
99  // std::cout << "FED #" << idx << " size = " << singleFED.size() << std::endl;
100  //}
101  }
102  totsize += expectedSize;
103  // build the FRDEvent into a temporary buffer
104  boost::shared_array<unsigned char> workBuffer(new unsigned char[expectedSize + 256]);
105  uint32 *bufPtr = (uint32*) workBuffer.get();
106  *bufPtr++ = (uint32) 2; // version number
107  *bufPtr++ = (uint32) event.id().run();
108  *bufPtr++ = (uint32) event.luminosityBlock();
109  *bufPtr++ = (uint32) event.id().event();
110  uint32 fedsize[1024];
111  for (int idx = 0; idx < 1024; ++idx) {
112  FEDRawData singleFED = fedBuffers->FEDData(idx);
113  fedsize[idx] = singleFED.size();
114  }
115  memcpy(bufPtr,fedsize,1024 * sizeof(uint32));
116  bufPtr += 1024;
117  for (int idx = 0; idx < 1024; ++idx) {
118  FEDRawData singleFED = fedBuffers->FEDData(idx);
119  if (singleFED.size() > 0) {
120  memcpy(bufPtr, singleFED.data(), singleFED.size());
121  bufPtr += singleFED.size()/4;
122  }
123  }
124 
125  // create the FRDEventMsgView and use the template consumer to write it out
126  FRDEventMsgView msg(workBuffer.get());
127  writtensize+=msg.size();
128 
129  if (templateConsumer_->sharedMode())
130  templateConsumer_->doOutputEvent(workBuffer);
131  else
132  templateConsumer_->doOutputEvent(msg);
133 }
134 
135 template <class Consumer>
137 {
138  edm::Service<evf::EvFDaqDirector>()->updateBuLock(1);
139  templateConsumer_->start();
140 }
141 
142 template <class Consumer>
144 {
145  templateConsumer_->stop();
146 }
147 
148 template <class Consumer>
150  index_ = 0;
151  std::string filename = edm::Service<evf::EvFDaqDirector>()->getOpenRawFilePath( ls.id().luminosityBlock(),index_);
152  std::string destinationDir = edm::Service<evf::EvFDaqDirector>()->buBaseDir();
153  templateConsumer_->initialize(destinationDir,filename,ls.id().luminosityBlock());
154  edm::Service<evf::EvFDaqDirector>()->updateBuLock(ls.id().luminosityBlock()+1);
155  if(!firstLumi_){
156  timeval now;
157  ::gettimeofday(&now,0);
158  long long elapsedusec = (now.tv_sec - startOfLastLumi.tv_sec)*1000000+now.tv_usec-startOfLastLumi.tv_usec;
159 /* std::cout << "(now.tv_sec - startOfLastLumi.tv_sec) " << now.tv_sec <<"-" << startOfLastLumi.tv_sec */
160 /* <<" (now.tv_usec-startOfLastLumi.tv_usec) " << now.tv_usec << "-" << startOfLastLumi.tv_usec << std::endl; */
161 /* std::cout << "elapsedusec " << elapsedusec << " totevents " << totevents << " size (GB)" << writtensize */
162 /* << " rate " << (writtensize-writtenSizeLast)/elapsedusec << " MB/s" <<std::endl; */
163  writtenSizeLast=writtensize;
164  ::gettimeofday(&startOfLastLumi,0);
165  edm::Service<evf::EvFDaqDirector>()->writeLsStatisticsBU(ls.id().luminosityBlock(), totevents, totsize, elapsedusec);
166  }
167  else
168  ::gettimeofday(&startOfLastLumi,0);
169  totevents = 0;
170  totsize = 0LL;
171  firstLumi_ = false;
172 }
173 template <class Consumer>
175 
176  // templateConsumer_->touchlock(ls.id().luminosityBlock(),basedir);
177  templateConsumer_->endOfLS(ls.id().luminosityBlock());
178 }
179 #endif
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
virtual void beginRun(edm::RunPrincipal const &, edm::ModuleCallingContext const *)
virtual void write(edm::EventPrincipal const &e, edm::ModuleCallingContext const *)
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
LuminosityBlockNumber_t luminosityBlock() const
RawEventOutputModuleForBU(edm::ParameterSet const &ps)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
virtual void writeLuminosityBlock(const edm::LuminosityBlockPrincipal &, edm::ModuleCallingContext const *)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void beginLuminosityBlock(edm::LuminosityBlockPrincipal const &, edm::ModuleCallingContext const *)
unsigned int uint32
Definition: MsgTools.h:13
virtual void endLuminosityBlock(edm::LuminosityBlockPrincipal const &, edm::ModuleCallingContext const *)
tuple description
Definition: idDealer.py:66
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
LuminosityBlockNumber_t luminosityBlock() const
virtual void endRun(edm::RunPrincipal const &, edm::ModuleCallingContext const *)
virtual void writeRun(const edm::RunPrincipal &, edm::ModuleCallingContext const *)
edm::EventID id() const
Definition: EventBase.h:56
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
tuple filename
Definition: lut2db_cfg.py:20
std::auto_ptr< Consumer > templateConsumer_