File indexing completed on 2025-01-12 23:41:56
0001
0002 #include "IOPool/Streamer/interface/StreamerOutputModuleBase.h"
0003
0004 #include "IOPool/Streamer/interface/InitMsgBuilder.h"
0005 #include "IOPool/Streamer/interface/EventMsgBuilder.h"
0006 #include "FWCore/Framework/interface/EventForOutput.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "DataFormats/Common/interface/TriggerResults.h"
0010 #include "DataFormats/Provenance/interface/ModuleDescription.h"
0011 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0012
0013 #include "zlib.h"
0014
0015 namespace edm::streamer {
0016 StreamerOutputModuleBase::StreamerOutputModuleBase(ParameterSet const& ps)
0017 : one::OutputModuleBase::OutputModuleBase(ps),
0018 one::OutputModule<one::WatchRuns, one::WatchLuminosityBlocks>(ps),
0019 StreamerOutputModuleCommon(ps, &keptProducts()[InEvent], description().moduleLabel()),
0020 trToken_(consumes<edm::TriggerResults>(edm::InputTag("TriggerResults"))),
0021 psetToken_(
0022 consumes<SendJobHeader::ParameterSetMap, edm::InRun>(ps.getUntrackedParameter<edm::InputTag>("psetMap"))) {}
0023
0024 StreamerOutputModuleBase::~StreamerOutputModuleBase() {}
0025
0026 void StreamerOutputModuleBase::beginRun(RunForOutput const& iRun) {
0027 start();
0028
0029 if (not initWritten_) {
0030 auto psetMapHandle = iRun.getHandle(psetToken_);
0031
0032 std::unique_ptr<InitMsgBuilder> init_message =
0033 serializeRegistry(OutputModule::processName(),
0034 description().moduleLabel(),
0035 moduleDescription().mainParameterSetID(),
0036 psetMapHandle.isValid() ? psetMapHandle.product() : nullptr);
0037
0038 doOutputHeader(*init_message);
0039 lastCallWasBeginRun_ = true;
0040 auto history = iRun.processHistory();
0041 lastHistory_ = history.reduce().id();
0042 initWritten_ = true;
0043
0044 clearHeaderBuffer();
0045 } else {
0046 auto history = iRun.processHistory();
0047 if (lastHistory_ != history.reduce().id()) {
0048 throw edm::Exception(errors::FileWriteError) << "Streamer output can not handle writing a new Run if the "
0049 "ProcessHistory changed since the last Run written.";
0050 }
0051
0052 lastCallWasBeginRun_ = true;
0053 }
0054 }
0055
0056 void StreamerOutputModuleBase::endRun(RunForOutput const&) { stop(); }
0057
0058 void StreamerOutputModuleBase::beginJob() {}
0059
0060 void StreamerOutputModuleBase::endJob() { stop(); }
0061
0062 void StreamerOutputModuleBase::writeRun(RunForOutput const&) {}
0063
0064 void StreamerOutputModuleBase::writeLuminosityBlock(LuminosityBlockForOutput const&) {}
0065
0066 void StreamerOutputModuleBase::write(EventForOutput const& e) {
0067 Handle<TriggerResults> const& triggerResults = getTriggerResults(trToken_, e);
0068
0069 if (lastCallWasBeginRun_) {
0070 auto msg = serializeEventMetaData(*branchIDLists(), *thinnedAssociationsHelper());
0071 doOutputEvent(*msg);
0072 lastCallWasBeginRun_ = false;
0073 }
0074 auto msg = serializeEvent(e, triggerResults, selectorConfig());
0075
0076 doOutputEvent(*msg);
0077 }
0078
0079 Trig StreamerOutputModuleBase::getTriggerResults(EDGetTokenT<TriggerResults> const& token,
0080 EventForOutput const& e) const {
0081 Trig result;
0082 e.getByToken<TriggerResults>(token, result);
0083 return result;
0084 }
0085
0086 void StreamerOutputModuleBase::fillDescription(ParameterSetDescription& desc) {
0087 StreamerOutputModuleCommon::fillDescription(desc);
0088 OutputModule::fillDescription(desc);
0089 desc.addUntracked<edm::InputTag>("psetMap", {"hltPSetMap"})
0090 ->setComment("Optionally allow the map of ParameterSets to be calculated externally.");
0091 }
0092 }