CMS 3D CMS Logo

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
46 
47 // forward declarations
48 
49 namespace edm {
51  class WaitingTaskHolder;
52  class ServiceWeakToken;
53  class ActivityRegistry;
54 
55  namespace one {
56  namespace impl {
57  template <bool V>
59 
60  template <>
62  edm::SerialTaskQueue* queue() { return &queue_; }
64  };
65 
66  template <>
68  edm::SerialTaskQueue* queue() { return nullptr; }
69  };
70 
71  template <typename T>
72  class SharedResourcesUser : public virtual T {
73  public:
74  template <typename... Args>
75  SharedResourcesUser(Args... args) : T(args...) {}
78 
79  ~SharedResourcesUser() override {}
80 
81  protected:
82  void usesResource(std::string const& iName);
83 
84  private:
86  std::set<std::string> resourceNames_;
87  };
88 
89  template <typename T>
90  class RunWatcher : public virtual T {
91  public:
92  RunWatcher() = default;
93  RunWatcher(RunWatcher const&) = delete;
94  RunWatcher& operator=(RunWatcher const&) = delete;
95  ~RunWatcher() noexcept(false) override{};
96 
97  private:
98  void doBeginRun_(Run const& rp, EventSetup const& c) final;
99  void doEndRun_(Run const& rp, EventSetup const& c) final;
100 
101  virtual void beginRun(edm::Run const&, edm::EventSetup const&) = 0;
102  virtual void endRun(edm::Run const&, edm::EventSetup const&) = 0;
103  };
104 
105  template <typename T>
106  class LuminosityBlockWatcher : public virtual T {
107  public:
108  LuminosityBlockWatcher() = default;
111  ~LuminosityBlockWatcher() noexcept(false) override{};
112 
113  private:
114  void doBeginLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) final;
115  void doEndLuminosityBlock_(LuminosityBlock const& rp, EventSetup const& c) final;
116 
117  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
118  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
119  };
120 
121  template <typename T>
122  class WatchProcessBlock : public virtual T {
123  public:
124  WatchProcessBlock() = default;
125  WatchProcessBlock(WatchProcessBlock const&) = delete;
127  ~WatchProcessBlock() noexcept(false) override {}
128 
129  private:
130  void doBeginProcessBlock_(ProcessBlock const&) final;
131  void doEndProcessBlock_(ProcessBlock const&) final;
132 
133  virtual void beginProcessBlock(ProcessBlock const&) {}
134  virtual void endProcessBlock(ProcessBlock const&) {}
135  };
136 
137  template <typename T>
138  class BeginProcessBlockProducer : public virtual T {
139  public:
140  BeginProcessBlockProducer() = default;
143  ~BeginProcessBlockProducer() noexcept(false) override{};
144 
145  private:
147 
148  virtual void beginProcessBlockProduce(edm::ProcessBlock&) = 0;
149  };
150 
151  template <typename T>
152  class EndProcessBlockProducer : public virtual T {
153  public:
154  EndProcessBlockProducer() = default;
157  ~EndProcessBlockProducer() noexcept(false) override{};
158 
159  private:
161 
162  virtual void endProcessBlockProduce(edm::ProcessBlock&) = 0;
163  };
164 
165  template <typename T>
166  class BeginRunProducer : public virtual T {
167  public:
168  BeginRunProducer() = default;
169  BeginRunProducer(BeginRunProducer const&) = delete;
170  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
171  ~BeginRunProducer() noexcept(false) override{};
172 
173  private:
174  void doBeginRunProduce_(Run& rp, EventSetup const& c) final;
175 
176  virtual void beginRunProduce(edm::Run&, edm::EventSetup const&) = 0;
177  };
178 
179  template <typename T>
180  class EndRunProducer : public virtual T {
181  public:
182  EndRunProducer() = default;
183  EndRunProducer(EndRunProducer const&) = delete;
184  EndRunProducer& operator=(EndRunProducer const&) = delete;
185  ~EndRunProducer() noexcept(false) override{};
186 
187  private:
188  void doEndRunProduce_(Run& rp, EventSetup const& c) final;
189 
190  virtual void endRunProduce(edm::Run&, edm::EventSetup const&) = 0;
191  };
192 
193  template <typename T>
194  class BeginLuminosityBlockProducer : public virtual T {
195  public:
196  BeginLuminosityBlockProducer() = default;
199  ~BeginLuminosityBlockProducer() noexcept(false) override{};
200 
201  private:
203 
205  };
206 
207  template <typename T>
208  class EndLuminosityBlockProducer : public virtual T {
209  public:
210  EndLuminosityBlockProducer() = default;
213  ~EndLuminosityBlockProducer() noexcept(false) override{};
214 
215  private:
216  void doEndLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) final;
217 
219  };
220 
221  template <typename T, typename... CacheTypes>
222  class InputProcessBlockCacheHolder : public virtual T {
223  public:
224  InputProcessBlockCacheHolder() = default;
228 
229  std::tuple<CacheHandle<CacheTypes>...> processBlockCaches(Event const& event) const {
231  }
232 
233  template <std::size_t ICacheType, typename DataType, typename Func>
235  cacheImpl_.template registerProcessBlockCacheFiller<ICacheType, DataType, Func>(token,
236  std::forward<Func>(func));
237  }
238 
239  template <typename CacheType, typename DataType, typename Func>
241  cacheImpl_.template registerProcessBlockCacheFiller<CacheType, DataType, Func>(token,
242  std::forward<Func>(func));
243  }
244 
245  // This is intended for use by Framework unit tests only
246  unsigned int cacheSize() const { return cacheImpl_.cacheSize(); }
247 
248  private:
249  void doSelectInputProcessBlocks(ProductRegistry const& productRegistry,
250  ProcessBlockHelperBase const& processBlockHelperBase) final {
251  cacheImpl_.selectInputProcessBlocks(productRegistry, processBlockHelperBase, *this);
252  }
253 
254  void doAccessInputProcessBlock_(ProcessBlock const& pb) final {
255  cacheImpl_.accessInputProcessBlock(pb);
257  }
258 
259  // Alternate method to access ProcessBlocks without using the caches
260  // Mostly intended for unit testing, but might have other uses...
261  virtual void accessInputProcessBlock(ProcessBlock const&) {}
262 
263  void clearInputProcessBlockCaches() final { cacheImpl_.clearCaches(); }
264 
266  };
267 
268  template <typename T, typename C>
269  class RunCacheHolder : public virtual T {
270  public:
271  RunCacheHolder() = default;
272  RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
274  ~RunCacheHolder() noexcept(false) override{};
275 
276  protected:
277  void preallocRuns(unsigned int iNRuns) final { caches_.reset(new std::shared_ptr<C>[iNRuns]); }
278 
279  C* runCache(edm::RunIndex iID) { return caches_[iID].get(); }
280  C const* runCache(edm::RunIndex iID) const { return caches_[iID].get(); }
281 
282  private:
283  void doBeginRun_(Run const& rp, EventSetup const& c) final { caches_[rp.index()] = globalBeginRun(rp, c); }
284  void doEndRun_(Run const& rp, EventSetup const& c) final {
285  globalEndRun(rp, c);
286  caches_[rp.index()].reset();
287  }
288 
289  virtual std::shared_ptr<C> globalBeginRun(edm::Run const&, edm::EventSetup const&) const = 0;
290  virtual void globalEndRun(edm::Run const&, edm::EventSetup const&) = 0;
291 
292  std::unique_ptr<std::shared_ptr<C>[]> caches_;
293  };
294 
295  template <typename T, typename C>
296  class LuminosityBlockCacheHolder : public virtual T {
297  public:
298  LuminosityBlockCacheHolder() = default;
301  ~LuminosityBlockCacheHolder() noexcept(false) override{};
302 
303  protected:
304  void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
305 
306  C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
308 
309  private:
310  void doBeginLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
311  caches_[lp.index()] = globalBeginLuminosityBlock(lp, c);
312  }
313  void doEndLuminosityBlock_(LuminosityBlock const& lp, EventSetup const& c) final {
315  caches_[lp.index()].reset();
316  }
317 
318  virtual std::shared_ptr<C> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
319  edm::EventSetup const&) const = 0;
320  virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
321  std::unique_ptr<std::shared_ptr<C>[]> caches_;
322  };
323 
324  template <typename T>
325  class Accumulator : public virtual T {
326  public:
327  Accumulator() = default;
328  Accumulator(Accumulator const&) = delete;
329  Accumulator& operator=(Accumulator const&) = delete;
330  ~Accumulator() noexcept(false) override{};
331 
332  private:
333  bool hasAccumulator() const noexcept override { return true; }
334 
335  void produce(Event& ev, EventSetup const& es) final { accumulate(ev, es); }
336 
337  virtual void accumulate(Event const& ev, EventSetup const& es) = 0;
338  };
339 
340  template <typename T>
341  class Transformer : public virtual T, private TransformerBase {
342  public:
343  Transformer() = default;
344  Transformer(Transformer const&) = delete;
345  Transformer& operator=(Transformer const&) = delete;
346  ~Transformer() noexcept(false) override{};
347 
348  template <typename G, typename F>
350  F&& iF,
351  std::string productInstance = std::string()) {
352  registerTransform(edm::EDPutTokenT<G>(iSetter), std::forward<F>(iF), std::move(productInstance));
353  }
354 
355  template <typename G, typename F>
356  void registerTransform(edm::EDPutTokenT<G> iToken, F iF, std::string productInstance = std::string()) {
357  using ReturnTypeT = decltype(iF(std::declval<G>()));
358  TypeID returnType(typeid(ReturnTypeT));
360  EDPutToken(iToken),
361  returnType,
362  std::move(productInstance),
363  [f = std::move(iF)](edm::WrapperBase const& iGotProduct) {
364  return std::make_unique<edm::Wrapper<ReturnTypeT>>(
366  f(*static_cast<edm::Wrapper<G> const&>(iGotProduct).product()));
367  });
368  }
369 
370  template <typename G, typename P, typename F>
372  P iPre,
373  F iF,
374  std::string productInstance = std::string()) {
375  using CacheTypeT = decltype(iPre(std::declval<G>(), WaitingTaskWithArenaHolder()));
376  using ReturnTypeT = decltype(iF(std::declval<CacheTypeT>()));
377  TypeID returnType(typeid(ReturnTypeT));
379  *this,
380  EDPutToken(iToken),
381  returnType,
382  std::move(productInstance),
383  [p = std::move(iPre)](edm::WrapperBase const& iGotProduct, WaitingTaskWithArenaHolder iHolder) {
384  return std::any(p(*static_cast<edm::Wrapper<G> const&>(iGotProduct).product(), std::move(iHolder)));
385  },
386  [f = std::move(iF)](std::any const& iCache) {
387  auto cache = std::any_cast<CacheTypeT>(iCache);
388  return std::make_unique<edm::Wrapper<ReturnTypeT>>(WrapperBase::Emplace{}, f(cache));
389  });
390  }
391 
392  private:
393  size_t transformIndex_(edm::BranchDescription const& iBranch) const noexcept final {
394  return TransformerBase::findMatchingIndex(*this, iBranch);
395  }
396  ProductResolverIndex transformPrefetch_(std::size_t iIndex) const noexcept final {
397  return TransformerBase::prefetchImp(iIndex);
398  }
400  std::size_t iIndex,
402  edm::ActivityRegistry* iAct,
403  ServiceWeakToken const& iToken) const noexcept final {
404  return TransformerBase::transformImpAsync(std::move(iTask), iIndex, iAct, *this, iEvent);
405  }
406  void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const& iHelper) override {
407  if (iBranchType == InEvent) {
408  TransformerBase::extendUpdateLookup(*this, this->moduleDescription(), iHelper);
409  }
410  }
411  };
412  } // namespace impl
413  } // namespace one
414 } // namespace edm
415 
416 #endif
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:321
void produce(Event &ev, EventSetup const &es) final
Definition: implementors.h:335
unsigned int ProductResolverIndex
void doBeginProcessBlockProduce_(ProcessBlock &) final
virtual void beginProcessBlock(ProcessBlock const &)
Definition: implementors.h:133
void doEndRun_(Run const &rp, EventSetup const &c) final
virtual void endRunProduce(edm::Run &, edm::EventSetup const &)=0
virtual void endRun(edm::Run const &, edm::EventSetup const &)=0
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:37
~EndProcessBlockProducer() noexcept(false) override
Definition: implementors.h:157
SharedResourcesUser & operator=(SharedResourcesUser const &)=delete
LuminosityBlockWatcher & operator=(LuminosityBlockWatcher const &)=delete
C const * luminosityBlockCache(edm::LuminosityBlockIndex iID) const
Definition: implementors.h:306
virtual void endProcessBlock(ProcessBlock const &)
Definition: implementors.h:134
virtual void accessInputProcessBlock(ProcessBlock const &)
Definition: implementors.h:261
~WatchProcessBlock() noexcept(false) override
Definition: implementors.h:127
void transformAsync_(WaitingTaskHolder iTask, std::size_t iIndex, edm::EventForTransformer &iEvent, edm::ActivityRegistry *iAct, ServiceWeakToken const &iToken) const noexcept final
Definition: implementors.h:399
BeginRunProducer & operator=(BeginRunProducer const &)=delete
void selectInputProcessBlocks(ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase, EDConsumerBase const &edConsumerBase)
void doEndRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:284
LuminosityBlockCacheHolder< T, C > & operator=(LuminosityBlockCacheHolder< T, C > const &)=delete
RunWatcher & operator=(RunWatcher const &)=delete
BeginProcessBlockProducer & operator=(BeginProcessBlockProducer const &)=delete
~Accumulator() noexcept(false) override
Definition: implementors.h:330
void preallocRuns(unsigned int iNRuns) final
Definition: implementors.h:277
BranchType
Definition: BranchType.h:11
virtual void accumulate(Event const &ev, EventSetup const &es)=0
void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const &iHelper) override
Definition: implementors.h:406
void doSelectInputProcessBlocks(ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase) final
Definition: implementors.h:249
C * runCache(edm::RunIndex iID)
Definition: implementors.h:279
int iEvent
Definition: GenABIO.cc:224
void doBeginLuminosityBlock_(LuminosityBlock const &rp, EventSetup const &c) final
void doBeginRunProduce_(Run &rp, EventSetup const &c) final
edm::impl::InputProcessBlockCacheImpl< CacheTypes... > cacheImpl_
Definition: implementors.h:265
BeginLuminosityBlockProducer & operator=(BeginLuminosityBlockProducer const &)=delete
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&func)
Definition: implementors.h:234
~EndRunProducer() noexcept(false) override
Definition: implementors.h:185
edm::TypeWithDict returnType(const edm::FunctionWithDict &)
Definition: returnType.cc:16
void doBeginProcessBlock_(ProcessBlock const &) final
virtual void beginLuminosityBlockProduce(edm::LuminosityBlock &, edm::EventSetup const &)=0
void extendUpdateLookup(ProducerBase const &, ModuleDescription const &iModuleDesc, ProductResolverIndexHelper const &iHelper)
void doEndLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:313
virtual void endProcessBlockProduce(edm::ProcessBlock &)=0
void doAccessInputProcessBlock_(ProcessBlock const &pb) final
Definition: implementors.h:254
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)=0
double f[11][100]
~LuminosityBlockWatcher() noexcept(false) override
Definition: implementors.h:111
~LuminosityBlockCacheHolder() noexcept(false) override
Definition: implementors.h:301
size_t transformIndex_(edm::BranchDescription const &iBranch) const noexcept final
Definition: implementors.h:393
~Transformer() noexcept(false) override
Definition: implementors.h:346
void doBeginRun_(Run const &rp, EventSetup const &c) final
void usesResource(std::string const &iName)
EndProcessBlockProducer & operator=(EndProcessBlockProducer const &)=delete
std::size_t findMatchingIndex(ProducerBase const &iBase, edm::BranchDescription const &) const noexcept
SharedResourcesAcquirer createAcquirer() override
void doEndLuminosityBlockProduce_(LuminosityBlock &lbp, EventSetup const &c) final
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)=0
void transformImpAsync(WaitingTaskHolder iTask, std::size_t iIndex, edm::ActivityRegistry *iAct, ProducerBase const &iBase, edm::EventForTransformer &) const noexcept
EndRunProducer & operator=(EndRunProducer const &)=delete
EndLuminosityBlockProducer & operator=(EndLuminosityBlockProducer const &)=delete
~EndLuminosityBlockProducer() noexcept(false) override
Definition: implementors.h:213
void registerTransformAsyncImp(ProducerBase &, EDPutToken, const TypeID &id, std::string instanceName, PreTransformFunction, TransformFunction)
void preallocLumis(unsigned int iNLumis) final
Definition: implementors.h:304
virtual void beginRunProduce(edm::Run &, edm::EventSetup const &)=0
void registerTransform(ProductRegistryHelper::BranchAliasSetterT< G > iSetter, F &&iF, std::string productInstance=std::string())
Definition: implementors.h:349
std::set< std::string > resourceNames_
Definition: implementors.h:86
std::pair< OmniClusterRef, TrackingParticleRef > P
virtual void beginProcessBlockProduce(edm::ProcessBlock &)=0
void doBeginRun_(Run const &rp, EventSetup const &c) final
Definition: implementors.h:283
void doEndLuminosityBlock_(LuminosityBlock const &rp, EventSetup const &c) final
C * luminosityBlockCache(edm::LuminosityBlockIndex iID)
Definition: implementors.h:307
~BeginLuminosityBlockProducer() noexcept(false) override
Definition: implementors.h:199
~BeginRunProducer() noexcept(false) override
Definition: implementors.h:171
C const * runCache(edm::RunIndex iID) const
Definition: implementors.h:280
std::tuple< CacheHandle< CacheTypes >... > processBlockCaches(Event const &event) const
virtual void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)=0
virtual void beginRun(edm::Run const &, edm::EventSetup const &)=0
void doEndProcessBlock_(ProcessBlock const &) final
HLT enums.
RunCacheHolder< T, C > & operator=(RunCacheHolder< T, C > const &)=delete
void doEndRunProduce_(Run &rp, EventSetup const &c) final
Accumulator & operator=(Accumulator const &)=delete
bool hasAccumulator() const noexcept override
Definition: implementors.h:333
virtual std::shared_ptr< C > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const =0
void doEndProcessBlockProduce_(ProcessBlock &) final
def cache(function)
Definition: utilities.py:3
~RunWatcher() noexcept(false) override
Definition: implementors.h:95
void doBeginLuminosityBlockProduce_(LuminosityBlock &lbp, EventSetup const &c) final
virtual void endLuminosityBlockProduce(edm::LuminosityBlock &, edm::EventSetup const &)=0
InputProcessBlockCacheHolder & operator=(InputProcessBlockCacheHolder const &)=delete
std::unique_ptr< std::shared_ptr< C >[]> caches_
Definition: implementors.h:292
virtual void globalEndRun(edm::Run const &, edm::EventSetup const &)=0
void registerTransformImp(ProducerBase &, EDPutToken, const TypeID &id, std::string instanceName, TransformFunction)
WatchProcessBlock & operator=(WatchProcessBlock const &)=delete
~BeginProcessBlockProducer() noexcept(false) override
Definition: implementors.h:143
std::tuple< CacheHandle< CacheTypes >... > processBlockCaches(Event const &event) const
Definition: implementors.h:229
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
void registerTransformAsync(edm::EDPutTokenT< G > iToken, P iPre, F iF, std::string productInstance=std::string())
Definition: implementors.h:371
long double T
ProductResolverIndex prefetchImp(std::size_t iIndex) const noexcept
void registerTransform(edm::EDPutTokenT< G > iToken, F iF, std::string productInstance=std::string())
Definition: implementors.h:356
Transformer & operator=(Transformer const &)=delete
ProductResolverIndex transformPrefetch_(std::size_t iIndex) const noexcept final
Definition: implementors.h:396
virtual std::shared_ptr< C > globalBeginRun(edm::Run const &, edm::EventSetup const &) const =0
void doBeginLuminosityBlock_(LuminosityBlock const &lp, EventSetup const &c) final
Definition: implementors.h:310
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45
~RunCacheHolder() noexcept(false) override
Definition: implementors.h:274