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
edm::stream::impl::LuminosityBlockSummaryCacheHolder::LuminosityBlockSummaryCacheHolder
LuminosityBlockSummaryCacheHolder()=default
edm::stream::impl::BeginProcessBlockProducer::operator=
BeginProcessBlockProducer & operator=(BeginProcessBlockProducer const &)=delete
edm::stream::impl::InputProcessBlockCacheHolder::cacheFillers
std::tuple< edm::impl::CacheFiller< CacheTypes >... > & cacheFillers()
Definition: implementors.h:108
edm::stream::impl::GlobalCacheHolder::cache_
C const * cache_
Definition: implementors.h:63
edm::stream::impl::InputProcessBlockCacheHolder::RegistrationInfo
Definition: implementors.h:150
edm::stream::impl::BeginRunProducer::operator=
BeginRunProducer & operator=(BeginRunProducer const &)=delete
funct::false
false
Definition: Factorize.h:29
edm::stream::impl::RunSummaryCacheHolder::~RunSummaryCacheHolder
virtual ~RunSummaryCacheHolder() noexcept(false)
Definition: implementors.h:194
edm::stream::impl::EndRunProducer::EndRunProducer
EndRunProducer()=default
edm::stream::impl::InputProcessBlockCacheHolder::RegistrationInfo::cacheFillers_
std::tuple< edm::impl::CacheFiller< CacheTypes >... > cacheFillers_
Definition: implementors.h:153
edm::stream::impl::RunCacheHolder::setRunCache
void setRunCache(C const *iCache)
Definition: implementors.h:164
edm::stream::impl::RunCacheHolder::cache_
C const * cache_
Definition: implementors.h:170
edm::stream::impl::EndProcessBlockProducer
Definition: implementors.h:232
edm::errors::LogicError
Definition: EDMException.h:37
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::stream::impl::ExternalWork::operator=
ExternalWork & operator=(ExternalWork const &)=delete
edm::stream::impl::InputProcessBlockCacheHolder::cacheFillersRegistered
bool cacheFillersRegistered() const
Definition: implementors.h:106
edm::stream::impl::RunSummaryCacheHolder
Definition: implementors.h:189
edm::stream::impl::InputProcessBlockCacheHolder::registrationInfo_
std::unique_ptr< RegistrationInfo > registrationInfo_
Definition: implementors.h:155
edm::stream::EDProducerBase
Definition: EDProducerBase.h:44
edm::stream::impl::GlobalCacheHolder::GlobalCacheHolder
GlobalCacheHolder()=default
cms::cuda::stream
uint32_t const T *__restrict__ const uint32_t *__restrict__ int32_t int Histo::index_type cudaStream_t stream
Definition: HistoContainer.h:51
TypeID.h
edm::stream::impl::InputProcessBlockCacheHolder::registerProcessBlockCacheFiller
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&cacheFiller)
Definition: implementors.h:121
edm::stream::impl::ExternalWork::~ExternalWork
virtual ~ExternalWork() noexcept(false)
Definition: implementors.h:287
edm::stream::impl::LuminosityBlockCacheHolder::LuminosityBlockCacheHolder
LuminosityBlockCacheHolder()=default
edm::stream::impl::InputProcessBlockCacheHolder::InputProcessBlockCacheHolder
InputProcessBlockCacheHolder()=default
edm::stream::impl::InputProcessBlockCacheHolder::processBlockCaches
std::tuple< CacheHandle< CacheTypes >... > processBlockCaches(Event const &event) const
Definition: implementors.h:73
edm::stream::impl::RunSummaryCacheHolder::operator=
RunSummaryCacheHolder< C > & operator=(RunSummaryCacheHolder< C > const &)=delete
edm::stream::impl::LuminosityBlockSummaryCacheHolder::endLuminosityBlockSummary
virtual void endLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, C *) const =0
edm::impl::InputProcessBlockCacheImpl< CacheTypes... >
edm::stream::impl::InputProcessBlockCacheHolder::RegistrationInfo::tokenInfos_
std::vector< edm::impl::TokenInfo > tokenInfos_
Definition: implementors.h:152
edm::stream::impl::BeginRunProducer::BeginRunProducer
BeginRunProducer()=default
edm::stream::impl::BeginLuminosityBlockProducer
Definition: implementors.h:262
edm::stream::impl::RunSummaryCacheHolder::endRunSummary
virtual void endRunSummary(edm::Run const &, edm::EventSetup const &, C *) const =0
edm::stream::impl::RunCacheHolder::RunCacheHolder
RunCacheHolder()=default
edm::stream::impl::BeginProcessBlockProducer::BeginProcessBlockProducer
BeginProcessBlockProducer()=default
edm::stream::impl::WatchProcessBlock::operator=
WatchProcessBlock & operator=(WatchProcessBlock const &)=delete
EDMException.h
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:34
edm::stream::impl::LuminosityBlockSummaryCacheHolder::~LuminosityBlockSummaryCacheHolder
virtual ~LuminosityBlockSummaryCacheHolder() noexcept(false)
Definition: implementors.h:206
Exhume::I
const std::complex< double > I
Definition: I.h:8
edm::stream::impl::EndRunProducer::operator=
EndRunProducer & operator=(EndRunProducer const &)=delete
edm::stream::impl::ExternalWork::ExternalWork
ExternalWork()=default
N
#define N
Definition: blowfish.cc:9
edm::stream::impl::EndLuminosityBlockProducer::EndLuminosityBlockProducer
EndLuminosityBlockProducer()=default
edm::stream::impl::LuminosityBlockCacheHolder
Definition: implementors.h:174
CacheHandle.h
edm::stream::impl::BeginLuminosityBlockProducer::operator=
BeginLuminosityBlockProducer & operator=(BeginLuminosityBlockProducer const &)=delete
edm::stream::impl::GlobalCacheHolder::setGlobalCache
void setGlobalCache(C const *iCache)
Definition: implementors.h:57
edm::impl::indexInputProcessBlockCache
constexpr std::size_t indexInputProcessBlockCache()
Definition: InputProcessBlockCacheImpl.h:50
edm::stream::impl::Accumulator::operator=
Accumulator & operator=(Accumulator const &)=delete
edm::stream::impl::Accumulator::produce
void produce(Event &ev, EventSetup const &es) final
Definition: implementors.h:301
InputProcessBlockCacheImpl.h
edm::stream::impl::InputProcessBlockCacheHolder::setProcessBlockCache
void setProcessBlockCache(edm::impl::InputProcessBlockCacheImpl< CacheTypes... > const *cacheImpl)
Definition: implementors.h:102
edm::stream::impl::LuminosityBlockSummaryCacheHolder::operator=
LuminosityBlockSummaryCacheHolder< C > & operator=(LuminosityBlockSummaryCacheHolder< C > const &)=delete
EDGetToken.h
edm::stream::impl::GlobalCacheHolder::operator=
GlobalCacheHolder< C > & operator=(GlobalCacheHolder< C > const &)=delete
RunIndex.h
edm::stream::impl::InputProcessBlockCacheHolder::operator=
InputProcessBlockCacheHolder & operator=(InputProcessBlockCacheHolder const &)=delete
funct::true
true
Definition: Factorize.h:173
edm::stream::impl::WatchProcessBlock::WatchProcessBlock
WatchProcessBlock()=default
edm::stream::impl::GlobalCacheHolder
Definition: implementors.h:51
edm::stream::impl::EndLuminosityBlockProducer
Definition: implementors.h:272
edm::stream::impl::InputProcessBlockCacheHolder
Definition: implementors.h:67
edm::stream::impl::ExternalWork::acquire
virtual void acquire(Event const &, edm::EventSetup const &, WaitingTaskWithArenaHolder)=0
edm::stream::impl::EndProcessBlockProducer::EndProcessBlockProducer
EndProcessBlockProducer()=default
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
edm::stream::impl::WatchProcessBlock
Definition: implementors.h:212
edm::stream::impl::InputProcessBlockCacheHolder::cacheImpl_
edm::impl::InputProcessBlockCacheImpl< CacheTypes... > const * cacheImpl_
Definition: implementors.h:141
edm::stream::impl::LuminosityBlockSummaryCacheHolder
Definition: implementors.h:201
edm::EventSetup
Definition: EventSetup.h:58
edm::stream::impl::InputProcessBlockCacheHolder::tokenInfos
std::vector< edm::impl::TokenInfo > & tokenInfos()
Definition: implementors.h:107
edm::EDGetToken
Definition: EDGetToken.h:35
edm::stream::impl::EndLuminosityBlockProducer::operator=
EndLuminosityBlockProducer & operator=(EndLuminosityBlockProducer const &)=delete
edm::stream::impl::LuminosityBlockCacheHolder::operator=
LuminosityBlockCacheHolder< C > & operator=(LuminosityBlockCacheHolder< C > const &)=delete
edm::stream::impl::RunCacheHolder
Definition: implementors.h:159
edm::stream::impl::LuminosityBlockCacheHolder::setLuminosityBlockCache
void setLuminosityBlockCache(C const *iCache)
Definition: implementors.h:179
edm::stream::impl::InputProcessBlockCacheHolder::CacheTypeT
typename std::tuple_element< N, std::tuple< CacheTypes... > >::type CacheTypeT
Definition: implementors.h:78
edm::stream::impl::InputProcessBlockCacheHolder::clearRegistration
void clearRegistration()
Definition: implementors.h:110
edm::TypeID
Definition: TypeID.h:22
impl
Definition: trackAlgoPriorityOrder.h:18
gen::C
C
Definition: PomwigHadronizer.cc:78
edm::stream::impl::InputProcessBlockCacheHolder::registerProcessBlockCacheFiller
void registerProcessBlockCacheFiller(EDGetTokenT< DataType > const &token, Func &&cacheFiller)
Definition: implementors.h:81
Frameworkfwd.h
edm::stream::impl::BeginProcessBlockProducer
Definition: implementors.h:222
edm::stream::impl::Accumulator::accumulate
virtual void accumulate(Event const &ev, EventSetup const &es)=0
ev
bool ev
Definition: Hydjet2Hadronizer.cc:97
Exception
Definition: hltDiff.cc:245
edm::stream::impl::Accumulator::~Accumulator
~Accumulator() noexcept(false) override
Definition: implementors.h:297
edm::stream::impl::ExternalWork
Definition: implementors.h:282
edm::stream::impl::EmptyType
Definition: implementors.h:48
EDProducerBase.h
LuminosityBlockIndex.h
edm::stream::impl::EndProcessBlockProducer::operator=
EndProcessBlockProducer & operator=(EndProcessBlockProducer const &)=delete
edm::stream::CallInputProcessBlockImpl
Definition: callAbilities.h:75
edm::stream::impl::RunCacheHolder::runCache
C const * runCache() const
Definition: implementors.h:167
edm::stream::impl::GlobalCacheHolder::globalCache
C const * globalCache() const
Definition: implementors.h:60
edm::stream::impl::LuminosityBlockCacheHolder::cache_
C const * cache_
Definition: implementors.h:185
edm::impl::TokenInfo
Definition: InputProcessBlockCacheImpl.h:65
edm::stream::impl::BeginLuminosityBlockProducer::BeginLuminosityBlockProducer
BeginLuminosityBlockProducer()=default
edm::stream::impl::RunCacheHolder::operator=
RunCacheHolder< C > & operator=(RunCacheHolder< C > const &)=delete
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
StreamID.h
edm::stream::impl::InputProcessBlockCacheHolder::accessInputProcessBlock
static void accessInputProcessBlock(edm::ProcessBlock const &)
Definition: implementors.h:115
edm::stream::impl::RunSummaryCacheHolder::RunSummaryCacheHolder
RunSummaryCacheHolder()=default
edm::stream::impl::LuminosityBlockCacheHolder::luminosityBlockCache
C const * luminosityBlockCache() const
Definition: implementors.h:182
edm::ProcessBlock
Definition: ProcessBlock.h:36
edm::stream::impl::BeginRunProducer
Definition: implementors.h:242
HLT_FULL_cff.DataType
DataType
Definition: HLT_FULL_cff.py:32781
edm::stream::impl::Accumulator::Accumulator
Accumulator()=default
edm::stream::impl::EndRunProducer
Definition: implementors.h:252
edm::stream::impl::Accumulator
Definition: implementors.h:292
edm::stream::impl::InputProcessBlockCacheHolder::accessInputProcessBlock
static void accessInputProcessBlock(edm::ProcessBlock const &, GlobalCacheType *)
Definition: implementors.h:118
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316