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 
43  template <typename T, typename C>
44  class StreamCacheHolder : public virtual T {
45  public:
46  StreamCacheHolder() = default;
47  StreamCacheHolder( StreamCacheHolder<T,C> const&) = delete;
48  StreamCacheHolder<T,C>& operator=(StreamCacheHolder<T,C> const&) = delete;
49  ~StreamCacheHolder() override {
50  for(auto c: caches_){
51  delete c;
52  }
53  }
54  protected:
55  C * streamCache(edm::StreamID iID) const { return caches_[iID.value()]; }
56  private:
57  void preallocStreams(unsigned int iNStreams) final {
58  caches_.resize(iNStreams,static_cast<C*>(nullptr));
59  }
60  void doBeginStream_(StreamID id) final {
61  caches_[id.value()] = beginStream(id).release();
62  }
63  void doEndStream_(StreamID id) final {
64  endStream(id);
65  delete caches_[id.value()];
66  caches_[id.value()]=nullptr;
67  }
68  void doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c) final {
69  streamBeginRun(id,rp,c);
70  }
71  void doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c) final {
72  streamEndRun(id,rp,c);
73  }
74  void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) final {
75  streamBeginLuminosityBlock(id,lbp,c);
76  }
77  void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) final {
78  streamEndLuminosityBlock(id,lbp,c);
79  }
80 
81  virtual std::unique_ptr<C> beginStream(edm::StreamID) const = 0;
82  virtual void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const {}
85  virtual void streamEndRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const {}
86  virtual void endStream(edm::StreamID) const {}
87 
88  //When threaded we will have a container for N items whre N is # of streams
89  std::vector<C*> caches_;
90  };
91 
92  template <typename T, typename C>
93  class RunCacheHolder : public virtual T {
94  public:
95  RunCacheHolder() = default;
96  RunCacheHolder( RunCacheHolder<T,C> const&) = delete;
97  RunCacheHolder<T,C>& operator=(RunCacheHolder<T,C> const&) = delete;
98  ~RunCacheHolder() noexcept(false) override {};
99  protected:
100  C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
101  private:
102  void doBeginRun_(Run const& rp, EventSetup const& c) final {
103  cache_ = globalBeginRun(rp,c);
104  }
105  void doEndRun_(Run const& rp, EventSetup const& c) final {
106  globalEndRun(rp,c);
107  cache_ = nullptr; // propagate_const<T> has no reset() function
108  }
109 
110  virtual std::shared_ptr<C> globalBeginRun(edm::Run const&, edm::EventSetup const&) const = 0;
111  virtual void globalEndRun(edm::Run const&, edm::EventSetup const&) const = 0;
112  //When threaded we will have a container for N items whre N is # of simultaneous runs
114  };
115 
116  template <typename T, typename C>
117  class LuminosityBlockCacheHolder : public virtual T {
118  public:
119  LuminosityBlockCacheHolder() = default;
123  protected:
124  void preallocLumis(unsigned int iNLumis) final {
125  caches_.reset( new std::shared_ptr<C>[iNLumis]);
126  }
127 
128  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
129  private:
130  void doBeginLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
131  caches_[lp.index()] = globalBeginLuminosityBlock(lp,c);
132  }
133  void doEndLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
134  globalEndLuminosityBlock(lp,c);
135  caches_[lp.index()].reset();
136  }
137 
138  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
139  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
140  //When threaded we will have a container for N items whre N is # of simultaneous runs
141  std::unique_ptr<std::shared_ptr<C>[]> caches_;
142  };
143 
144  template<typename T, typename C> class EndRunSummaryProducer;
145 
146  template <typename T, typename C>
147  class RunSummaryCacheHolder : public virtual T {
148  public:
149  RunSummaryCacheHolder() = default;
151  RunSummaryCacheHolder<T,C>& operator=(RunSummaryCacheHolder<T,C> const&) = delete;
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 {
164  globalEndRunSummary(rp,c,cache_.get());
165  }
166 
167  virtual std::shared_ptr<C> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const = 0;
168  virtual void streamEndRunSummary(StreamID, edm::Run const&, edm::EventSetup const&, C*) const = 0;
169 
170  virtual void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, C*) const = 0;
171 
172  //When threaded we will have a container for N items where N is # of simultaneous runs
173  std::shared_ptr<C> cache_;
175  };
176 
177  template<typename T, typename C> class EndLuminosityBlockSummaryProducer;
178 
179 
180  template <typename T, typename C>
181  class LuminosityBlockSummaryCacheHolder : public virtual T {
182  public:
187  private:
188  friend class EndLuminosityBlockSummaryProducer<T,C>;
189 
191  cache_ = globalBeginLuminosityBlockSummary(lb,c);
192  }
193 
195  {
196  std::lock_guard<std::mutex> guard(mutex_);
197  streamEndLuminosityBlockSummary(id,lb,c,cache_.get());
198  }
200  globalEndLuminosityBlockSummary(lb,c,cache_.get());
201  }
202 
203  virtual std::shared_ptr<C> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
204  virtual void streamEndLuminosityBlockSummary(StreamID, edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
205 
206  virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
207 
208  //When threaded we will have a container for N items where N is # of simultaneous Lumis
209  std::shared_ptr<C> cache_;
211  };
212 
213 
214  template <typename T>
215  class BeginRunProducer : public virtual T {
216  public:
217  BeginRunProducer() = default;
218  BeginRunProducer( BeginRunProducer const&) = delete;
219  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
221 
222  private:
223  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
224 
225  virtual void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
226  };
227 
228  template <typename T>
229  class EndRunProducer : public virtual T {
230  public:
231  EndRunProducer() = default;
232  EndRunProducer( EndRunProducer const&) = delete;
233  EndRunProducer& operator=(EndRunProducer const&) = delete;
235 
236  private:
237 
238  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
239 
240  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
241  };
242 
243  template <typename T, typename C>
244  class EndRunSummaryProducer : public RunSummaryCacheHolder<T,C> {
245  public:
246  EndRunSummaryProducer() = default;
248  EndRunSummaryProducer& operator=(EndRunSummaryProducer const&) = delete;
250 
251  private:
252 
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:
263  BeginLuminosityBlockProducer() = default;
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:
276  EndLuminosityBlockProducer() = default;
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:
293 
294  private:
296  globalEndLuminosityBlockProduce(lb,c,LuminosityBlockSummaryCacheHolder<T,S>::cache_.get());
297  }
298 
299  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, S const*) const = 0;
300  };
301 
302  template <typename T>
303  class ExternalWork : public virtual T {
304  public:
305  ExternalWork() = default;
306  ExternalWork(ExternalWork const&) = delete;
307  ExternalWork& operator=(ExternalWork const&) = delete;
308  ~ExternalWork() noexcept(false) override {};
309 
310  private:
311 
312  bool hasAcquire() const override { return true; }
313 
314  void doAcquire_(StreamID,
315  Event const&,
316  edm::EventSetup const&,
318 
319  virtual void acquire(StreamID,
320  Event const&,
321  edm::EventSetup const&,
322  WaitingTaskWithArenaHolder) const = 0;
323  };
324 
325  template <typename T>
326  class Accumulator : public virtual T {
327  public:
328  Accumulator() = default;
329  Accumulator(Accumulator const&) = delete;
330  Accumulator& operator=(Accumulator const&) = delete;
331  ~Accumulator() noexcept(false) override {};
332 
333  private:
334 
335  bool hasAccumulator() const override { return true; }
336 
337  void produce(StreamID streamID, Event& ev, EventSetup const& es) const final {
338  accumulate(streamID, ev, es);
339  }
340 
341  virtual void accumulate(StreamID streamID, Event const& ev, EventSetup const& es) const = 0;
342  };
343  }
344  }
345 }
346 
347 
348 #endif
static boost::mutex mutex
Definition: Proxy.cc:11
~RunCacheHolder()(false) override
Definition: implementors.h:98
virtual void streamEndRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:85
virtual void endStream(edm::StreamID) const
Definition: implementors.h:86
void produce(StreamID streamID, Event &ev, EventSetup const &es) const final
Definition: implementors.h:337
void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:77
#define noexcept
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:190
void doEndRunSummary_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:163
~Accumulator()(false) override
Definition: implementors.h:331
virtual void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:82
void preallocStreams(unsigned int iNStreams) final
Definition: implementors.h:57
void doEndStream_(StreamID id) final
Definition: implementors.h:63
void doEndRunProduce_(Run &rp, EventSetup const &c) final
Definition: implementors.h:253
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:105
bool hasAcquire() const override
Definition: implementors.h:312
edm::propagate_const< std::shared_ptr< C > > cache_
Definition: implementors.h:113
virtual void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:84
void doEndLuminosityBlockProduce_(LuminosityBlock &lb, EventSetup const &c) final
Definition: implementors.h:295
void doStreamEndRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:71
void doBeginLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:130
void doEndLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:133
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:100
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:141
virtual void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:83
unsigned int value() const
Definition: StreamID.h:46
void doBeginRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:102
~ExternalWork()(false) override
Definition: implementors.h:308
bool hasAccumulator() const override
Definition: implementors.h:335
void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:74
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:128
HLT enums.
C * streamCache(edm::StreamID iID) const
Definition: implementors.h:55
void preallocLumis(unsigned int iNLumis) final
Definition: implementors.h:124
void doBeginStream_(StreamID id) final
Definition: implementors.h:60
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:194
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:68
Definition: Run.h:43