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, bool isComplete);
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 { return isComplete_;}
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;
271  };
272 
273  template <typename PROD>
274  inline
275  std::ostream&
276  operator<<(std::ostream& os, Handle<PROD> const& h) {
277  os << h.product() << " " << h.provenance() << " " << h.id();
278  return os;
279  }
280 
281 
282  //------------------------------------------------------------
283  // Metafunction support for compile-time selection of code used in
284  // PrincipalGetAdapter::put member template.
285  //
286 
287  // has_postinsert is a metafunction of one argument, the type T. As
288  // with many metafunctions, it is implemented as a class with a data
289  // member 'value', which contains the value 'returned' by the
290  // metafunction.
291  //
292  // has_postinsert<T>::value is 'true' if T has the post_insert
293  // member function (with the right signature), and 'false' if T has
294  // no such member function.
295 
296  namespace detail {
297  using no_tag = std::false_type; // type indicating FALSE
298  using yes_tag = std::true_type; // type indicating TRUE
299 
300  // Definitions forthe following struct and function templates are
301  // not needed; we only require the declarations.
302  template <typename T, void (T::*)()> struct postinsert_function;
303  template <typename T> no_tag has_postinsert_helper(...);
305 
306 
307  template<typename T>
308  struct has_postinsert {
309  static constexpr bool value = std::is_same<decltype(has_postinsert_helper<T>(nullptr)), yes_tag>::value &&
311  };
312 
313  }
314 
315  //------------------------------------------------------------
316 
317  // The following function objects are used by Event::put, under the
318  // control of a metafunction if, to either call the given object's
319  // post_insert function (if it has one), or to do nothing (if it
320  // does not have a post_insert function).
321  template <typename T>
322  struct DoPostInsert {
323  void operator()(T* p) const { p->post_insert(); }
324  };
325 
326  template <typename T>
328  void operator()(T*) const { }
329  };
330 
331  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
332  // implementation of non-template members.
333  //
334 
335  template <typename PROD>
336  inline
337  bool
339  return isComplete() || !detail::has_mergeProduct_function<PROD>::value;
340  }
341 
342  template <typename PROD>
343  inline
344  void
346  ModuleCallingContext const* mcc) const {
347  BasicHandleVec bhv;
348  this->getManyByType_(TypeID(typeid(PROD)), bhv, mcc);
349 
350  // Go through the returned handles; for each element,
351  // 1. create a Handle<PROD> and
352  //
353  // This function presents an exception safety difficulty. If an
354  // exception is thrown when converting a handle, the "got
355  // products" record will be wrong.
356  //
357  // Since EDProducers are not allowed to use this function,
358  // the problem does not seem too severe.
359  //
360  // Question: do we even need to keep track of the "got products"
361  // for this function, since it is *not* to be used by EDProducers?
362  std::vector<Handle<PROD> > products;
363 
364  typename BasicHandleVec::iterator it = bhv.begin();
365  typename BasicHandleVec::iterator end = bhv.end();
366 
367  while (it != end) {
369  convert_handle(std::move(*it), result); // throws on conversion error
370  products.push_back(result);
371  ++it;
372  }
373  results.swap(products);
374  }
375 }
376 #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:20
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:39
Definition: value.py:1
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
std::true_type yes_tag
Definition: WrapperDetail.h:21
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