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