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 
145  void setSharedResourcesAcquirer(SharedResourcesAcquirer* iSra) { resourcesAcquirer_ = iSra; }
146 
147  void setProducer(ProducerBase const* iProd) { prodBase_ = iProd; }
148 
149  size_t numberOfProductsConsumed() const;
150 
151  bool isComplete() const { return isComplete_; }
152 
153  template <typename PROD>
154  bool checkIfComplete() const;
155 
156  Transition transition() const;
157 
158  template <typename PROD>
159  void getManyByType(std::vector<Handle<PROD> >& results, ModuleCallingContext const* mcc) const;
160 
161  ProcessHistory const& processHistory() const;
162 
163  Principal const& principal() const { return principal_; }
164 
165  BranchDescription const& getBranchDescription(TypeID const& type, std::string const& productInstanceName) const;
166 
167  EDPutToken::value_type getPutTokenIndex(TypeID const& type, std::string const& productInstanceName) const;
168 
169  TypeID const& getTypeIDForPutTokenIndex(EDPutToken::value_type index) const;
170  std::string const& productInstanceLabel(EDPutToken) const;
171  typedef std::vector<BasicHandle> BasicHandleVec;
172 
173  BranchDescription const& getBranchDescription(unsigned int iPutTokenIndex) const;
174  ProductID const& getProductID(unsigned int iPutTokenIndex) const;
175 
176  std::vector<edm::ProductResolverIndex> const& putTokenIndexToProductResolverIndex() const;
177 
178  //uses the EDPutToken index
179  std::vector<bool> const& recordProvenanceList() const;
180  //------------------------------------------------------------
181  // Protected functions.
182  //
183 
184  // The following 'get' functions serve to isolate the PrincipalGetAdapter class
185  // from the Principal class.
186 
187  BasicHandle getByLabel_(TypeID const& tid, InputTag const& tag, ModuleCallingContext const* mcc) const;
188 
189  BasicHandle getByLabel_(TypeID const& tid,
190  std::string const& label,
191  std::string const& instance,
192  std::string const& process,
193  ModuleCallingContext const* mcc) const;
194 
195  BasicHandle getByToken_(TypeID const& id,
196  KindOfType kindOfType,
197  EDGetToken token,
198  ModuleCallingContext const* mcc) const;
199 
200  BasicHandle getMatchingSequenceByLabel_(TypeID const& typeID,
201  InputTag const& tag,
202  ModuleCallingContext const* mcc) const;
203 
204  BasicHandle getMatchingSequenceByLabel_(TypeID const& typeID,
205  std::string const& label,
206  std::string const& instance,
207  std::string const& process,
208  ModuleCallingContext const* mcc) const;
209 
210  void getManyByType_(TypeID const& tid, BasicHandleVec& results, ModuleCallingContext const* mcc) const;
211 
212  // Also isolates the PrincipalGetAdapter class
213  // from the Principal class.
214  EDProductGetter const* prodGetter() const;
215 
216  void labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const;
217 
218  private:
219  // Is this an Event, a LuminosityBlock, or a Run.
220  BranchType const& branchType() const;
221 
222  BasicHandle makeFailToGetException(KindOfType, TypeID const&, EDGetToken) const;
223 
224  void throwAmbiguousException(TypeID const& productType, EDGetToken token) const;
225 
226  void throwUnregisteredPutException(TypeID const& type, std::string const& productInstanceLabel) const;
227 
228  private:
229  //------------------------------------------------------------
230  // Data members
231  //
232 
233  // Each PrincipalGetAdapter must have an associated Principal, used as the
234  // source of all 'gets' and the target of 'puts'.
236 
237  // Each PrincipalGetAdapter must have a description of the module executing the
238  // "transaction" which the PrincipalGetAdapter represents.
240 
242  SharedResourcesAcquirer* resourcesAcquirer_; // We do not use propagate_const because the acquirer is itself mutable.
243  ProducerBase const* prodBase_ = nullptr;
245  };
246 
247  template <typename PROD>
248  inline std::ostream& operator<<(std::ostream& os, Handle<PROD> const& h) {
249  os << h.product() << " " << h.provenance() << " " << h.id();
250  return os;
251  }
252 
253  //------------------------------------------------------------
254  // Metafunction support for compile-time selection of code used in
255  // PrincipalGetAdapter::put member template.
256  //
257 
258  // has_postinsert is a metafunction of one argument, the type T. As
259  // with many metafunctions, it is implemented as a class with a data
260  // member 'value', which contains the value 'returned' by the
261  // metafunction.
262  //
263  // has_postinsert<T>::value is 'true' if T has the post_insert
264  // member function (with the right signature), and 'false' if T has
265  // no such member function.
266 
267  namespace detail {
268  using no_tag = std::false_type; // type indicating FALSE
269  using yes_tag = std::true_type; // type indicating TRUE
270 
271  // Definitions forthe following struct and function templates are
272  // not needed; we only require the declarations.
273  template <typename T, void (T::*)()>
275  template <typename T>
277  template <typename T>
279 
280  template <typename T>
281  struct has_postinsert {
282  static constexpr bool value = std::is_same<decltype(has_postinsert_helper<T>(nullptr)), yes_tag>::value &&
284  };
285 
286  } // namespace detail
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>
310  return isComplete() || !detail::has_mergeProduct_function<PROD>::value;
311  }
312 
313  template <typename PROD>
314  inline void PrincipalGetAdapter::getManyByType(std::vector<Handle<PROD> >& results,
315  ModuleCallingContext const* mcc) const {
316  BasicHandleVec bhv;
317  this->getManyByType_(TypeID(typeid(PROD)), bhv, mcc);
318 
319  // Go through the returned handles; for each element,
320  // 1. create a Handle<PROD> and
321  //
322  // This function presents an exception safety difficulty. If an
323  // exception is thrown when converting a handle, the "got
324  // products" record will be wrong.
325  //
326  // Since EDProducers are not allowed to use this function,
327  // the problem does not seem too severe.
328  //
329  // Question: do we even need to keep track of the "got products"
330  // for this function, since it is *not* to be used by EDProducers?
331  std::vector<Handle<PROD> > products;
332 
333  typename BasicHandleVec::iterator it = bhv.begin();
334  typename BasicHandleVec::iterator end = bhv.end();
335 
336  while (it != end) {
337  products.push_back(convert_handle<PROD>(std::move(*it)));
338  ++it;
339  }
340  results.swap(products);
341  }
342 } // namespace edm
343 #endif
SharedResourcesAcquirer * resourcesAcquirer_
type
Definition: HCALResponse.h:21
void setConsumer(EDConsumerBase const *iConsumer)
void operator()(T *p) const
Principal const & principal() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static PFTauRenderPlugin instance
void throwOnPutOfUninitializedToken(char const *principalType, std::type_info const &productType)
std::false_type no_tag
Definition: WrapperDetail.h:20
EDConsumerBase const * consumer_
void setSharedResourcesAcquirer(SharedResourcesAcquirer *iSra)
BranchType
Definition: BranchType.h:11
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&...args)
Definition: ESProducts.h:128
static void throwAmbiguousException(const char *where, TypeID const &productType, std::string const &label, std::string const &instance, std::string const &process)
Definition: Principal.cc:77
void setProducer(ProducerBase const *iProd)
char const * label
yes_tag has_postinsert_helper(postinsert_function< T,&T::post_insert > *p)
unsigned int value_type
Definition: EDPutToken.h:42
Transition
Definition: Transition.h:12
void throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
void getManyByType(std::vector< Handle< PROD > > &results, ModuleCallingContext const *mcc) const
#define end
Definition: vmac.h:39
Definition: value.py:1
std::true_type yes_tag
Definition: WrapperDetail.h:21
HLT enums.
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)
long double T
def move(src, dest)
Definition: eostools.py:511
def branchType(schema, name)
Definition: revisionDML.py:114
#define constexpr
std::vector< BasicHandle > BasicHandleVec