1 #ifndef IOPool_Streamer_RawEventOutputModuleForBU_h
2 #define IOPool_Streamer_RawEventOutputModuleForBU_h
21 #include "boost/shared_array.hpp"
23 template <
class Consumer>
62 template <
class Consumer>
65 edm::one::OutputModule<
edm::one::WatchRuns,
edm::one::WatchLuminosityBlocks>(ps),
66 templateConsumer_(new Consumer(ps)),
67 label_(ps.getUntrackedParameter<
std::
string>(
"ProductLabel",
"source")),
68 instance_(ps.getUntrackedParameter<
std::
string>(
"ProductInstance",
"")),
70 numEventsPerFile_(ps.getUntrackedParameter<unsigned
int>(
"numEventsPerFile", 100)),
71 frdVersion_(ps.getUntrackedParameter<unsigned
int>(
"frdVersion", 6)),
79 template <
class Consumer>
82 template <
class Consumer>
84 unsigned int ls =
e.luminosityBlock();
85 if (totevents > 0 && totevents % numEventsPerFile_ == 0) {
89 templateConsumer_->initialize(destinationDir,
filename,
ls);
95 e.getByToken(token_, fedBuffers);
100 int expectedSize = headerSize;
105 expectedSize += singleFED.
size();
108 totsize += expectedSize;
110 boost::shared_array<unsigned char> workBuffer(
new unsigned char[expectedSize + 256]);
112 if (frdVersion_ <= 5) {
113 *bufPtr++ = (
uint32)frdVersion_;
116 if (!
e.eventAuxiliary().isRealData())
122 *bufPtr++ = (
uint32)
e.id().run();
123 *bufPtr++ = (
uint32)
e.luminosityBlock();
124 *bufPtr++ = (
uint32)
e.id().event();
125 if (frdVersion_ == 4)
128 if (frdVersion_ < 3) {
132 fedsize[
idx] = singleFED.
size();
135 memcpy(bufPtr, fedsize, 1024 *
sizeof(
uint32));
138 *bufPtr++ = expectedSize - headerSize;
140 if (frdVersion_ <= 4)
143 uint32* payloadPtr = bufPtr;
146 if (singleFED.
size() > 0) {
147 memcpy(bufPtr, singleFED.
data(), singleFED.
size());
148 bufPtr += singleFED.
size() / 4;
151 if (frdVersion_ > 4) {
154 *(payloadPtr - 1) =
crc32c(crc, (
const unsigned char*)payloadPtr, expectedSize - headerSize);
155 }
else if (frdVersion_ >= 3) {
159 cms::Adler32((
const char*)payloadPtr, expectedSize - headerSize, adlera, adlerb);
160 *(payloadPtr - 1) = (adlerb << 16) | adlera;
165 writtensize +=
msg.size();
167 if (templateConsumer_->sharedMode())
168 templateConsumer_->doOutputEvent(workBuffer);
170 templateConsumer_->doOutputEvent(
msg);
173 template <
class Consumer>
176 templateConsumer_->start();
179 template <
class Consumer>
181 templateConsumer_->stop();
184 template <
class Consumer>
189 std::cout <<
" writing to destination dir " << destinationDir <<
" name: " <<
filename << std::endl;
190 templateConsumer_->initialize(destinationDir,
filename,
ls.id().luminosityBlock());
194 ::gettimeofday(&
now,
nullptr);
200 writtenSizeLast = writtensize;
201 ::gettimeofday(&startOfLastLumi,
nullptr);
204 ::gettimeofday(&startOfLastLumi,
nullptr);
209 template <
class Consumer>
212 templateConsumer_->endOfLS(
ls.id().luminosityBlock());