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