CMS 3D CMS Logo

PrincipalGetAdapter.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_PrincipalGetAdapter_h
2 #define FWCore_Framework_PrincipalGetAdapter_h
3 
4 // -*- C++ -*-
5 //
6 
7 // Class : PrincipalGetAdapter
8 //
80 /*----------------------------------------------------------------------
81 
82 ----------------------------------------------------------------------*/
83 #include <cassert>
84 #include <typeinfo>
85 #include <string>
86 #include <vector>
87 #include <type_traits>
88 
92 
94 
96 
98 
100 
102 
110 
111 
112 namespace edm {
113 
114  class ModuleCallingContext;
116  class ProducerBase;
117 
118  namespace principal_get_adapter_detail {
119  void
120  throwOnPutOfNullProduct(char const* principalType, TypeID const& productType, std::string const& productInstanceName);
121  void
122  throwOnPutOfUninitializedToken(char const* principalType, std::type_info const& productType);
123  void
124  throwOnPutOfWrongType(std::type_info const& wrongType, TypeID const& rightType);
125  void
126  throwOnPrematureRead(char const* principalType, TypeID const& productType, std::string const& moduleLabel, std::string const& productInstanceName);
127  void
128  throwOnPrematureRead(char const* principalType, TypeID const& productType);
129 
130  void
131  throwOnPrematureRead(char const* principalType, TypeID const& productType, EDGetToken);
132 
133  }
135  public:
136  PrincipalGetAdapter(Principal const& pcpl,
137  ModuleDescription const& md);
138 
140 
141  PrincipalGetAdapter(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
142  PrincipalGetAdapter& operator=(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
143 
144  //size_t size() const;
145 
146  void setConsumer(EDConsumerBase const* iConsumer) {
147  consumer_ = iConsumer;
148  }
149 
151  resourcesAcquirer_ = iSra;
152  }
153 
154  void setProducer(ProducerBase const* iProd) {
155  prodBase_ = iProd;
156  }
157 
158  size_t numberOfProductsConsumed() const ;
159 
160  bool isComplete() const;
161 
162  template <typename PROD>
163  bool
164  checkIfComplete() const;
165 
166  Transition transition() const;
167 
168  template <typename PROD>
169  void
170  getManyByType(std::vector<Handle<PROD> >& results, ModuleCallingContext const* mcc) const;
171 
172  ProcessHistory const&
173  processHistory() const;
174 
175  Principal const& principal() const {return principal_;}
176 
177  BranchDescription const&
178  getBranchDescription(TypeID const& type, std::string const& productInstanceName) const;
179 
181  getPutTokenIndex(TypeID const& type, std::string const& productInstanceName) const;
182 
183  TypeID const& getTypeIDForPutTokenIndex(EDPutToken::value_type index) const;
184  std::string const& productInstanceLabel(EDPutToken) const;
185  typedef std::vector<BasicHandle> BasicHandleVec;
186 
187  BranchDescription const&
188  getBranchDescription(unsigned int iPutTokenIndex) const;
189  ProductID const& getProductID(unsigned int iPutTokenIndex) const;
190 
191  std::vector<edm::ProductResolverIndex> const&
192  putTokenIndexToProductResolverIndex() const ;
193 
194  //uses the EDPutToken index
195  std::vector<bool> const& recordProvenanceList() const;
196  //------------------------------------------------------------
197  // Protected functions.
198  //
199 
200  // The following 'get' functions serve to isolate the PrincipalGetAdapter class
201  // from the Principal class.
202 
203  BasicHandle
204  getByLabel_(TypeID const& tid, InputTag const& tag,
205  ModuleCallingContext const* mcc) const;
206 
207  BasicHandle
208  getByLabel_(TypeID const& tid,
209  std::string const& label,
210  std::string const& instance,
211  std::string const& process,
212  ModuleCallingContext const* mcc) const;
213 
215  getByToken_(TypeID const& id, KindOfType kindOfType, EDGetToken token,
216  ModuleCallingContext const* mcc) const;
217 
219  getMatchingSequenceByLabel_(TypeID const& typeID,
220  InputTag const& tag,
221  ModuleCallingContext const* mcc) const;
222 
224  getMatchingSequenceByLabel_(TypeID const& typeID,
225  std::string const& label,
226  std::string const& instance,
227  std::string const& process,
228  ModuleCallingContext const* mcc) const;
229 
230  void
231  getManyByType_(TypeID const& tid,
232  BasicHandleVec& results,
233  ModuleCallingContext const* mcc) const;
234 
235  // Also isolates the PrincipalGetAdapter class
236  // from the Principal class.
237  EDProductGetter const* prodGetter() const;
238 
239  void labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const;
240 
241  private:
242  // Is this an Event, a LuminosityBlock, or a Run.
243  BranchType const& branchType() const;
244 
246  makeFailToGetException(KindOfType,TypeID const&,EDGetToken) const;
247 
248  void
249  throwAmbiguousException(TypeID const& productType, EDGetToken token) const;
250 
251  void
252  throwUnregisteredPutException(TypeID const& type,
253  std::string const& productInstanceLabel) const;
254  private:
255  //------------------------------------------------------------
256  // Data members
257  //
258 
259  // Each PrincipalGetAdapter must have an associated Principal, used as the
260  // source of all 'gets' and the target of 'puts'.
262 
263  // Each PrincipalGetAdapter must have a description of the module executing the
264  // "transaction" which the PrincipalGetAdapter represents.
266 
268  SharedResourcesAcquirer* resourcesAcquirer_; // We do not use propagate_const because the acquirer is itself mutable.
269  ProducerBase const* prodBase_ = nullptr;
270  };
271 
272  template <typename PROD>
273  inline
274  std::ostream&
275  operator<<(std::ostream& os, Handle<PROD> const& h) {
276  os << h.product() << " " << h.provenance() << " " << h.id();
277  return os;
278  }
279 
280 
281  //------------------------------------------------------------
282  // Metafunction support for compile-time selection of code used in
283  // PrincipalGetAdapter::put member template.
284  //
285 
286  // has_postinsert is a metafunction of one argument, the type T. As
287  // with many metafunctions, it is implemented as a class with a data
288  // member 'value', which contains the value 'returned' by the
289  // metafunction.
290  //
291  // has_postinsert<T>::value is 'true' if T has the post_insert
292  // member function (with the right signature), and 'false' if T has
293  // no such member function.
294 
295  namespace detail {
296  using no_tag = std::false_type; // type indicating FALSE
297  using yes_tag = std::true_type; // type indicating TRUE
298 
299  // Definitions forthe following struct and function templates are
300  // not needed; we only require the declarations.
301  template <typename T, void (T::*)()> struct postinsert_function;
302  template <typename T> no_tag has_postinsert_helper(...);
304 
305 
306  template<typename T>
307  struct has_postinsert {
308  static constexpr bool value = std::is_same<decltype(has_postinsert_helper<T>(nullptr)), yes_tag>::value &&
310  };
311 
312  }
313 
314  //------------------------------------------------------------
315 
316  // The following function objects are used by Event::put, under the
317  // control of a metafunction if, to either call the given object's
318  // post_insert function (if it has one), or to do nothing (if it
319  // does not have a post_insert function).
320  template <typename T>
321  struct DoPostInsert {
322  void operator()(T* p) const { p->post_insert(); }
323  };
324 
325  template <typename T>
327  void operator()(T*) const { }
328  };
329 
330  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
331  // implementation of non-template members.
332  //
333 
334  template <typename PROD>
335  inline
336  bool
338  return isComplete() || !detail::has_mergeProduct_function<PROD>::value;
339  }
340 
341  template <typename PROD>
342  inline
343  void
345  ModuleCallingContext const* mcc) const {
346  BasicHandleVec bhv;
347  this->getManyByType_(TypeID(typeid(PROD)), bhv, mcc);
348 
349  // Go through the returned handles; for each element,
350  // 1. create a Handle<PROD> and
351  //
352  // This function presents an exception safety difficulty. If an
353  // exception is thrown when converting a handle, the "got
354  // products" record will be wrong.
355  //
356  // Since EDProducers are not allowed to use this function,
357  // the problem does not seem too severe.
358  //
359  // Question: do we even need to keep track of the "got products"
360  // for this function, since it is *not* to be used by EDProducers?
361  std::vector<Handle<PROD> > products;
362 
363  typename BasicHandleVec::iterator it = bhv.begin();
364  typename BasicHandleVec::iterator end = bhv.end();
365 
366  while (it != end) {
368  convert_handle(std::move(*it), result); // throws on conversion error
369  products.push_back(result);
370  ++it;
371  }
372  results.swap(products);
373  }
374 }
375 #endif
SharedResourcesAcquirer * resourcesAcquirer_
type
Definition: HCALResponse.h:21
void setConsumer(EDConsumerBase const *iConsumer)
void operator()(T *p) const
Principal const & principal() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static PFTauRenderPlugin instance
void throwOnPutOfUninitializedToken(char const *principalType, std::type_info const &productType)
std::false_type no_tag
Definition: WrapperDetail.h:19
EDConsumerBase const * consumer_
void setSharedResourcesAcquirer(SharedResourcesAcquirer *iSra)
#define constexpr
BranchType
Definition: BranchType.h:11
static void throwAmbiguousException(const char *where, TypeID const &productType, std::string const &label, std::string const &instance, std::string const &process)
Definition: Principal.cc:73
void setProducer(ProducerBase const *iProd)
yes_tag has_postinsert_helper(postinsert_function< T,&T::post_insert > *p)
ESProducts< T, S > products(const T &i1, const S &i2)
Definition: ESProducts.h:191
unsigned int value_type
Definition: EDPutToken.h:39
Transition
Definition: Transition.h:12
void throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
void getManyByType(std::vector< Handle< PROD > > &results, ModuleCallingContext const *mcc) const
#define end
Definition: vmac.h:37
Definition: value.py:1
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
std::true_type yes_tag
Definition: WrapperDetail.h:20
HLT enums.
void operator()(T *) const
#define PROD(A, B)
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
ModuleDescription const & md_
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
long double T
def move(src, dest)
Definition: eostools.py:510
def branchType(schema, name)
Definition: revisionDML.py:112
std::vector< BasicHandle > BasicHandleVec