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 
128  void throwOnPrematureRead(char const* principalType, TypeID const& productType, EDGetToken);
129 
130  } // namespace principal_get_adapter_detail
132  public:
133  PrincipalGetAdapter(Principal const& pcpl, ModuleDescription const& md, bool isComplete);
134 
136 
137  PrincipalGetAdapter(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
138  PrincipalGetAdapter& operator=(PrincipalGetAdapter const&) = delete; // Disallow copying and moving
139 
140  //size_t size() const;
141 
142  void setConsumer(EDConsumerBase const* iConsumer) { consumer_ = iConsumer; }
143  EDConsumerBase const* getConsumer() const { return consumer_; }
144 
147 
148  void setProducer(ProducerBase const* iProd) { prodBase_ = iProd; }
149 
150  size_t numberOfProductsConsumed() const;
151 
152  bool isComplete() const { return isComplete_; }
153 
154  template <typename PROD>
155  bool checkIfComplete() const;
156 
157  Transition transition() const;
158 
159  ProcessHistory const& processHistory() const;
160 
161  Principal const& principal() const { return principal_; }
162 
163  BranchDescription const& getBranchDescription(TypeID const& type, std::string const& productInstanceName) const;
164 
165  EDPutToken::value_type getPutTokenIndex(TypeID const& type, std::string const& productInstanceName) const;
166 
169  typedef std::vector<BasicHandle> BasicHandleVec;
170 
171  BranchDescription const& getBranchDescription(unsigned int iPutTokenIndex) const;
172  ProductID const& getProductID(unsigned int iPutTokenIndex) const;
173  ModuleDescription const& moduleDescription() const { return md_; }
174 
175  std::vector<edm::ProductResolverIndex> const& putTokenIndexToProductResolverIndex() const;
176 
177  //uses the EDPutToken index
178  std::vector<bool> const& recordProvenanceList() const;
179  //------------------------------------------------------------
180  // Protected functions.
181  //
182 
183  // The following 'get' functions serve to isolate the PrincipalGetAdapter class
184  // from the Principal class.
185 
186  BasicHandle getByLabel_(TypeID const& tid, InputTag const& tag, ModuleCallingContext const* mcc) const;
187 
188  BasicHandle getByLabel_(TypeID const& tid,
189  std::string const& label,
190  std::string const& instance,
191  std::string const& process,
192  ModuleCallingContext const* mcc) const;
193 
194  BasicHandle getByToken_(TypeID const& id,
195  KindOfType kindOfType,
197  ModuleCallingContext const* mcc) const;
198 
200  InputTag const& tag,
201  ModuleCallingContext const* mcc) const;
202 
204  std::string const& label,
205  std::string const& instance,
206  std::string const& process,
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  unsigned int processBlockIndex(std::string const& processName) const;
216 
217  private:
218  template <typename T>
220  if constexpr (requires(T& a, T const& b) { a.mergeProduct(b); }) {
221  return true;
222  }
223  return false;
224  }
225  // Is this an Event, a LuminosityBlock, or a Run.
226  BranchType const& branchType() const;
227 
229 
230  void throwAmbiguousException(TypeID const& productType, EDGetToken token) const;
231 
233 
234  private:
235  //------------------------------------------------------------
236  // Data members
237  //
238 
239  // Each PrincipalGetAdapter must have an associated Principal, used as the
240  // source of all 'gets' and the target of 'puts'.
242 
243  // Each PrincipalGetAdapter must have a description of the module executing the
244  // "transaction" which the PrincipalGetAdapter represents.
246 
248  SharedResourcesAcquirer* resourcesAcquirer_; // We do not use propagate_const because the acquirer is itself mutable.
249  ProducerBase const* prodBase_ = nullptr;
251  };
252 
253  template <typename PROD>
254  inline std::ostream& operator<<(std::ostream& os, Handle<PROD> const& h) {
255  os << h.product() << " " << h.provenance() << " " << h.id();
256  return os;
257  }
258 
259  //------------------------------------------------------------
260  // Metafunction support for compile-time selection of code used in
261  // PrincipalGetAdapter::put member template.
262  //
263 
264  namespace detail {
265  template <typename T>
266  void do_post_insert_if_available(T& iProduct) {
267  if constexpr (not std::derived_from<T, DoNotSortUponInsertion> and requires(T& p) { p.post_insert(); }) {
268  iProduct.post_insert();
269  }
270  }
271  } // namespace detail
272 
273  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
274  // implementation of non-template members.
275  //
276 
277  template <typename PROD>
279  return isComplete() || !hasMergeProductFunction<PROD>();
280  }
281 
282 } // namespace edm
283 #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
requires requires
Definition: RefToBase.h:238
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
EDProductGetter const * prodGetter() const
EDConsumerBase const * consumer_
SharedResourcesAcquirer * getSharedResourcesAcquirer() const
void setSharedResourcesAcquirer(SharedResourcesAcquirer *iSra)
static constexpr bool hasMergeProductFunction()
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
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 throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
void throwUnregisteredPutException(TypeID const &type, std::string const &productInstanceLabel) const
PrincipalGetAdapter & operator=(PrincipalGetAdapter const &)=delete
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md, bool isComplete)
unsigned int processBlockIndex(std::string const &processName) const
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
double b
Definition: hdecay.h:120
void do_post_insert_if_available(T &iProduct)
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
HLT enums.
size_t numberOfProductsConsumed() const
double a
Definition: hdecay.h:121
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
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
TypeID const & getTypeIDForPutTokenIndex(EDPutToken::value_type index) const
std::vector< BasicHandle > BasicHandleVec