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