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 {
76  return cacheImpl_->processBlockCaches(event);
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 
294  class Transformer : private TransformerBase, public EDProducerBase {
295  public:
296  Transformer() = default;
297  Transformer(Transformer const&) = delete;
298  Transformer& operator=(Transformer const&) = delete;
299  ~Transformer() noexcept(false) override{};
300 
301  template <typename G, typename F>
303  F&& iF,
304  std::string productInstance = std::string()) {
305  registerTransform(edm::EDPutTokenT<G>(iSetter), std::forward<F>(iF), std::move(productInstance));
306  }
307 
308  template <typename G, typename F>
309  void registerTransform(edm::EDPutTokenT<G> iToken, F iF, std::string productInstance = std::string()) {
310  using ReturnTypeT = decltype(iF(std::declval<G>()));
311  TypeID returnType(typeid(ReturnTypeT));
313  *this,
314  EDPutToken(iToken),
315  returnType,
316  std::move(productInstance),
317  [f = std::move(iF)](std::any const& iGotProduct) {
318  auto pGotProduct = std::any_cast<edm::WrapperBase const*>(iGotProduct);
319  return std::make_unique<edm::Wrapper<ReturnTypeT>>(
320  WrapperBase::Emplace{}, f(*static_cast<edm::Wrapper<G> const*>(pGotProduct)->product()));
321  });
322  }
323 
324  template <typename G, typename P, typename F>
326  P iPre,
327  F iF,
328  std::string productInstance = std::string()) {
329  using CacheTypeT = decltype(iPre(std::declval<G>(), WaitingTaskWithArenaHolder()));
330  using ReturnTypeT = decltype(iF(std::declval<CacheTypeT>()));
331  TypeID returnType(typeid(ReturnTypeT));
333  *this,
334  EDPutToken(iToken),
335  returnType,
336  std::move(productInstance),
337  [p = std::move(iPre)](edm::WrapperBase const& iGotProduct, WaitingTaskWithArenaHolder iHolder) {
338  return std::any(p(*static_cast<edm::Wrapper<G> const&>(iGotProduct).product(), std::move(iHolder)));
339  },
340  [f = std::move(iF)](std::any const& iCache) {
341  auto cache = std::any_cast<CacheTypeT>(iCache);
342  return std::make_unique<edm::Wrapper<ReturnTypeT>>(WrapperBase::Emplace{}, f(cache));
343  });
344  }
345 
346  private:
347  size_t transformIndex_(edm::BranchDescription const& iBranch) const final {
348  return TransformerBase::findMatchingIndex(*this, iBranch);
349  }
350  ProductResolverIndex transformPrefetch_(std::size_t iIndex) const final {
351  return TransformerBase::prefetchImp(iIndex);
352  }
354  std::size_t iIndex,
356  ServiceWeakToken const& iToken) const final {
357  return TransformerBase::transformImpAsync(std::move(iTask), iIndex, *this, iEvent);
358  }
359  void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const& iHelper) override {
360  if (iBranchType == InEvent) {
362  }
363  }
364  };
365 
366  class Accumulator : public EDProducerBase {
367  public:
368  Accumulator() = default;
369  Accumulator(Accumulator const&) = delete;
370  Accumulator& operator=(Accumulator const&) = delete;
371  ~Accumulator() noexcept(false) override{};
372 
373  virtual void accumulate(Event const& ev, EventSetup const& es) = 0;
374 
375  void produce(Event& ev, EventSetup const& es) final { accumulate(ev, es); }
376  };
377  } // namespace impl
378  } // namespace stream
379 } // namespace edm
380 
381 #endif
void transformImpAsync(WaitingTaskHolder iTask, std::size_t iIndex, ProducerBase const &iBase, edm::EventForTransformer &) const
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:299
void registerTransform(edm::EDPutTokenT< G > iToken, F iF, std::string productInstance=std::string())
Definition: implementors.h:309
virtual void accumulate(Event const &ev, EventSetup const &es)=0
std::tuple< CacheHandle< CacheTypes >... > processBlockCaches(Event const &event) const
Definition: implementors.h:75
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
ProductResolverIndex prefetchImp(std::size_t iIndex) const
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:359
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
size_t transformIndex_(edm::BranchDescription const &iBranch) const final
Definition: implementors.h:347
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:325
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:371
void registerTransform(ProducerBase::BranchAliasSetterT< G > iSetter, F &&iF, std::string productInstance=std::string())
Definition: implementors.h:302
Transformer & operator=(Transformer const &)=delete
void setRunCache(C const *iCache)
Definition: implementors.h:166
void transformAsync_(WaitingTaskHolder iTask, std::size_t iIndex, edm::EventForTransformer &iEvent, ServiceWeakToken const &iToken) const final
Definition: implementors.h:353
typename std::tuple_element< N, std::tuple< CacheTypes... > >::type CacheTypeT
Definition: implementors.h:80
LuminosityBlockSummaryCacheHolder< C > & operator=(LuminosityBlockSummaryCacheHolder< C > const &)=delete
#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
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 transformPrefetch_(std::size_t iIndex) const final
Definition: implementors.h:350
void produce(Event &ev, EventSetup const &es) final
Definition: implementors.h:375
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
std::size_t findMatchingIndex(ProducerBase const &iBase, edm::BranchDescription const &) const