File indexing completed on 2025-01-25 08:29:59
0001
0002 #include "FWCore/Framework/interface/global/OutputModule.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/Framework/interface/RunForOutput.h"
0009
0010 #include <memory>
0011 #include <string>
0012 #include <vector>
0013
0014 namespace edm {
0015
0016 class TestGlobalOutput : public global::OutputModule<WatchInputFiles, RunCache<int>, LuminosityBlockCache<int>> {
0017 public:
0018 explicit TestGlobalOutput(ParameterSet const& pset);
0019 ~TestGlobalOutput() override;
0020 static void fillDescriptions(ConfigurationDescriptions& descriptions);
0021
0022 private:
0023 void write(EventForOutput const& e) override;
0024 void writeLuminosityBlock(LuminosityBlockForOutput const&) override;
0025 void writeRun(RunForOutput const&) override;
0026 void writeProcessBlock(ProcessBlockForOutput const&) override;
0027
0028 void respondToOpenInputFile(FileBlock const&) override;
0029 void respondToCloseInputFile(FileBlock const&) override;
0030
0031 std::shared_ptr<int> globalBeginRun(RunForOutput const&) const override;
0032 void globalEndRun(RunForOutput const&) const override;
0033
0034 std::shared_ptr<int> globalBeginLuminosityBlock(LuminosityBlockForOutput const&) const override;
0035 void globalEndLuminosityBlock(LuminosityBlockForOutput const&) const override;
0036 void endJob() override;
0037
0038 bool verbose_;
0039 std::vector<std::string> expectedProcessesWithProcessBlockProducts_;
0040 int expectedWriteProcessBlockTransitions_;
0041 int countWriteProcessBlockTransitions_ = 0;
0042 };
0043
0044 TestGlobalOutput::TestGlobalOutput(ParameterSet const& pset)
0045 : global::OutputModuleBase(pset),
0046 global::OutputModule<WatchInputFiles, RunCache<int>, LuminosityBlockCache<int>>(pset),
0047 verbose_(pset.getUntrackedParameter<bool>("verbose")),
0048 expectedProcessesWithProcessBlockProducts_(
0049 pset.getUntrackedParameter<std::vector<std::string>>("expectedProcessesWithProcessBlockProducts")),
0050 expectedWriteProcessBlockTransitions_(pset.getUntrackedParameter<int>("expectedWriteProcessBlockTransitions")) {
0051 }
0052
0053 TestGlobalOutput::~TestGlobalOutput() {}
0054
0055 void TestGlobalOutput::write(EventForOutput const& e) {
0056 if (verbose_) {
0057 LogAbsolute("TestGlobalOutput") << "global write event";
0058 }
0059 }
0060
0061 void TestGlobalOutput::writeLuminosityBlock(LuminosityBlockForOutput const&) {
0062 if (verbose_) {
0063 LogAbsolute("TestGlobalOutput") << "global writeLuminosityBlock";
0064 }
0065 }
0066
0067 void TestGlobalOutput::writeRun(RunForOutput const&) { LogAbsolute("TestGlobalOutput") << "global writeRun"; }
0068
0069 void TestGlobalOutput::writeProcessBlock(ProcessBlockForOutput const&) {
0070 LogAbsolute("TestGlobalOutput") << "global writeProcessBlock";
0071 ++countWriteProcessBlockTransitions_;
0072 if (!expectedProcessesWithProcessBlockProducts_.empty()) {
0073 for (auto const& process : outputProcessBlockHelper().processesWithProcessBlockProducts()) {
0074 LogAbsolute("TestGlobalOutput") << " " << process;
0075 }
0076 if (expectedProcessesWithProcessBlockProducts_ !=
0077 outputProcessBlockHelper().processesWithProcessBlockProducts()) {
0078 throw cms::Exception("TestFailure") << "TestGlobalOutput::writeProcessBlock unexpected process name list";
0079 }
0080 }
0081 }
0082
0083 void TestGlobalOutput::respondToOpenInputFile(FileBlock const&) {
0084 if (verbose_) {
0085 LogAbsolute("TestGlobalOutput") << "global respondToOpenInputFile";
0086 }
0087 }
0088
0089 void TestGlobalOutput::respondToCloseInputFile(FileBlock const&) {
0090 if (verbose_) {
0091 LogAbsolute("TestGlobalOutput") << "global respondToCloseInputFile";
0092 }
0093 }
0094
0095 std::shared_ptr<int> TestGlobalOutput::globalBeginRun(RunForOutput const& iRun) const {
0096 LogAbsolute("TestGlobalOutput") << "global globalBeginRun";
0097 if (verbose_) {
0098 BranchIDLists const* theBranchIDLists = branchIDLists();
0099 for (auto const& branchIDList : *theBranchIDLists) {
0100 LogAbsolute("TestGlobalOutput") << "A branchID list";
0101 for (auto const& branchID : branchIDList) {
0102 LogAbsolute("TestGlobalOutput") << " global branchID " << branchID;
0103 }
0104 }
0105 for (auto const& it : iRun.productRegistry().productList()) {
0106 LogAbsolute("TestGlobalOutput") << it.second;
0107 }
0108 }
0109 return std::make_shared<int>(0);
0110 }
0111
0112 void TestGlobalOutput::globalEndRun(RunForOutput const&) const {
0113 LogAbsolute("TestGlobalOutput") << "global globalEndRun";
0114 }
0115
0116 std::shared_ptr<int> TestGlobalOutput::globalBeginLuminosityBlock(LuminosityBlockForOutput const&) const {
0117 if (verbose_) {
0118 LogAbsolute("TestGlobalOutput") << "global globalBeginLuminosityBlock";
0119 }
0120 return std::make_shared<int>(0);
0121 }
0122
0123 void TestGlobalOutput::globalEndLuminosityBlock(LuminosityBlockForOutput const&) const {
0124 if (verbose_) {
0125 LogAbsolute("TestGlobalOutput") << "global globalEndLuminosityBlock";
0126 }
0127 }
0128
0129 void TestGlobalOutput::endJob() {
0130 if (expectedWriteProcessBlockTransitions_ >= 0) {
0131 if (expectedWriteProcessBlockTransitions_ != countWriteProcessBlockTransitions_) {
0132 throw cms::Exception("TestFailure")
0133 << "TestGlobalOutput::writeProcessBlock unexpected number of writeProcessBlock transitions";
0134 }
0135 }
0136 }
0137
0138 void TestGlobalOutput::fillDescriptions(ConfigurationDescriptions& descriptions) {
0139 ParameterSetDescription desc;
0140 OutputModule::fillDescription(desc);
0141 desc.addUntracked<bool>("verbose", true);
0142 desc.addUntracked<std::vector<std::string>>("expectedProcessesWithProcessBlockProducts",
0143 std::vector<std::string>());
0144 desc.addUntracked<int>("expectedWriteProcessBlockTransitions", -1);
0145 descriptions.addDefault(desc);
0146 }
0147 }
0148
0149 using edm::TestGlobalOutput;
0150 DEFINE_FWK_MODULE(TestGlobalOutput);