CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
implementors.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_global_implementors_h
2 #define FWCore_Framework_global_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 <cstddef>
23 #include <memory>
24 #include <mutex>
25 #include <string>
26 #include <tuple>
27 #include <utility>
28 #include <vector>
29 
30 // user include files
42 
43 // forward declarations
44 namespace edm {
45 
46  class WaitingTaskWithArenaHolder;
47 
48  namespace global {
49  namespace impl {
50  class EmptyType {};
51 
52  template <typename T, typename C>
53  class StreamCacheHolder : public virtual T {
54  public:
55  StreamCacheHolder() = default;
58  ~StreamCacheHolder() override {
59  for (auto c : caches_) {
60  delete c;
61  }
62  }
63 
64  protected:
65  C* streamCache(edm::StreamID iID) const { return caches_[iID.value()]; }
66 
67  private:
68  void preallocStreams(unsigned int iNStreams) final { caches_.resize(iNStreams, static_cast<C*>(nullptr)); }
69  void doBeginStream_(StreamID id) final { caches_[id.value()] = beginStream(id).release(); }
70  void doEndStream_(StreamID id) final {
71  endStream(id);
72  delete caches_[id.value()];
73  caches_[id.value()] = nullptr;
74  }
75  void doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c) final { streamBeginRun(id, rp, c); }
76  void doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c) final { streamEndRun(id, rp, c); }
77  void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) final {
78  streamBeginLuminosityBlock(id, lbp, c);
79  }
80  void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) final {
81  streamEndLuminosityBlock(id, lbp, c);
82  }
83 
84  virtual std::unique_ptr<C> beginStream(edm::StreamID) const = 0;
85  virtual void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const {}
87  edm::LuminosityBlock const&,
88  edm::EventSetup const&) const {}
90  edm::LuminosityBlock const&,
91  edm::EventSetup const&) const {}
92  virtual void streamEndRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const {}
93  virtual void endStream(edm::StreamID) const {}
94 
95  //When threaded we will have a container for N items whre N is # of streams
96  std::vector<C*> caches_;
97  };
98 
99  template <typename T, typename... CacheTypes>
100  class InputProcessBlockCacheHolder : public virtual T {
101  public:
102  InputProcessBlockCacheHolder() = default;
106 
107  std::tuple<CacheHandle<CacheTypes>...> processBlockCaches(Event const& event) const {
108  return cacheImpl_.processBlockCaches(event);
109  }
110 
111  template <std::size_t ICacheType, typename DataType, typename Func>
113  cacheImpl_.template registerProcessBlockCacheFiller<ICacheType, DataType, Func>(token,
114  std::forward<Func>(func));
115  }
116 
117  template <typename CacheType, typename DataType, typename Func>
119  cacheImpl_.template registerProcessBlockCacheFiller<CacheType, DataType, Func>(token,
120  std::forward<Func>(func));
121  }
122 
123  // This is intended for use by Framework unit tests only
124  unsigned int cacheSize() const { return cacheImpl_.cacheSize(); }
125 
126  private:
127  void doSelectInputProcessBlocks(ProductRegistry const& productRegistry,
128  ProcessBlockHelperBase const& processBlockHelperBase) final {
129  cacheImpl_.selectInputProcessBlocks(productRegistry, processBlockHelperBase, *this);
130  }
131 
132  void doAccessInputProcessBlock_(ProcessBlock const& pb) final {
133  cacheImpl_.accessInputProcessBlock(pb);
135  }
136 
137  // Alternate method to access ProcessBlocks without using the caches
138  // Mostly intended for unit testing, but might have other uses...
139  virtual void accessInputProcessBlock(ProcessBlock const&) {}
140 
141  void clearInputProcessBlockCaches() final { cacheImpl_.clearCaches(); }
142 
144  };
145 
146  template <typename T, typename C>
147  class RunCacheHolder : public virtual T {
148  public:
149  RunCacheHolder() = default;
150  RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
152  ~RunCacheHolder() noexcept(false) override{};
153 
154  protected:
155  C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
156 
157  private:
158  void doBeginRun_(Run const& rp, EventSetup const& c) final { cache_ = globalBeginRun(rp, c); }
159  void doEndRun_(Run const& rp, EventSetup const& c) final {
160  globalEndRun(rp, c);
161  cache_ = nullptr; // propagate_const<T> has no reset() function
162  }
163 
164  virtual std::shared_ptr<C> globalBeginRun(edm::Run const&, edm::EventSetup const&) const = 0;
165  virtual void globalEndRun(edm::Run const&, edm::EventSetup const&) const = 0;
166  //When threaded we will have a container for N items whre N is # of simultaneous runs
168  };
169 
170  template <typename T, typename C>
171  class LuminosityBlockCacheHolder : public virtual T {
172  public:
173  LuminosityBlockCacheHolder() = default;
176  ~LuminosityBlockCacheHolder() noexcept(false) override{};
177 
178  protected:
179  void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
180 
181  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
182 
183  private:
184  void doBeginLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
185  caches_[lp.index()] = globalBeginLuminosityBlock(lp, c);
186  }
187  void doEndLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
189  caches_[lp.index()].reset();
190  }
191 
192  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
193  edm::EventSetup const&) const = 0;
194  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
195  //When threaded we will have a container for N items whre N is # of simultaneous runs
196  std::unique_ptr<std::shared_ptr<C>[]> caches_;
197  };
198 
199  template <typename T, typename C>
201 
202  template <typename T, typename C>
203  class RunSummaryCacheHolder : public virtual T {
204  public:
205  RunSummaryCacheHolder() = default;
208  ~RunSummaryCacheHolder() noexcept(false) override{};
209 
210  private:
211  friend class EndRunSummaryProducer<T, C>;
212  void doBeginRunSummary_(edm::Run const& rp, EventSetup const& c) final {
214  }
215  void doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c) final {
216  //NOTE: in future this will need to be serialized
217  std::lock_guard<std::mutex> guard(mutex_);
218  streamEndRunSummary(id, rp, c, cache_.get());
219  }
220  void doEndRunSummary_(Run const& rp, EventSetup const& c) final { globalEndRunSummary(rp, c, cache_.get()); }
221 
222  virtual std::shared_ptr<C> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const = 0;
223  virtual void streamEndRunSummary(StreamID, edm::Run const&, edm::EventSetup const&, C*) const = 0;
224 
225  virtual void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, C*) const = 0;
226 
227  //When threaded we will have a container for N items where N is # of simultaneous runs
228  std::shared_ptr<C> cache_;
230  };
231 
232  template <typename T, typename C>
234 
235  template <typename T, typename C>
236  class LuminosityBlockSummaryCacheHolder : public virtual T {
237  public:
242 
243  private:
244  void preallocLumisSummary(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
245 
247 
249  caches_[lb.index()] = globalBeginLuminosityBlockSummary(lb, c);
250  }
251 
253  std::lock_guard<std::mutex> guard(mutex_);
254  streamEndLuminosityBlockSummary(id, lb, c, caches_[lb.index()].get());
255  }
257  globalEndLuminosityBlockSummary(lb, c, caches_[lb.index()].get());
258  maybeClearCache(lb);
259  }
260 
261  virtual std::shared_ptr<C> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
262  edm::EventSetup const&) const = 0;
264  edm::LuminosityBlock const&,
265  edm::EventSetup const&,
266  C*) const = 0;
267 
268  virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
269 
270  virtual void maybeClearCache(LuminosityBlock const& lb) { caches_[lb.index()].reset(); }
271 
272  //When threaded we will have a container for N items where N is # of simultaneous Lumis
273  std::unique_ptr<std::shared_ptr<C>[]> caches_;
275  };
276 
277  template <typename T>
278  class WatchProcessBlock : public virtual T {
279  public:
280  WatchProcessBlock() = default;
281  WatchProcessBlock(WatchProcessBlock const&) = delete;
283  ~WatchProcessBlock() noexcept(false) override {}
284 
285  private:
286  void doBeginProcessBlock_(ProcessBlock const&) final;
288 
290  virtual void endProcessBlock(ProcessBlock const&) {}
291  };
292 
293  template <typename T>
294  class BeginProcessBlockProducer : public virtual T {
295  public:
296  BeginProcessBlockProducer() = default;
299  ~BeginProcessBlockProducer() noexcept(false) override{};
300 
301  private:
303 
304  virtual void beginProcessBlockProduce(edm::ProcessBlock&) = 0;
305  };
306 
307  template <typename T>
308  class EndProcessBlockProducer : public virtual T {
309  public:
310  EndProcessBlockProducer() = default;
313  ~EndProcessBlockProducer() noexcept(false) override{};
314 
315  private:
316  void doEndProcessBlockProduce_(ProcessBlock&) final;
317 
318  virtual void endProcessBlockProduce(edm::ProcessBlock&) = 0;
319  };
320 
321  template <typename T>
322  class BeginRunProducer : public virtual T {
323  public:
324  BeginRunProducer() = default;
325  BeginRunProducer(BeginRunProducer const&) = delete;
326  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
327  ~BeginRunProducer() noexcept(false) override{};
328 
329  private:
330  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
331 
332  virtual void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
333  };
334 
335  template <typename T>
336  class EndRunProducer : public virtual T {
337  public:
338  EndRunProducer() = default;
339  EndRunProducer(EndRunProducer const&) = delete;
340  EndRunProducer& operator=(EndRunProducer const&) = delete;
341  ~EndRunProducer() noexcept(false) override{};
342 
343  private:
344  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
345 
346  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
347  };
348 
349  template <typename T, typename C>
350  class EndRunSummaryProducer : public RunSummaryCacheHolder<T, C> {
351  public:
352  EndRunSummaryProducer() = default;
353  EndRunSummaryProducer(EndRunSummaryProducer const&) = delete;
354  EndRunSummaryProducer& operator=(EndRunSummaryProducer const&) = delete;
355  ~EndRunSummaryProducer() noexcept(false) override{};
356 
357  private:
358  void doEndRunProduce_(Run& rp, EventSetup const& c) final {
359  globalEndRunProduce(rp, c, RunSummaryCacheHolder<T, C>::cache_.get());
360  }
361 
362  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&, C const*) const = 0;
363  };
364 
365  template <typename T>
366  class BeginLuminosityBlockProducer : public virtual T {
367  public:
368  BeginLuminosityBlockProducer() = default;
371  ~BeginLuminosityBlockProducer() noexcept(false) override{};
372 
373  private:
374  void doBeginLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
375  virtual void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
376  };
377 
378  template <typename T>
379  class EndLuminosityBlockProducer : public virtual T {
380  public:
381  EndLuminosityBlockProducer() = default;
384  ~EndLuminosityBlockProducer() noexcept(false) override{};
385 
386  private:
387  void doEndLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
388  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
389  };
390 
391  template <typename T, typename S>
392  class EndLuminosityBlockSummaryProducer : public LuminosityBlockSummaryCacheHolder<T, S> {
393  public:
394  EndLuminosityBlockSummaryProducer() = default;
395  EndLuminosityBlockSummaryProducer(EndLuminosityBlockSummaryProducer const&) = delete;
396  EndLuminosityBlockSummaryProducer& operator=(EndLuminosityBlockSummaryProducer const&) = delete;
398 
399  private:
401  globalEndLuminosityBlockProduce(lb, c, LuminosityBlockSummaryCacheHolder<T, S>::caches_[lb.index()].get());
403  }
404 
405  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, S const*) const = 0;
406 
407  // Do nothing because the cache is cleared in doEndLuminosityBlockProduce_
408  void maybeClearCache(LuminosityBlock const&) final {}
409  };
410 
411  template <typename T>
412  class ExternalWork : public virtual T {
413  public:
414  ExternalWork() = default;
415  ExternalWork(ExternalWork const&) = delete;
416  ExternalWork& operator=(ExternalWork const&) = delete;
417  ~ExternalWork() noexcept(false) override{};
418 
419  private:
420  bool hasAcquire() const override { return true; }
421 
422  void doAcquire_(StreamID, Event const&, edm::EventSetup const&, WaitingTaskWithArenaHolder&) final;
423 
424  virtual void acquire(StreamID, Event const&, edm::EventSetup const&, WaitingTaskWithArenaHolder) const = 0;
425  };
426 
427  template <typename T>
428  class Accumulator : public virtual T {
429  public:
430  Accumulator() = default;
431  Accumulator(Accumulator const&) = delete;
432  Accumulator& operator=(Accumulator const&) = delete;
433  ~Accumulator() noexcept(false) override{};
434 
435  private:
436  bool hasAccumulator() const override { return true; }
437 
438  void produce(StreamID streamID, Event& ev, EventSetup const& es) const final { accumulate(streamID, ev, es); }
439 
440  virtual void accumulate(StreamID streamID, Event const& ev, EventSetup const& es) const = 0;
441  };
442  } // namespace impl
443  } // namespace global
444 } // namespace edm
445 
446 #endif
void preallocLumisSummary(unsigned int iNLumis) final
Definition: implementors.h:244
~EndLuminosityBlockSummaryProducer() noexcept(false) override
Definition: implementors.h:397
bool hasAcquire() const override
Definition: implementors.h:420
InputProcessBlockCacheHolder & operator=(InputProcessBlockCacheHolder const &)=delete
const edm::EventSetup & c
~LuminosityBlockSummaryCacheHolder() noexcept(false) override
Definition: implementors.h:241
~EndRunProducer() noexcept(false) override
Definition: implementors.h:341
LuminosityBlockIndex index() const
virtual void globalEndRun(edm::Run const &, edm::EventSetup const &) const =0
StreamCacheHolder< T, C > & operator=(StreamCacheHolder< T, C > const &)=delete
virtual void streamEndRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:92
virtual void endStream(edm::StreamID) const
Definition: implementors.h:93
RunCacheHolder< T, C > & operator=(RunCacheHolder< T, C > const &)=delete
~EndRunSummaryProducer() noexcept(false) override
Definition: implementors.h:355
void maybeClearCache(LuminosityBlock const &) final
Definition: implementors.h:408
~BeginProcessBlockProducer() noexcept(false) override
Definition: implementors.h:299
static std::mutex mutex
Definition: Proxy.cc:8
void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:80
~EndLuminosityBlockProducer() noexcept(false) override
Definition: implementors.h:384
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
~EndProcessBlockProducer() noexcept(false) override
Definition: implementors.h:313
void doStreamEndRunSummary_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:215
void doBeginLuminosityBlockSummary_(edm::LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:248
virtual std::shared_ptr< C > globalBeginLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &) const =0
WatchProcessBlock & operator=(WatchProcessBlock const &)=delete
void doEndRunSummary_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:220
~Accumulator() noexcept(false) override
Definition: implementors.h:433
virtual void streamEndRunSummary(StreamID, edm::Run const &, edm::EventSetup const &, C *) const =0
virtual std::unique_ptr< C > beginStream(edm::StreamID) const =0
virtual void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:85
virtual void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const =0
virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, C *) const =0
~BeginRunProducer() noexcept(false) override
Definition: implementors.h:327
void preallocStreams(unsigned int iNStreams) final
Definition: implementors.h:68
void doEndStream_(StreamID id) final
Definition: implementors.h:70
~RunSummaryCacheHolder() noexcept(false) override
Definition: implementors.h:208
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:273
virtual void beginProcessBlockProduce(edm::ProcessBlock &)=0
void doEndRunProduce_(Run &rp, EventSetup const &c) final
Definition: implementors.h:358
void doBeginProcessBlock_(ProcessBlock const &) final
virtual std::shared_ptr< C > globalBeginRun(edm::Run const &, edm::EventSetup const &) const =0
void doEndProcessBlock_(ProcessBlock const &) final
virtual void streamEndLuminosityBlockSummary(StreamID, edm::LuminosityBlock const &, edm::EventSetup const &, C *) const =0
std::tuple< CacheHandle< CacheTypes >...> processBlockCaches(Event const &event) const
Definition: implementors.h:107
LuminosityBlockCacheHolder< T, C > & operator=(LuminosityBlockCacheHolder< T, C > const &)=delete
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:159
void doBeginProcessBlockProduce_(ProcessBlock &) final
edm::propagate_const< std::shared_ptr< C > > cache_
Definition: implementors.h:167
virtual void beginProcessBlock(ProcessBlock const &)
Definition: implementors.h:289
~RunCacheHolder() noexcept(false) override
Definition: implementors.h:152
LuminosityBlockSummaryCacheHolder< T, C > & operator=(LuminosityBlockSummaryCacheHolder< T, C > const &)=delete
virtual void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:89
virtual std::shared_ptr< C > globalBeginRunSummary(edm::Run const &, edm::EventSetup const &) const =0
void doStreamEndRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:76
void doBeginLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:184
RunSummaryCacheHolder< T, C > & operator=(RunSummaryCacheHolder< T, C > const &)=delete
void doEndLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:187
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:155
bool hasAccumulator() const override
Definition: implementors.h:436
virtual void endProcessBlock(ProcessBlock const &)
Definition: implementors.h:290
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:196
virtual void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:86
void doSelectInputProcessBlocks(ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase) final
Definition: implementors.h:127
edm::impl::InputProcessBlockCacheImpl< CacheTypes...> cacheImpl_
Definition: implementors.h:143
unsigned int value() const
Definition: StreamID.h:43
void doBeginRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:158
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&func)
Definition: implementors.h:112
void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:77
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:181
virtual void maybeClearCache(LuminosityBlock const &lb)
Definition: implementors.h:270
constexpr element_type const * get() const
~LuminosityBlockCacheHolder() noexcept(false) override
Definition: implementors.h:176
virtual void globalEndRunSummary(edm::Run const &, edm::EventSetup const &, C *) const =0
void doEndLuminosityBlockProduce_(LuminosityBlock &lb, EventSetup const &c) final
Definition: implementors.h:400
BeginProcessBlockProducer & operator=(BeginProcessBlockProducer const &)=delete
C * streamCache(edm::StreamID iID) const
Definition: implementors.h:65
void preallocLumis(unsigned int iNLumis) final
Definition: implementors.h:179
void doBeginStream_(StreamID id) final
Definition: implementors.h:69
void doBeginRunSummary_(edm::Run const &rp, EventSetup const &c) final
Definition: implementors.h:212
~ExternalWork() noexcept(false) override
Definition: implementors.h:417
void doStreamEndLuminosityBlockSummary_(StreamID id, LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:252
void doAccessInputProcessBlock_(ProcessBlock const &pb) final
Definition: implementors.h:132
~WatchProcessBlock() noexcept(false) override
Definition: implementors.h:283
virtual void accessInputProcessBlock(ProcessBlock const &)
Definition: implementors.h:139
long double T
~BeginLuminosityBlockProducer() noexcept(false) override
Definition: implementors.h:371
void doEndLuminosityBlockSummary_(LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:256
void doStreamBeginRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:75
virtual std::shared_ptr< C > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const =0
def template
Definition: svgfig.py:521
void produce(StreamID streamID, Event &ev, EventSetup const &es) const final
Definition: implementors.h:438
Definition: Run.h:45