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