CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FRDEventOutputModule.h
Go to the documentation of this file.
1 #ifndef IOPool_Streamer_FRDEventOutputModule_h
2 #define IOPool_Streamer_FRDEventOutputModule_h
3 
5 
13 
14 #include "boost/shared_array.hpp"
15 
16 namespace edm {
17  class ModuleCallingContext;
18 }
19 
20 class FRDEventMsgView;
21 template <class Consumer>
23 {
24  typedef unsigned int uint32;
32  public:
33  explicit FRDEventOutputModule(edm::ParameterSet const& ps);
35 
36  private:
37  virtual void write(edm::EventPrincipal const& e, edm::ModuleCallingContext const*) override;
38  virtual void beginRun(edm::RunPrincipal const&, edm::ModuleCallingContext const*) override;
39  virtual void endRun(edm::RunPrincipal const&, edm::ModuleCallingContext const*) override;
40  virtual void writeRun(edm::RunPrincipal const&, edm::ModuleCallingContext const*) override {}
42 
43  std::auto_ptr<Consumer> templateConsumer_;
46 };
47 
48 template <class Consumer>
50  edm::OutputModule(ps),
51  templateConsumer_(new Consumer(ps)),
52  label_(ps.getUntrackedParameter<std::string>("ProductLabel","source")),
53  instance_(ps.getUntrackedParameter<std::string>("ProductInstance",""))
54 {
55 }
56 
57 template <class Consumer>
59 
60 template <class Consumer>
62 
63  static const edm::TypeID fedType(typeid(FEDRawDataCollection));
64  static const std::string emptyString("");
65 
68  fedType,
69  label_,
70  instance_,
71  emptyString,
72  nullptr,
73  mcc);
74  convert_handle(std::move(h), fedBuffers);
75 
76  // determine the expected size of the FRDEvent
77  int expectedSize = (4 + 1024) * sizeof(uint32);
78  for (int idx = 0; idx < 1024; ++idx) {
79  FEDRawData singleFED = fedBuffers->FEDData(idx);
80  expectedSize += singleFED.size();
81  //if (singleFED.size() > 0) {
82  // std::cout << "FED #" << idx << " size = " << singleFED.size() << std::endl;
83  //}
84  }
85 
86  // build the FRDEvent into a temporary buffer
87  boost::shared_array<unsigned char> workBuffer(new unsigned char[expectedSize + 256]);
88  uint32 *bufPtr = (uint32*) workBuffer.get();
89  *bufPtr++ = (uint32) 2; // version number
90  *bufPtr++ = (uint32) e.run();
91  *bufPtr++ = (uint32) e.luminosityBlock();
92  *bufPtr++ = (uint32) e.id().event();
93  for (int idx = 0; idx < 1024; ++idx) {
94  FEDRawData singleFED = fedBuffers->FEDData(idx);
95  *bufPtr++ = singleFED.size();
96  }
97  for (int idx = 0; idx < 1024; ++idx) {
98  FEDRawData singleFED = fedBuffers->FEDData(idx);
99  if (singleFED.size() > 0) {
100  memcpy(bufPtr, singleFED.data(), singleFED.size());
101  *bufPtr += singleFED.size();
102  }
103  }
104 
105  // create the FRDEventMsgView and use the template consumer to write it out
106  FRDEventMsgView msg(workBuffer.get());
107  templateConsumer_->doOutputEvent(msg);
108 }
109 
110 template <class Consumer>
112 {
113  templateConsumer_->start();
114 }
115 
116 template <class Consumer>
118 {
119  templateConsumer_->stop();
120 }
121 
122 #endif
virtual void write(edm::EventPrincipal const &e, edm::ModuleCallingContext const *) override
EventNumber_t event() const
Definition: EventID.h:44
virtual void endRun(edm::RunPrincipal const &, edm::ModuleCallingContext const *) override
virtual void writeLuminosityBlock(edm::LuminosityBlockPrincipal const &, edm::ModuleCallingContext const *) override
RunNumber_t run() const
virtual void beginRun(edm::RunPrincipal const &, edm::ModuleCallingContext const *) override
FRDEventOutputModule(edm::ParameterSet const &ps)
EventID const & id() const
std::auto_ptr< Consumer > templateConsumer_
LuminosityBlockNumber_t luminosityBlock() const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
virtual void writeRun(edm::RunPrincipal const &, edm::ModuleCallingContext const *) override
unsigned int uint32
Definition: MsgTools.h:13
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
static std::string const emptyString("")
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, ModuleCallingContext const *mcc) const
Definition: Principal.cc:445