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  friend class EndLuminosityBlockSummaryProducer<T, C>;
188 
190  cache_ = globalBeginLuminosityBlockSummary(lb, c);
191  }
192 
194  std::lock_guard<std::mutex> guard(mutex_);
195  streamEndLuminosityBlockSummary(id, lb, c, cache_.get());
196  }
198  globalEndLuminosityBlockSummary(lb, c, cache_.get());
199  }
200 
201  virtual std::shared_ptr<C> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
202  edm::EventSetup const&) const = 0;
203  virtual void streamEndLuminosityBlockSummary(StreamID,
204  edm::LuminosityBlock const&,
205  edm::EventSetup const&,
206  C*) const = 0;
207 
208  virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
209 
210  //When threaded we will have a container for N items where N is # of simultaneous Lumis
211  std::shared_ptr<C> cache_;
213  };
214 
215  template <typename T>
216  class BeginRunProducer : public virtual T {
217  public:
218  BeginRunProducer() = default;
219  BeginRunProducer(BeginRunProducer const&) = delete;
220  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
222 
223  private:
224  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
225 
226  virtual void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
227  };
228 
229  template <typename T>
230  class EndRunProducer : public virtual T {
231  public:
232  EndRunProducer() = default;
233  EndRunProducer(EndRunProducer const&) = delete;
234  EndRunProducer& operator=(EndRunProducer const&) = delete;
236 
237  private:
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  void doEndRunProduce_(Run& rp, EventSetup const& c) final {
253  globalEndRunProduce(rp, c, RunSummaryCacheHolder<T, C>::cache_.get());
254  }
255 
256  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&, C const*) const = 0;
257  };
258 
259  template <typename T>
260  class BeginLuminosityBlockProducer : public virtual T {
261  public:
262  BeginLuminosityBlockProducer() = default;
266 
267  private:
268  void doBeginLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
269  virtual void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
270  };
271 
272  template <typename T>
273  class EndLuminosityBlockProducer : public virtual T {
274  public:
275  EndLuminosityBlockProducer() = default;
277  EndLuminosityBlockProducer& operator=(EndLuminosityBlockProducer const&) = delete;
279 
280  private:
281  void doEndLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
282  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
283  };
284 
285  template <typename T, typename S>
287  public:
292 
293  private:
295  globalEndLuminosityBlockProduce(lb, c, LuminosityBlockSummaryCacheHolder<T, S>::cache_.get());
296  }
297 
298  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, S const*) const = 0;
299  };
300 
301  template <typename T>
302  class ExternalWork : public virtual T {
303  public:
304  ExternalWork() = default;
305  ExternalWork(ExternalWork const&) = delete;
306  ExternalWork& operator=(ExternalWork const&) = delete;
307  ~ExternalWork() noexcept(false) override{};
308 
309  private:
310  bool hasAcquire() const override { return true; }
311 
312  void doAcquire_(StreamID, Event const&, edm::EventSetup const&, WaitingTaskWithArenaHolder&) final;
313 
314  virtual void acquire(StreamID, Event const&, edm::EventSetup const&, WaitingTaskWithArenaHolder) const = 0;
315  };
316 
317  template <typename T>
318  class Accumulator : public virtual T {
319  public:
320  Accumulator() = default;
321  Accumulator(Accumulator const&) = delete;
322  Accumulator& operator=(Accumulator const&) = delete;
323  ~Accumulator() noexcept(false) override{};
324 
325  private:
326  bool hasAccumulator() const override { return true; }
327 
328  void produce(StreamID streamID, Event& ev, EventSetup const& es) const final { accumulate(streamID, ev, es); }
329 
330  virtual void accumulate(StreamID streamID, Event const& ev, EventSetup const& es) const = 0;
331  };
332  } // namespace impl
333  } // namespace global
334 } // namespace edm
335 
336 #endif
static boost::mutex mutex
Definition: Proxy.cc:11
~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:328
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:189
void doEndRunSummary_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:163
~Accumulator()(false) override
Definition: implementors.h:323
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
void doEndRunProduce_(Run &rp, EventSetup const &c) final
Definition: implementors.h:252
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:102
bool hasAcquire() const override
Definition: implementors.h:310
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:294
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:307
bool hasAccumulator() const override
Definition: implementors.h:326
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
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:193
long double T
void doEndLuminosityBlockSummary_(LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:197
void doStreamBeginRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:65
Definition: Run.h:45