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  void preallocLumisSummary(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
189 
191 
193  caches_[lb.index()] = globalBeginLuminosityBlockSummary(lb, c);
194  }
195 
197  std::lock_guard<std::mutex> guard(mutex_);
198  streamEndLuminosityBlockSummary(id, lb, c, caches_[lb.index()].get());
199  }
201  globalEndLuminosityBlockSummary(lb, c, caches_[lb.index()].get());
202  maybeClearCache(lb);
203  }
204 
205  virtual std::shared_ptr<C> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
206  edm::EventSetup const&) const = 0;
207  virtual void streamEndLuminosityBlockSummary(StreamID,
208  edm::LuminosityBlock const&,
209  edm::EventSetup const&,
210  C*) const = 0;
211 
212  virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
213 
214  virtual void maybeClearCache(LuminosityBlock const& lb) { caches_[lb.index()].reset(); }
215 
216  //When threaded we will have a container for N items where N is # of simultaneous Lumis
217  std::unique_ptr<std::shared_ptr<C>[]> caches_;
219  };
220 
221  template <typename T>
222  class BeginRunProducer : public virtual T {
223  public:
224  BeginRunProducer(edm::ParameterSet const& iPSet) : T(iPSet) {}
225  BeginRunProducer(BeginRunProducer const&) = delete;
226  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
228 
229  private:
230  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
231 
232  virtual void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
233  };
234 
235  template <typename T>
236  class EndRunProducer : public virtual T {
237  public:
238  EndRunProducer(edm::ParameterSet const& iPSet) : T(iPSet) {}
239  EndRunProducer(EndRunProducer const&) = delete;
240  EndRunProducer& operator=(EndRunProducer const&) = delete;
242 
243  private:
244  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
245 
246  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
247  };
248 
249  template <typename T, typename C>
250  class EndRunSummaryProducer : public RunSummaryCacheHolder<T, C> {
251  public:
252  EndRunSummaryProducer(edm::ParameterSet const& iPSet) : T(iPSet), RunSummaryCacheHolder<T, C>(iPSet) {}
254  EndRunSummaryProducer& operator=(EndRunSummaryProducer const&) = delete;
256 
257  private:
258  void doEndRunProduce_(Run& rp, EventSetup const& c) final {
259  globalEndRunProduce(rp, c, RunSummaryCacheHolder<T, C>::cache_.get());
260  }
261 
262  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&, C const*) const = 0;
263  };
264 
265  template <typename T>
266  class BeginLuminosityBlockProducer : public virtual T {
267  public:
272 
273  private:
274  void doBeginLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
275  virtual void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
276  };
277 
278  template <typename T>
279  class EndLuminosityBlockProducer : public virtual T {
280  public:
283  EndLuminosityBlockProducer& operator=(EndLuminosityBlockProducer const&) = delete;
285 
286  private:
287  void doEndLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
288  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
289  };
290 
291  template <typename T, typename S>
293  public:
295  : T(iPSet), LuminosityBlockSummaryCacheHolder<T, S>(iPSet) {}
299 
300  private:
302  globalEndLuminosityBlockProduce(lb, c, LuminosityBlockSummaryCacheHolder<T, S>::caches_[lb.index()].get());
304  }
305 
306  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, S const*) const = 0;
307 
308  // Do nothing because the cache is cleared in doEndLuminosityBlockProduce_
309  void maybeClearCache(LuminosityBlock const&) final {}
310  };
311 
312  template <typename T>
313  class Accumulator : public virtual T {
314  public:
315  Accumulator(edm::ParameterSet const& iPSet) : T(iPSet) {}
316  Accumulator() = default;
317  Accumulator(Accumulator const&) = delete;
318  Accumulator& operator=(Accumulator const&) = delete;
319  ~Accumulator() noexcept(false) override{};
320 
321  private:
322  bool hasAccumulator() const override { return true; }
323 
324  void produce(StreamID streamID, Event& ev, EventSetup const& es) const final { accumulate(streamID, ev, es); }
325 
326  virtual void accumulate(StreamID streamID, Event const& ev, EventSetup const& es) const = 0;
327  };
328  } // namespace impl
329  } // namespace limited
330 } // namespace edm
331 
332 #endif
void preallocLumisSummary(unsigned int iNLumis) final
Definition: implementors.h:188
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:99
static boost::mutex mutex
Definition: Proxy.cc:9
void doBeginLuminosityBlockSummary_(edm::LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:192
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
LuminosityBlockIndex index() const
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:268
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:200
EndRunSummaryProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:252
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:224
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:258
Accumulator(edm::ParameterSet const &iPSet)
Definition: implementors.h:315
virtual void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:80
EndRunProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:238
void maybeClearCache(LuminosityBlock const &) final
Definition: implementors.h:309
void doStreamEndLuminosityBlockSummary_(StreamID id, LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:196
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:294
EndLuminosityBlockProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:281
#define noexcept
~Accumulator()(false) override
Definition: implementors.h:319
unsigned int value() const
Definition: StreamID.h:42
void doEndLuminosityBlockProduce_(LuminosityBlock &lb, EventSetup const &c) final
Definition: implementors.h:301
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
virtual void maybeClearCache(LuminosityBlock const &lb)
Definition: implementors.h:214
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:217
bool hasAccumulator() const override
Definition: implementors.h:322
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:324
void preallocLumis(unsigned int iNLumis) final
Definition: implementors.h:126