CMS 3D CMS Logo

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 <memory>
23 #include <mutex>
24 
25 // user include files
32 
33 // forward declarations
34 namespace edm {
35 
36  class WaitingTaskWithArenaHolder;
37 
38  namespace global {
39  namespace impl {
40  class EmptyType {};
41 
42  template <typename T, typename C>
43  class StreamCacheHolder : public virtual T {
44  public:
45  StreamCacheHolder() = default;
47  StreamCacheHolder<T, C>& operator=(StreamCacheHolder<T, C> const&) = delete;
48  ~StreamCacheHolder() override {
49  for (auto c : caches_) {
50  delete c;
51  }
52  }
53 
54  protected:
55  C* streamCache(edm::StreamID iID) const { return caches_[iID.value()]; }
56 
57  private:
58  void preallocStreams(unsigned int iNStreams) final { caches_.resize(iNStreams, static_cast<C*>(nullptr)); }
59  void doBeginStream_(StreamID id) final { caches_[id.value()] = beginStream(id).release(); }
60  void doEndStream_(StreamID id) final {
61  endStream(id);
62  delete caches_[id.value()];
63  caches_[id.value()] = nullptr;
64  }
65  void doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c) final { streamBeginRun(id, rp, c); }
66  void doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c) final { streamEndRun(id, rp, c); }
67  void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) final {
68  streamBeginLuminosityBlock(id, lbp, c);
69  }
70  void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) final {
71  streamEndLuminosityBlock(id, lbp, c);
72  }
73 
74  virtual std::unique_ptr<C> beginStream(edm::StreamID) const = 0;
75  virtual void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const {}
77  edm::LuminosityBlock const&,
78  edm::EventSetup const&) const {}
80  edm::LuminosityBlock const&,
81  edm::EventSetup const&) const {}
82  virtual void streamEndRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const {}
83  virtual void endStream(edm::StreamID) const {}
84 
85  //When threaded we will have a container for N items whre N is # of streams
86  std::vector<C*> caches_;
87  };
88 
89  template <typename T, typename C>
90  class RunCacheHolder : public virtual T {
91  public:
92  RunCacheHolder() = default;
93  RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
94  RunCacheHolder<T, C>& operator=(RunCacheHolder<T, C> const&) = delete;
96 
97  protected:
98  C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
99 
100  private:
101  void doBeginRun_(Run const& rp, EventSetup const& c) final { cache_ = globalBeginRun(rp, c); }
102  void doEndRun_(Run const& rp, EventSetup const& c) final {
103  globalEndRun(rp, c);
104  cache_ = nullptr; // propagate_const<T> has no reset() function
105  }
106 
107  virtual std::shared_ptr<C> globalBeginRun(edm::Run const&, edm::EventSetup const&) const = 0;
108  virtual void globalEndRun(edm::Run const&, edm::EventSetup const&) const = 0;
109  //When threaded we will have a container for N items whre N is # of simultaneous runs
111  };
112 
113  template <typename T, typename C>
114  class LuminosityBlockCacheHolder : public virtual T {
115  public:
116  LuminosityBlockCacheHolder() = default;
120 
121  protected:
122  void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
123 
124  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
125 
126  private:
127  void doBeginLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
128  caches_[lp.index()] = globalBeginLuminosityBlock(lp, c);
129  }
130  void doEndLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
131  globalEndLuminosityBlock(lp, c);
132  caches_[lp.index()].reset();
133  }
134 
135  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
136  edm::EventSetup const&) const = 0;
137  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
138  //When threaded we will have a container for N items whre N is # of simultaneous runs
139  std::unique_ptr<std::shared_ptr<C>[]> caches_;
140  };
141 
142  template <typename T, typename C>
144 
145  template <typename T, typename C>
146  class RunSummaryCacheHolder : public virtual T {
147  public:
148  RunSummaryCacheHolder() = default;
150  RunSummaryCacheHolder<T, C>& operator=(RunSummaryCacheHolder<T, C> const&) = delete;
152 
153  private:
154  friend class EndRunSummaryProducer<T, C>;
155  void doBeginRunSummary_(edm::Run const& rp, EventSetup const& c) final {
156  cache_ = globalBeginRunSummary(rp, c);
157  }
158  void doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c) final {
159  //NOTE: in future this will need to be serialized
160  std::lock_guard<std::mutex> guard(mutex_);
161  streamEndRunSummary(id, rp, c, cache_.get());
162  }
163  void doEndRunSummary_(Run const& rp, EventSetup const& c) final { globalEndRunSummary(rp, c, cache_.get()); }
164 
165  virtual std::shared_ptr<C> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const = 0;
166  virtual void streamEndRunSummary(StreamID, edm::Run const&, edm::EventSetup const&, C*) const = 0;
167 
168  virtual void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, C*) const = 0;
169 
170  //When threaded we will have a container for N items where N is # of simultaneous runs
171  std::shared_ptr<C> cache_;
173  };
174 
175  template <typename T, typename C>
177 
178  template <typename T, typename C>
179  class LuminosityBlockSummaryCacheHolder : public virtual T {
180  public:
185 
186  private:
187  void preallocLumisSummary(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
188 
190 
192  caches_[lb.index()] = globalBeginLuminosityBlockSummary(lb, c);
193  }
194 
196  std::lock_guard<std::mutex> guard(mutex_);
197  streamEndLuminosityBlockSummary(id, lb, c, caches_[lb.index()].get());
198  }
200  globalEndLuminosityBlockSummary(lb, c, caches_[lb.index()].get());
201  maybeClearCache(lb);
202  }
203 
204  virtual std::shared_ptr<C> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
205  edm::EventSetup const&) const = 0;
206  virtual void streamEndLuminosityBlockSummary(StreamID,
207  edm::LuminosityBlock const&,
208  edm::EventSetup const&,
209  C*) const = 0;
210 
211  virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
212 
213  virtual void maybeClearCache(LuminosityBlock const& lb) { caches_[lb.index()].reset(); }
214 
215  //When threaded we will have a container for N items where N is # of simultaneous Lumis
216  std::unique_ptr<std::shared_ptr<C>[]> caches_;
218  };
219 
220  template <typename T>
221  class BeginRunProducer : public virtual T {
222  public:
223  BeginRunProducer() = default;
224  BeginRunProducer(BeginRunProducer const&) = delete;
225  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
227 
228  private:
229  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
230 
231  virtual void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
232  };
233 
234  template <typename T>
235  class EndRunProducer : public virtual T {
236  public:
237  EndRunProducer() = default;
238  EndRunProducer(EndRunProducer const&) = delete;
239  EndRunProducer& operator=(EndRunProducer const&) = delete;
241 
242  private:
243  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
244 
245  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
246  };
247 
248  template <typename T, typename C>
249  class EndRunSummaryProducer : public RunSummaryCacheHolder<T, C> {
250  public:
251  EndRunSummaryProducer() = default;
253  EndRunSummaryProducer& operator=(EndRunSummaryProducer const&) = delete;
255 
256  private:
257  void doEndRunProduce_(Run& rp, EventSetup const& c) final {
258  globalEndRunProduce(rp, c, RunSummaryCacheHolder<T, C>::cache_.get());
259  }
260 
261  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&, C const*) const = 0;
262  };
263 
264  template <typename T>
265  class BeginLuminosityBlockProducer : public virtual T {
266  public:
267  BeginLuminosityBlockProducer() = default;
271 
272  private:
273  void doBeginLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
274  virtual void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
275  };
276 
277  template <typename T>
278  class EndLuminosityBlockProducer : public virtual T {
279  public:
280  EndLuminosityBlockProducer() = default;
282  EndLuminosityBlockProducer& operator=(EndLuminosityBlockProducer const&) = delete;
284 
285  private:
286  void doEndLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
287  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
288  };
289 
290  template <typename T, typename S>
292  public:
297 
298  private:
300  globalEndLuminosityBlockProduce(lb, c, LuminosityBlockSummaryCacheHolder<T, S>::caches_[lb.index()].get());
302  }
303 
304  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, S const*) const = 0;
305 
306  // Do nothing because the cache is cleared in doEndLuminosityBlockProduce_
307  void maybeClearCache(LuminosityBlock const&) final {}
308  };
309 
310  template <typename T>
311  class ExternalWork : public virtual T {
312  public:
313  ExternalWork() = default;
314  ExternalWork(ExternalWork const&) = delete;
315  ExternalWork& operator=(ExternalWork const&) = delete;
316  ~ExternalWork() noexcept(false) override{};
317 
318  private:
319  bool hasAcquire() const override { return true; }
320 
321  void doAcquire_(StreamID, Event const&, edm::EventSetup const&, WaitingTaskWithArenaHolder&) final;
322 
323  virtual void acquire(StreamID, Event const&, edm::EventSetup const&, WaitingTaskWithArenaHolder) const = 0;
324  };
325 
326  template <typename T>
327  class Accumulator : public virtual T {
328  public:
329  Accumulator() = default;
330  Accumulator(Accumulator const&) = delete;
331  Accumulator& operator=(Accumulator const&) = delete;
332  ~Accumulator() noexcept(false) override{};
333 
334  private:
335  bool hasAccumulator() const override { return true; }
336 
337  void produce(StreamID streamID, Event& ev, EventSetup const& es) const final { accumulate(streamID, ev, es); }
338 
339  virtual void accumulate(StreamID streamID, Event const& ev, EventSetup const& es) const = 0;
340  };
341  } // namespace impl
342  } // namespace global
343 } // namespace edm
344 
345 #endif
void preallocLumisSummary(unsigned int iNLumis) final
Definition: implementors.h:187
static boost::mutex mutex
Definition: Proxy.cc:9
LuminosityBlockIndex index() const
~RunCacheHolder()(false) override
Definition: implementors.h:95
virtual void streamEndRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:82
virtual void endStream(edm::StreamID) const
Definition: implementors.h:83
void produce(StreamID streamID, Event &ev, EventSetup const &es) const final
Definition: implementors.h:337
void maybeClearCache(LuminosityBlock const &) final
Definition: implementors.h:307
void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:70
bool ev
void doStreamEndRunSummary_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:158
void doBeginLuminosityBlockSummary_(edm::LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:191
void doEndRunSummary_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:163
~Accumulator()(false) override
Definition: implementors.h:332
virtual void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:75
void preallocStreams(unsigned int iNStreams) final
Definition: implementors.h:58
void doEndStream_(StreamID id) final
Definition: implementors.h:60
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:216
void doEndRunProduce_(Run &rp, EventSetup const &c) final
Definition: implementors.h:257
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:102
bool hasAcquire() const override
Definition: implementors.h:319
edm::propagate_const< std::shared_ptr< C > > cache_
Definition: implementors.h:110
virtual void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:79
void doEndLuminosityBlockProduce_(LuminosityBlock &lb, EventSetup const &c) final
Definition: implementors.h:299
void doStreamEndRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:66
void doBeginLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:127
void doEndLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:130
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:98
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:139
#define noexcept
virtual void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:76
unsigned int value() const
Definition: StreamID.h:42
void doBeginRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:101
~ExternalWork()(false) override
Definition: implementors.h:316
bool hasAccumulator() const override
Definition: implementors.h:335
void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:67
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:124
virtual void maybeClearCache(LuminosityBlock const &lb)
Definition: implementors.h:213
HLT enums.
C * streamCache(edm::StreamID iID) const
Definition: implementors.h:55
void preallocLumis(unsigned int iNLumis) final
Definition: implementors.h:122
void doBeginStream_(StreamID id) final
Definition: implementors.h:59
void doBeginRunSummary_(edm::Run const &rp, EventSetup const &c) final
Definition: implementors.h:155
void doStreamEndLuminosityBlockSummary_(StreamID id, LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:195
long double T
void doEndLuminosityBlockSummary_(LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:199
void doStreamBeginRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:65
Definition: Run.h:45