Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-19 01:44:01

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