00001 #ifndef IOPool_Streamer_FRDEventOutputModule_h
00002 #define IOPool_Streamer_FRDEventOutputModule_h
00003
00004 #include "FWCore/Framework/interface/OutputModule.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00007 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00008
00009 template <class Consumer>
00010 class FRDEventOutputModule : public edm::OutputModule
00011 {
00012
00020 public:
00021 explicit FRDEventOutputModule(edm::ParameterSet const& ps);
00022 ~FRDEventOutputModule();
00023
00024 private:
00025 virtual void write(edm::EventPrincipal const& e);
00026 virtual void beginRun(edm::RunPrincipal const&);
00027 virtual void endRun(edm::RunPrincipal const&);
00028 virtual void writeRun(edm::RunPrincipal const&) {}
00029 virtual void writeLuminosityBlock(edm::LuminosityBlockPrincipal const&) {}
00030
00031 std::auto_ptr<Consumer> templateConsumer_;
00032 std::string label_;
00033 std::string instance_;
00034 };
00035
00036 template <class Consumer>
00037 FRDEventOutputModule<Consumer>::FRDEventOutputModule(edm::ParameterSet const& ps) :
00038 edm::OutputModule(ps),
00039 templateConsumer_(new Consumer(ps)),
00040 label_(ps.getUntrackedParameter<std::string>("ProductLabel","source")),
00041 instance_(ps.getUntrackedParameter<std::string>("ProductInstance",""))
00042 {
00043 }
00044
00045 template <class Consumer>
00046 FRDEventOutputModule<Consumer>::~FRDEventOutputModule() {}
00047
00048 template <class Consumer>
00049 void FRDEventOutputModule<Consumer>::write(edm::EventPrincipal const& e) {
00050
00051
00052
00053 edm::Event event(const_cast<edm::EventPrincipal&>(e), description());
00054 edm::Handle<FEDRawDataCollection> fedBuffers;
00055 event.getByLabel(label_, instance_, fedBuffers);
00056
00057
00058 int expectedSize = (4 + 1024) * sizeof(uint32);
00059 for (int idx = 0; idx < 1024; ++idx) {
00060 FEDRawData singleFED = fedBuffers->FEDData(idx);
00061 expectedSize += singleFED.size();
00062
00063
00064
00065 }
00066
00067
00068 unsigned char *workBuffer = new unsigned char[expectedSize + 256];
00069 uint32 *bufPtr = (uint32*) workBuffer;
00070 *bufPtr++ = (uint32) 2;
00071 *bufPtr++ = (uint32) event.id().run();
00072 *bufPtr++ = (uint32) event.luminosityBlock();
00073 *bufPtr++ = (uint32) event.id().event();
00074 for (int idx = 0; idx < 1024; ++idx) {
00075 FEDRawData singleFED = fedBuffers->FEDData(idx);
00076 *bufPtr++ = singleFED.size();
00077 }
00078 for (int idx = 0; idx < 1024; ++idx) {
00079 FEDRawData singleFED = fedBuffers->FEDData(idx);
00080 if (singleFED.size() > 0) {
00081 memcpy(bufPtr, singleFED.data(), singleFED.size());
00082 *bufPtr += singleFED.size();
00083 }
00084 }
00085
00086
00087 FRDEventMsgView msg(workBuffer);
00088 templateConsumer_->doOutputEvent(msg);
00089
00090
00091 delete[] workBuffer;
00092 }
00093
00094 template <class Consumer>
00095 void FRDEventOutputModule<Consumer>::beginRun(edm::RunPrincipal const&)
00096 {
00097 templateConsumer_->start();
00098 }
00099
00100 template <class Consumer>
00101 void FRDEventOutputModule<Consumer>::endRun(edm::RunPrincipal const&)
00102 {
00103 templateConsumer_->stop();
00104 }
00105
00106 #endif