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  namespace global {
36  namespace impl {
37  class EmptyType {};
38 
39 
40  template <typename T, typename C>
41  class StreamCacheHolder : public virtual T {
42  public:
43  StreamCacheHolder() = default;
44  StreamCacheHolder( StreamCacheHolder<T,C> const&) = delete;
45  StreamCacheHolder<T,C>& operator=(StreamCacheHolder<T,C> const&) = delete;
47  for(auto c: caches_){
48  delete c;
49  }
50  }
51  protected:
52  C * streamCache(edm::StreamID iID) const { return caches_[iID.value()]; }
53  private:
54  virtual void preallocStreams(unsigned int iNStreams) override final {
55  caches_.resize(iNStreams,static_cast<C*>(nullptr));
56  }
57  virtual void doBeginStream_(StreamID id) override final {
58  caches_[id.value()] = beginStream(id).release();
59  }
60  virtual void doEndStream_(StreamID id) override final {
61  endStream(id);
62  delete caches_[id.value()];
63  caches_[id.value()]=nullptr;
64  }
65  virtual void doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c) override final {
66  streamBeginRun(id,rp,c);
67  }
68  virtual void doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c) override final {
69  streamEndRun(id,rp,c);
70  }
71  virtual void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) override final {
72  streamBeginLuminosityBlock(id,lbp,c);
73  }
74  virtual void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) override final {
75  streamEndLuminosityBlock(id,lbp,c);
76  }
77 
78  virtual std::unique_ptr<C> beginStream(edm::StreamID) const = 0;
79  virtual void streamBeginRun(edm::StreamID, edm::Run const&, 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  protected:
97  C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
98  private:
99  void doBeginRun_(Run const& rp, EventSetup const& c) override final {
100  cache_ = globalBeginRun(rp,c);
101  }
102  void doEndRun_(Run const& rp, EventSetup const& c) override 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  protected:
121  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return cache_.get(); }
122  private:
123  void doBeginLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) override final {
124  cache_ = globalBeginLuminosityBlock(rp,c);
125  }
126  void doEndLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) override final {
127  globalEndLuminosityBlock(rp,c);
128  cache_.reset();
129  }
130 
131  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
132  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
133  //When threaded we will have a container for N items whre N is # of simultaneous runs
134  std::shared_ptr<C> cache_;
135  };
136 
137  template<typename T, typename C> class EndRunSummaryProducer;
138 
139  template <typename T, typename C>
140  class RunSummaryCacheHolder : public virtual T {
141  public:
142  RunSummaryCacheHolder() = default;
144  RunSummaryCacheHolder<T,C>& operator=(RunSummaryCacheHolder<T,C> const&) = delete;
146  private:
147  friend class EndRunSummaryProducer<T,C>;
148  void doBeginRunSummary_(edm::Run const& rp, EventSetup const& c) override final {
149  cache_ = globalBeginRunSummary(rp,c);
150  }
151  void doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c) override final {
152  //NOTE: in future this will need to be serialized
153  std::lock_guard<std::mutex> guard(mutex_);
154  streamEndRunSummary(id,rp,c,cache_.get());
155  }
156  void doEndRunSummary_(Run const& rp, EventSetup const& c) override final {
157  globalEndRunSummary(rp,c,cache_.get());
158  }
159 
160  virtual std::shared_ptr<C> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const = 0;
161  virtual void streamEndRunSummary(StreamID, edm::Run const&, edm::EventSetup const&, C*) const = 0;
162 
163  virtual void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, C*) const = 0;
164 
165  //When threaded we will have a container for N items where N is # of simultaneous runs
166  std::shared_ptr<C> cache_;
168  };
169 
170  template<typename T, typename C> class EndLuminosityBlockSummaryProducer;
171 
172 
173  template <typename T, typename C>
174  class LuminosityBlockSummaryCacheHolder : public virtual T {
175  public:
180  private:
181  friend class EndLuminosityBlockSummaryProducer<T,C>;
182 
183  void doBeginLuminosityBlockSummary_(edm::LuminosityBlock const& lb, EventSetup const& c) override final {
184  cache_ = globalBeginLuminosityBlockSummary(lb,c);
185  }
186 
187  virtual void doStreamEndLuminosityBlockSummary_(StreamID id, LuminosityBlock const& lb, EventSetup const& c) override final
188  {
189  std::lock_guard<std::mutex> guard(mutex_);
190  streamEndLuminosityBlockSummary(id,lb,c,cache_.get());
191  }
192  void doEndLuminosityBlockSummary_(LuminosityBlock const& lb, EventSetup const& c) override final {
193  globalEndLuminosityBlockSummary(lb,c,cache_.get());
194  }
195 
196  virtual std::shared_ptr<C> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
197  virtual void streamEndLuminosityBlockSummary(StreamID, edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
198 
199  virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
200 
201  //When threaded we will have a container for N items where N is # of simultaneous Lumis
202  std::shared_ptr<C> cache_;
204  };
205 
206 
207  template <typename T>
208  class BeginRunProducer : public virtual T {
209  public:
210  BeginRunProducer() = default;
211  BeginRunProducer( BeginRunProducer const&) = delete;
212  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
214 
215  private:
216  void doBeginRunProduce_(Run& rp, EventSetup const& c) override final;
217 
218  virtual void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
219  };
220 
221  template <typename T>
222  class EndRunProducer : public virtual T {
223  public:
224  EndRunProducer() = default;
225  EndRunProducer( EndRunProducer const&) = delete;
226  EndRunProducer& operator=(EndRunProducer const&) = delete;
228 
229  private:
230 
231  void doEndRunProduce_(Run& rp, EventSetup const& c) override final;
232 
233  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
234  };
235 
236  template <typename T, typename C>
237  class EndRunSummaryProducer : public RunSummaryCacheHolder<T,C> {
238  public:
239  EndRunSummaryProducer() = default;
241  EndRunSummaryProducer& operator=(EndRunSummaryProducer const&) = delete;
243 
244  private:
245 
246  void doEndRunProduce_(Run& rp, EventSetup const& c) override final {
247  globalEndRunProduce(rp,c,RunSummaryCacheHolder<T,C>::cache_.get());
248  }
249 
250  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&, C const*) const = 0;
251  };
252 
253  template <typename T>
254  class BeginLuminosityBlockProducer : public virtual T {
255  public:
256  BeginLuminosityBlockProducer() = default;
260 
261  private:
262  void doBeginLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) override final;
263  virtual void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
264  };
265 
266  template <typename T>
267  class EndLuminosityBlockProducer : public virtual T {
268  public:
269  EndLuminosityBlockProducer() = default;
271  EndLuminosityBlockProducer& operator=(EndLuminosityBlockProducer const&) = delete;
273 
274  private:
275  void doEndLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) override final;
276  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
277  };
278 
279  template <typename T, typename S>
281  public:
286 
287  private:
288  void doEndLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) override final {
289  globalEndLuminosityBlockProduce(lb,c,LuminosityBlockSummaryCacheHolder<T,S>::cache_.get());
290  }
291 
292  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, S const*) const = 0;
293  };
294  }
295  }
296 }
297 
298 
299 #endif
void doEndLuminosityBlock_(LuminosityBlock const &rp, EventSetup const &c) override final
Definition: implementors.h:126
void doBeginRunSummary_(edm::Run const &rp, EventSetup const &c) override final
Definition: implementors.h:148
static boost::mutex mutex
Definition: LHEProxy.cc:11
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 doEndLuminosityBlockSummary_(LuminosityBlock const &lb, EventSetup const &c) override final
Definition: implementors.h:192
void doEndRunProduce_(Run &rp, EventSetup const &c) override final
Definition: implementors.h:246
#define noexcept
virtual void doStreamEndLuminosityBlockSummary_(StreamID id, LuminosityBlock const &lb, EventSetup const &c) override final
Definition: implementors.h:187
~RunCacheHolder() noexcept(false)
Definition: implementors.h:95
void doBeginLuminosityBlock_(LuminosityBlock const &rp, EventSetup const &c) override final
Definition: implementors.h:123
virtual void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:79
virtual void preallocStreams(unsigned int iNStreams) override final
Definition: implementors.h:54
void doStreamEndRunSummary_(StreamID id, Run const &rp, EventSetup const &c) override final
Definition: implementors.h:151
virtual void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) override final
Definition: implementors.h:74
edm::propagate_const< std::shared_ptr< C > > cache_
Definition: implementors.h:110
virtual void doStreamEndRun_(StreamID id, Run const &rp, EventSetup const &c) override final
Definition: implementors.h:68
virtual void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:81
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:97
virtual void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:80
unsigned int value() const
Definition: StreamID.h:46
void doEndLuminosityBlockProduce_(LuminosityBlock &lb, EventSetup const &c) override final
Definition: implementors.h:288
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:121
virtual void doBeginStream_(StreamID id) override final
Definition: implementors.h:57
HLT enums.
C * streamCache(edm::StreamID iID) const
Definition: implementors.h:52
virtual void doEndStream_(StreamID id) override final
Definition: implementors.h:60
void doEndRun_(Run const &rp, EventSetup const &c) override final
Definition: implementors.h:102
void doBeginLuminosityBlockSummary_(edm::LuminosityBlock const &lb, EventSetup const &c) override final
Definition: implementors.h:183
virtual void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) override final
Definition: implementors.h:71
void doBeginRun_(Run const &rp, EventSetup const &c) override final
Definition: implementors.h:99
void doEndRunSummary_(Run const &rp, EventSetup const &c) override final
Definition: implementors.h:156
long double T
Definition: Run.h:42
virtual void doStreamBeginRun_(StreamID id, Run const &rp, EventSetup const &c) override final
Definition: implementors.h:65