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 
17 
18 #include "boost/shared_array.hpp"
19 
20 class FRDEventMsgView;
21 template <class Consumer>
23 {
24  typedef unsigned int uint32;
32  public:
33  explicit RawEventOutputModuleForBU(edm::ParameterSet const& ps);
35 
36  private:
37  virtual void write(edm::EventPrincipal const& e, edm::ModuleCallingContext const*);
38  virtual void beginRun(edm::RunPrincipal const&, edm::ModuleCallingContext const*);
39  virtual void endRun(edm::RunPrincipal const&, edm::ModuleCallingContext const*);
40  virtual void writeRun(const edm::RunPrincipal&, edm::ModuleCallingContext const*){}
42 
45 
46  std::auto_ptr<Consumer> templateConsumer_;
49  unsigned int numEventsPerFile_;
50  unsigned int frdVersion_;
51  unsigned long long totsize;
52  unsigned long long writtensize;
53  unsigned long long writtenSizeLast;
54  unsigned int totevents;
55  unsigned int index_;
56  timeval startOfLastLumi;
57  bool firstLumi_;
58 };
59 
60 template <class Consumer>
62  edm::OutputModule(ps),
63  templateConsumer_(new Consumer(ps)),
64  label_(ps.getUntrackedParameter<std::string>("ProductLabel","source")),
65  instance_(ps.getUntrackedParameter<std::string>("ProductInstance","")),
66  numEventsPerFile_(ps.getUntrackedParameter<unsigned int>("numEventsPerFile",100)),
67  frdVersion_(ps.getUntrackedParameter<unsigned int>("frdVersion",3)),
68  totsize(0LL),
69  writtensize(0LL),
70  writtenSizeLast(0LL),
71  totevents(0),
72  index_(0),
73  firstLumi_(true)
74 {
75 }
76 
77 template <class Consumer>
79 
80 template <class Consumer>
82 {
83  unsigned int ls = e.luminosityBlock();
84  if(totevents>0 && totevents%numEventsPerFile_==0){
85  index_++;
86  std::string filename = edm::Service<evf::EvFDaqDirector>()->getOpenRawFilePath( ls,index_);
87  std::string destinationDir = edm::Service<evf::EvFDaqDirector>()->buBaseRunDir();
88  templateConsumer_->initialize(destinationDir,filename,ls);
89  }
90  totevents++;
91  // serialize the FEDRawDataCollection into the format that we expect for
92  // FRDEventMsgView objects (may be better ways to do this)
93  edm::Event event(const_cast<edm::EventPrincipal&>(e), description(),mcc);
95  event.getByLabel(label_, instance_, fedBuffers);
96 
97  // determine the expected size of the FRDEvent IN BYTES !!!!!
98  int headerSize = frdVersion_<3 ? (4+1024)*sizeof(uint32) : 7*sizeof(uint32);
99  int expectedSize = headerSize;
100 
101  for (int idx = 0; idx < 1024; ++idx) {
102  FEDRawData singleFED = fedBuffers->FEDData(idx);
103  expectedSize += singleFED.size();
104  }
105 
106  totsize += expectedSize;
107  // build the FRDEvent into a temporary buffer
108  boost::shared_array<unsigned char> workBuffer(new unsigned char[expectedSize + 256]);
109  uint32 *bufPtr = (uint32*) workBuffer.get();
110  *bufPtr++ = (uint32) frdVersion_; // version number
111  *bufPtr++ = (uint32) event.id().run();
112  *bufPtr++ = (uint32) event.luminosityBlock();
113  *bufPtr++ = (uint32) event.id().event();
114 
115  if (frdVersion_<3) {
116  uint32 fedsize[1024];
117  for (int idx = 0; idx < 1024; ++idx) {
118  FEDRawData singleFED = fedBuffers->FEDData(idx);
119  fedsize[idx] = singleFED.size();
120  //std::cout << "fed size " << singleFED.size()<< std::endl;
121  }
122  memcpy(bufPtr,fedsize,1024 * sizeof(uint32));
123  bufPtr += 1024;
124  }
125  else {
126  *bufPtr++ = expectedSize-headerSize;
127  *bufPtr++ = 0;
128  *bufPtr++ = 0;
129  }
130  uint32 *payloadPtr=bufPtr;
131  for (int idx = 0; idx < 1024; ++idx) {
132  FEDRawData singleFED = fedBuffers->FEDData(idx);
133  if (singleFED.size() > 0) {
134  memcpy(bufPtr, singleFED.data(), singleFED.size());
135  bufPtr += singleFED.size()/4;
136  }
137  }
138  if (frdVersion_>=3) {
139  //adler32 checksum
140  uint32 adlera = 1;
141  uint32 adlerb = 0;
142  cms::Adler32((const char*) payloadPtr, expectedSize-7*sizeof(uint32), adlera, adlerb);
143  *(payloadPtr-1) = (adlerb << 16) | adlera;
144  }
145 
146  // create the FRDEventMsgView and use the template consumer to write it out
147  FRDEventMsgView msg(workBuffer.get());
148  writtensize+=msg.size();
149 
150  if (templateConsumer_->sharedMode())
151  templateConsumer_->doOutputEvent(workBuffer);
152  else
153  templateConsumer_->doOutputEvent(msg);
154 }
155 
156 template <class Consumer>
158 {
159  // edm::Service<evf::EvFDaqDirector>()->updateBuLock(1);
160  templateConsumer_->start();
161 }
162 
163 template <class Consumer>
165 {
166  templateConsumer_->stop();
167 }
168 
169 template <class Consumer>
171  index_ = 0;
172  std::string filename = edm::Service<evf::EvFDaqDirector>()->getOpenRawFilePath( ls.id().luminosityBlock(),index_);
173  std::string destinationDir = edm::Service<evf::EvFDaqDirector>()->buBaseRunDir();
174  std::cout << " writing to destination dir " << destinationDir << " name: " << filename << std::endl;
175  templateConsumer_->initialize(destinationDir,filename,ls.id().luminosityBlock());
176  //edm::Service<evf::EvFDaqDirector>()->updateBuLock(ls.id().luminosityBlock()+1);
177  if(!firstLumi_){
178  timeval now;
179  ::gettimeofday(&now,0);
180  //long long elapsedusec = (now.tv_sec - startOfLastLumi.tv_sec)*1000000+now.tv_usec-startOfLastLumi.tv_usec;
181 /* std::cout << "(now.tv_sec - startOfLastLumi.tv_sec) " << now.tv_sec <<"-" << startOfLastLumi.tv_sec */
182 /* <<" (now.tv_usec-startOfLastLumi.tv_usec) " << now.tv_usec << "-" << startOfLastLumi.tv_usec << std::endl; */
183 /* std::cout << "elapsedusec " << elapsedusec << " totevents " << totevents << " size (GB)" << writtensize */
184 /* << " rate " << (writtensize-writtenSizeLast)/elapsedusec << " MB/s" <<std::endl; */
185  writtenSizeLast=writtensize;
186  ::gettimeofday(&startOfLastLumi,0);
187  //edm::Service<evf::EvFDaqDirector>()->writeLsStatisticsBU(ls.id().luminosityBlock(), totevents, totsize, elapsedusec);
188  }
189  else
190  ::gettimeofday(&startOfLastLumi,0);
191  totevents = 0;
192  totsize = 0LL;
193  firstLumi_ = false;
194 }
195 template <class Consumer>
197 
198  // templateConsumer_->touchlock(ls.id().luminosityBlock(),basedir);
199  templateConsumer_->endOfLS(ls.id().luminosityBlock());
200 }
201 #endif
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
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 *)
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
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
tuple cout
Definition: gather_cfg.py:121
std::auto_ptr< Consumer > templateConsumer_