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
40 
41 // forward declarations
42 namespace edm {
43 
44  class WaitingTaskWithArenaHolder;
45 
46  namespace stream {
47  namespace impl {
48  class EmptyType {};
49 
50  template <typename C>
52  public:
53  GlobalCacheHolder() = default;
54  GlobalCacheHolder(GlobalCacheHolder<C> const&) = delete;
56 
57  void setGlobalCache(C const* iCache) { cache_ = iCache; }
58 
59  protected:
60  C const* globalCache() const { return cache_; }
61 
62  private:
63  C const* cache_;
64  };
65 
66  template <typename... CacheTypes>
68  public:
69  InputProcessBlockCacheHolder() = default;
72 
73  std::tuple<CacheHandle<CacheTypes>...> processBlockCaches(Event const& event) const {
74  return cacheImpl_->processBlockCaches(event);
75  }
76 
77  template <std::size_t N>
78  using CacheTypeT = typename std::tuple_element<N, std::tuple<CacheTypes...>>::type;
79 
80  template <std::size_t ICacheType, typename DataType, typename Func>
81  void registerProcessBlockCacheFiller(EDGetTokenT<DataType> const& token, Func&& cacheFiller) {
82  registerProcessBlockCacheFiller<ICacheType, CacheTypeT<ICacheType>, DataType, Func>(
83  token, std::forward<Func>(cacheFiller));
84  }
85 
86  template <typename CacheType, typename DataType, typename Func>
87  void registerProcessBlockCacheFiller(EDGetTokenT<DataType> const& token, Func&& cacheFiller) {
88  static_assert(edm::impl::countTypeInParameterPack<CacheType, CacheTypes...>() == 1u,
89  "If registerProcessBlockCacheFiller is called with a type template parameter\n"
90  "then that type must appear exactly once in the template parameters of InputProcessBlockCache");
91 
92  // Find the index into the parameter pack from the CacheType
93  constexpr unsigned int I = edm::impl::indexInputProcessBlockCache<CacheType, CacheTypes...>();
94 
95  registerProcessBlockCacheFiller<I, CacheType, DataType, Func>(token, std::forward<Func>(cacheFiller));
96  }
97 
98  private:
99  template <typename T, bool, bool>
101 
103  cacheImpl_ = cacheImpl;
104  }
105 
106  bool cacheFillersRegistered() const { return registrationInfo_ ? true : false; }
107  std::vector<edm::impl::TokenInfo>& tokenInfos() { return registrationInfo_->tokenInfos_; }
108  std::tuple<edm::impl::CacheFiller<CacheTypes>...>& cacheFillers() { return registrationInfo_->cacheFillers_; }
109 
111 
112  // The next two functions exist so that it is optional whether modules
113  // with this ability implement them.
114 
116 
117  template <typename GlobalCacheType>
118  static void accessInputProcessBlock(edm::ProcessBlock const&, GlobalCacheType*) {}
119 
120  template <std::size_t ICacheType, typename CacheType, typename DataType, typename Func>
122  if (!registrationInfo_) {
123  registrationInfo_ = std::make_unique<RegistrationInfo>();
124  tokenInfos().resize(sizeof...(CacheTypes));
125  }
126 
127  if (!tokenInfos()[ICacheType].token_.isUninitialized()) {
129  << "registerProcessBlockCacheFiller should only be called once per cache type";
130  }
131 
132  tokenInfos()[ICacheType] = edm::impl::TokenInfo{EDGetToken(token), TypeID(typeid(DataType))};
133 
134  std::get<ICacheType>(cacheFillers()).func_ =
135  std::function<std::shared_ptr<CacheType>(ProcessBlock const&, std::shared_ptr<CacheType> const&)>(
136  std::forward<Func>(cacheFiller));
137  }
138 
139  // ------------ Data members --------------------
140 
142 
143  // The RegistrationInfo is filled while the module constructor runs.
144  // Later this information is copied to the InputProcessBlockCacheImpl
145  // object owned by the adaptor and then registrationInfo_ is cleared.
146  // Note that this is really only needed for one of the stream instances,
147  // but we fill for all streams so registerProcessBlockCacheFiller can
148  // be called in the constructor. This keeps the interface as simple as
149  // possible and makes it similar to the consumes interface.
151  public:
152  std::vector<edm::impl::TokenInfo> tokenInfos_;
153  std::tuple<edm::impl::CacheFiller<CacheTypes>...> cacheFillers_;
154  };
155  std::unique_ptr<RegistrationInfo> registrationInfo_;
156  };
157 
158  template <typename C>
160  public:
161  RunCacheHolder() = default;
162  RunCacheHolder(RunCacheHolder<C> const&) = delete;
164  void setRunCache(C const* iCache) { cache_ = iCache; }
165 
166  protected:
167  C const* runCache() const { return cache_; }
168 
169  private:
170  C const* cache_;
171  };
172 
173  template <typename C>
175  public:
176  LuminosityBlockCacheHolder() = default;
179  void setLuminosityBlockCache(C const* iCache) { cache_ = iCache; }
180 
181  protected:
182  C const* luminosityBlockCache() const { return cache_; }
183 
184  private:
185  C const* cache_;
186  };
187 
188  template <typename C>
190  public:
191  RunSummaryCacheHolder() = default;
194  virtual ~RunSummaryCacheHolder() noexcept(false) {}
195 
196  private:
197  virtual void endRunSummary(edm::Run const&, edm::EventSetup const&, C*) const = 0;
198  };
199 
200  template <typename C>
202  public:
207 
208  private:
209  virtual void endLuminosityBlockSummary(edm::LuminosityBlock const&, edm::EventSetup const&, C*) const = 0;
210  };
211 
213  public:
214  WatchProcessBlock() = default;
215  WatchProcessBlock(WatchProcessBlock const&) = delete;
217 
220  };
221 
223  public:
224  BeginProcessBlockProducer() = default;
227 
230  };
231 
233  public:
234  EndProcessBlockProducer() = default;
237 
240  };
241 
243  public:
244  BeginRunProducer() = default;
245  BeginRunProducer(BeginRunProducer const&) = delete;
246  BeginRunProducer& operator=(BeginRunProducer const&) = delete;
247 
250  };
251 
253  public:
254  EndRunProducer() = default;
255  EndRunProducer(EndRunProducer const&) = delete;
256  EndRunProducer& operator=(EndRunProducer const&) = delete;
257 
260  };
261 
263  public:
264  BeginLuminosityBlockProducer() = default;
267 
270  };
271 
273  public:
274  EndLuminosityBlockProducer() = default;
277 
280  };
281 
282  class ExternalWork {
283  public:
284  ExternalWork() = default;
285  ExternalWork(ExternalWork const&) = delete;
286  ExternalWork& operator=(ExternalWork const&) = delete;
287  virtual ~ExternalWork() noexcept(false){};
288 
289  virtual void acquire(Event const&, edm::EventSetup const&, WaitingTaskWithArenaHolder) = 0;
290  };
291 
292  class Accumulator : public EDProducerBase {
293  public:
294  Accumulator() = default;
295  Accumulator(Accumulator const&) = delete;
296  Accumulator& operator=(Accumulator const&) = delete;
297  ~Accumulator() noexcept(false) override{};
298 
299  virtual void accumulate(Event const& ev, EventSetup const& es) = 0;
300 
301  void produce(Event& ev, EventSetup const& es) final { accumulate(ev, es); }
302  };
303  } // namespace impl
304  } // namespace stream
305 } // namespace edm
306 
307 #endif
std::tuple< edm::impl::CacheFiller< CacheTypes >... > & cacheFillers()
Definition: implementors.h:108
RunCacheHolder< C > & operator=(RunCacheHolder< C > const &)=delete
BeginRunProducer & operator=(BeginRunProducer const &)=delete
std::tuple< edm::impl::CacheFiller< CacheTypes >... > cacheFillers_
Definition: implementors.h:153
std::unique_ptr< RegistrationInfo > registrationInfo_
Definition: implementors.h:155
GlobalCacheHolder< C > & operator=(GlobalCacheHolder< C > const &)=delete
virtual ~RunSummaryCacheHolder() noexcept(false)
Definition: implementors.h:194
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&cacheFiller)
Definition: implementors.h:121
constexpr std::size_t indexInputProcessBlockCache()
virtual void accumulate(Event const &ev, EventSetup const &es)=0
std::tuple< CacheHandle< CacheTypes >... > processBlockCaches(Event const &event) const
Definition: implementors.h:73
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
EndLuminosityBlockProducer & operator=(EndLuminosityBlockProducer const &)=delete
virtual void endRunSummary(edm::Run const &, edm::EventSetup const &, C *) const =0
Accumulator & operator=(Accumulator const &)=delete
RunSummaryCacheHolder< C > & operator=(RunSummaryCacheHolder< C > const &)=delete
virtual void acquire(Event const &, edm::EventSetup const &, WaitingTaskWithArenaHolder)=0
BeginProcessBlockProducer & operator=(BeginProcessBlockProducer const &)=delete
virtual ~LuminosityBlockSummaryCacheHolder() noexcept(false)
Definition: implementors.h:206
EndProcessBlockProducer & operator=(EndProcessBlockProducer const &)=delete
virtual void endLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, C *) const =0
virtual ~ExternalWork() noexcept(false)
Definition: implementors.h:287
InputProcessBlockCacheHolder & operator=(InputProcessBlockCacheHolder const &)=delete
BeginLuminosityBlockProducer & operator=(BeginLuminosityBlockProducer const &)=delete
void setGlobalCache(C const *iCache)
Definition: implementors.h:57
ExternalWork & operator=(ExternalWork const &)=delete
void setProcessBlockCache(edm::impl::InputProcessBlockCacheImpl< CacheTypes... > const *cacheImpl)
Definition: implementors.h:102
const std::complex< double > I
Definition: I.h:8
~Accumulator() noexcept(false) override
Definition: implementors.h:297
void setRunCache(C const *iCache)
Definition: implementors.h:164
typename std::tuple_element< N, std::tuple< CacheTypes... > >::type CacheTypeT
Definition: implementors.h:78
LuminosityBlockSummaryCacheHolder< C > & operator=(LuminosityBlockSummaryCacheHolder< C > const &)=delete
#define N
Definition: blowfish.cc:9
edm::impl::InputProcessBlockCacheImpl< CacheTypes... > const * cacheImpl_
Definition: implementors.h:141
WatchProcessBlock & operator=(WatchProcessBlock const &)=delete
std::vector< edm::impl::TokenInfo > & tokenInfos()
Definition: implementors.h:107
EndRunProducer & operator=(EndRunProducer const &)=delete
HLT enums.
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&cacheFiller)
Definition: implementors.h:81
LuminosityBlockCacheHolder< C > & operator=(LuminosityBlockCacheHolder< C > const &)=delete
static void accessInputProcessBlock(edm::ProcessBlock const &)
Definition: implementors.h:115
void produce(Event &ev, EventSetup const &es) final
Definition: implementors.h:301
static void accessInputProcessBlock(edm::ProcessBlock const &, GlobalCacheType *)
Definition: implementors.h:118
Definition: event.py:1
Definition: Run.h:45