CMS 3D CMS Logo

implementors.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_limited_implementors_h
2 #define FWCore_Framework_limited_implementors_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : implementors
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Thu, 18 Jul 2013 11:52:34 GMT
19 //
20 
21 // system include files
22 #include <memory>
23 #include <mutex>
24 
25 // user include files
32 
33 // forward declarations
34 namespace edm {
35 
36  namespace limited {
37  namespace impl {
38  class EmptyType {
39  public:
41  };
42 
43  template <typename T, typename C>
44  class StreamCacheHolder : public virtual T {
45  public:
46  StreamCacheHolder(edm::ParameterSet const& iPSet) : T(iPSet) {}
48  StreamCacheHolder<T, C>& operator=(StreamCacheHolder<T, C> const&) = delete;
50  for (auto c : caches_) {
51  delete c;
52  }
53  }
54 
55  protected:
56  C* streamCache(edm::StreamID iID) const { return caches_[iID.value()]; }
57 
58  private:
59  void preallocStreams(unsigned int iNStreams) final { caches_.resize(iNStreams, static_cast<C*>(nullptr)); }
60  void doBeginStream_(StreamID id) final { caches_[id.value()] = beginStream(id).release(); }
61  void doEndStream_(StreamID id) final {
62  endStream(id);
63  delete caches_[id.value()];
64  caches_[id.value()] = nullptr;
65  }
66  void doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c) final { streamBeginRun(id, rp, c); }
67  void doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c) final { streamEndRun(id, rp, c); }
68  void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) final {
69  streamBeginLuminosityBlock(id, lbp, c);
70  }
71  void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) final {
72  streamEndLuminosityBlock(id, lbp, c);
73  }
74 
75  virtual std::unique_ptr<C> beginStream(edm::StreamID) const = 0;
76  virtual void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const {}
78  edm::LuminosityBlock const&,
79  edm::EventSetup const&) const {}
81  edm::LuminosityBlock const&,
82  edm::EventSetup const&) const {}
83  virtual void streamEndRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const {}
84  virtual void endStream(edm::StreamID) const {}
85 
86  //When threaded we will have a container for N items whre N is # of streams
87  std::vector<C*> caches_;
88  };
89 
90  template <typename T, typename C>
91  class RunCacheHolder : public virtual T {
92  public:
93  RunCacheHolder(edm::ParameterSet const& iPSet) : T(iPSet) {}
94  RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
95  RunCacheHolder<T, C>& operator=(RunCacheHolder<T, C> const&) = delete;
97 
98  protected:
99  C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
100 
101  private:
102  void doBeginRun_(Run const& rp, EventSetup const& c) final { cache_ = globalBeginRun(rp, c); }
103  void doEndRun_(Run const& rp, EventSetup const& c) final {
104  globalEndRun(rp, c);
105  cache_ = nullptr; // propagate_const<T> has no reset() function
106  }
107 
108  virtual std::shared_ptr<C> globalBeginRun(edm::Run const&, edm::EventSetup const&) const = 0;
109  virtual void globalEndRun(edm::Run const&, edm::EventSetup const&) const = 0;
110  //When threaded we will have a container for N items whre N is # of simultaneous runs
112  };
113 
114  template <typename T, typename C>
115  class LuminosityBlockCacheHolder : public virtual T {
116  public:
121 
122  protected:
123  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
124 
125  private:
126  void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
127 
128  void doBeginLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
129  caches_[lp.index()] = globalBeginLuminosityBlock(lp, c);
130  }
131  void doEndLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
132  globalEndLuminosityBlock(lp, c);
133  caches_[lp.index()].reset();
134  }
135 
136  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
137  edm::EventSetup const&) const = 0;
138  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
139  //When threaded we will have a container for N items whre N is # of simultaneous runs
140  std::unique_ptr<std::shared_ptr<C>[]> caches_;
141  };
142 
143  template <typename T, typename C>
145 
146  template <typename T, typename C>
147  class RunSummaryCacheHolder : public virtual T {
148  public:
149  RunSummaryCacheHolder(edm::ParameterSet const& iPSet) : T(iPSet) {}
151  RunSummaryCacheHolder<T, C>& operator=(RunSummaryCacheHolder<T, C> const&) = delete;
153 
154  private:
155  friend class EndRunSummaryProducer<T, C>;
156  void doBeginRunSummary_(edm::Run const& rp, EventSetup const& c) final {
157  cache_ = globalBeginRunSummary(rp, c);
158  }
159  void doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c) final {
160  //NOTE: in future this will need to be serialized
161  std::lock_guard<std::mutex> guard(mutex_);
162  streamEndRunSummary(id, rp, c, cache_.get());
163  }
164  void doEndRunSummary_(Run const& rp, EventSetup const& c) final { globalEndRunSummary(rp, c, cache_.get()); }
165 
166  virtual std::shared_ptr<C> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const = 0;
167  virtual void streamEndRunSummary(StreamID, edm::Run const&, edm::EventSetup const&, C*) const = 0;
168 
169  virtual void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, C*) const = 0;
170 
171  //When threaded we will have a container for N items where N is # of simultaneous runs
172  std::shared_ptr<C> cache_;
174  };
175 
176  template <typename T, typename C>
178 
179  template <typename T, typename C>
180  class LuminosityBlockSummaryCacheHolder : public virtual T {
181  public:
186 
187  private:
188  friend class EndLuminosityBlockSummaryProducer<T, C>;
189 
191  cache_ = globalBeginLuminosityBlockSummary(lb, c);
192  }
193 
195  std::lock_guard<std::mutex> guard(mutex_);
196  streamEndLuminosityBlockSummary(id, lb, c, cache_.get());
197  }
199  globalEndLuminosityBlockSummary(lb, c, cache_.get());
200  }
201 
202  virtual std::shared_ptr<C> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
203  edm::EventSetup const&) const = 0;
204  virtual void streamEndLuminosityBlockSummary(StreamID,
205  edm::LuminosityBlock const&,
206  edm::EventSetup const&,
207  C*) const = 0;
208 
209  virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
210 
211  //When threaded we will have a container for N items where N is # of simultaneous Lumis
212  std::shared_ptr<C> cache_;
214  };
215 
216  template <typename T>
217  class BeginRunProducer : public virtual T {
218  public:
219  BeginRunProducer(edm::ParameterSet const& iPSet) : T(iPSet) {}
220  BeginRunProducer(BeginRunProducer const&) = delete;
221  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
223 
224  private:
225  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
226 
227  virtual void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
228  };
229 
230  template <typename T>
231  class EndRunProducer : public virtual T {
232  public:
233  EndRunProducer(edm::ParameterSet const& iPSet) : T(iPSet) {}
234  EndRunProducer(EndRunProducer const&) = delete;
235  EndRunProducer& operator=(EndRunProducer const&) = delete;
237 
238  private:
239  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
240 
241  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
242  };
243 
244  template <typename T, typename C>
245  class EndRunSummaryProducer : public RunSummaryCacheHolder<T, C> {
246  public:
247  EndRunSummaryProducer(edm::ParameterSet const& iPSet) : T(iPSet), RunSummaryCacheHolder<T, C>(iPSet) {}
249  EndRunSummaryProducer& operator=(EndRunSummaryProducer const&) = delete;
251 
252  private:
253  void doEndRunProduce_(Run& rp, EventSetup const& c) final {
254  globalEndRunProduce(rp, c, RunSummaryCacheHolder<T, C>::cache_.get());
255  }
256 
257  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&, C const*) const = 0;
258  };
259 
260  template <typename T>
261  class BeginLuminosityBlockProducer : public virtual T {
262  public:
267 
268  private:
269  void doBeginLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
270  virtual void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
271  };
272 
273  template <typename T>
274  class EndLuminosityBlockProducer : public virtual T {
275  public:
278  EndLuminosityBlockProducer& operator=(EndLuminosityBlockProducer const&) = delete;
280 
281  private:
282  void doEndLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
283  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
284  };
285 
286  template <typename T, typename S>
288  public:
290  : T(iPSet), LuminosityBlockSummaryCacheHolder<T, S>(iPSet) {}
294 
295  private:
297  globalEndLuminosityBlockProduce(lb, c, LuminosityBlockSummaryCacheHolder<T, S>::cache_.get());
298  }
299 
300  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, S const*) const = 0;
301  };
302 
303  template <typename T>
304  class Accumulator : public virtual T {
305  public:
306  Accumulator(edm::ParameterSet const& iPSet) : T(iPSet) {}
307  Accumulator() = default;
308  Accumulator(Accumulator const&) = delete;
309  Accumulator& operator=(Accumulator const&) = delete;
310  ~Accumulator() noexcept(false) override{};
311 
312  private:
313  bool hasAccumulator() const override { return true; }
314 
315  void produce(StreamID streamID, Event& ev, EventSetup const& es) const final { accumulate(streamID, ev, es); }
316 
317  virtual void accumulate(StreamID streamID, Event const& ev, EventSetup const& es) const = 0;
318  };
319  } // namespace impl
320  } // namespace limited
321 } // namespace edm
322 
323 #endif
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:99
static boost::mutex mutex
Definition: Proxy.cc:11
void doBeginLuminosityBlockSummary_(edm::LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:190
void doEndStream_(StreamID id) final
Definition: implementors.h:61
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:103
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:123
StreamCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:46
virtual void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:76
void doEndRunSummary_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:164
void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:71
bool ev
void doBeginRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:102
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:140
BeginLuminosityBlockProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:263
virtual void endStream(edm::StreamID) const
Definition: implementors.h:84
void doEndLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:131
void preallocStreams(unsigned int iNStreams) final
Definition: implementors.h:59
LuminosityBlockSummaryCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:182
void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:68
void doStreamEndRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:67
edm::propagate_const< std::shared_ptr< C > > cache_
Definition: implementors.h:111
void doEndLuminosityBlockSummary_(LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:198
EndRunSummaryProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:247
EmptyType(edm::ParameterSet const &)
Definition: implementors.h:40
LuminosityBlockCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:117
BeginRunProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:219
RunCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:93
void doBeginLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:128
RunSummaryCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:149
void doEndRunProduce_(Run &rp, EventSetup const &c) final
Definition: implementors.h:253
Accumulator(edm::ParameterSet const &iPSet)
Definition: implementors.h:306
virtual void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:80
EndRunProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:233
void doStreamEndLuminosityBlockSummary_(StreamID id, LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:194
void doBeginStream_(StreamID id) final
Definition: implementors.h:60
void doStreamEndRunSummary_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:159
EndLuminosityBlockSummaryProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:289
EndLuminosityBlockProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:276
#define noexcept
~Accumulator()(false) override
Definition: implementors.h:310
unsigned int value() const
Definition: StreamID.h:42
void doEndLuminosityBlockProduce_(LuminosityBlock &lb, EventSetup const &c) final
Definition: implementors.h:296
void doStreamBeginRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:66
HLT enums.
void doBeginRunSummary_(edm::Run const &rp, EventSetup const &c) final
Definition: implementors.h:156
virtual void streamEndRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:83
bool hasAccumulator() const override
Definition: implementors.h:313
virtual void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:77
C * streamCache(edm::StreamID iID) const
Definition: implementors.h:56
long double T
Definition: Run.h:45
void produce(StreamID streamID, Event &ev, EventSetup const &es) const final
Definition: implementors.h:315
void preallocLumis(unsigned int iNLumis) final
Definition: implementors.h:126