Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:36

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Integration
0004 // Class  :     ThingAnalyzer
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  root
0010 //         Created:  Fri, 21 Apr 2017 13:34:58 GMT
0011 //
0012 
0013 // system include files
0014 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0015 #include "DataFormats/TestObjects/interface/ThingCollection.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/LuminosityBlock.h"
0018 #include "FWCore/Framework/interface/Run.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/Utilities/interface/Exception.h"
0021 #include "FWCore/Utilities/interface/EDGetToken.h"
0022 
0023 // user include files
0024 
0025 namespace edmtest {
0026   struct Empty {};
0027   class ThingAnalyzer : public edm::global::EDAnalyzer<edm::RunCache<Empty>, edm::LuminosityBlockCache<Empty>> {
0028   public:
0029     ThingAnalyzer(edm::ParameterSet const&);
0030 
0031     void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override final;
0032     std::shared_ptr<Empty> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override final;
0033     void globalEndRun(edm::Run const&, edm::EventSetup const&) const override final;
0034     std::shared_ptr<Empty> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0035                                                       edm::EventSetup const&) const override final;
0036     void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const override final;
0037 
0038     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0039 
0040   private:
0041     void shouldBeInvalid(edm::Handle<ThingCollection> const&) const;
0042 
0043     edm::EDGetTokenT<ThingCollection> beginRun_;
0044     edm::EDGetTokenT<ThingCollection> beginLumi_;
0045     edm::EDGetTokenT<ThingCollection> event_;
0046     edm::EDGetTokenT<ThingCollection> endLumi_;
0047     edm::EDGetTokenT<ThingCollection> endRun_;
0048   };
0049 
0050   ThingAnalyzer::ThingAnalyzer(edm::ParameterSet const& iPSet)
0051       : beginRun_(consumes<edm::InRun>(iPSet.getUntrackedParameter<edm::InputTag>("beginRun"))),
0052         beginLumi_(consumes<edm::InLumi>(iPSet.getUntrackedParameter<edm::InputTag>("beginLumi"))),
0053         event_(consumes(iPSet.getUntrackedParameter<edm::InputTag>("event"))),
0054         endLumi_(consumes<edm::InLumi>(iPSet.getUntrackedParameter<edm::InputTag>("endLumi"))),
0055         endRun_(consumes<edm::InRun>(iPSet.getUntrackedParameter<edm::InputTag>("endRun"))) {}
0056 
0057   void ThingAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0058     edm::ParameterSetDescription desc;
0059     desc.addUntracked("beginRun", edm::InputTag{"thing", "beginRun"})->setComment("Collection to get from Run");
0060     desc.addUntracked("beginLumi", edm::InputTag{"thing", "beginLumi"})->setComment("Collection to get from Lumi");
0061     desc.addUntracked("event", edm::InputTag{"thing", ""})->setComment("Collection to get from event");
0062     desc.addUntracked("endLumi", edm::InputTag{"thing", "endLumi"})
0063         ->setComment("Collection to get from Lumi but only available at end");
0064     desc.addUntracked("endRun", edm::InputTag{"thing", "endRun"})
0065         ->setComment("Collection to get from Run but only available at end");
0066     descriptions.add("thingAnalyzer", desc);
0067   }
0068 
0069   void ThingAnalyzer::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0070     auto const& lumi = iEvent.getLuminosityBlock();
0071 
0072     auto const& run = lumi.getRun();
0073 
0074     (void)run.get(beginRun_);
0075 
0076     shouldBeInvalid(run.getHandle(endRun_));
0077 
0078     (void)lumi.get(beginLumi_);
0079 
0080     shouldBeInvalid(lumi.getHandle(endLumi_));
0081 
0082     (void)iEvent.get(event_);
0083   }
0084 
0085   std::shared_ptr<Empty> ThingAnalyzer::globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const {
0086     (void)iRun.get(beginRun_);
0087 
0088     shouldBeInvalid(iRun.getHandle(endRun_));
0089 
0090     return std::shared_ptr<Empty>();
0091   }
0092 
0093   void ThingAnalyzer::globalEndRun(edm::Run const& iRun, edm::EventSetup const&) const {
0094     (void)iRun.get(beginRun_);
0095 
0096     (void)iRun.get(endRun_);
0097   }
0098 
0099   std::shared_ptr<Empty> ThingAnalyzer::globalBeginLuminosityBlock(edm::LuminosityBlock const& iLumi,
0100                                                                    edm::EventSetup const&) const {
0101     auto const& run = iLumi.getRun();
0102 
0103     (void)run.get(beginRun_);
0104 
0105     shouldBeInvalid(run.getHandle(endRun_));
0106 
0107     (void)iLumi.get(beginLumi_);
0108 
0109     shouldBeInvalid(iLumi.getHandle(endLumi_));
0110 
0111     return std::shared_ptr<Empty>();
0112   }
0113 
0114   void ThingAnalyzer::globalEndLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) const {
0115     auto const& run = iLumi.getRun();
0116 
0117     (void)run.get(beginRun_);
0118 
0119     shouldBeInvalid(run.getHandle(endRun_));
0120 
0121     (void)iLumi.get(beginLumi_);
0122 
0123     (void)iLumi.get(endLumi_);
0124   }
0125 
0126   void ThingAnalyzer::shouldBeInvalid(edm::Handle<ThingCollection> const& iHandle) const {
0127     if (iHandle.isValid()) {
0128       throw cms::Exception("ShouldNotBeValid") << "handle was valid when it should not have been";
0129     }
0130   }
0131 
0132 }  // namespace edmtest
0133 
0134 DEFINE_FWK_MODULE(edmtest::ThingAnalyzer);