22 #include <boost/algorithm/string.hpp>
43 LogDebug(
"EvFOutputModule") <<
"writing .dat files to -: " << baseRunDir;
72 std::stringstream tmpss,
ss;
73 tmpss << baseRunDir <<
"/open/"
74 <<
"output_" << getpid() <<
".jsd";
75 ss << baseRunDir <<
"/"
76 <<
"output_" << getpid() <<
".jsd";
82 if (
stat(outJsonDefName.c_str(), &fstat) != 0) {
83 LogDebug(
"EvFOutputModule") <<
"writing output definition file -: " << outJsonDefName;
87 std::filesystem::rename(outTmpJsonDefName, outJsonDefName);
111 streamLabel_(ps.getParameter<
std::
string>(
"@module_label")),
114 ps.getUntrackedParameter<
edm::
InputTag>(
"psetMap"))) {
121 throw cms::Exception(
"EvFOutputModule") <<
"Underscore character is reserved can not be used for stream names in "
122 "FFF, but was detected in stream name -: "
128 auto streampos = streamLabelLow.rfind(
"stream");
129 if (streampos != 0 && streampos != std::string::npos)
131 <<
"stream (case-insensitive) sequence was found in stream suffix. This is reserved and can not be used for "
132 "names in FFF based HLT, but was detected in stream name";
144 ->setComment(
"Optionally allow the map of ParameterSets to be calculated externally.");
145 descriptions.
add(
"evfOutputModule",
desc);
154 edm::LogInfo(
"EvFOutputModule") <<
"beginRun init stream -: " << openIniFileName;
157 uint32 preamble_adler32 = 1;
162 std::unique_ptr<InitMsgBuilder> init_message =
169 psetMapHandle.
isValid() ? psetMapHandle.product() :
nullptr);
175 stream_writer_preamble.
write(view);
176 preamble_adler32 = stream_writer_preamble.
adler32();
177 stream_writer_preamble.
close();
180 stat(openIniFileName.c_str(), &istat);
183 uint32_t adlera = 1, adlerb = 0;
184 FILE*
src = fopen(openIniFileName.c_str(),
"r");
187 unsigned char* outBuf =
new unsigned char[1024 * 1024];
188 while (readInput < istat.st_size) {
189 size_t toRead = readInput + 1024 * 1024 < istat.st_size ? 1024 * 1024 : istat.st_size - readInput;
190 fread(outBuf, toRead, 1,
src);
191 cms::Adler32((
const char*)outBuf, toRead, adlera, adlerb);
197 jsonWriter_->streamerCommon_.getSerializerBuffer()->clearHeaderBuffer();
203 uint32_t adler32c = (adlerb << 16) | adlera;
204 if (adler32c != preamble_adler32) {
205 throw cms::Exception(
"EvFOutputModule") <<
"Checksum mismatch of ini file -: " << openIniFileName
206 <<
" expected:" << preamble_adler32 <<
" obtained:" << adler32c;
224 return std::make_shared<EvFOutputEventWriter>(openDatFilePath);
231 auto lumiWriter = luminosityBlockCache(
e.getLuminosityBlock().index());
232 std::unique_ptr<EventMsgBuilder>
msg =
jsonWriter_->streamerCommon_.serializeEvent(
234 lumiWriter->incAccepted();
235 lumiWriter->doOutputEvent(*
msg);
239 auto lumiWriter = luminosityBlockCache(iLB.
index());
243 jsonWriter_->fileAdler32_.value() = lumiWriter->get_adler32();
244 jsonWriter_->accepted_.value() = lumiWriter->getAccepted();
246 bool abortFlag =
false;
249 edm::LogInfo(
"EvFOutputModule") <<
"Abort flag has been set. Output is suppressed";
256 stat(openDatFilePath.string().c_str(), &istat);
258 std::filesystem::rename(openDatFilePath.string().c_str(),
260 jsonWriter_->filelist_ = openDatFilePath.filename().string();
263 remove(lumiWriter->getFilePath().c_str());