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>
80 unsigned int ls =
e.luminosityBlock();
81 if (totevents > 0 && totevents % numEventsPerFile_ == 0) {
85 templateConsumer_->initialize(destinationDir,
filename,
ls);
91 e.getByToken(token_, fedBuffers);
96 int expectedSize = headerSize;
101 expectedSize += singleFED.
size();
104 totsize += expectedSize;
106 std::unique_ptr<std::vector<unsigned char>> workBuffer(
107 std::make_unique<std::vector<unsigned char>>(expectedSize + 256));
109 if (frdVersion_ <= 5) {
110 *bufPtr++ = (
uint32)frdVersion_;
113 if (!
e.eventAuxiliary().isRealData())
119 *bufPtr++ = (
uint32)
e.id().run();
120 *bufPtr++ = (
uint32)
e.luminosityBlock();
121 *bufPtr++ = (
uint32)
e.id().event();
122 if (frdVersion_ == 4)
125 if (frdVersion_ < 3) {
129 fedsize[
idx] = singleFED.
size();
132 memcpy(bufPtr, fedsize, 1024 *
sizeof(
uint32));
135 *bufPtr++ = expectedSize - headerSize;
137 if (frdVersion_ <= 4)
140 uint32* payloadPtr = bufPtr;
143 if (singleFED.
size() > 0) {
144 memcpy(bufPtr, singleFED.
data(), singleFED.
size());
145 bufPtr += singleFED.
size() / 4;
148 if (frdVersion_ > 4) {
151 *(payloadPtr - 1) =
crc32c(crc, (
const unsigned char*)payloadPtr, expectedSize - headerSize);
152 }
else if (frdVersion_ >= 3) {
156 cms::Adler32((
const char*)payloadPtr, expectedSize - headerSize, adlera, adlerb);
157 *(payloadPtr - 1) = (adlerb << 16) | adlera;
162 writtensize +=
msg.size();
164 templateConsumer_->doOutputEvent(
msg);
167 template <
class Consumer>
170 templateConsumer_->start();
173 template <
class Consumer>
175 templateConsumer_->stop();
178 template <
class Consumer>
183 std::cout <<
" writing to destination dir " << destinationDir <<
" name: " <<
filename << std::endl;
184 templateConsumer_->initialize(destinationDir,
filename,
ls.id().luminosityBlock());
188 ::gettimeofday(&
now,
nullptr);
194 writtenSizeLast = writtensize;
195 ::gettimeofday(&startOfLastLumi,
nullptr);
198 ::gettimeofday(&startOfLastLumi,
nullptr);
204 template <
class Consumer>
207 templateConsumer_->endOfLS(
ls.id().luminosityBlock());
210 template <
class Consumer>
214 desc.add<
unsigned int>(
"numEventsPerFile", 100);
215 desc.add<
unsigned int>(
"frdVersion", 6);
216 Consumer::extendDescription(
desc);
221 #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 std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
const unsigned int frdVersion_
constexpr size_t FRDHeaderMaxVersion
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
const uint16 FRDEVENT_MASK_ISGENDATA
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 unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void writeLuminosityBlock(const edm::LuminosityBlockForOutput &) override
void writeRun(const edm::RunForOutput &) override
static constexpr int lastFEDId()