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 
108 
109 
110 namespace edm {
111 
112  class ModuleCallingContext;
114 
115  namespace principal_get_adapter_detail {
116  void
117  throwOnPutOfNullProduct(char const* principalType, TypeID const& productType, std::string const& productInstanceName);
118  void
119  throwOnPrematureRead(char const* principalType, TypeID const& productType, std::string const& moduleLabel, std::string const& productInstanceName);
120  void
121  throwOnPrematureRead(char const* principalType, TypeID const& productType);
122 
123  void
124  throwOnPrematureRead(char const* principalType, TypeID const& productType, EDGetToken);
125 
126  }
128  public:
129  PrincipalGetAdapter(Principal const& pcpl,
130  ModuleDescription const& md);
131 
133 
134  PrincipalGetAdapter(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
135  PrincipalGetAdapter& operator=(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
136 
137  //size_t size() const;
138 
139  void setConsumer(EDConsumerBase const* iConsumer) {
140  consumer_ = iConsumer;
141  }
142 
144  resourcesAcquirer_ = iSra;
145  }
146 
147 
148  bool isComplete() const;
149 
150  template <typename PROD>
151  bool
152  checkIfComplete() const;
153 
154  template <typename PROD>
155  void
156  getManyByType(std::vector<Handle<PROD> >& results, ModuleCallingContext const* mcc) const;
157 
158  ProcessHistory const&
159  processHistory() const;
160 
161  Principal const& principal() const {return principal_;}
162 
163  BranchDescription const&
164  getBranchDescription(TypeID const& type, std::string const& productInstanceName) const;
165 
166  typedef std::vector<BasicHandle> BasicHandleVec;
167 
168  //------------------------------------------------------------
169  // Protected functions.
170  //
171 
172  // The following 'get' functions serve to isolate the PrincipalGetAdapter class
173  // from the Principal class.
174 
175  BasicHandle
176  getByLabel_(TypeID const& tid, InputTag const& tag,
177  ModuleCallingContext const* mcc) const;
178 
179  BasicHandle
180  getByLabel_(TypeID const& tid,
181  std::string const& label,
182  std::string const& instance,
183  std::string const& process,
184  ModuleCallingContext const* mcc) const;
185 
187  getByToken_(TypeID const& id, KindOfType kindOfType, EDGetToken token,
188  ModuleCallingContext const* mcc) const;
189 
191  getMatchingSequenceByLabel_(TypeID const& typeID,
192  InputTag const& tag,
193  ModuleCallingContext const* mcc) const;
194 
196  getMatchingSequenceByLabel_(TypeID const& typeID,
197  std::string const& label,
198  std::string const& instance,
199  std::string const& process,
200  ModuleCallingContext const* mcc) const;
201 
202  void
203  getManyByType_(TypeID const& tid,
204  BasicHandleVec& results,
205  ModuleCallingContext const* mcc) const;
206 
207  // Also isolates the PrincipalGetAdapter class
208  // from the Principal class.
209  EDProductGetter const* prodGetter() const;
210 
211  void labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const;
212 
213  private:
214  // Is this an Event, a LuminosityBlock, or a Run.
215  BranchType const& branchType() const;
216 
218  makeFailToGetException(KindOfType,TypeID const&,EDGetToken) const;
219 
220  void
221  throwAmbiguousException(TypeID const& productType, EDGetToken token) const;
222 
223  private:
224  //------------------------------------------------------------
225  // Data members
226  //
227 
228  // Each PrincipalGetAdapter must have an associated Principal, used as the
229  // source of all 'gets' and the target of 'puts'.
231 
232  // Each PrincipalGetAdapter must have a description of the module executing the
233  // "transaction" which the PrincipalGetAdapter represents.
235 
237  SharedResourcesAcquirer* resourcesAcquirer_; // We do not use propagate_const because the acquirer is itself mutable.
238  };
239 
240  template <typename PROD>
241  inline
242  std::ostream&
243  operator<<(std::ostream& os, Handle<PROD> const& h) {
244  os << h.product() << " " << h.provenance() << " " << h.id();
245  return os;
246  }
247 
248 
249  //------------------------------------------------------------
250  // Metafunction support for compile-time selection of code used in
251  // PrincipalGetAdapter::put member template.
252  //
253 
254  // has_postinsert is a metafunction of one argument, the type T. As
255  // with many metafunctions, it is implemented as a class with a data
256  // member 'value', which contains the value 'returned' by the
257  // metafunction.
258  //
259  // has_postinsert<T>::value is 'true' if T has the post_insert
260  // member function (with the right signature), and 'false' if T has
261  // no such member function.
262 
263  namespace detail {
264  using no_tag = std::false_type; // type indicating FALSE
265  using yes_tag = std::true_type; // type indicating TRUE
266 
267  // Definitions forthe following struct and function templates are
268  // not needed; we only require the declarations.
269  template <typename T, void (T::*)()> struct postinsert_function;
270  template <typename T> no_tag has_postinsert_helper(...);
272 
273 
274  template<typename T>
275  struct has_postinsert {
276  static constexpr bool value = std::is_same<decltype(has_postinsert_helper<T>(nullptr)), yes_tag>::value &&
278  };
279 
280 
281  // has_donotrecordparents<T>::value is true if we should not
282  // record parentage for type T, and false otherwise.
283 
284  template <typename T>
286  static constexpr bool value =
288  };
289 
290  }
291 
292  //------------------------------------------------------------
293 
294  // The following function objects are used by Event::put, under the
295  // control of a metafunction if, to either call the given object's
296  // post_insert function (if it has one), or to do nothing (if it
297  // does not have a post_insert function).
298  template <typename T>
299  struct DoPostInsert {
300  void operator()(T* p) const { p->post_insert(); }
301  };
302 
303  template <typename T>
305  void operator()(T*) const { }
306  };
307 
308  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
309  // implementation of non-template members.
310  //
311 
312  template <typename PROD>
313  inline
314  bool
316  return isComplete() || !detail::has_mergeProduct_function<PROD>::value;
317  }
318 
319  template <typename PROD>
320  inline
321  void
323  ModuleCallingContext const* mcc) const {
324  BasicHandleVec bhv;
325  this->getManyByType_(TypeID(typeid(PROD)), bhv, mcc);
326 
327  // Go through the returned handles; for each element,
328  // 1. create a Handle<PROD> and
329  //
330  // This function presents an exception safety difficulty. If an
331  // exception is thrown when converting a handle, the "got
332  // products" record will be wrong.
333  //
334  // Since EDProducers are not allowed to use this function,
335  // the problem does not seem too severe.
336  //
337  // Question: do we even need to keep track of the "got products"
338  // for this function, since it is *not* to be used by EDProducers?
339  std::vector<Handle<PROD> > products;
340 
341  typename BasicHandleVec::iterator it = bhv.begin();
342  typename BasicHandleVec::iterator end = bhv.end();
343 
344  while (it != end) {
346  convert_handle(std::move(*it), result); // throws on conversion error
347  products.push_back(result);
348  ++it;
349  }
350  results.swap(products);
351  }
352 }
353 #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
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
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
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