1 #ifndef IOPool_Streamer_interface_RawEventOutputModuleForBU_h 2 #define IOPool_Streamer_interface_RawEventOutputModuleForBU_h 25 template <
class Consumer>
64 template <
class Consumer>
68 templateConsumer_(new Consumer(ps)),
70 numEventsPerFile_(ps.getParameter<unsigned
int>(
"numEventsPerFile")),
71 frdVersion_(ps.getParameter<unsigned
int>(
"frdVersion")) {}
73 template <
class Consumer>
76 template <
class Consumer>
78 unsigned int ls =
e.luminosityBlock();
79 if (totevents > 0 && totevents % numEventsPerFile_ == 0) {
83 templateConsumer_->initialize(destinationDir,
filename,
ls);
89 e.getByToken(token_, fedBuffers);
94 int expectedSize = headerSize;
99 expectedSize += singleFED.
size();
102 totsize += expectedSize;
104 std::unique_ptr<std::vector<unsigned char>> workBuffer(
105 std::make_unique<std::vector<unsigned char>>(expectedSize + 256));
107 if (frdVersion_ <= 5) {
108 *bufPtr++ = (
uint32)frdVersion_;
111 if (!
e.eventAuxiliary().isRealData())
117 *bufPtr++ = (
uint32)
e.id().run();
118 *bufPtr++ = (
uint32)
e.luminosityBlock();
119 *bufPtr++ = (
uint32)
e.id().event();
120 if (frdVersion_ == 4)
123 if (frdVersion_ < 3) {
127 fedsize[
idx] = singleFED.
size();
130 memcpy(bufPtr, fedsize, 1024 *
sizeof(
uint32));
133 *bufPtr++ = expectedSize - headerSize;
135 if (frdVersion_ <= 4)
138 uint32* payloadPtr = bufPtr;
141 if (singleFED.
size() > 0) {
142 memcpy(bufPtr, singleFED.
data(), singleFED.
size());
143 bufPtr += singleFED.
size() / 4;
146 if (frdVersion_ > 4) {
149 *(payloadPtr - 1) =
crc32c(crc, (
const unsigned char*)payloadPtr, expectedSize - headerSize);
150 }
else if (frdVersion_ >= 3) {
154 cms::Adler32((
const char*)payloadPtr, expectedSize - headerSize, adlera, adlerb);
155 *(payloadPtr - 1) = (adlerb << 16) | adlera;
160 writtensize +=
msg.size();
162 templateConsumer_->doOutputEvent(
msg);
165 template <
class Consumer>
168 templateConsumer_->start();
171 template <
class Consumer>
173 templateConsumer_->stop();
176 template <
class Consumer>
181 std::cout <<
" writing to destination dir " << destinationDir <<
" name: " <<
filename << std::endl;
182 templateConsumer_->initialize(destinationDir,
filename,
ls.id().luminosityBlock());
186 ::gettimeofday(&
now,
nullptr);
192 writtenSizeLast = writtensize;
193 ::gettimeofday(&startOfLastLumi,
nullptr);
196 ::gettimeofday(&startOfLastLumi,
nullptr);
202 template <
class Consumer>
205 templateConsumer_->endOfLS(
ls.id().luminosityBlock());
208 template <
class Consumer>
212 desc.add<
unsigned int>(
"numEventsPerFile", 100);
213 desc.add<
unsigned int>(
"frdVersion", 6);
214 Consumer::extendDescription(
desc);
219 #endif // IOPool_Streamer_interface_RawEventOutputModuleForBU_h std::unique_ptr< Consumer > templateConsumer_
const edm::EDGetTokenT< FEDRawDataCollection > token_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
void endRun(edm::RunForOutput const &) override
void beginRun(edm::RunForOutput const &) override
constexpr size_t FRDHeaderMaxVersion
const unsigned int frdVersion_
unsigned long long writtensize
size_t size() const
Lenght of the data buffer in bytes.
void write(edm::EventForOutput const &e) override
RawEventOutputModuleForBU(edm::ParameterSet const &ps)
void beginLuminosityBlock(edm::LuminosityBlockForOutput const &) override
const unsigned int numEventsPerFile_
unsigned long long totsize
~RawEventOutputModuleForBU() override
unsigned long long writtenSizeLast
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
uint32_t crc32c(uint32_t crc, const unsigned char *buf, size_t len)
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
void endLuminosityBlock(edm::LuminosityBlockForOutput const &) override
const uint16 FRDEVENT_MASK_ISGENDATA
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
void writeLuminosityBlock(const edm::LuminosityBlockForOutput &) override
void writeRun(const edm::RunForOutput &) override
static constexpr int lastFEDId()