CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrincipalGetAdapter.h
Go to the documentation of this file.
1 #ifndef Framework_PrincipalGetAdapter_h
2 #define Framework_PrincipalGetAdapter_h
3 
4 // -*- C++ -*-
5 //
6 
7 // Class : PrincipalGetAdapter
8 //
82 /*----------------------------------------------------------------------
83 
84 ----------------------------------------------------------------------*/
85 #include <cassert>
86 #include <typeinfo>
87 #include <string>
88 #include <vector>
89 
93 
95 
97 
99 
101 
103 
104 namespace edm {
105 
106  namespace principal_get_adapter_detail {
107  struct deleter {
108  void operator()(std::pair<WrapperOwningHolder, ConstBranchDescription const*> const p) const;
109  };
110  void
111  throwOnPutOfNullProduct(char const* principalType, TypeID const& productType, std::string const& productInstanceName);
112  }
114  public:
116  ModuleDescription const& md);
117 
119 
120  //size_t size() const;
121 
122  template <typename PROD>
123  bool
124  get(SelectorBase const&, Handle<PROD>& result) const;
125 
126  template <typename PROD>
127  bool
128  getByLabel(std::string const& label, Handle<PROD>& result) const;
129 
130  template <typename PROD>
131  bool
132  getByLabel(std::string const& label,
133  std::string const& productInstanceName,
134  Handle<PROD>& result) const;
135 
137  template <typename PROD>
138  bool
139  getByLabel(InputTag const& tag, Handle<PROD>& result) const;
140 
141  template <typename PROD>
142  void
143  getMany(SelectorBase const&, std::vector<Handle<PROD> >& results) const;
144 
145  template <typename PROD>
146  bool
147  getByType(Handle<PROD>& result) const;
148 
149  template <typename PROD>
150  void
151  getManyByType(std::vector<Handle<PROD> >& results) const;
152 
153  ProcessHistory const&
154  processHistory() const;
155 
157  Principal const& principal() const {return principal_;}
158 
160  getBranchDescription(TypeID const& type, std::string const& productInstanceName) const;
161 
162  typedef std::vector<BasicHandle> BasicHandleVec;
163 
164  //------------------------------------------------------------
165  // Protected functions.
166  //
167 
168  // The following 'get' functions serve to isolate the PrincipalGetAdapter class
169  // from the Principal class.
170 
171  BasicHandle
172  get_(TypeID const& tid, SelectorBase const&) const;
173 
174  BasicHandle
175  getByLabel_(TypeID const& tid,
176  std::string const& label,
177  std::string const& productInstanceName,
178  std::string const& processName) const;
179 
180  BasicHandle
181  getByLabel_(TypeID const& tid, InputTag const& tag) const;
182 
183  void
184  getMany_(TypeID const& tid,
185  SelectorBase const& sel,
186  BasicHandleVec& results) const;
187 
188  BasicHandle
189  getByType_(TypeID const& tid) const;
190 
191  void
192  getManyByType_(TypeID const& tid,
193  BasicHandleVec& results) const;
194 
195  int
196  getMatchingSequence_(TypeID const& typeID,
197  SelectorBase const& selector,
198  BasicHandle& result) const;
199 
200  int
201  getMatchingSequenceByLabel_(TypeID const& typeID,
202  std::string const& label,
203  std::string const& productInstanceName,
204  BasicHandle& result) const;
205 
206  int
207  getMatchingSequenceByLabel_(TypeID const& typeID,
208  std::string const& label,
209  std::string const& productInstanceName,
210  std::string const& processName,
211  BasicHandle& result) const;
212 
213  // Also isolates the PrincipalGetAdapter class
214  // from the Principal class.
215  EDProductGetter const* prodGetter() const;
216  private:
217  //------------------------------------------------------------
218  // Copying and assignment of PrincipalGetAdapters is disallowed
219  //
220  PrincipalGetAdapter(PrincipalGetAdapter const&); // not implemented
221  PrincipalGetAdapter const& operator=(PrincipalGetAdapter const&); // not implemented
222 
223  // Is this an Event, a LuminosityBlock, or a Run.
224  BranchType const& branchType() const;
225 
226  private:
227  //------------------------------------------------------------
228  // Data members
229  //
230 
231  // Each PrincipalGetAdapter must have an associated Principal, used as the
232  // source of all 'gets' and the target of 'puts'.
234 
235  // Each PrincipalGetAdapter must have a description of the module executing the
236  // "transaction" which the PrincipalGetAdapter represents.
238 
239  };
240 
241  template <typename PROD>
242  inline
243  std::ostream&
244  operator<<(std::ostream& os, Handle<PROD> const& h) {
245  os << h.product() << " " << h.provenance() << " " << h.id();
246  return os;
247  }
248 
249 
250  //------------------------------------------------------------
251  // Metafunction support for compile-time selection of code used in
252  // PrincipalGetAdapter::put member template.
253  //
254 
255  // has_postinsert is a metafunction of one argument, the type T. As
256  // with many metafunctions, it is implemented as a class with a data
257  // member 'value', which contains the value 'returned' by the
258  // metafunction.
259  //
260  // has_postinsert<T>::value is 'true' if T has the post_insert
261  // member function (with the right signature), and 'false' if T has
262  // no such member function.
263 
264  namespace detail {
265  typedef char (& no_tag)[1]; // type indicating FALSE
266  typedef char (& yes_tag)[2]; // type indicating TRUE
267 
268  // Definitions forthe following struct and function templates are
269  // not needed; we only require the declarations.
270  template <typename T, void (T::*)()> struct postinsert_function;
271  template <typename T> no_tag has_postinsert_helper(...);
273 
274 
275  template<typename T>
276  struct has_postinsert {
277  static bool const value =
278  sizeof(has_postinsert_helper<T>(0)) == sizeof(yes_tag) &&
280  };
281 
282 
283  // has_donotrecordparents<T>::value is true if we should not
284  // record parentage for type T, and false otherwise.
285 
286  template <typename T>
288  static bool const value =
290  };
291 
292  }
293 
294  //------------------------------------------------------------
295 
296  // The following function objects are used by Event::put, under the
297  // control of a metafunction if, to either call the given object's
298  // post_insert function (if it has one), or to do nothing (if it
299  // does not have a post_insert function).
300  template <typename T>
301  struct DoPostInsert {
302  void operator()(T* p) const { p->post_insert(); }
303  };
304 
305  template <typename T>
307  void operator()(T*) const { }
308  };
309 
310  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
311  // implementation of non-template members.
312  //
313 
314  template <typename PROD>
315  inline
316  bool
318  Handle<PROD>& result) const {
319  result.clear();
320  BasicHandle bh = this->get_(TypeID(typeid(PROD)),sel);
321  convert_handle(bh, result); // throws on conversion error
322  if (bh.failedToGet()) {
323  return false;
324  }
325  return true;
326  }
327 
328  template <typename PROD>
329  inline
330  bool
332  Handle<PROD>& result) const {
333  result.clear();
334  return getByLabel(label, std::string(), result);
335  }
336 
337  template <typename PROD>
338  inline
339  bool
341  result.clear();
342  BasicHandle bh = this->getByLabel_(TypeID(typeid(PROD)), tag);
343  convert_handle(bh, result); // throws on conversion error
344  if (bh.failedToGet()) {
345  return false;
346  }
347  return true;
348  }
349 
350  template <typename PROD>
351  inline
352  bool
354  std::string const& productInstanceName,
355  Handle<PROD>& result) const {
356  result.clear();
357  BasicHandle bh = this->getByLabel_(TypeID(typeid(PROD)), label, productInstanceName, std::string());
358  convert_handle(bh, result); // throws on conversion error
359  if (bh.failedToGet()) {
360  return false;
361  }
362  return true;
363  }
364 
365  template <typename PROD>
366  inline
367  void
369  std::vector<Handle<PROD> >& results) const {
370  BasicHandleVec bhv;
371  this->getMany_(TypeID(typeid(PROD)), sel, bhv);
372 
373  // Go through the returned handles; for each element,
374  // 1. create a Handle<PROD> and
375  //
376  // This function presents an exception safety difficulty. If an
377  // exception is thrown when converting a handle, the "got
378  // products" record will be wrong.
379  //
380  // Since EDProducers are not allowed to use this function,
381  // the problem does not seem too severe.
382  //
383  // Question: do we even need to keep track of the "got products"
384  // for this function, since it is *not* to be used by EDProducers?
385  std::vector<Handle<PROD> > products;
386 
387  typename BasicHandleVec::const_iterator it = bhv.begin();
388  typename BasicHandleVec::const_iterator end = bhv.end();
389 
390  while (it != end) {
392  convert_handle(*it, result); // throws on conversion error
393  products.push_back(result);
394  ++it;
395  }
396  results.swap(products);
397  }
398 
399  template <typename PROD>
400  inline
401  bool
403  result.clear();
404  BasicHandle bh = this->getByType_(TypeID(typeid(PROD)));
405  convert_handle(bh, result); // throws on conversion error
406  if (bh.failedToGet()) {
407  return false;
408  }
409  return true;
410  }
411 
412  template <typename PROD>
413  inline
414  void
416  BasicHandleVec bhv;
417  this->getManyByType_(TypeID(typeid(PROD)), bhv);
418 
419  // Go through the returned handles; for each element,
420  // 1. create a Handle<PROD> and
421  //
422  // This function presents an exception safety difficulty. If an
423  // exception is thrown when converting a handle, the "got
424  // products" record will be wrong.
425  //
426  // Since EDProducers are not allowed to use this function,
427  // the problem does not seem too severe.
428  //
429  // Question: do we even need to keep track of the "got products"
430  // for this function, since it is *not* to be used by EDProducers?
431  std::vector<Handle<PROD> > products;
432 
433  typename BasicHandleVec::const_iterator it = bhv.begin();
434  typename BasicHandleVec::const_iterator end = bhv.end();
435 
436  while (it != end) {
438  convert_handle(*it, result); // throws on conversion error
439  products.push_back(result);
440  ++it;
441  }
442  results.swap(products);
443  }
444 }
445 #endif
ProcessHistory const & processHistory() const
BasicHandle getByType_(TypeID const &tid) const
type
Definition: HCALResponse.h:22
bool getByLabel(std::string const &label, Handle< PROD > &result) const
PrincipalGetAdapter const & operator=(PrincipalGetAdapter const &)
char(& yes_tag)[2]
Definition: Wrapper.h:250
void operator()(T *p) const
Principal const & principal() const
void getManyByType_(TypeID const &tid, BasicHandleVec &results) const
PrincipalGetAdapter(Principal &pcpl, ModuleDescription const &md)
int getMatchingSequence_(TypeID const &typeID, SelectorBase const &selector, BasicHandle &result) const
no_tag has_postinsert_helper(...)
int getMatchingSequenceByLabel_(TypeID const &typeID, std::string const &label, std::string const &productInstanceName, BasicHandle &result) const
void getManyByType(std::vector< Handle< PROD > > &results) const
BranchType
Definition: BranchType.h:11
BranchType const & branchType() const
EDProductGetter const * prodGetter() const
void operator()(std::pair< WrapperOwningHolder, ConstBranchDescription const * > const p) const
ESProducts< T, S > products(const T &i1, const S &i2)
Definition: ESProducts.h:189
tuple result
Definition: query.py:137
void getMany_(TypeID const &tid, SelectorBase const &sel, BasicHandleVec &results) const
#define end
Definition: vmac.h:38
void getMany(SelectorBase const &, std::vector< Handle< PROD > > &results) const
char(& no_tag)[1]
Definition: Wrapper.h:249
bool failedToGet() const
Definition: BasicHandle.h:94
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool get(SelectorBase const &, Handle< PROD > &result) const
void convert_handle(BasicHandle const &bh, Handle< T > &result)
Definition: ConvertHandle.h:19
BasicHandle getByLabel_(TypeID const &tid, std::string const &label, std::string const &productInstanceName, std::string const &processName) const
void operator()(T *) const
#define PROD(A, B)
BasicHandle get_(TypeID const &tid, SelectorBase const &) const
ModuleDescription const & md_
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
ConstBranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
long double T
std::vector< BasicHandle > BasicHandleVec
bool getByType(Handle< PROD > &result) const