CMS 3D CMS Logo

RawEventOutputModuleForBU.h
Go to the documentation of this file.
1 #ifndef IOPool_Streamer_interface_RawEventOutputModuleForBU_h
2 #define IOPool_Streamer_interface_RawEventOutputModuleForBU_h
3 
4 #include <memory>
5 #include <vector>
6 
24 
25 template <class Consumer>
26 class RawEventOutputModuleForBU : public edm::one::OutputModule<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
27  typedef unsigned int uint32;
35 public:
36  explicit RawEventOutputModuleForBU(edm::ParameterSet const& ps);
37  ~RawEventOutputModuleForBU() override;
38 
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41 private:
42  void write(edm::EventForOutput const& e) override;
43  void beginRun(edm::RunForOutput const&) override;
44  void endRun(edm::RunForOutput const&) override;
45  void writeRun(const edm::RunForOutput&) override {}
47 
50 
51  std::unique_ptr<Consumer> templateConsumer_;
53  const unsigned int numEventsPerFile_;
54  const unsigned int frdVersion_;
55  unsigned long long totsize = 0LL;
56  unsigned long long writtensize = 0LL;
57  unsigned long long writtenSizeLast = 0LL;
58  unsigned int totevents = 0;
59  unsigned int index_ = 0;
60  timeval startOfLastLumi;
61  bool firstLumi_ = true;
62 };
63 
64 template <class Consumer>
67  edm::one::OutputModule<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks>(ps),
68  templateConsumer_(new Consumer(ps)),
69  token_(consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("source"))),
70  numEventsPerFile_(ps.getParameter<unsigned int>("numEventsPerFile")),
71  frdVersion_(ps.getParameter<unsigned int>("frdVersion")) {}
72 
73 template <class Consumer>
75 
76 template <class Consumer>
78  unsigned int ls = e.luminosityBlock();
79  if (totevents > 0 && totevents % numEventsPerFile_ == 0) {
80  index_++;
81  std::string filename = edm::Service<evf::EvFDaqDirector>()->getOpenRawFilePath(ls, index_);
82  std::string destinationDir = edm::Service<evf::EvFDaqDirector>()->buBaseRunDir();
83  templateConsumer_->initialize(destinationDir, filename, ls);
84  }
85  totevents++;
86  // serialize the FEDRawDataCollection into the format that we expect for
87  // FRDEventMsgView objects (may be better ways to do this)
89  e.getByToken(token_, fedBuffers);
90 
91  // determine the expected size of the FRDEvent IN BYTES !!!!!
92  assert(frdVersion_ <= FRDHeaderMaxVersion);
93  int headerSize = FRDHeaderVersionSize[frdVersion_];
94  int expectedSize = headerSize;
95  int nFeds = frdVersion_ < 3 ? 1024 : FEDNumbering::lastFEDId() + 1;
96 
97  for (int idx = 0; idx < nFeds; ++idx) {
98  FEDRawData singleFED = fedBuffers->FEDData(idx);
99  expectedSize += singleFED.size();
100  }
101 
102  totsize += expectedSize;
103  // build the FRDEvent into a temporary buffer
104  std::unique_ptr<std::vector<unsigned char>> workBuffer(
105  std::make_unique<std::vector<unsigned char>>(expectedSize + 256));
106  uint32* bufPtr = (uint32*)(workBuffer.get()->data());
107  if (frdVersion_ <= 5) {
108  *bufPtr++ = (uint32)frdVersion_; // version number only
109  } else {
110  uint16 flags = 0;
111  if (!e.eventAuxiliary().isRealData())
113  *(uint16*)bufPtr = (uint16)(frdVersion_ & 0xffff);
114  *((uint16*)bufPtr + 1) = flags;
115  bufPtr++;
116  }
117  *bufPtr++ = (uint32)e.id().run();
118  *bufPtr++ = (uint32)e.luminosityBlock();
119  *bufPtr++ = (uint32)e.id().event();
120  if (frdVersion_ == 4)
121  *bufPtr++ = 0; //64-bit event id high part
122 
123  if (frdVersion_ < 3) {
124  uint32 fedsize[1024];
125  for (int idx = 0; idx < 1024; ++idx) {
126  FEDRawData singleFED = fedBuffers->FEDData(idx);
127  fedsize[idx] = singleFED.size();
128  //std::cout << "fed size " << singleFED.size()<< std::endl;
129  }
130  memcpy(bufPtr, fedsize, 1024 * sizeof(uint32));
131  bufPtr += 1024;
132  } else {
133  *bufPtr++ = expectedSize - headerSize;
134  *bufPtr++ = 0;
135  if (frdVersion_ <= 4)
136  *bufPtr++ = 0;
137  }
138  uint32* payloadPtr = bufPtr;
139  for (int idx = 0; idx < nFeds; ++idx) {
140  FEDRawData singleFED = fedBuffers->FEDData(idx);
141  if (singleFED.size() > 0) {
142  memcpy(bufPtr, singleFED.data(), singleFED.size());
143  bufPtr += singleFED.size() / 4;
144  }
145  }
146  if (frdVersion_ > 4) {
147  //crc32c checksum
148  uint32_t crc = 0;
149  *(payloadPtr - 1) = crc32c(crc, (const unsigned char*)payloadPtr, expectedSize - headerSize);
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()->data());
160  writtensize += msg.size();
161 
162  templateConsumer_->doOutputEvent(msg);
163 }
164 
165 template <class Consumer>
167  // edm::Service<evf::EvFDaqDirector>()->updateBuLock(1);
168  templateConsumer_->start();
169 }
170 
171 template <class Consumer>
173  templateConsumer_->stop();
174 }
175 
176 template <class Consumer>
178  index_ = 0;
179  std::string filename = edm::Service<evf::EvFDaqDirector>()->getOpenRawFilePath(ls.id().luminosityBlock(), index_);
180  std::string destinationDir = edm::Service<evf::EvFDaqDirector>()->buBaseRunDir();
181  std::cout << " writing to destination dir " << destinationDir << " name: " << filename << std::endl;
182  templateConsumer_->initialize(destinationDir, filename, ls.id().luminosityBlock());
183  //edm::Service<evf::EvFDaqDirector>()->updateBuLock(ls.id().luminosityBlock()+1);
184  if (!firstLumi_) {
185  timeval now;
186  ::gettimeofday(&now, nullptr);
187  //long long elapsedusec = (now.tv_sec - startOfLastLumi.tv_sec)*1000000+now.tv_usec-startOfLastLumi.tv_usec;
188  /* std::cout << "(now.tv_sec - startOfLastLumi.tv_sec) " << now.tv_sec <<"-" << startOfLastLumi.tv_sec */
189  /* <<" (now.tv_usec-startOfLastLumi.tv_usec) " << now.tv_usec << "-" << startOfLastLumi.tv_usec << std::endl; */
190  /* std::cout << "elapsedusec " << elapsedusec << " totevents " << totevents << " size (GB)" << writtensize */
191  /* << " rate " << (writtensize-writtenSizeLast)/elapsedusec << " MB/s" <<std::endl; */
192  writtenSizeLast = writtensize;
193  ::gettimeofday(&startOfLastLumi, nullptr);
194  //edm::Service<evf::EvFDaqDirector>()->writeLsStatisticsBU(ls.id().luminosityBlock(), totevents, totsize, elapsedusec);
195  } else
196  ::gettimeofday(&startOfLastLumi, nullptr);
197  totevents = 0;
198  totsize = 0LL;
199  firstLumi_ = false;
200 }
201 
202 template <class Consumer>
204  // templateConsumer_->touchlock(ls.id().luminosityBlock(),basedir);
205  templateConsumer_->endOfLS(ls.id().luminosityBlock());
206 }
207 
208 template <class Consumer>
211  desc.add<edm::InputTag>("source", edm::InputTag("rawDataCollector"));
212  desc.add<unsigned int>("numEventsPerFile", 100);
213  desc.add<unsigned int>("frdVersion", 6);
214  Consumer::extendDescription(desc);
215 
216  descriptions.addWithDefaultLabel(desc);
217 }
218 
219 #endif // IOPool_Streamer_interface_RawEventOutputModuleForBU_h
ConfigurationDescriptions.h
edm::one::OutputModule
Definition: OutputModule.h:30
FEDNumbering.h
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
Handle.h
ModuleCallingContext.h
SiPixelPI::one
Definition: SiPixelPayloadInspectorHelper.h:39
RawEventOutputModuleForBU::frdVersion_
const unsigned int frdVersion_
Definition: RawEventOutputModuleForBU.h:54
OutputModule.h
FRDEventMsgView
Definition: FRDEventMessage.h:137
RawEventOutputModuleForBU
Definition: RawEventOutputModuleForBU.h:26
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
FEDNumbering::lastFEDId
static constexpr int lastFEDId()
Definition: FEDNumbering.h:19
EvFBuildingThrottle.h
edm::EDGetTokenT< FEDRawDataCollection >
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
RawEventOutputModuleForBU::totsize
unsigned long long totsize
Definition: RawEventOutputModuleForBU.h:55
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
RawEventOutputModuleForBU::writtensize
unsigned long long writtensize
Definition: RawEventOutputModuleForBU.h:56
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
RawEventOutputModuleForBU::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlockForOutput const &) override
Definition: RawEventOutputModuleForBU.h:177
cms::cuda::assert
assert(be >=bs)
RawEventOutputModuleForBU::beginRun
void beginRun(edm::RunForOutput const &) override
Definition: RawEventOutputModuleForBU.h:166
RawEventOutputModuleForBU::write
void write(edm::EventForOutput const &e) override
Definition: RawEventOutputModuleForBU.h:77
mps_check.msg
tuple msg
Definition: mps_check.py:285
FRDEventMessage.h
EventForOutput.h
FEDRawData.h
edm::Handle< FEDRawDataCollection >
FRDHeaderVersionSize
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
Definition: FRDEventMessage.h:129
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
uint32
unsigned int uint32
Definition: MsgTools.h:13
FEDRawData
Definition: FEDRawData.h:19
FRDEVENT_MASK_ISGENDATA
const uint16 FRDEVENT_MASK_ISGENDATA
Definition: FRDEventMessage.h:126
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
edm::LuminosityBlockForOutput
Definition: LuminosityBlockForOutput.h:40
edm::RunForOutput
Definition: RunForOutput.h:39
RawEventOutputModuleForBU::token_
const edm::EDGetTokenT< FEDRawDataCollection > token_
Definition: RawEventOutputModuleForBU.h:52
RawEventOutputModuleForBU::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: RawEventOutputModuleForBU.h:209
RawEventOutputModuleForBU::endRun
void endRun(edm::RunForOutput const &) override
Definition: RawEventOutputModuleForBU.h:172
cms::Adler32
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
Definition: Adler32Calculator.cc:10
Service.h
FRDHeaderMaxVersion
constexpr size_t FRDHeaderMaxVersion
Definition: FRDEventMessage.h:128
RawEventOutputModuleForBU::uint32
unsigned int uint32
Definition: RawEventOutputModuleForBU.h:27
uint16
unsigned short uint16
Definition: MsgTools.h:12
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
RawEventOutputModuleForBU::~RawEventOutputModuleForBU
~RawEventOutputModuleForBU() override
Definition: RawEventOutputModuleForBU.h:74
ParameterSetDescription.h
EDGetToken.h
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
OutputModuleBase
crc32c
uint32_t crc32c(uint32_t crc, const unsigned char *buf, size_t len)
Definition: crc32c.cc:340
RawEventOutputModuleForBU::firstLumi_
bool firstLumi_
Definition: RawEventOutputModuleForBU.h:61
edm::ParameterSet
Definition: ParameterSet.h:47
RawEventOutputModuleForBU::totevents
unsigned int totevents
Definition: RawEventOutputModuleForBU.h:58
RawEventOutputModuleForBU::RawEventOutputModuleForBU
RawEventOutputModuleForBU(edm::ParameterSet const &ps)
Definition: RawEventOutputModuleForBU.h:65
edm::Service
Definition: Service.h:30
createfilelist.int
int
Definition: createfilelist.py:10
EvFDaqDirector.h
FEDRawDataCollection.h
crc32c.h
RawEventOutputModuleForBU::writeRun
void writeRun(const edm::RunForOutput &) override
Definition: RawEventOutputModuleForBU.h:45
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
edm::EventForOutput
Definition: EventForOutput.h:50
L1DTConfigBti_cff.LL
LL
Definition: L1DTConfigBti_cff.py:25
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
RawEventOutputModuleForBU::writeLuminosityBlock
void writeLuminosityBlock(const edm::LuminosityBlockForOutput &) override
Definition: RawEventOutputModuleForBU.h:46
RawEventOutputModuleForBU::numEventsPerFile_
const unsigned int numEventsPerFile_
Definition: RawEventOutputModuleForBU.h:53
RawEventOutputModuleForBU::writtenSizeLast
unsigned long long writtenSizeLast
Definition: RawEventOutputModuleForBU.h:57
RawEventOutputModuleForBU::templateConsumer_
std::unique_ptr< Consumer > templateConsumer_
Definition: RawEventOutputModuleForBU.h:51
Adler32Calculator.h
LuminosityBlockForOutput.h
HLT_FULL_cff.flags
flags
Definition: HLT_FULL_cff.py:13150
RawEventOutputModuleForBU::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlockForOutput const &) override
Definition: RawEventOutputModuleForBU.h:203
edm::InputTag
Definition: InputTag.h:15
RawEventOutputModuleForBU::index_
unsigned int index_
Definition: RawEventOutputModuleForBU.h:59
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
RawEventOutputModuleForBU::startOfLastLumi
timeval startOfLastLumi
Definition: RawEventOutputModuleForBU.h:60
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37