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 FWCore_Framework_PrincipalGetAdapter_h
2 #define FWCore_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 
107 
108 
109 namespace edm {
110 
111  namespace principal_get_adapter_detail {
112  struct deleter {
113  void operator()(std::pair<WrapperOwningHolder, ConstBranchDescription const*> const p) const;
114  };
115  void
116  throwOnPutOfNullProduct(char const* principalType, TypeID const& productType, std::string const& productInstanceName);
117  void
118  throwOnPrematureRead(char const* principalType, TypeID const& productType, std::string const& moduleLabel, std::string const& productInstanceName);
119  void
120  throwOnPrematureRead(char const* principalType, TypeID const& productType);
121 
122  void
123  throwOnPrematureRead(char const* principalType, TypeID const& productType, EDGetToken);
124 
125  }
127  public:
129  ModuleDescription const& md);
130 
132 
133  PrincipalGetAdapter(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
134  PrincipalGetAdapter& operator=(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
135 
136  //size_t size() const;
137 
138  void setConsumer(EDConsumerBase const* iConsumer) {
139  consumer_ = iConsumer;
140  }
141 
142  bool isComplete() const;
143 
144  template <typename PROD>
145  bool
146  checkIfComplete() const;
147 
148  template <typename PROD>
149  void
150  getManyByType(std::vector<Handle<PROD> >& results) const;
151 
152  ProcessHistory const&
153  processHistory() const;
154 
156  Principal const& principal() const {return principal_;}
157 
159  getBranchDescription(TypeID const& type, std::string const& productInstanceName) const;
160 
161  typedef std::vector<BasicHandle> BasicHandleVec;
162 
163  //------------------------------------------------------------
164  // Protected functions.
165  //
166 
167  // The following 'get' functions serve to isolate the PrincipalGetAdapter class
168  // from the Principal class.
169 
170  BasicHandle
171  getByLabel_(TypeID const& tid, InputTag const& tag) const;
172 
173  BasicHandle
174  getByLabel_(TypeID const& tid,
175  std::string const& label,
176  std::string const& instance,
177  std::string const& process) const;
178 
180  getByToken_(TypeID const& id, KindOfType kindOfType, EDGetToken token) const;
181 
183  getMatchingSequenceByLabel_(TypeID const& typeID,
184  InputTag const& tag) const;
185 
187  getMatchingSequenceByLabel_(TypeID const& typeID,
188  std::string const& label,
189  std::string const& instance,
190  std::string const& process) const;
191 
192  void
193  getManyByType_(TypeID const& tid,
194  BasicHandleVec& results) const;
195 
196  // Also isolates the PrincipalGetAdapter class
197  // from the Principal class.
198  EDProductGetter const* prodGetter() const;
199 
200  private:
201  // Is this an Event, a LuminosityBlock, or a Run.
202  BranchType const& branchType() const;
203 
206 
207  void
208  throwAmbiguousException(TypeID const& productType, EDGetToken token) const;
209 
210  private:
211  //------------------------------------------------------------
212  // Data members
213  //
214 
215  // Each PrincipalGetAdapter must have an associated Principal, used as the
216  // source of all 'gets' and the target of 'puts'.
218 
219  // Each PrincipalGetAdapter must have a description of the module executing the
220  // "transaction" which the PrincipalGetAdapter represents.
222 
224 
225  };
226 
227  template <typename PROD>
228  inline
229  std::ostream&
230  operator<<(std::ostream& os, Handle<PROD> const& h) {
231  os << h.product() << " " << h.provenance() << " " << h.id();
232  return os;
233  }
234 
235 
236  //------------------------------------------------------------
237  // Metafunction support for compile-time selection of code used in
238  // PrincipalGetAdapter::put member template.
239  //
240 
241  // has_postinsert is a metafunction of one argument, the type T. As
242  // with many metafunctions, it is implemented as a class with a data
243  // member 'value', which contains the value 'returned' by the
244  // metafunction.
245  //
246  // has_postinsert<T>::value is 'true' if T has the post_insert
247  // member function (with the right signature), and 'false' if T has
248  // no such member function.
249 
250  namespace detail {
251  typedef char (& no_tag)[1]; // type indicating FALSE
252  typedef char (& yes_tag)[2]; // type indicating TRUE
253 
254  // Definitions forthe following struct and function templates are
255  // not needed; we only require the declarations.
256  template <typename T, void (T::*)()> struct postinsert_function;
257  template <typename T> no_tag has_postinsert_helper(...);
259 
260 
261  template<typename T>
262  struct has_postinsert {
263  static bool const value =
264  sizeof(has_postinsert_helper<T>(nullptr)) == sizeof(yes_tag) &&
266  };
267 
268 
269  // has_donotrecordparents<T>::value is true if we should not
270  // record parentage for type T, and false otherwise.
271 
272  template <typename T>
274  static bool const value =
276  };
277 
278  }
279 
280  //------------------------------------------------------------
281 
282  // The following function objects are used by Event::put, under the
283  // control of a metafunction if, to either call the given object's
284  // post_insert function (if it has one), or to do nothing (if it
285  // does not have a post_insert function).
286  template <typename T>
287  struct DoPostInsert {
288  void operator()(T* p) const { p->post_insert(); }
289  };
290 
291  template <typename T>
293  void operator()(T*) const { }
294  };
295 
296  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
297  // implementation of non-template members.
298  //
299 
300  template <typename PROD>
301  inline
302  bool
305  }
306 
307  template <typename PROD>
308  inline
309  void
311  BasicHandleVec bhv;
312  this->getManyByType_(TypeID(typeid(PROD)), bhv);
313 
314  // Go through the returned handles; for each element,
315  // 1. create a Handle<PROD> and
316  //
317  // This function presents an exception safety difficulty. If an
318  // exception is thrown when converting a handle, the "got
319  // products" record will be wrong.
320  //
321  // Since EDProducers are not allowed to use this function,
322  // the problem does not seem too severe.
323  //
324  // Question: do we even need to keep track of the "got products"
325  // for this function, since it is *not* to be used by EDProducers?
326  std::vector<Handle<PROD> > products;
327 
328  typename BasicHandleVec::const_iterator it = bhv.begin();
329  typename BasicHandleVec::const_iterator end = bhv.end();
330 
331  while (it != end) {
333  convert_handle(*it, result); // throws on conversion error
334  products.push_back(result);
335  ++it;
336  }
337  results.swap(products);
338  }
339 }
340 #endif
ProcessHistory const & processHistory() const
type
Definition: HCALResponse.h:21
void setConsumer(EDConsumerBase const *iConsumer)
char(& yes_tag)[2]
Definition: Wrapper.h:249
void operator()(T *p) const
Principal const & principal() const
void getManyByType_(TypeID const &tid, BasicHandleVec &results) const
PrincipalGetAdapter(Principal &pcpl, ModuleDescription const &md)
static PFTauRenderPlugin instance
no_tag has_postinsert_helper(...)
EDConsumerBase const * consumer_
void getManyByType(std::vector< Handle< PROD > > &results) const
BranchType
Definition: BranchType.h:11
BranchType const & branchType() const
EDProductGetter const * prodGetter() const
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag) 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
#define end
Definition: vmac.h:38
PrincipalGetAdapter & operator=(PrincipalGetAdapter const &)=delete
char(& no_tag)[1]
Definition: Wrapper.h:248
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void convert_handle(BasicHandle const &bh, Handle< T > &result)
Definition: ConvertHandle.h:19
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
void operator()(T *) const
#define PROD(A, B)
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag) 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
tuple process
Definition: LaserDQM_cfg.py:3
long double T
BasicHandle getByToken_(TypeID const &id, KindOfType kindOfType, EDGetToken token) const
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
std::vector< BasicHandle > BasicHandleVec