CMS 3D CMS Logo

implementors.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_limited_implementors_h
2 #define FWCore_Framework_limited_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 limited {
36  namespace impl {
37  class EmptyType {
38  public:
40  };
41 
42 
43  template <typename T, typename C>
44  class StreamCacheHolder : public virtual T {
45  public:
46  StreamCacheHolder(edm::ParameterSet const& iPSet) : T(iPSet) {}
47  StreamCacheHolder( StreamCacheHolder<T,C> const&) = delete;
48  StreamCacheHolder<T,C>& operator=(StreamCacheHolder<T,C> const&) = delete;
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(edm::ParameterSet const& iPSet) : T(iPSet) {}
96  RunCacheHolder( RunCacheHolder<T,C> const&) = delete;
97  RunCacheHolder<T,C>& operator=(RunCacheHolder<T,C> const&) = delete;
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:
123  protected:
124  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return cache_.get(); }
125  private:
126  void doBeginLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) final {
127  cache_ = globalBeginLuminosityBlock(rp,c);
128  }
129  void doEndLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) final {
130  globalEndLuminosityBlock(rp,c);
131  cache_.reset();
132  }
133 
134  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
135  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
136  //When threaded we will have a container for N items whre N is # of simultaneous runs
137  std::shared_ptr<C> cache_;
138  };
139 
140  template<typename T, typename C> class EndRunSummaryProducer;
141 
142  template <typename T, typename C>
143  class RunSummaryCacheHolder : public virtual T {
144  public:
145  RunSummaryCacheHolder(edm::ParameterSet const& iPSet) : T(iPSet) {}
147  RunSummaryCacheHolder<T,C>& operator=(RunSummaryCacheHolder<T,C> const&) = delete;
149  private:
150  friend class EndRunSummaryProducer<T,C>;
151  void doBeginRunSummary_(edm::Run const& rp, EventSetup const& c) final {
152  cache_ = globalBeginRunSummary(rp,c);
153  }
154  void doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c) final {
155  //NOTE: in future this will need to be serialized
156  std::lock_guard<std::mutex> guard(mutex_);
157  streamEndRunSummary(id,rp,c,cache_.get());
158  }
159  void doEndRunSummary_(Run const& rp, EventSetup const& c) final {
160  globalEndRunSummary(rp,c,cache_.get());
161  }
162 
163  virtual std::shared_ptr<C> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const = 0;
164  virtual void streamEndRunSummary(StreamID, edm::Run const&, edm::EventSetup const&, C*) const = 0;
165 
166  virtual void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, C*) const = 0;
167 
168  //When threaded we will have a container for N items where N is # of simultaneous runs
169  std::shared_ptr<C> cache_;
171  };
172 
173  template<typename T, typename C> class EndLuminosityBlockSummaryProducer;
174 
175 
176  template <typename T, typename C>
177  class LuminosityBlockSummaryCacheHolder : public virtual T {
178  public:
183  private:
184  friend class EndLuminosityBlockSummaryProducer<T,C>;
185 
187  cache_ = globalBeginLuminosityBlockSummary(lb,c);
188  }
189 
191  {
192  std::lock_guard<std::mutex> guard(mutex_);
193  streamEndLuminosityBlockSummary(id,lb,c,cache_.get());
194  }
196  globalEndLuminosityBlockSummary(lb,c,cache_.get());
197  }
198 
199  virtual std::shared_ptr<C> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&) const = 0;
200  virtual void streamEndLuminosityBlockSummary(StreamID, edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
201 
202  virtual void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
203 
204  //When threaded we will have a container for N items where N is # of simultaneous Lumis
205  std::shared_ptr<C> cache_;
207  };
208 
209 
210  template <typename T>
211  class BeginRunProducer : public virtual T {
212  public:
213  BeginRunProducer(edm::ParameterSet const& iPSet) : T(iPSet) {}
214  BeginRunProducer( BeginRunProducer const&) = delete;
215  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
217 
218  private:
219  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
220 
221  virtual void globalBeginRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
222  };
223 
224  template <typename T>
225  class EndRunProducer : public virtual T {
226  public:
227  EndRunProducer(edm::ParameterSet const& iPSet) : T(iPSet) {}
228  EndRunProducer( EndRunProducer const&) = delete;
229  EndRunProducer& operator=(EndRunProducer const&) = delete;
231 
232  private:
233 
234  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
235 
236  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&) const = 0;
237  };
238 
239  template <typename T, typename C>
240  class EndRunSummaryProducer : public RunSummaryCacheHolder<T,C> {
241  public:
244  EndRunSummaryProducer& operator=(EndRunSummaryProducer const&) = delete;
246 
247  private:
248 
249  void doEndRunProduce_(Run& rp, EventSetup const& c) final {
250  globalEndRunProduce(rp,c,RunSummaryCacheHolder<T,C>::cache_.get());
251  }
252 
253  virtual void globalEndRunProduce(edm::Run&, edm::EventSetup const&, C const*) const = 0;
254  };
255 
256  template <typename T>
257  class BeginLuminosityBlockProducer : public virtual T {
258  public:
263 
264  private:
265  void doBeginLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
266  virtual void globalBeginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
267  };
268 
269  template <typename T>
270  class EndLuminosityBlockProducer : public virtual T {
271  public:
274  EndLuminosityBlockProducer& operator=(EndLuminosityBlockProducer const&) = delete;
276 
277  private:
278  void doEndLuminosityBlockProduce_(LuminosityBlock& lb, EventSetup const& c) final;
279  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) const = 0;
280  };
281 
282  template <typename T, typename S>
284  public:
289 
290  private:
292  globalEndLuminosityBlockProduce(lb,c,LuminosityBlockSummaryCacheHolder<T,S>::cache_.get());
293  }
294 
295  virtual void globalEndLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&, S const*) const = 0;
296  };
297  }
298  }
299 }
300 
301 
302 #endif
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:100
void doBeginLuminosityBlockSummary_(edm::LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:186
void doEndStream_(StreamID id) final
Definition: implementors.h:63
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:105
~EndLuminosityBlockProducer() noexcept(false) override
Definition: implementors.h:275
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:124
StreamCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:46
virtual void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:82
static boost::mutex mutex
Definition: LHEProxy.cc:11
void doEndRunSummary_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:159
void doEndLuminosityBlock_(LuminosityBlock const &rp, EventSetup const &c) final
Definition: implementors.h:129
#define noexcept
void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:77
void doBeginRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:102
BeginLuminosityBlockProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:259
virtual void endStream(edm::StreamID) const
Definition: implementors.h:86
~BeginLuminosityBlockProducer() noexcept(false) override
Definition: implementors.h:262
void preallocStreams(unsigned int iNStreams) final
Definition: implementors.h:57
~EndRunProducer() noexcept(false) override
Definition: implementors.h:230
LuminosityBlockSummaryCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:179
void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const &lbp, EventSetup const &c) final
Definition: implementors.h:74
void doStreamEndRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:71
edm::propagate_const< std::shared_ptr< C > > cache_
Definition: implementors.h:113
void doEndLuminosityBlockSummary_(LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:195
EndRunSummaryProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:242
EmptyType(edm::ParameterSet const &)
Definition: implementors.h:39
LuminosityBlockCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:119
BeginRunProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:213
RunCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:95
RunSummaryCacheHolder(edm::ParameterSet const &iPSet)
Definition: implementors.h:145
void doEndRunProduce_(Run &rp, EventSetup const &c) final
Definition: implementors.h:249
virtual void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:84
EndRunProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:227
void doBeginLuminosityBlock_(LuminosityBlock const &rp, EventSetup const &c) final
Definition: implementors.h:126
void doStreamEndLuminosityBlockSummary_(StreamID id, LuminosityBlock const &lb, EventSetup const &c) final
Definition: implementors.h:190
void doBeginStream_(StreamID id) final
Definition: implementors.h:60
void doStreamEndRunSummary_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:154
EndLuminosityBlockSummaryProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:285
EndLuminosityBlockProducer(edm::ParameterSet const &iPSet)
Definition: implementors.h:272
~BeginRunProducer() noexcept(false) override
Definition: implementors.h:216
unsigned int value() const
Definition: StreamID.h:46
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
void doEndLuminosityBlockProduce_(LuminosityBlock &lb, EventSetup const &c) final
Definition: implementors.h:291
void doStreamBeginRun_(StreamID id, Run const &rp, EventSetup const &c) final
Definition: implementors.h:68
HLT enums.
void doBeginRunSummary_(edm::Run const &rp, EventSetup const &c) final
Definition: implementors.h:151
virtual void streamEndRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const
Definition: implementors.h:85
virtual void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const
Definition: implementors.h:83
C * streamCache(edm::StreamID iID) const
Definition: implementors.h:55
long double T
Definition: Run.h:43