CMS 3D CMS Logo

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 //
80 /*----------------------------------------------------------------------
81 
82 ----------------------------------------------------------------------*/
83 #include <cassert>
84 #include <typeinfo>
85 #include <string>
86 #include <vector>
87 #include <type_traits>
88 
92 
94 
96 
98 
100 
102 
110 
111 namespace edm {
112 
113  class ModuleCallingContext;
115  class ProducerBase;
116 
117  namespace principal_get_adapter_detail {
118  void throwOnPutOfNullProduct(char const* principalType,
119  TypeID const& productType,
120  std::string const& productInstanceName);
121  void throwOnPutOfUninitializedToken(char const* principalType, std::type_info const& productType);
122  void throwOnPutOfWrongType(std::type_info const& wrongType, TypeID const& rightType);
123  void throwOnPrematureRead(char const* principalType,
124  TypeID const& productType,
125  std::string const& moduleLabel,
126  std::string const& productInstanceName);
127  void throwOnPrematureRead(char const* principalType, TypeID const& productType);
128 
129  void throwOnPrematureRead(char const* principalType, TypeID const& productType, EDGetToken);
130 
131  } // namespace principal_get_adapter_detail
133  public:
134  PrincipalGetAdapter(Principal const& pcpl, ModuleDescription const& md, bool isComplete);
135 
137 
138  PrincipalGetAdapter(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
139  PrincipalGetAdapter& operator=(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
140 
141  //size_t size() const;
142 
143  void setConsumer(EDConsumerBase const* iConsumer) { consumer_ = iConsumer; }
144  EDConsumerBase const* getConsumer() const { return consumer_; }
145 
148 
149  void setProducer(ProducerBase const* iProd) { prodBase_ = iProd; }
150 
151  size_t numberOfProductsConsumed() const;
152 
153  bool isComplete() const { return isComplete_; }
154 
155  template <typename PROD>
156  bool checkIfComplete() const;
157 
158  Transition transition() const;
159 
160  template <typename PROD>
162 
163  ProcessHistory const& processHistory() const;
164 
165  Principal const& principal() const { return principal_; }
166 
167  BranchDescription const& getBranchDescription(TypeID const& type, std::string const& productInstanceName) const;
168 
169  EDPutToken::value_type getPutTokenIndex(TypeID const& type, std::string const& productInstanceName) const;
170 
173  typedef std::vector<BasicHandle> BasicHandleVec;
174 
175  BranchDescription const& getBranchDescription(unsigned int iPutTokenIndex) const;
176  ProductID const& getProductID(unsigned int iPutTokenIndex) const;
177  ModuleDescription const& moduleDescription() const { return md_; }
178 
179  std::vector<edm::ProductResolverIndex> const& putTokenIndexToProductResolverIndex() const;
180 
181  //uses the EDPutToken index
182  std::vector<bool> const& recordProvenanceList() const;
183  //------------------------------------------------------------
184  // Protected functions.
185  //
186 
187  // The following 'get' functions serve to isolate the PrincipalGetAdapter class
188  // from the Principal class.
189 
190  BasicHandle getByLabel_(TypeID const& tid, InputTag const& tag, ModuleCallingContext const* mcc) const;
191 
192  BasicHandle getByLabel_(TypeID const& tid,
193  std::string const& label,
194  std::string const& instance,
195  std::string const& process,
196  ModuleCallingContext const* mcc) const;
197 
198  BasicHandle getByToken_(TypeID const& id,
199  KindOfType kindOfType,
201  ModuleCallingContext const* mcc) const;
202 
204  InputTag const& tag,
205  ModuleCallingContext const* mcc) const;
206 
208  std::string const& label,
209  std::string const& instance,
210  std::string const& process,
211  ModuleCallingContext const* mcc) const;
212 
213  void getManyByType_(TypeID const& tid, BasicHandleVec& results, ModuleCallingContext const* mcc) const;
214 
215  // Also isolates the PrincipalGetAdapter class
216  // from the Principal class.
217  EDProductGetter const* prodGetter() const;
218 
219  void labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const;
220 
221  unsigned int processBlockIndex(std::string const& processName) const;
222 
223  private:
224  // Is this an Event, a LuminosityBlock, or a Run.
225  BranchType const& branchType() const;
226 
228 
229  void throwAmbiguousException(TypeID const& productType, EDGetToken token) const;
230 
232 
233  private:
234  //------------------------------------------------------------
235  // Data members
236  //
237 
238  // Each PrincipalGetAdapter must have an associated Principal, used as the
239  // source of all 'gets' and the target of 'puts'.
241 
242  // Each PrincipalGetAdapter must have a description of the module executing the
243  // "transaction" which the PrincipalGetAdapter represents.
245 
247  SharedResourcesAcquirer* resourcesAcquirer_; // We do not use propagate_const because the acquirer is itself mutable.
248  ProducerBase const* prodBase_ = nullptr;
250  };
251 
252  template <typename PROD>
253  inline std::ostream& operator<<(std::ostream& os, Handle<PROD> const& h) {
254  os << h.product() << " " << h.provenance() << " " << h.id();
255  return os;
256  }
257 
258  //------------------------------------------------------------
259  // Metafunction support for compile-time selection of code used in
260  // PrincipalGetAdapter::put member template.
261  //
262 
263  // has_postinsert is a metafunction of one argument, the type T. As
264  // with many metafunctions, it is implemented as a class with a data
265  // member 'value', which contains the value 'returned' by the
266  // metafunction.
267  //
268  // has_postinsert<T>::value is 'true' if T has the post_insert
269  // member function (with the right signature), and 'false' if T has
270  // no such member function.
271 
272  namespace detail {
273  using no_tag = std::false_type; // type indicating FALSE
274  using yes_tag = std::true_type; // type indicating TRUE
275 
276  // Definitions forthe following struct and function templates are
277  // not needed; we only require the declarations.
278  template <typename T, void (T::*)()>
280  template <typename T>
282  template <typename T>
284 
285  template <typename T>
286  struct has_postinsert {
287  static constexpr bool value = std::is_same<decltype(has_postinsert_helper<T>(nullptr)), yes_tag>::value &&
289  };
290 
291  } // namespace detail
292 
293  //------------------------------------------------------------
294 
295  // The following function objects are used by Event::put, under the
296  // control of a metafunction if, to either call the given object's
297  // post_insert function (if it has one), or to do nothing (if it
298  // does not have a post_insert function).
299  template <typename T>
300  struct DoPostInsert {
301  void operator()(T* p) const { p->post_insert(); }
302  };
303 
304  template <typename T>
306  void operator()(T*) const {}
307  };
308 
309  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
310  // implementation of non-template members.
311  //
312 
313  template <typename PROD>
316  }
317 
318  template <typename PROD>
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) {
342  products.push_back(convert_handle<PROD>(std::move(*it)));
343  ++it;
344  }
345  results.swap(products);
346  }
347 } // namespace edm
348 #endif
EDPutToken::value_type getPutTokenIndex(TypeID const &type, std::string const &productInstanceName) const
SharedResourcesAcquirer * resourcesAcquirer_
void setConsumer(EDConsumerBase const *iConsumer)
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
static PFTauRenderPlugin instance
void throwOnPutOfUninitializedToken(char const *principalType, std::type_info const &productType)
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag, ModuleCallingContext const *mcc) const
no_tag has_postinsert_helper(...)
EDProductGetter const * prodGetter() const
std::false_type no_tag
Definition: WrapperDetail.h:22
EDConsumerBase const * consumer_
SharedResourcesAcquirer * getSharedResourcesAcquirer() const
void setSharedResourcesAcquirer(SharedResourcesAcquirer *iSra)
ProducerBase const * prodBase_
ProcessHistory const & processHistory() const
BranchType
Definition: BranchType.h:11
std::string const & productInstanceLabel(EDPutToken) const
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
void setProducer(ProducerBase const *iProd)
std::vector< bool > const & recordProvenanceList() const
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
char const * label
BranchType const & branchType() const
BasicHandle getByToken_(TypeID const &id, KindOfType kindOfType, EDGetToken token, ModuleCallingContext const *mcc) const
EDConsumerBase const * getConsumer() const
ProductID const & getProductID(unsigned int iPutTokenIndex) const
Principal const & principal() const
unsigned int value_type
Definition: EDPutToken.h:42
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
Transition
Definition: Transition.h:12
void operator()(T *p) const
void throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
void throwUnregisteredPutException(TypeID const &type, std::string const &productInstanceLabel) const
Definition: value.py:1
void operator()(T *) const
PrincipalGetAdapter & operator=(PrincipalGetAdapter const &)=delete
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md, bool isComplete)
void getManyByType(std::vector< Handle< PROD > > &results, ModuleCallingContext const *mcc) const
unsigned int processBlockIndex(std::string const &processName) const
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
std::true_type yes_tag
Definition: WrapperDetail.h:23
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
HLT enums.
size_t numberOfProductsConsumed() const
#define PROD(A, B)
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
results
Definition: mysort.py:8
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
ModuleDescription const & moduleDescription() const
ModuleDescription const & md_
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
long double T
def move(src, dest)
Definition: eostools.py:511
TypeID const & getTypeIDForPutTokenIndex(EDPutToken::value_type index) const
std::vector< BasicHandle > BasicHandleVec