CMS 3D CMS Logo

implementors.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_one_implementors_h
2 #define FWCore_Framework_one_implementors_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : implementors
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Thu, 09 May 2013 18:40:17 GMT
19 //
20 
21 // system include files
22 #include <string>
23 #include <set>
24 
25 // user include files
32 
33 // forward declarations
34 
35 namespace edm {
37 
38  namespace one {
39  namespace impl {
40  template <bool V>
42 
43  template <>
45  edm::SerialTaskQueue* queue() { return &queue_; }
47  };
48 
49  template <>
51  edm::SerialTaskQueue* queue() { return nullptr; }
52  };
53 
54  template <typename T>
55  class SharedResourcesUser : public virtual T {
56  public:
57  template <typename... Args>
58  SharedResourcesUser(Args... args) : T(args...) {}
60  SharedResourcesUser& operator=(SharedResourcesUser const&) = delete;
61 
62  ~SharedResourcesUser() override {}
63 
64  protected:
65  void usesResource(std::string const& iName);
66  void usesResource();
67 
68  private:
69  SharedResourcesAcquirer createAcquirer() override;
70  std::set<std::string> resourceNames_;
71  };
72 
73  template <typename T>
74  class RunWatcher : public virtual T {
75  public:
76  RunWatcher() = default;
77  RunWatcher(RunWatcher const&) = delete;
78  RunWatcher& operator=(RunWatcher const&) = delete;
79  ~RunWatcher() noexcept(false) override{};
80 
81  private:
82  void doBeginRun_(Run const& rp, EventSetup const& c) final;
83  void doEndRun_(Run const& rp, EventSetup const& c) final;
84 
85  virtual void beginRun(edm::Run const&, edm::EventSetup const&) = 0;
86  virtual void endRun(edm::Run const&, edm::EventSetup const&) = 0;
87  };
88 
89  template <typename T>
90  class LuminosityBlockWatcher : public virtual T {
91  public:
92  LuminosityBlockWatcher() = default;
94  LuminosityBlockWatcher& operator=(LuminosityBlockWatcher const&) = delete;
96 
97  private:
98  void doBeginLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) final;
99  void doEndLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) final;
100 
101  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
102  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
103  };
104 
105  template <typename T>
106  class BeginRunProducer : public virtual T {
107  public:
108  BeginRunProducer() = default;
109  BeginRunProducer(BeginRunProducer const&) = delete;
110  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
112 
113  private:
114  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
115 
116  virtual void beginRunProduce(edm::Run&, edm::EventSetup const&) = 0;
117  };
118 
119  template <typename T>
120  class EndRunProducer : public virtual T {
121  public:
122  EndRunProducer() = default;
123  EndRunProducer(EndRunProducer const&) = delete;
124  EndRunProducer& operator=(EndRunProducer const&) = delete;
126 
127  private:
128  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
129 
130  virtual void endRunProduce(edm::Run&, edm::EventSetup const&) = 0;
131  };
132 
133  template <typename T>
134  class BeginLuminosityBlockProducer : public virtual T {
135  public:
136  BeginLuminosityBlockProducer() = default;
140 
141  private:
142  void doBeginLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) final;
143 
144  virtual void beginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) = 0;
145  };
146 
147  template <typename T>
148  class EndLuminosityBlockProducer : public virtual T {
149  public:
150  EndLuminosityBlockProducer() = default;
152  EndLuminosityBlockProducer& operator=(EndLuminosityBlockProducer const&) = delete;
154 
155  private:
156  void doEndLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) final;
157 
158  virtual void endLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) = 0;
159  };
160 
161  template <typename T, typename C>
162  class RunCacheHolder : public virtual T {
163  public:
164  RunCacheHolder() = default;
165  RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
166  RunCacheHolder<T, C>& operator=(RunCacheHolder<T, C> const&) = delete;
168 
169  protected:
170  C* runCache(edm::RunIndex iID) { return cache_.get(); }
171  C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
172 
173  private:
174  void doBeginRun_(Run const& rp, EventSetup const& c) final { cache_ = globalBeginRun(rp, c); }
175  void doEndRun_(Run const& rp, EventSetup const& c) final {
176  globalEndRun(rp, c);
177  cache_ = nullptr; // propagate_const<T> has no reset() function
178  }
179 
180  virtual std::shared_ptr<C> globalBeginRun(edm::Run const&, edm::EventSetup const&) const = 0;
181  virtual void globalEndRun(edm::Run const&, edm::EventSetup const&) = 0;
182  //When threaded we will have a container for N items whre N is # of simultaneous runs
184  };
185 
186  template <typename T, typename C>
187  class LuminosityBlockCacheHolder : public virtual T {
188  public:
189  LuminosityBlockCacheHolder() = default;
193 
194  protected:
195  void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
196 
197  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
198  C* luminosityBlockCache(edm::LuminosityBlockIndex iID) { return caches_[iID].get(); }
199 
200  private:
201  void doBeginLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
202  caches_[lp.index()] = globalBeginLuminosityBlock(lp, c);
203  }
204  void doEndLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
205  globalEndLuminosityBlock(lp, c);
206  caches_[lp.index()].reset();
207  }
208 
209  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
210  edm::EventSetup const&) const = 0;
211  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
212  std::unique_ptr<std::shared_ptr<C>[]> caches_;
213  };
214 
215  template <typename T>
216  class Accumulator : public virtual T {
217  public:
218  Accumulator() = default;
219  Accumulator(Accumulator const&) = delete;
220  Accumulator& operator=(Accumulator const&) = delete;
221  ~Accumulator() noexcept(false) override{};
222 
223  private:
224  bool hasAccumulator() const override { return true; }
225 
226  void produce(Event& ev, EventSetup const& es) final { accumulate(ev, es); }
227 
228  virtual void accumulate(Event const& ev, EventSetup const& es) = 0;
229  };
230  } // namespace impl
231  } // namespace one
232 } // namespace edm
233 
234 #endif
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:212
void produce(Event &ev, EventSetup const &es) final
Definition: implementors.h:226
~RunWatcher()(false) override
Definition: implementors.h:79
bool ev
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:175
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:171
C * runCache(edm::RunIndex iID)
Definition: implementors.h:170
~RunCacheHolder()(false) override
Definition: implementors.h:167
bool hasAccumulator() const override
Definition: implementors.h:224
void doEndLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:204
~BeginRunProducer()(false) override
Definition: implementors.h:111
edm::propagate_const< std::shared_ptr< C > > cache_
Definition: implementors.h:183
~Accumulator()(false) override
Definition: implementors.h:221
#define noexcept
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:197
void preallocLumis(unsigned int iNLumis) final
Definition: implementors.h:195
~EndRunProducer()(false) override
Definition: implementors.h:125
std::set< std::string > resourceNames_
Definition: implementors.h:70
void doBeginRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:174
C * luminosityBlockCache(edm::LuminosityBlockIndex iID)
Definition: implementors.h:198
HLT enums.
long double T
void doBeginLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:201
Definition: Run.h:45