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