22 #include <boost/algorithm/string.hpp>
29 : streamerCommon_(ps, selections),
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")),
112 trToken_(consumes<edm::TriggerResults>(edm::
InputTag(
"TriggerResults"))),
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);
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());
void addLegendItem(std::string const &name, std::string const &type, std::string const &operation)
ParameterSetID const & mainParameterSetID() const
EvFOutputModule(edm::ParameterSet const &ps)
std::unique_ptr< evf::EvFOutputJSONWriter > jsonWriter_
static const std::string BINARYOR
std::vector< BranchIDList > BranchIDLists
edm::ParameterSet const & ps_
jsoncollector::IntJ fileAdler32_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static const std::string ADLER32
std::shared_ptr< EvFOutputEventWriter > globalBeginLuminosityBlock(edm::LuminosityBlockForOutput const &iLB) const override
static const std::string SUM
static bool serialize(JsonSerializable *pObj, std::string &output)
void write(const InitMsgBuilder &)
EvFOutputJSONWriter(edm::ParameterSet const &ps, edm::SelectedProducts const *selections, std::string const &streamLabel)
std::string to_lower(const std::string &s)
jsoncollector::DataPointDefinition outJsonDef_
jsoncollector::IntJ hltErrorEvents_
std::string const & moduleLabel() const
jsoncollector::StringJ inputFiles_
void beginRun(edm::RunForOutput const &run) override
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
LuminosityBlockIndex index() const
std::vector< std::pair< BranchDescription const *, EDGetToken > > SelectedProducts
LuminosityBlockForOutput const & getLuminosityBlock() const
LuminosityBlockNumber_t luminosityBlock() const
jsoncollector::IntJ retCodeMask_
static void fillDescription(ParameterSetDescription &desc)
virtual void setName(std::string name)
ModuleDescription const & description() const
~EvFOutputModule() override
static const std::string MERGE
void globalEndLuminosityBlock(edm::LuminosityBlockForOutput const &iLB) override
static std::string const triggerResults
ThinnedAssociationsHelper const * thinnedAssociationsHelper() const
static void writeStringToFile(std::string const &filename, std::string &content)
static const std::string CAT
jsoncollector::IntJ processed_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
BranchIDLists const * branchIDLists() const
Log< level::Info, false > LogInfo
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
void write(edm::EventForOutput const &e) override
ParameterSetID selectorConfig() const
edm::EDGetTokenT< edm::TriggerResults > trToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
jsoncollector::IntJ filesize_
jsoncollector::StringJ filelist_
jsoncollector::StringJ transferDestination_
edm::EDGetTokenT< edm::SendJobHeader::ParameterSetMap > psetToken_
std::shared_ptr< jsoncollector::FastMonitor > jsonMonitor_
SelectedProductsForBranchType const & keptProducts() const
const ModuleDescription & moduleDescription() const
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=nullptr)
void setDefaultGroup(std::string const &group)
jsoncollector::IntJ accepted_
jsoncollector::StringJ mergeType_
static void fillDescription(ParameterSetDescription &desc, std::vector< std::string > const &iDefaultOutputCommands=ProductSelectorRules::defaultSelectionStrings())
jsoncollector::IntJ errorEvents_
Trig getTriggerResults(edm::EDGetTokenT< edm::TriggerResults > const &token, edm::EventForOutput const &e) const
static const std::string SAME
evf::FastMonitoringService * fms_