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