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