CMS 3D CMS Logo

implementors.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_stream_implementors_h
2 #define FWCore_Framework_stream_implementors_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : implementors
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Fri, 02 Aug 2013 11:52:34 GMT
19 //
20 
21 // system include files
22 #include <cstddef>
23 #include <functional>
24 #include <memory>
25 #include <tuple>
26 #include <utility>
27 #include <vector>
28 
29 // user include files
42 
43 // forward declarations
44 namespace edm {
45 
46  class WaitingTaskWithArenaHolder;
47 
48  namespace stream {
49  namespace impl {
50  class EmptyType {};
51 
52  template <typename C>
54  public:
55  GlobalCacheHolder() = default;
56  GlobalCacheHolder(GlobalCacheHolder<C> const&) = delete;
58 
59  void setGlobalCache(C const* iCache) { cache_ = iCache; }
60 
61  protected:
62  C const* globalCache() const { return cache_; }
63 
64  private:
65  C const* cache_;
66  };
67 
68  template <typename... CacheTypes>
70  public:
71  InputProcessBlockCacheHolder() = default;
74 
75  std::tuple<CacheHandle<CacheTypes>...> processBlockCaches(Event const& event) const {
77  }
78 
79  template <std::size_t N>
80  using CacheTypeT = typename std::tuple_element<N, std::tuple<CacheTypes...>>::type;
81 
82  template <std::size_t ICacheType, typename DataType, typename Func>
83  void registerProcessBlockCacheFiller(EDGetTokenT<DataType> const& token, Func&& cacheFiller) {
84  registerProcessBlockCacheFiller<ICacheType, CacheTypeT<ICacheType>, DataType, Func>(
85  token, std::forward<Func>(cacheFiller));
86  }
87 
88  template <typename CacheType, typename DataType, typename Func>
89  void registerProcessBlockCacheFiller(EDGetTokenT<DataType> const& token, Func&& cacheFiller) {
90  static_assert(edm::impl::countTypeInParameterPack<CacheType, CacheTypes...>() == 1u,
91  "If registerProcessBlockCacheFiller is called with a type template parameter\n"
92  "then that type must appear exactly once in the template parameters of InputProcessBlockCache");
93 
94  // Find the index into the parameter pack from the CacheType
95  constexpr unsigned int I = edm::impl::indexInputProcessBlockCache<CacheType, CacheTypes...>();
96 
97  registerProcessBlockCacheFiller<I, CacheType, DataType, Func>(token, std::forward<Func>(cacheFiller));
98  }
99 
100  private:
101  template <typename T, bool, bool>
103 
105  cacheImpl_ = cacheImpl;
106  }
107 
108  bool cacheFillersRegistered() const { return registrationInfo_ ? true : false; }
109  std::vector<edm::impl::TokenInfo>& tokenInfos() { return registrationInfo_->tokenInfos_; }
110  std::tuple<edm::impl::CacheFiller<CacheTypes>...>& cacheFillers() { return registrationInfo_->cacheFillers_; }
111 
113 
114  // The next two functions exist so that it is optional whether modules
115  // with this ability implement them.
116 
118 
119  template <typename GlobalCacheType>
120  static void accessInputProcessBlock(edm::ProcessBlock const&, GlobalCacheType*) {}
121 
122  template <std::size_t ICacheType, typename CacheType, typename DataType, typename Func>
124  if (!registrationInfo_) {
125  registrationInfo_ = std::make_unique<RegistrationInfo>();
126  tokenInfos().resize(sizeof...(CacheTypes));
127  }
128 
129  if (!tokenInfos()[ICacheType].token_.isUninitialized()) {
131  << "registerProcessBlockCacheFiller should only be called once per cache type";
132  }
133 
134  tokenInfos()[ICacheType] = edm::impl::TokenInfo{EDGetToken(token), TypeID(typeid(DataType))};
135 
136  std::get<ICacheType>(cacheFillers()).func_ =
137  std::function<std::shared_ptr<CacheType>(ProcessBlock const&, std::shared_ptr<CacheType> const&)>(
138  std::forward<Func>(cacheFiller));
139  }
140 
141  // ------------ Data members --------------------
142 
144 
145  // The RegistrationInfo is filled while the module constructor runs.
146  // Later this information is copied to the InputProcessBlockCacheImpl
147  // object owned by the adaptor and then registrationInfo_ is cleared.
148  // Note that this is really only needed for one of the stream instances,
149  // but we fill for all streams so registerProcessBlockCacheFiller can
150  // be called in the constructor. This keeps the interface as simple as
151  // possible and makes it similar to the consumes interface.
153  public:
154  std::vector<edm::impl::TokenInfo> tokenInfos_;
155  std::tuple<edm::impl::CacheFiller<CacheTypes>...> cacheFillers_;
156  };
157  std::unique_ptr<RegistrationInfo> registrationInfo_;
158  };
159 
160  template <typename C>
162  public:
163  RunCacheHolder() = default;
164  RunCacheHolder(RunCacheHolder<C> const&) = delete;
166  void setRunCache(C const* iCache) { cache_ = iCache; }
167 
168  protected:
169  C const* runCache() const { return cache_; }
170 
171  private:
172  C const* cache_;
173  };
174 
175  template <typename C>
177  public:
178  LuminosityBlockCacheHolder() = default;
181  void setLuminosityBlockCache(C const* iCache) { cache_ = iCache; }
182 
183  protected:
184  C const* luminosityBlockCache() const { return cache_; }
185 
186  private:
187  C const* cache_;
188  };
189 
190  template <typename C>
192  public:
193  RunSummaryCacheHolder() = default;
196  virtual ~RunSummaryCacheHolder() noexcept(false) {}
197 
198  private:
199  virtual void endRunSummary(edm::Run const&, edm::EventSetup const&, C*) const = 0;
200  };
201 
202  template <typename C>
204  public:
209 
210  private:
211  virtual void endLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
212  };
213 
215  public:
216  WatchProcessBlock() = default;
217  WatchProcessBlock(WatchProcessBlock const&) = delete;
219 
222  };
223 
225  public:
226  BeginProcessBlockProducer() = default;
229 
232  };
233 
235  public:
236  EndProcessBlockProducer() = default;
239 
242  };
243 
245  public:
246  BeginRunProducer() = default;
247  BeginRunProducer(BeginRunProducer const&) = delete;
248  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
249 
252  };
253 
255  public:
256  EndRunProducer() = default;
257  EndRunProducer(EndRunProducer const&) = delete;
258  EndRunProducer& operator=(EndRunProducer const&) = delete;
259 
262  };
263 
265  public:
266  BeginLuminosityBlockProducer() = default;
269 
272  };
273 
275  public:
276  EndLuminosityBlockProducer() = default;
279 
282  };
283 
284  class ExternalWork {
285  public:
286  ExternalWork() = default;
287  ExternalWork(ExternalWork const&) = delete;
288  ExternalWork& operator=(ExternalWork const&) = delete;
289  virtual ~ExternalWork() noexcept(false){};
290 
291  virtual void acquire(Event const&, edm::EventSetup const&, WaitingTaskWithArenaHolder) = 0;
292  };
293 
295  public:
296  WatchLuminosityBlocks() = default;
299  virtual ~WatchLuminosityBlocks() noexcept(false){};
300 
301  // virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
302  // virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {}
303  };
304 
305  class WatchRuns {
306  public:
307  WatchRuns() = default;
308  WatchRuns(WatchRuns const&) = delete;
309  WatchRuns& operator=(WatchRuns const&) = delete;
310  virtual ~WatchRuns() noexcept(false){};
311 
312  // virtual void beginRun(edm::Run const&, edm::EventSetup const&) = 0;
313  // virtual void endRun(edm::Run const&, edm::EventSetup const&) {}
314  };
315  class Transformer : private TransformerBase, public EDProducerBase {
316  public:
317  Transformer() = default;
318  Transformer(Transformer const&) = delete;
319  Transformer& operator=(Transformer const&) = delete;
320  ~Transformer() noexcept(false) override{};
321 
322  template <typename G, typename F>
324  F&& iF,
325  std::string productInstance = std::string()) {
326  registerTransform(edm::EDPutTokenT<G>(iSetter), std::forward<F>(iF), std::move(productInstance));
327  }
328 
329  template <typename G, typename F>
330  void registerTransform(edm::EDPutTokenT<G> iToken, F iF, std::string productInstance = std::string()) {
331  using ReturnTypeT = decltype(iF(std::declval<G>()));
332  TypeID returnType(typeid(ReturnTypeT));
334  *this,
335  EDPutToken(iToken),
336  returnType,
337  std::move(productInstance),
338  [f = std::move(iF)](std::any const& iGotProduct) {
339  auto pGotProduct = std::any_cast<edm::WrapperBase const*>(iGotProduct);
340  return std::make_unique<edm::Wrapper<ReturnTypeT>>(
341  WrapperBase::Emplace{}, f(*static_cast<edm::Wrapper<G> const*>(pGotProduct)->product()));
342  });
343  }
344 
345  template <typename G, typename P, typename F>
347  P iPre,
348  F iF,
349  std::string productInstance = std::string()) {
350  using CacheTypeT = decltype(iPre(std::declval<G>(), WaitingTaskWithArenaHolder()));
351  using ReturnTypeT = decltype(iF(std::declval<CacheTypeT>()));
352  TypeID returnType(typeid(ReturnTypeT));
354  *this,
355  EDPutToken(iToken),
356  returnType,
357  std::move(productInstance),
358  [p = std::move(iPre)](edm::WrapperBase const& iGotProduct, WaitingTaskWithArenaHolder iHolder) {
359  return std::any(p(*static_cast<edm::Wrapper<G> const&>(iGotProduct).product(), std::move(iHolder)));
360  },
361  [f = std::move(iF)](std::any const& iCache) {
362  auto cache = std::any_cast<CacheTypeT>(iCache);
363  return std::make_unique<edm::Wrapper<ReturnTypeT>>(WrapperBase::Emplace{}, f(cache));
364  });
365  }
366 
367  private:
368  size_t transformIndex_(edm::BranchDescription const& iBranch) const noexcept final {
369  return TransformerBase::findMatchingIndex(*this, iBranch);
370  }
371  ProductResolverIndex transformPrefetch_(std::size_t iIndex) const noexcept final {
372  return TransformerBase::prefetchImp(iIndex);
373  }
375  std::size_t iIndex,
377  edm::ActivityRegistry* iAct,
378  ServiceWeakToken const& iToken) const noexcept final {
379  return TransformerBase::transformImpAsync(std::move(iTask), iIndex, iAct, *this, iEvent);
380  }
381  void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const& iHelper) override {
382  if (iBranchType == InEvent) {
384  }
385  }
386  };
387 
388  class Accumulator : public EDProducerBase {
389  public:
390  Accumulator() = default;
391  Accumulator(Accumulator const&) = delete;
392  Accumulator& operator=(Accumulator const&) = delete;
393  ~Accumulator() noexcept(false) override{};
394 
395  virtual void accumulate(Event const& ev, EventSetup const& es) = 0;
396 
397  void produce(Event& ev, EventSetup const& es) final { accumulate(ev, es); }
398  };
399  } // namespace impl
400  } // namespace stream
401 } // namespace edm
402 
403 #endif
unsigned int ProductResolverIndex
std::tuple< edm::impl::CacheFiller< CacheTypes >... > & cacheFillers()
Definition: implementors.h:110
RunCacheHolder< C > & operator=(RunCacheHolder< C > const &)=delete
BeginRunProducer & operator=(BeginRunProducer const &)=delete
std::tuple< edm::impl::CacheFiller< CacheTypes >... > cacheFillers_
Definition: implementors.h:155
std::unique_ptr< RegistrationInfo > registrationInfo_
Definition: implementors.h:157
GlobalCacheHolder< C > & operator=(GlobalCacheHolder< C > const &)=delete
virtual ~RunSummaryCacheHolder() noexcept(false)
Definition: implementors.h:196
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&cacheFiller)
Definition: implementors.h:123
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:37
constexpr std::size_t indexInputProcessBlockCache()
~Transformer() noexcept(false) override
Definition: implementors.h:320
WatchLuminosityBlocks & operator=(WatchLuminosityBlocks const &)=delete
void registerTransform(edm::EDPutTokenT< G > iToken, F iF, std::string productInstance=std::string())
Definition: implementors.h:330
virtual void accumulate(Event const &ev, EventSetup const &es)=0
std::tuple< CacheHandle< CacheTypes >... > processBlockCaches(Event const &event) const
Definition: implementors.h:75
void transformAsync_(WaitingTaskHolder iTask, std::size_t iIndex, edm::EventForTransformer &iEvent, edm::ActivityRegistry *iAct, ServiceWeakToken const &iToken) const noexcept final
Definition: implementors.h:374
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
BranchType
Definition: BranchType.h:11
EndLuminosityBlockProducer & operator=(EndLuminosityBlockProducer const &)=delete
virtual void endRunSummary(edm::Run const &, edm::EventSetup const &, C *) const =0
void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const &iHelper) override
Definition: implementors.h:381
ProductResolverIndex transformPrefetch_(std::size_t iIndex) const noexcept final
Definition: implementors.h:371
Accumulator & operator=(Accumulator const &)=delete
RunSummaryCacheHolder< C > & operator=(RunSummaryCacheHolder< C > const &)=delete
virtual void acquire(Event const &, edm::EventSetup const &, WaitingTaskWithArenaHolder)=0
int iEvent
Definition: GenABIO.cc:224
BeginProcessBlockProducer & operator=(BeginProcessBlockProducer const &)=delete
virtual ~LuminosityBlockSummaryCacheHolder() noexcept(false)
Definition: implementors.h:208
EndProcessBlockProducer & operator=(EndProcessBlockProducer const &)=delete
virtual void endLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, C *) const =0
virtual ~ExternalWork() noexcept(false)
Definition: implementors.h:289
virtual ~WatchLuminosityBlocks() noexcept(false)
Definition: implementors.h:299
edm::TypeWithDict returnType(const edm::FunctionWithDict &)
Definition: returnType.cc:16
InputProcessBlockCacheHolder & operator=(InputProcessBlockCacheHolder const &)=delete
void extendUpdateLookup(ProducerBase const &, ModuleDescription const &iModuleDesc, ProductResolverIndexHelper const &iHelper)
BeginLuminosityBlockProducer & operator=(BeginLuminosityBlockProducer const &)=delete
void setGlobalCache(C const *iCache)
Definition: implementors.h:59
void registerTransformAsync(edm::EDPutTokenT< G > iToken, P iPre, F iF, std::string productInstance=std::string())
Definition: implementors.h:346
WatchRuns & operator=(WatchRuns const &)=delete
ExternalWork & operator=(ExternalWork const &)=delete
void setProcessBlockCache(edm::impl::InputProcessBlockCacheImpl< CacheTypes... > const *cacheImpl)
Definition: implementors.h:104
const std::complex< double > I
Definition: I.h:8
double f[11][100]
~Accumulator() noexcept(false) override
Definition: implementors.h:393
void registerTransform(ProducerBase::BranchAliasSetterT< G > iSetter, F &&iF, std::string productInstance=std::string())
Definition: implementors.h:323
Transformer & operator=(Transformer const &)=delete
void setRunCache(C const *iCache)
Definition: implementors.h:166
std::size_t findMatchingIndex(ProducerBase const &iBase, edm::BranchDescription const &) const noexcept
typename std::tuple_element< N, std::tuple< CacheTypes... > >::type CacheTypeT
Definition: implementors.h:80
LuminosityBlockSummaryCacheHolder< C > & operator=(LuminosityBlockSummaryCacheHolder< C > const &)=delete
void transformImpAsync(WaitingTaskHolder iTask, std::size_t iIndex, edm::ActivityRegistry *iAct, ProducerBase const &iBase, edm::EventForTransformer &) const noexcept
#define N
Definition: blowfish.cc:9
edm::impl::InputProcessBlockCacheImpl< CacheTypes... > const * cacheImpl_
Definition: implementors.h:143
void registerTransformAsyncImp(ProducerBase &, EDPutToken, const TypeID &id, std::string instanceName, PreTransformFunction, TransformFunction)
WatchProcessBlock & operator=(WatchProcessBlock const &)=delete
std::vector< edm::impl::TokenInfo > & tokenInfos()
Definition: implementors.h:109
std::pair< OmniClusterRef, TrackingParticleRef > P
EndRunProducer & operator=(EndRunProducer const &)=delete
size_t transformIndex_(edm::BranchDescription const &iBranch) const noexcept final
Definition: implementors.h:368
std::tuple< CacheHandle< CacheTypes >... > processBlockCaches(Event const &event) const
HLT enums.
def cache(function)
Definition: utilities.py:3
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&cacheFiller)
Definition: implementors.h:83
LuminosityBlockCacheHolder< C > & operator=(LuminosityBlockCacheHolder< C > const &)=delete
void registerTransformImp(ProducerBase &, EDPutToken, const TypeID &id, std::string instanceName, TransformFunction)
static void accessInputProcessBlock(edm::ProcessBlock const &)
Definition: implementors.h:117
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
ModuleDescription const & moduleDescription() const
ProductResolverIndex prefetchImp(std::size_t iIndex) const noexcept
void produce(Event &ev, EventSetup const &es) final
Definition: implementors.h:397
static void accessInputProcessBlock(edm::ProcessBlock const &, GlobalCacheType *)
Definition: implementors.h:120
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45
virtual ~WatchRuns() noexcept(false)
Definition: implementors.h:310