1 #ifndef IOPool_Streamer_interface_RawEventOutputModuleForBU_h
2 #define IOPool_Streamer_interface_RawEventOutputModuleForBU_h
25 template <
class Consumer>
64 template <
class Consumer>
67 edm::
one::OutputModule<edm::
one::WatchRuns, edm::
one::WatchLuminosityBlocks>(ps),
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>
79 if (totevents > 0 && totevents % numEventsPerFile_ == 0) {
83 templateConsumer_->initialize(destinationDir, filename, ls);
94 int expectedSize = headerSize;
97 for (
int idx = 0; idx < nFeds; ++idx) {
98 FEDRawData singleFED = fedBuffers->FEDData(idx);
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_;
114 *((
uint16*)bufPtr + 1) = flags;
120 if (frdVersion_ == 4)
123 if (frdVersion_ < 3) {
125 for (
int idx = 0; idx < 1024; ++idx) {
126 FEDRawData singleFED = fedBuffers->FEDData(idx);
127 fedsize[idx] = singleFED.
size();
130 memcpy(bufPtr, fedsize, 1024 *
sizeof(
uint32));
133 *bufPtr++ = expectedSize - headerSize;
135 if (frdVersion_ <= 4)
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;
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>
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_
EventNumber_t event() const
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
void endRun(edm::RunForOutput const &) override
EventID const & id() const
void beginRun(edm::RunForOutput const &) override
EventAuxiliary const & eventAuxiliary() const
constexpr size_t FRDHeaderMaxVersion
const unsigned int frdVersion_
unsigned long long writtensize
void write(edm::EventForOutput const &e) override
RawEventOutputModuleForBU(edm::ParameterSet const &ps)
constexpr Matriplex::idx_t LL
size_t size() const
Lenght of the data buffer in bytes.
void beginLuminosityBlock(edm::LuminosityBlockForOutput const &) override
const unsigned int numEventsPerFile_
unsigned long long totsize
~RawEventOutputModuleForBU() override
unsigned long long writtenSizeLast
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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
LuminosityBlockNumber_t luminosityBlock() const
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
const uint16 FRDEVENT_MASK_ISGENDATA
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
LuminosityBlockNumber_t luminosityBlock() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
void writeLuminosityBlock(const edm::LuminosityBlockForOutput &) override
LuminosityBlockID const & id() const
void writeRun(const edm::RunForOutput &) override
static constexpr int lastFEDId()