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  private:
222  // Is this an Event, a LuminosityBlock, or a Run.
223  BranchType const& branchType() const;
224 
226 
227  void throwAmbiguousException(TypeID const& productType, EDGetToken token) const;
228 
230 
231  private:
232  //------------------------------------------------------------
233  // Data members
234  //
235 
236  // Each PrincipalGetAdapter must have an associated Principal, used as the
237  // source of all 'gets' and the target of 'puts'.
239 
240  // Each PrincipalGetAdapter must have a description of the module executing the
241  // "transaction" which the PrincipalGetAdapter represents.
243 
245  SharedResourcesAcquirer* resourcesAcquirer_; // We do not use propagate_const because the acquirer is itself mutable.
246  ProducerBase const* prodBase_ = nullptr;
248  };
249 
250  template <typename PROD>
251  inline std::ostream& operator<<(std::ostream& os, Handle<PROD> const& h) {
252  os << h.product() << " " << h.provenance() << " " << h.id();
253  return os;
254  }
255 
256  //------------------------------------------------------------
257  // Metafunction support for compile-time selection of code used in
258  // PrincipalGetAdapter::put member template.
259  //
260 
261  // has_postinsert is a metafunction of one argument, the type T. As
262  // with many metafunctions, it is implemented as a class with a data
263  // member 'value', which contains the value 'returned' by the
264  // metafunction.
265  //
266  // has_postinsert<T>::value is 'true' if T has the post_insert
267  // member function (with the right signature), and 'false' if T has
268  // no such member function.
269 
270  namespace detail {
271  using no_tag = std::false_type; // type indicating FALSE
272  using yes_tag = std::true_type; // type indicating TRUE
273 
274  // Definitions forthe following struct and function templates are
275  // not needed; we only require the declarations.
276  template <typename T, void (T::*)()>
278  template <typename T>
280  template <typename T>
282 
283  template <typename T>
284  struct has_postinsert {
285  static constexpr bool value = std::is_same<decltype(has_postinsert_helper<T>(nullptr)), yes_tag>::value &&
287  };
288 
289  } // namespace detail
290 
291  //------------------------------------------------------------
292 
293  // The following function objects are used by Event::put, under the
294  // control of a metafunction if, to either call the given object's
295  // post_insert function (if it has one), or to do nothing (if it
296  // does not have a post_insert function).
297  template <typename T>
298  struct DoPostInsert {
299  void operator()(T* p) const { p->post_insert(); }
300  };
301 
302  template <typename T>
304  void operator()(T*) const {}
305  };
306 
307  // Implementation of PrincipalGetAdapter member templates. See PrincipalGetAdapter.cc for the
308  // implementation of non-template members.
309  //
310 
311  template <typename PROD>
314  }
315 
316  template <typename PROD>
318  ModuleCallingContext const* mcc) const {
319  BasicHandleVec bhv;
320  this->getManyByType_(TypeID(typeid(PROD)), bhv, mcc);
321 
322  // Go through the returned handles; for each element,
323  // 1. create a Handle<PROD> and
324  //
325  // This function presents an exception safety difficulty. If an
326  // exception is thrown when converting a handle, the "got
327  // products" record will be wrong.
328  //
329  // Since EDProducers are not allowed to use this function,
330  // the problem does not seem too severe.
331  //
332  // Question: do we even need to keep track of the "got products"
333  // for this function, since it is *not* to be used by EDProducers?
334  std::vector<Handle<PROD> > products;
335 
336  typename BasicHandleVec::iterator it = bhv.begin();
337  typename BasicHandleVec::iterator end = bhv.end();
338 
339  while (it != end) {
340  products.push_back(convert_handle<PROD>(std::move(*it)));
341  ++it;
342  }
343  results.swap(products);
344  }
345 } // namespace edm
346 #endif
edm::SharedResourcesAcquirer
Definition: SharedResourcesAcquirer.h:34
edm::PrincipalGetAdapter::~PrincipalGetAdapter
~PrincipalGetAdapter()
Definition: PrincipalGetAdapter.cc:30
edm::PrincipalGetAdapter::setConsumer
void setConsumer(EDConsumerBase const *iConsumer)
Definition: PrincipalGetAdapter.h:143
ProvenanceFwd.h
edm::PrincipalGetAdapter::principal
Principal const & principal() const
Definition: PrincipalGetAdapter.h:165
edm::PrincipalGetAdapter::principal_
Principal const & principal_
Definition: PrincipalGetAdapter.h:238
Handle.h
edm::principal_get_adapter_detail::throwOnPutOfWrongType
void throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
Definition: PrincipalGetAdapter.cc:48
edm::PrincipalGetAdapter::setProducer
void setProducer(ProducerBase const *iProd)
Definition: PrincipalGetAdapter.h:149
edm::detail::has_postinsert
Definition: PrincipalGetAdapter.h:284
edm::BasicHandle
Definition: BasicHandle.h:43
propagate_const.h
edm::PrincipalGetAdapter
Definition: PrincipalGetAdapter.h:132
edm::PrincipalGetAdapter::recordProvenanceList
std::vector< bool > const & recordProvenanceList() const
Definition: PrincipalGetAdapter.cc:293
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::PrincipalGetAdapter::getSharedResourcesAcquirer
SharedResourcesAcquirer * getSharedResourcesAcquirer() const
Definition: PrincipalGetAdapter.h:147
edm::PrincipalGetAdapter::operator=
PrincipalGetAdapter & operator=(PrincipalGetAdapter const &)=delete
edm::PrincipalGetAdapter::getManyByType_
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:187
edm::principal_get_adapter_detail::throwOnPutOfUninitializedToken
void throwOnPutOfUninitializedToken(char const *principalType, std::type_info const &productType)
Definition: PrincipalGetAdapter.cc:41
edm::Principal
Definition: Principal.h:57
bookConverter.results
results
Definition: bookConverter.py:144
edm::PrincipalGetAdapter::PrincipalGetAdapter
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md, bool isComplete)
Definition: PrincipalGetAdapter.cc:22
detail
Definition: ConvertingESProducerWithDependenciesT.h:23
edm::PrincipalGetAdapter::isComplete
bool isComplete() const
Definition: PrincipalGetAdapter.h:153
edm::PrincipalGetAdapter::putTokenIndexToProductResolverIndex
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
Definition: PrincipalGetAdapter.cc:289
edm::PrincipalGetAdapter::md_
ModuleDescription const & md_
Definition: PrincipalGetAdapter.h:242
edm::Handle
Definition: AssociativeIterator.h:50
edm::detail::no_tag
std::false_type no_tag
Definition: WrapperDetail.h:22
edm::PrincipalGetAdapter::moduleDescription
ModuleDescription const & moduleDescription() const
Definition: PrincipalGetAdapter.h:177
edm::PrincipalGetAdapter::labelsForToken
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
Definition: PrincipalGetAdapter.cc:84
edm::BranchType
BranchType
Definition: BranchType.h:11
edm::es::products
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
edm::ModuleDescription
Definition: ModuleDescription.h:21
edm::PrincipalGetAdapter::setSharedResourcesAcquirer
void setSharedResourcesAcquirer(SharedResourcesAcquirer *iSra)
Definition: PrincipalGetAdapter.h:146
edm::detail::has_postinsert_helper
no_tag has_postinsert_helper(...)
edm::EDPutToken::value_type
unsigned int value_type
Definition: EDPutToken.h:42
edm::operator<<
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
Definition: HLTGlobalStatus.h:106
edm::PrincipalGetAdapter::getBranchDescription
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
Definition: PrincipalGetAdapter.cc:220
edm::PrincipalGetAdapter::makeFailToGetException
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
Definition: PrincipalGetAdapter.cc:88
edm::EDProductGetter
Definition: EDProductGetter.h:41
edm::PrincipalGetAdapter::throwUnregisteredPutException
void throwUnregisteredPutException(TypeID const &type, std::string const &productInstanceLabel) const
Definition: PrincipalGetAdapter.cc:195
edm::EDConsumerBase
Definition: EDConsumerBase.h:70
edm::DoPostInsert::operator()
void operator()(T *p) const
Definition: PrincipalGetAdapter.h:299
edm::PrincipalGetAdapter::getByToken_
BasicHandle getByToken_(TypeID const &id, KindOfType kindOfType, EDGetToken token, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:147
edm::EDPutToken
Definition: EDPutToken.h:38
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
edm::PrincipalGetAdapter::prodBase_
ProducerBase const * prodBase_
Definition: PrincipalGetAdapter.h:246
edm::principal_get_adapter_detail::throwOnPrematureRead
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
Definition: PrincipalGetAdapter.cc:55
edm::detail::postinsert_function
Definition: PrincipalGetAdapter.h:277
mps_fire.end
end
Definition: mps_fire.py:242
edm::detail::has_mergeProduct_function
Definition: WrapperDetail.h:100
edm::PrincipalGetAdapter::getByLabel_
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:133
edm::PrincipalGetAdapter::transition
Transition transition() const
Definition: PrincipalGetAdapter.cc:249
h
Transition.h
EDGetToken.h
edm::PrincipalGetAdapter::consumer_
EDConsumerBase const * consumer_
Definition: PrincipalGetAdapter.h:244
edm::PrincipalGetAdapter::numberOfProductsConsumed
size_t numberOfProductsConsumed() const
Definition: PrincipalGetAdapter.cc:82
edm::PrincipalGetAdapter::prodGetter
EDProductGetter const * prodGetter() const
Definition: PrincipalGetAdapter.cc:297
SharedResourcesAcquirer
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::DoNotPostInsert::operator()
void operator()(T *) const
Definition: PrincipalGetAdapter.h:304
edm::Transition
Transition
Definition: Transition.h:12
ConvertHandle.h
EDPutToken.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
LaserDQM_cfg.process
process
Definition: LaserDQM_cfg.py:3
value
Definition: value.py:1
edm::PrincipalGetAdapter::getTypeIDForPutTokenIndex
TypeID const & getTypeIDForPutTokenIndex(EDPutToken::value_type index) const
Definition: PrincipalGetAdapter.cc:285
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::PrincipalGetAdapter::productInstanceLabel
std::string const & productInstanceLabel(EDPutToken) const
Definition: PrincipalGetAdapter.cc:281
edm::EDGetToken
Definition: EDGetToken.h:35
edm::PrincipalGetAdapter::getProductID
ProductID const & getProductID(unsigned int iPutTokenIndex) const
Definition: PrincipalGetAdapter.cc:240
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
InputTag.h
edm::PrincipalGetAdapter::getConsumer
EDConsumerBase const * getConsumer() const
Definition: PrincipalGetAdapter.h:144
edm::principal_get_adapter_detail::throwOnPutOfNullProduct
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
Definition: PrincipalGetAdapter.cc:32
edm::TypeID
Definition: TypeID.h:22
edm::DoNotPostInsert
Definition: PrincipalGetAdapter.h:303
Wrapper.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::KindOfType
KindOfType
Definition: ProductKindOfType.h:5
edm::PrincipalGetAdapter::getPutTokenIndex
EDPutToken::value_type getPutTokenIndex(TypeID const &type, std::string const &productInstanceName) const
Definition: PrincipalGetAdapter.cc:267
edm::detail::yes_tag
std::true_type yes_tag
Definition: WrapperDetail.h:23
Frameworkfwd.h
edm::DoPostInsert
Definition: PrincipalGetAdapter.h:298
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::PrincipalGetAdapter::resourcesAcquirer_
SharedResourcesAcquirer * resourcesAcquirer_
Definition: PrincipalGetAdapter.h:245
BasicHandle.h
edm::PrincipalGetAdapter::isComplete_
bool isComplete_
Definition: PrincipalGetAdapter.h:247
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::BranchDescription
Definition: BranchDescription.h:32
edm::PrincipalGetAdapter::throwAmbiguousException
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
Definition: PrincipalGetAdapter.cc:116
PROD
#define PROD(A, B)
Definition: Simplify_begin.h:55
edm::PrincipalGetAdapter::getMatchingSequenceByLabel_
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:172
traits.h
edm::ProcessHistory
Definition: ProcessHistory.h:13
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::ProducerBase
Definition: ProducerBase.h:70
edm::PrincipalGetAdapter::BasicHandleVec
std::vector< BasicHandle > BasicHandleVec
Definition: PrincipalGetAdapter.h:173
ProductKindOfType.h
EDProductfwd.h
edm::PrincipalGetAdapter::getManyByType
void getManyByType(std::vector< Handle< PROD > > &results, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.h:317
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::ProductID
Definition: ProductID.h:27
ProductLabels.h
edm::PrincipalGetAdapter::checkIfComplete
bool checkIfComplete() const
Definition: PrincipalGetAdapter.h:312
edm::ProductLabels
Definition: ProductLabels.h:4
edm::PrincipalGetAdapter::processHistory
ProcessHistory const & processHistory() const
Definition: PrincipalGetAdapter.cc:193
edm::PrincipalGetAdapter::branchType
BranchType const & branchType() const
Definition: PrincipalGetAdapter.cc:131
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:318