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 <boost/type_traits.hpp>
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  typedef char (& no_tag)[1]; // type indicating FALSE
265  typedef char (& yes_tag)[2]; // 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 bool const value =
277  sizeof(has_postinsert_helper<T>(nullptr)) == sizeof(yes_tag) &&
279  };
280 
281 
282  // has_donotrecordparents<T>::value is true if we should not
283  // record parentage for type T, and false otherwise.
284 
285  template <typename T>
287  static bool const value =
289  };
290 
291  }
292 
293  //------------------------------------------------------------
294 
295  // The following function objects are used by Event::put, under the
296  // control of a metafunction if, to either call the given object's
297  // post_insert function (if it has one), or to do nothing (if it
298  // does not have a post_insert function).
299  template <typename T>
300  struct DoPostInsert {
301  void operator()(T* p) const { p->post_insert(); }
302  };
303 
304  template <typename T>
306  void operator()(T*) const { }
307  };
308 
309  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
310  // implementation of non-template members.
311  //
312 
313  template <typename PROD>
314  inline
315  bool
317  return isComplete() || !detail::has_mergeProduct_function<PROD>::value;
318  }
319 
320  template <typename PROD>
321  inline
322  void
324  ModuleCallingContext const* mcc) const {
325  BasicHandleVec bhv;
326  this->getManyByType_(TypeID(typeid(PROD)), bhv, mcc);
327 
328  // Go through the returned handles; for each element,
329  // 1. create a Handle<PROD> and
330  //
331  // This function presents an exception safety difficulty. If an
332  // exception is thrown when converting a handle, the "got
333  // products" record will be wrong.
334  //
335  // Since EDProducers are not allowed to use this function,
336  // the problem does not seem too severe.
337  //
338  // Question: do we even need to keep track of the "got products"
339  // for this function, since it is *not* to be used by EDProducers?
340  std::vector<Handle<PROD> > products;
341 
342  typename BasicHandleVec::iterator it = bhv.begin();
343  typename BasicHandleVec::iterator end = bhv.end();
344 
345  while (it != end) {
347  convert_handle(std::move(*it), result); // throws on conversion error
348  products.push_back(result);
349  ++it;
350  }
351  results.swap(products);
352  }
353 }
354 #endif
SharedResourcesAcquirer * resourcesAcquirer_
type
Definition: HCALResponse.h:21
void setConsumer(EDConsumerBase const *iConsumer)
char(& yes_tag)[2]
Definition: WrapperDetail.h:18
void operator()(T *p) const
Principal const & principal() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static PFTauRenderPlugin instance
EDConsumerBase const * consumer_
void setSharedResourcesAcquirer(SharedResourcesAcquirer *iSra)
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:60
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
char(& no_tag)[1]
Definition: WrapperDetail.h:17
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