CMS 3D CMS Logo

PrincipalGetAdapter.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <algorithm>
5 
17 
19 
20 namespace edm {
21 
22  PrincipalGetAdapter::PrincipalGetAdapter(Principal const& pcpl, ModuleDescription const& md, bool isComplete)
23  : //putProducts_(),
24  principal_(pcpl),
25  md_(md),
26  consumer_(nullptr),
27  resourcesAcquirer_(nullptr),
28  isComplete_(isComplete) {}
29 
31 
33  TypeID const& productType,
34  std::string const& productInstanceName) {
36  << principalType << "::put: A null unique_ptr was passed to 'put'.\n"
37  << "The pointer is of type " << productType << ".\nThe specified productInstanceName was '"
38  << productInstanceName << "'.\n";
39  }
40 
42  std::type_info const& type) {
43  TypeID productType{type};
44  throw Exception(errors::LogicError) << principalType << "::put: An uninitialized EDPutToken was passed to 'put'.\n"
45  << "The pointer is of type " << productType << ".\n";
46  }
47 
48  void principal_get_adapter_detail::throwOnPutOfWrongType(std::type_info const& wrongType, TypeID const& rightType) {
49  TypeID wrongTypeID{wrongType};
50  throw Exception(errors::LogicError) << "The registered type for an EDPutToken does not match the put type.\n"
51  << "The expected type " << rightType << "\nThe put type " << wrongTypeID
52  << ".\n";
53  }
54 
56  TypeID const& productType,
57  std::string const& moduleLabel,
58  std::string const& productInstanceName) {
59  //throw Exception(errors::LogicError)
60  LogWarning("LogicError") << "::getByLabel: An attempt was made to read a " << principalType << " product before end"
61  << principalType << "() was called.\n"
62  << "The product is of type '" << productType << "'.\nThe specified ModuleLabel was '"
63  << moduleLabel << "'.\nThe specified productInstanceName was '" << productInstanceName
64  << "'.\n";
65  }
66 
67  void principal_get_adapter_detail::throwOnPrematureRead(char const* principalType, TypeID const& productType) {
68  //throw Exception(errors::LogicError)
69  LogWarning("LogicError") << "::getManyByType: An attempt was made to read a " << principalType
70  << " product before end" << principalType << "() was called.\n"
71  << "The product is of type '" << productType << "'.\n";
72  }
73 
75  TypeID const& productType,
76  EDGetToken token) {
77  throw Exception(errors::LogicError) << "::getByToken: An attempt was made to read a " << principalType
78  << " product before end" << principalType << "() was called.\n"
79  << "The index of the token was " << token.index() << ".\n";
80  }
81 
83 
84  void PrincipalGetAdapter::labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const {
85  consumer_->labelsForToken(iToken, oLabels);
86  }
87 
89  TypeID const& productType,
90  EDGetToken token) const {
93  //no need to copy memory since the exception will no occur after the
94  // const char* have been deleted
95  return BasicHandle(
96  makeHandleExceptionFactory([labels, kindOfType, productType]() -> std::shared_ptr<cms::Exception> {
97  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
98  if (kindOfType == PRODUCT_TYPE) {
99  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: "
100  << productType << "\n"
101  << "Looking for module label: " << labels.module << "\n"
102  << "Looking for productInstanceName: " << labels.productInstance << "\n"
103  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
104  } else {
105  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container "
106  "with elements of type: "
107  << productType << "\n"
108  << "Looking for module label: " << labels.module << "\n"
109  << "Looking for productInstanceName: " << labels.productInstance << "\n"
110  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
111  }
112  return exception;
113  }));
114  }
115 
119  cms::Exception exception("AmbiguousProduct");
120  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with "
121  "elements of type: "
122  << productType << "\n"
123  << "Looking for module label: " << labels.module << "\n"
124  << "Looking for productInstanceName: " << labels.productInstance << "\n"
125  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
126  << "This can only occur with get function calls using a Handle<View> argument.\n"
127  << "Try a get not using a View or change the instance name of one of the products";
128  throw exception;
129  }
130 
132 
134  InputTag const& tag,
135  ModuleCallingContext const* mcc) const {
137  }
138 
140  std::string const& label,
141  std::string const& instance,
142  std::string const& process,
143  ModuleCallingContext const* mcc) const {
145  }
146 
148  KindOfType kindOfType,
150  ModuleCallingContext const* mcc) const {
153  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
155  return makeFailToGetException(kindOfType, id, token);
157  // This deals with ambiguities where the process is specified
159  }
160  bool ambiguous = false;
161  BasicHandle h =
162  principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, resourcesAcquirer_, mcc);
163  if (ambiguous) {
164  // This deals with ambiguities where the process is not specified
166  } else if (!h.isValid()) {
167  return makeFailToGetException(kindOfType, id, token);
168  }
169  return h;
170  }
171 
173  InputTag const& tag,
174  ModuleCallingContext const* mcc) const {
176  }
177 
179  std::string const& label,
180  std::string const& instance,
181  std::string const& process,
182  ModuleCallingContext const* mcc) const {
184  return h;
185  }
186 
189  ModuleCallingContext const* mcc) const {
191  }
192 
194 
196  std::string const& productInstanceName) const {
197  std::ostringstream str;
198  for (auto branchDescription : principal_.productRegistry().allBranchDescriptions()) {
199  if (branchDescription->moduleLabel() == md_.moduleLabel() and
200  branchDescription->processName() == md_.processName()) {
201  str << *branchDescription << "-----\n";
202  }
203  }
205  << "Illegal attempt to 'put' an unregistered product.\n"
206  << "No product is registered for\n"
207  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
208  << " module label: '" << md_.moduleLabel() << "'\n"
209  << " product instance name: '" << productInstanceName << "'\n"
210  << " process name: '" << md_.processName() << "'\n"
211 
212  << "The following data products are registered for production by " << md_.moduleLabel() << ":\n"
213  << str.str() << '\n'
214  << "To correct the problem:\n"
215  " 1) make sure the proper 'produce' call is being made in the module's constructor,\n"
216  " 2) if 'produce' exists and uses a product instance name make sure that same name is used during the "
217  "'put' call.";
218  }
219 
221  std::string const& productInstanceName) const {
222  ProductResolverIndexHelper const& productResolverIndexHelper = principal_.productLookup();
223  ProductResolverIndex index = productResolverIndexHelper.index(
224  PRODUCT_TYPE, type, md_.moduleLabel().c_str(), productInstanceName.c_str(), md_.processName().c_str());
226  throwUnregisteredPutException(type, productInstanceName);
227  }
229  assert(phb != nullptr);
230  return phb->branchDescription();
231  }
232 
233  BranchDescription const& PrincipalGetAdapter::getBranchDescription(unsigned int iPutTokenIndex) const {
234  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
236  assert(phb != nullptr);
237  return phb->branchDescription();
238  }
239 
240  ProductID const& PrincipalGetAdapter::getProductID(unsigned int iPutTokenIndex) const {
241  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
243  assert(phb != nullptr);
244  auto prov = phb->stableProvenance();
245  assert(prov != nullptr);
246  return prov->productID();
247  }
248 
250  if (LIKELY(principal().branchType() == InEvent)) {
251  return Transition::Event;
252  }
253  if (principal().branchType() == InRun) {
254  if (isComplete()) {
255  return Transition::EndRun;
256  } else {
257  return Transition::BeginRun;
258  }
259  }
260  if (isComplete()) {
262  }
264  //Must be lumi
265  }
266 
268  std::string const& productInstanceName) const {
269  auto tran = transition();
270  size_t index = 0;
271  for (auto const& tl : prodBase_->typeLabelList()) {
272  if ((tran == tl.transition_) and (type == tl.typeID_) and (productInstanceName == tl.productInstanceName_)) {
273  return index;
274  }
275  ++index;
276  }
277  throwUnregisteredPutException(type, productInstanceName);
279  }
280 
282  return prodBase_->typeLabelList()[iToken.index()].productInstanceName_;
283  }
284 
286  return prodBase_->typeLabelList()[index].typeID_;
287  }
288 
289  std::vector<edm::ProductResolverIndex> const& PrincipalGetAdapter::putTokenIndexToProductResolverIndex() const {
291  }
292 
293  std::vector<bool> const& PrincipalGetAdapter::recordProvenanceList() const {
295  }
296 
298 } // namespace edm
Likely.h
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
edm::PrincipalGetAdapter::~PrincipalGetAdapter
~PrincipalGetAdapter()
Definition: PrincipalGetAdapter.cc:30
edm::ModuleDescription::moduleLabel
std::string const & moduleLabel() const
Definition: ModuleDescription.h:43
edm::PrincipalGetAdapter::principal
Principal const & principal() const
Definition: PrincipalGetAdapter.h:165
edm::PrincipalGetAdapter::principal_
Principal const & principal_
Definition: PrincipalGetAdapter.h:238
edm::principal_get_adapter_detail::throwOnPutOfWrongType
void throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
Definition: PrincipalGetAdapter.cc:48
ProductResolverIndexHelper.h
edm::ProductResolverIndex
unsigned int ProductResolverIndex
Definition: ProductResolverIndex.h:8
MessageLogger.h
edm::EDPutToken::index
value_type index() const
Definition: EDPutToken.h:50
FunctorHandleExceptionFactory.h
edm::PRODUCT_TYPE
Definition: ProductKindOfType.h:5
edm::BasicHandle
Definition: BasicHandle.h:43
edm::errors::LogicError
Definition: EDMException.h:37
edm::ProductResolverBase::stableProvenance
StableProvenance const * stableProvenance() const
Definition: ProductResolverBase.h:136
edm::ProductResolverIndexAndSkipBit
Definition: ProductResolverIndexAndSkipBit.h:28
edm::PrincipalGetAdapter::recordProvenanceList
std::vector< bool > const & recordProvenanceList() const
Definition: PrincipalGetAdapter.cc:293
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Transition::Event
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
edm::PrincipalGetAdapter::getManyByType_
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:187
cms::cuda::assert
assert(be >=bs)
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:56
edm::ProductResolverIndexHelper::index
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=nullptr) const
Definition: ProductResolverIndexHelper.cc:81
bookConverter.results
results
Definition: bookConverter.py:144
edm::ModuleDescription::processName
std::string const & processName() const
Definition: ModuleDescription.cc:47
ProductRegistry.h
edm::PrincipalGetAdapter::PrincipalGetAdapter
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md, bool isComplete)
Definition: PrincipalGetAdapter.cc:22
edm::ProductResolverIndexHelper
Definition: ProductResolverIndexHelper.h:89
edm::Principal::processHistory
ProcessHistory const & processHistory() const
Definition: Principal.h:140
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::EDConsumerBase::itemsToGetFrom
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
Definition: EDConsumerBase.h:91
edm::PrincipalGetAdapter::md_
ModuleDescription const & md_
Definition: PrincipalGetAdapter.h:242
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::InRun
Definition: BranchType.h:11
edm::ProducerBase::putTokenIndexToProductResolverIndex
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
Definition: ProducerBase.h:98
edm::PrincipalGetAdapter::labelsForToken
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
Definition: PrincipalGetAdapter.cc:84
edm::Principal::getProductResolverByIndex
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:562
edm::BranchType
BranchType
Definition: BranchType.h:11
edm::ModuleDescription
Definition: ModuleDescription.h:21
edm::makeHandleExceptionFactory
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
Definition: FunctorHandleExceptionFactory.h:45
ModuleDescription.h
edm::ProducerBase::typeLabelList
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
Definition: ProductRegistryHelper.cc:20
edm::EDPutToken::value_type
unsigned int value_type
Definition: EDPutToken.h:42
EDMException.h
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::errors::ProductNotFound
Definition: EDMException.h:33
edm::PrincipalGetAdapter::throwUnregisteredPutException
void throwUnregisteredPutException(TypeID const &type, std::string const &productInstanceLabel) const
Definition: PrincipalGetAdapter.cc:195
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
edm::errors::NullPointerError
Definition: EDMException.h:40
edm::ProductResolverIndexAndSkipBit::productResolverIndex
ProductResolverIndex productResolverIndex() const
Definition: ProductResolverIndexAndSkipBit.h:32
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
str
#define str(s)
Definition: TestProcessor.cc:52
edm::Principal::branchType
BranchType const & branchType() const
Definition: Principal.h:181
edm::PrincipalGetAdapter::getByLabel_
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:133
edm::errors::InsertFailure
Definition: EDMException.h:35
edm::PrincipalGetAdapter::transition
Transition transition() const
Definition: PrincipalGetAdapter.cc:249
edm::InEvent
Definition: BranchType.h:11
h
edm::Transition::BeginLuminosityBlock
edm::PrincipalGetAdapter::consumer_
EDConsumerBase const * consumer_
Definition: PrincipalGetAdapter.h:244
ProducerBase.h
edm::PrincipalGetAdapter::numberOfProductsConsumed
size_t numberOfProductsConsumed() const
Definition: PrincipalGetAdapter.cc:82
edm::PrincipalGetAdapter::prodGetter
EDProductGetter const * prodGetter() const
Definition: PrincipalGetAdapter.cc:297
edm::Principal::productRegistry
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
edm::ProducerBase::recordProvenanceList
std::vector< bool > const & recordProvenanceList() const
Definition: ProductRegistryHelper.h:91
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Principal::productLookup
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:148
Principal.h
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::Transition
Transition
Definition: Transition.h:12
EDConsumerBase.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
LaserDQM_cfg.process
process
Definition: LaserDQM_cfg.py:3
edm::ProductResolverIndexInvalid
Definition: ProductResolverIndex.h:16
edm::PrincipalGetAdapter::getTypeIDForPutTokenIndex
TypeID const & getTypeIDForPutTokenIndex(EDPutToken::value_type index) const
Definition: PrincipalGetAdapter.cc:285
edm::PrincipalGetAdapter::productInstanceLabel
std::string const & productInstanceLabel(EDPutToken) const
Definition: PrincipalGetAdapter.cc:281
edm::ProductRegistry::allBranchDescriptions
std::vector< BranchDescription const * > allBranchDescriptions() const
Definition: ProductRegistry.cc:199
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
edm::ProductResolverIndexAmbiguous
Definition: ProductResolverIndex.h:18
edm::EDConsumerBase::labelsForToken
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
Definition: EDConsumerBase.cc:338
edm::principal_get_adapter_detail::throwOnPutOfNullProduct
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
Definition: PrincipalGetAdapter.cc:32
edm::Principal::getByToken
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductResolverIndex index, bool skipCurrentProcess, bool &ambiguous, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:609
edm::TypeID
Definition: TypeID.h:22
edm::Transition::EndLuminosityBlock
edm::ProductResolverBase::branchDescription
BranchDescription const & branchDescription() const
Definition: ProductResolverBase.h:110
edm::KindOfType
KindOfType
Definition: ProductKindOfType.h:5
edm::Principal::prodGetter
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
edm::Principal::getManyByType
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:645
edm::PrincipalGetAdapter::getPutTokenIndex
EDPutToken::value_type getPutTokenIndex(TypeID const &type, std::string const &productInstanceName) const
Definition: PrincipalGetAdapter.cc:267
edm::ELEMENT_TYPE
Definition: ProductKindOfType.h:5
edm::ProductResolverBase
Definition: ProductResolverBase.h:34
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
edm::Transition::BeginRun
Exception
Definition: hltDiff.cc:245
edm::PrincipalGetAdapter::resourcesAcquirer_
SharedResourcesAcquirer * resourcesAcquirer_
Definition: PrincipalGetAdapter.h:245
edm::ProductResolverIndexAndSkipBit::skipCurrentProcess
bool skipCurrentProcess() const
Definition: ProductResolverIndexAndSkipBit.h:36
edm::Principal::getByLabel
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:567
PrincipalGetAdapter.h
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
cms::Exception
Definition: Exception.h:70
edm::PrincipalGetAdapter::getMatchingSequenceByLabel_
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:172
edm::ProcessHistory
Definition: ProcessHistory.h:13
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::Transition::EndRun
edm::PrincipalGetAdapter::BasicHandleVec
std::vector< BasicHandle > BasicHandleVec
Definition: PrincipalGetAdapter.h:173
ProductKindOfType.h
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::ProductID
Definition: ProductID.h:27
edm::EDConsumerBase::indexFrom
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
Definition: EDConsumerBase.cc:251
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:316