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