CMS 3D CMS Logo

ThingAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Integration
4 // Class : ThingAnalyzer
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: root
10 // Created: Fri, 21 Apr 2017 13:34:58 GMT
11 //
12 
13 // system include files
15 #include "DataFormats/TestObjects/interface/ThingCollection.h"
22 
23 // user include files
24 
25 namespace edmtest {
26  struct Empty {};
27  class ThingAnalyzer : public edm::global::EDAnalyzer<edm::RunCache<Empty>, edm::LuminosityBlockCache<Empty>> {
28  public:
30 
31  void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const final;
32  std::shared_ptr<Empty> globalBeginRun(edm::Run const&, edm::EventSetup const&) const final;
33  void globalEndRun(edm::Run const&, edm::EventSetup const&) const final;
34  std::shared_ptr<Empty> globalBeginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const final;
35  void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const final;
36 
37  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
38 
39  private:
41 
47  };
48 
50  : beginRun_(consumes<edm::InRun>(iPSet.getUntrackedParameter<edm::InputTag>("beginRun"))),
51  beginLumi_(consumes<edm::InLumi>(iPSet.getUntrackedParameter<edm::InputTag>("beginLumi"))),
52  event_(consumes(iPSet.getUntrackedParameter<edm::InputTag>("event"))),
53  endLumi_(consumes<edm::InLumi>(iPSet.getUntrackedParameter<edm::InputTag>("endLumi"))),
54  endRun_(consumes<edm::InRun>(iPSet.getUntrackedParameter<edm::InputTag>("endRun"))) {}
55 
58  desc.addUntracked("beginRun", edm::InputTag{"thing", "beginRun"})->setComment("Collection to get from Run");
59  desc.addUntracked("beginLumi", edm::InputTag{"thing", "beginLumi"})->setComment("Collection to get from Lumi");
60  desc.addUntracked("event", edm::InputTag{"thing", ""})->setComment("Collection to get from event");
61  desc.addUntracked("endLumi", edm::InputTag{"thing", "endLumi"})
62  ->setComment("Collection to get from Lumi but only available at end");
63  desc.addUntracked("endRun", edm::InputTag{"thing", "endRun"})
64  ->setComment("Collection to get from Run but only available at end");
65  descriptions.add("thingAnalyzer", desc);
66  }
67 
69  auto const& lumi = iEvent.getLuminosityBlock();
70 
71  auto const& run = lumi.getRun();
72 
73  (void)run.get(beginRun_);
74 
75  shouldBeInvalid(run.getHandle(endRun_));
76 
77  (void)lumi.get(beginLumi_);
78 
79  shouldBeInvalid(lumi.getHandle(endLumi_));
80 
81  (void)iEvent.get(event_);
82  }
83 
84  std::shared_ptr<Empty> ThingAnalyzer::globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const {
85  (void)iRun.get(beginRun_);
86 
88 
89  return std::shared_ptr<Empty>();
90  }
91 
92  void ThingAnalyzer::globalEndRun(edm::Run const& iRun, edm::EventSetup const&) const {
93  (void)iRun.get(beginRun_);
94 
95  (void)iRun.get(endRun_);
96  }
97 
99  edm::EventSetup const&) const {
100  auto const& run = iLumi.getRun();
101 
102  (void)run.get(beginRun_);
103 
104  shouldBeInvalid(run.getHandle(endRun_));
105 
106  (void)iLumi.get(beginLumi_);
107 
109 
110  return std::shared_ptr<Empty>();
111  }
112 
114  auto const& run = iLumi.getRun();
115 
116  (void)run.get(beginRun_);
117 
118  shouldBeInvalid(run.getHandle(endRun_));
119 
120  (void)iLumi.get(beginLumi_);
121 
122  (void)iLumi.get(endLumi_);
123  }
124 
126  if (iHandle.isValid()) {
127  throw cms::Exception("ShouldNotBeValid") << "handle was valid when it should not have been";
128  }
129  }
130 
131 } // namespace edmtest
132 
Run const & getRun() const
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const final
ThingAnalyzer(edm::ParameterSet const &)
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
edm::EDGetTokenT< ThingCollection > endLumi_
int iEvent
Definition: GenABIO.cc:224
std::shared_ptr< Empty > globalBeginRun(edm::Run const &, edm::EventSetup const &) const final
void shouldBeInvalid(edm::Handle< ThingCollection > const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PROD const & get(EDGetTokenT< PROD > token) const noexcept(false)
Definition: Run.h:352
edm::EDGetTokenT< ThingCollection > beginLumi_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< ThingCollection > endRun_
edm::EDGetTokenT< ThingCollection > beginRun_
void globalEndRun(edm::Run const &, edm::EventSetup const &) const final
HLT enums.
std::shared_ptr< Empty > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const final
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
PROD const & get(EDGetTokenT< PROD > token) const noexcept(false)
void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const final
edm::EDGetTokenT< ThingCollection > event_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Run.h:343
Definition: Run.h:45