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 #include <boost/type_traits.hpp>
90 
94 
96 
98 
100 
102 
104 
109 
110 
111 namespace edm {
112 
113  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:
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 
143  bool isComplete() const;
144 
145  template <typename PROD>
146  bool
147  checkIfComplete() const;
148 
149  template <typename PROD>
150  void
151  getManyByType(std::vector<Handle<PROD> >& results, ModuleCallingContext const* mcc) const;
152 
153  ProcessHistory const&
154  processHistory() const;
155 
157  Principal const& principal() const {return principal_;}
158 
159  BranchDescription const&
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  getByLabel_(TypeID const& tid, InputTag const& tag,
173  ModuleCallingContext const* mcc) const;
174 
175  BasicHandle
176  getByLabel_(TypeID const& tid,
177  std::string const& label,
178  std::string const& instance,
179  std::string const& process,
180  ModuleCallingContext const* mcc) const;
181 
183  getByToken_(TypeID const& id, KindOfType kindOfType, EDGetToken token,
184  ModuleCallingContext const* mcc) const;
185 
187  getMatchingSequenceByLabel_(TypeID const& typeID,
188  InputTag const& tag,
189  ModuleCallingContext const* mcc) const;
190 
192  getMatchingSequenceByLabel_(TypeID const& typeID,
193  std::string const& label,
194  std::string const& instance,
195  std::string const& process,
196  ModuleCallingContext const* mcc) const;
197 
198  void
199  getManyByType_(TypeID const& tid,
201  ModuleCallingContext const* mcc) const;
202 
203  // Also isolates the PrincipalGetAdapter class
204  // from the Principal class.
205  EDProductGetter const* prodGetter() const;
206 
207  void labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const;
208 
209  private:
210  // Is this an Event, a LuminosityBlock, or a Run.
211  BranchType const& branchType() const;
212 
215 
216  void
217  throwAmbiguousException(TypeID const& productType, EDGetToken token) const;
218 
219  private:
220  //------------------------------------------------------------
221  // Data members
222  //
223 
224  // Each PrincipalGetAdapter must have an associated Principal, used as the
225  // source of all 'gets' and the target of 'puts'.
227 
228  // Each PrincipalGetAdapter must have a description of the module executing the
229  // "transaction" which the PrincipalGetAdapter represents.
231 
233 
234  };
235 
236  template <typename PROD>
237  inline
238  std::ostream&
239  operator<<(std::ostream& os, Handle<PROD> const& h) {
240  os << h.product() << " " << h.provenance() << " " << h.id();
241  return os;
242  }
243 
244 
245  //------------------------------------------------------------
246  // Metafunction support for compile-time selection of code used in
247  // PrincipalGetAdapter::put member template.
248  //
249 
250  // has_postinsert is a metafunction of one argument, the type T. As
251  // with many metafunctions, it is implemented as a class with a data
252  // member 'value', which contains the value 'returned' by the
253  // metafunction.
254  //
255  // has_postinsert<T>::value is 'true' if T has the post_insert
256  // member function (with the right signature), and 'false' if T has
257  // no such member function.
258 
259  namespace detail {
260  typedef char (& no_tag)[1]; // type indicating FALSE
261  typedef char (& yes_tag)[2]; // type indicating TRUE
262 
263  // Definitions forthe following struct and function templates are
264  // not needed; we only require the declarations.
265  template <typename T, void (T::*)()> struct postinsert_function;
266  template <typename T> no_tag has_postinsert_helper(...);
268 
269 
270  template<typename T>
271  struct has_postinsert {
272  static bool const value =
273  sizeof(has_postinsert_helper<T>(nullptr)) == sizeof(yes_tag) &&
275  };
276 
277 
278  // has_donotrecordparents<T>::value is true if we should not
279  // record parentage for type T, and false otherwise.
280 
281  template <typename T>
283  static bool const value =
285  };
286 
287  }
288 
289  //------------------------------------------------------------
290 
291  // The following function objects are used by Event::put, under the
292  // control of a metafunction if, to either call the given object's
293  // post_insert function (if it has one), or to do nothing (if it
294  // does not have a post_insert function).
295  template <typename T>
296  struct DoPostInsert {
297  void operator()(T* p) const { p->post_insert(); }
298  };
299 
300  template <typename T>
302  void operator()(T*) const { }
303  };
304 
305  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
306  // implementation of non-template members.
307  //
308 
309  template <typename PROD>
310  inline
311  bool
314  }
315 
316  template <typename PROD>
317  inline
318  void
320  ModuleCallingContext const* mcc) const {
321  BasicHandleVec bhv;
322  this->getManyByType_(TypeID(typeid(PROD)), bhv, mcc);
323 
324  // Go through the returned handles; for each element,
325  // 1. create a Handle<PROD> and
326  //
327  // This function presents an exception safety difficulty. If an
328  // exception is thrown when converting a handle, the "got
329  // products" record will be wrong.
330  //
331  // Since EDProducers are not allowed to use this function,
332  // the problem does not seem too severe.
333  //
334  // Question: do we even need to keep track of the "got products"
335  // for this function, since it is *not* to be used by EDProducers?
336  std::vector<Handle<PROD> > products;
337 
338  typename BasicHandleVec::iterator it = bhv.begin();
339  typename BasicHandleVec::iterator end = bhv.end();
340 
341  while (it != end) {
343  convert_handle(std::move(*it), result); // throws on conversion error
344  products.push_back(result);
345  ++it;
346  }
347  results.swap(products);
348  }
349 }
350 #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: WrapperDetail.h:18
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: WrapperDetail.h:17
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
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
std::vector< BasicHandle > BasicHandleVec