CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
implementors.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_one_implementors_h
2 #define FWCore_Framework_one_implementors_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : implementors
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Thu, 09 May 2013 18:40:17 GMT
19 //
20 
21 // system include files
22 #include <cstddef>
23 #include <memory>
24 #include <set>
25 #include <string>
26 #include <tuple>
27 #include <utility>
28 
29 // user include files
41 
42 // forward declarations
43 
44 namespace edm {
46 
47  namespace one {
48  namespace impl {
49  template <bool V>
51 
52  template <>
54  edm::SerialTaskQueue* queue() { return &queue_; }
56  };
57 
58  template <>
60  edm::SerialTaskQueue* queue() { return nullptr; }
61  };
62 
63  template <typename T>
64  class SharedResourcesUser : public virtual T {
65  public:
66  template <typename... Args>
67  SharedResourcesUser(Args... args) : T(args...) {}
70 
71  ~SharedResourcesUser() override {}
72 
73  protected:
74  void usesResource(std::string const& iName);
75  void usesResource();
76 
77  private:
79  std::set<std::string> resourceNames_;
80  };
81 
82  template <typename T>
83  class RunWatcher : public virtual T {
84  public:
85  RunWatcher() = default;
86  RunWatcher(RunWatcher const&) = delete;
87  RunWatcher& operator=(RunWatcher const&) = delete;
88  ~RunWatcher() noexcept(false) override{};
89 
90  private:
91  void doBeginRun_(Run const& rp, EventSetup const& c) final;
92  void doEndRun_(Run const& rp, EventSetup const& c) final;
93 
94  virtual void beginRun(edm::Run const&, edm::EventSetup const&) = 0;
95  virtual void endRun(edm::Run const&, edm::EventSetup const&) = 0;
96  };
97 
98  template <typename T>
99  class LuminosityBlockWatcher : public virtual T {
100  public:
101  LuminosityBlockWatcher() = default;
104  ~LuminosityBlockWatcher() noexcept(false) override{};
105 
106  private:
107  void doBeginLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) final;
108  void doEndLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) final;
109 
110  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
111  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
112  };
113 
114  template <typename T>
115  class WatchProcessBlock : public virtual T {
116  public:
117  WatchProcessBlock() = default;
118  WatchProcessBlock(WatchProcessBlock const&) = delete;
120  ~WatchProcessBlock() noexcept(false) override {}
121 
122  private:
123  void doBeginProcessBlock_(ProcessBlock const&) final;
125 
127  virtual void endProcessBlock(ProcessBlock const&) {}
128  };
129 
130  template <typename T>
131  class BeginProcessBlockProducer : public virtual T {
132  public:
133  BeginProcessBlockProducer() = default;
136  ~BeginProcessBlockProducer() noexcept(false) override{};
137 
138  private:
140 
141  virtual void beginProcessBlockProduce(edm::ProcessBlock&) = 0;
142  };
143 
144  template <typename T>
145  class EndProcessBlockProducer : public virtual T {
146  public:
147  EndProcessBlockProducer() = default;
150  ~EndProcessBlockProducer() noexcept(false) override{};
151 
152  private:
153  void doEndProcessBlockProduce_(ProcessBlock&) final;
154 
155  virtual void endProcessBlockProduce(edm::ProcessBlock&) = 0;
156  };
157 
158  template <typename T>
159  class BeginRunProducer : public virtual T {
160  public:
161  BeginRunProducer() = default;
162  BeginRunProducer(BeginRunProducer const&) = delete;
163  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
164  ~BeginRunProducer() noexcept(false) override{};
165 
166  private:
167  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
168 
169  virtual void beginRunProduce(edm::Run&, edm::EventSetup const&) = 0;
170  };
171 
172  template <typename T>
173  class EndRunProducer : public virtual T {
174  public:
175  EndRunProducer() = default;
176  EndRunProducer(EndRunProducer const&) = delete;
177  EndRunProducer& operator=(EndRunProducer const&) = delete;
178  ~EndRunProducer() noexcept(false) override{};
179 
180  private:
181  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
182 
183  virtual void endRunProduce(edm::Run&, edm::EventSetup const&) = 0;
184  };
185 
186  template <typename T>
187  class BeginLuminosityBlockProducer : public virtual T {
188  public:
189  BeginLuminosityBlockProducer() = default;
192  ~BeginLuminosityBlockProducer() noexcept(false) override{};
193 
194  private:
195  void doBeginLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) final;
196 
197  virtual void beginLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) = 0;
198  };
199 
200  template <typename T>
201  class EndLuminosityBlockProducer : public virtual T {
202  public:
203  EndLuminosityBlockProducer() = default;
206  ~EndLuminosityBlockProducer() noexcept(false) override{};
207 
208  private:
209  void doEndLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) final;
210 
211  virtual void endLuminosityBlockProduce(edm::LuminosityBlock&, edm::EventSetup const&) = 0;
212  };
213 
214  template <typename T, typename... CacheTypes>
215  class InputProcessBlockCacheHolder : public virtual T {
216  public:
217  InputProcessBlockCacheHolder() = default;
221 
222  std::tuple<CacheHandle<CacheTypes>...> processBlockCaches(Event const& event) const {
223  return cacheImpl_.processBlockCaches(event);
224  }
225 
226  template <std::size_t ICacheType, typename DataType, typename Func>
228  cacheImpl_.template registerProcessBlockCacheFiller<ICacheType, DataType, Func>(token,
229  std::forward<Func>(func));
230  }
231 
232  template <typename CacheType, typename DataType, typename Func>
234  cacheImpl_.template registerProcessBlockCacheFiller<CacheType, DataType, Func>(token,
235  std::forward<Func>(func));
236  }
237 
238  // This is intended for use by Framework unit tests only
239  unsigned int cacheSize() const { return cacheImpl_.cacheSize(); }
240 
241  private:
242  void doSelectInputProcessBlocks(ProductRegistry const& productRegistry,
243  ProcessBlockHelperBase const& processBlockHelperBase) final {
244  cacheImpl_.selectInputProcessBlocks(productRegistry, processBlockHelperBase, *this);
245  }
246 
247  void doAccessInputProcessBlock_(ProcessBlock const& pb) final {
248  cacheImpl_.accessInputProcessBlock(pb);
249  accessInputProcessBlock(pb);
250  }
251 
252  // Alternate method to access ProcessBlocks without using the caches
253  // Mostly intended for unit testing, but might have other uses...
254  virtual void accessInputProcessBlock(ProcessBlock const&) {}
255 
256  void clearInputProcessBlockCaches() final { cacheImpl_.clearCaches(); }
257 
259  };
260 
261  template <typename T, typename C>
262  class RunCacheHolder : public virtual T {
263  public:
264  RunCacheHolder() = default;
265  RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
267  ~RunCacheHolder() noexcept(false) override{};
268 
269  protected:
270  C* runCache(edm::RunIndex iID) { return cache_.get(); }
271  C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
272 
273  private:
274  void doBeginRun_(Run const& rp, EventSetup const& c) final { cache_ = globalBeginRun(rp, c); }
275  void doEndRun_(Run const& rp, EventSetup const& c) final {
276  globalEndRun(rp, c);
277  cache_ = nullptr; // propagate_const<T> has no reset() function
278  }
279 
280  virtual std::shared_ptr<C> globalBeginRun(edm::Run const&, edm::EventSetup const&) const = 0;
281  virtual void globalEndRun(edm::Run const&, edm::EventSetup const&) = 0;
282  //When threaded we will have a container for N items whre N is # of simultaneous runs
284  };
285 
286  template <typename T, typename C>
287  class LuminosityBlockCacheHolder : public virtual T {
288  public:
289  LuminosityBlockCacheHolder() = default;
292  ~LuminosityBlockCacheHolder() noexcept(false) override{};
293 
294  protected:
295  void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
296 
297  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
298  C* luminosityBlockCache(edm::LuminosityBlockIndex iID) { return caches_[iID].get(); }
299 
300  private:
301  void doBeginLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
302  caches_[lp.index()] = globalBeginLuminosityBlock(lp, c);
303  }
304  void doEndLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
305  globalEndLuminosityBlock(lp, c);
306  caches_[lp.index()].reset();
307  }
308 
309  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
310  edm::EventSetup const&) const = 0;
311  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
312  std::unique_ptr<std::shared_ptr<C>[]> caches_;
313  };
314 
315  template <typename T>
316  class Accumulator : public virtual T {
317  public:
318  Accumulator() = default;
319  Accumulator(Accumulator const&) = delete;
320  Accumulator& operator=(Accumulator const&) = delete;
321  ~Accumulator() noexcept(false) override{};
322 
323  private:
324  bool hasAccumulator() const override { return true; }
325 
326  void produce(Event& ev, EventSetup const& es) final { accumulate(ev, es); }
327 
328  virtual void accumulate(Event const& ev, EventSetup const& es) = 0;
329  };
330  } // namespace impl
331  } // namespace one
332 } // namespace edm
333 
334 #endif
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:312
void produce(Event &ev, EventSetup const &es) final
Definition: implementors.h:326
const edm::EventSetup & c
void doBeginProcessBlockProduce_(ProcessBlock &) final
virtual void beginProcessBlock(ProcessBlock const &)
Definition: implementors.h:126
void doEndRun_(Run const &rp, EventSetup const &c) final
virtual void endRun(edm::Run const &, edm::EventSetup const &)=0
~EndProcessBlockProducer() noexcept(false) override
Definition: implementors.h:150
SharedResourcesUser & operator=(SharedResourcesUser const &)=delete
LuminosityBlockWatcher & operator=(LuminosityBlockWatcher const &)=delete
virtual void endProcessBlock(ProcessBlock const &)
Definition: implementors.h:127
virtual void accessInputProcessBlock(ProcessBlock const &)
Definition: implementors.h:254
~WatchProcessBlock() noexcept(false) override
Definition: implementors.h:120
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
bool ev
std::tuple< CacheHandle< CacheTypes >...> processBlockCaches(Event const &event) const
Definition: implementors.h:222
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:275
RunWatcher & operator=(RunWatcher const &)=delete
BeginProcessBlockProducer & operator=(BeginProcessBlockProducer const &)=delete
~Accumulator() noexcept(false) override
Definition: implementors.h:321
void doSelectInputProcessBlocks(ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase) final
Definition: implementors.h:242
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:271
C * runCache(edm::RunIndex iID)
Definition: implementors.h:270
void doBeginLuminosityBlock_(LuminosityBlock const &rp, EventSetup const &c) final
edm::impl::InputProcessBlockCacheImpl< CacheTypes...> cacheImpl_
Definition: implementors.h:258
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&func)
Definition: implementors.h:227
~EndRunProducer() noexcept(false) override
Definition: implementors.h:178
void doBeginProcessBlock_(ProcessBlock const &) final
void doEndLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:304
void doAccessInputProcessBlock_(ProcessBlock const &pb) final
Definition: implementors.h:247
edm::propagate_const< std::shared_ptr< C > > cache_
Definition: implementors.h:283
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)=0
~LuminosityBlockWatcher() noexcept(false) override
Definition: implementors.h:104
~LuminosityBlockCacheHolder() noexcept(false) override
Definition: implementors.h:292
void doBeginRun_(Run const &rp, EventSetup const &c) final
SharedResourcesAcquirer createAcquirer() override
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)=0
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:297
~EndLuminosityBlockProducer() noexcept(false) override
Definition: implementors.h:206
void preallocLumis(unsigned int iNLumis) final
Definition: implementors.h:295
bool hasAccumulator() const override
Definition: implementors.h:324
std::set< std::string > resourceNames_
Definition: implementors.h:79
virtual void beginProcessBlockProduce(edm::ProcessBlock &)=0
void doBeginRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:274
void doEndLuminosityBlock_(LuminosityBlock const &rp, EventSetup const &c) final
C * luminosityBlockCache(edm::LuminosityBlockIndex iID)
Definition: implementors.h:298
~BeginLuminosityBlockProducer() noexcept(false) override
Definition: implementors.h:192
~BeginRunProducer() noexcept(false) override
Definition: implementors.h:164
virtual void beginRun(edm::Run const &, edm::EventSetup const &)=0
void doEndProcessBlock_(ProcessBlock const &) final
~RunWatcher() noexcept(false) override
Definition: implementors.h:88
WatchProcessBlock & operator=(WatchProcessBlock const &)=delete
~BeginProcessBlockProducer() noexcept(false) override
Definition: implementors.h:136
long double T
void doBeginLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:301
def template
Definition: svgfig.py:521
Definition: Run.h:45
~RunCacheHolder() noexcept(false) override
Definition: implementors.h:267