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 
90  }
91 
93  TypeID const& productType,
94  EDGetToken token) const {
97  //no need to copy memory since the exception will no occur after the
98  // const char* have been deleted
99  return BasicHandle(
100  makeHandleExceptionFactory([labels, kindOfType, productType]() -> std::shared_ptr<cms::Exception> {
101  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
102  if (kindOfType == PRODUCT_TYPE) {
103  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: "
104  << productType << "\n"
105  << "Looking for module label: " << labels.module << "\n"
106  << "Looking for productInstanceName: " << labels.productInstance << "\n"
107  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
108  } else {
109  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container "
110  "with elements of type: "
111  << productType << "\n"
112  << "Looking for module label: " << labels.module << "\n"
113  << "Looking for productInstanceName: " << labels.productInstance << "\n"
114  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
115  }
116  return exception;
117  }));
118  }
119 
123  cms::Exception exception("AmbiguousProduct");
124  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with "
125  "elements of type: "
126  << productType << "\n"
127  << "Looking for module label: " << labels.module << "\n"
128  << "Looking for productInstanceName: " << labels.productInstance << "\n"
129  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
130  << "This can only occur with get function calls using a Handle<View> argument.\n"
131  << "Try a get not using a View or change the instance name of one of the products";
132  throw exception;
133  }
134 
136 
138  InputTag const& tag,
139  ModuleCallingContext const* mcc) const {
141  }
142 
144  std::string const& label,
145  std::string const& instance,
146  std::string const& process,
147  ModuleCallingContext const* mcc) const {
149  }
150 
152  KindOfType kindOfType,
154  ModuleCallingContext const* mcc) const {
157  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
159  return makeFailToGetException(kindOfType, id, token);
161  // This deals with ambiguities where the process is specified
163  }
164  bool ambiguous = false;
165  BasicHandle h =
166  principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, resourcesAcquirer_, mcc);
167  if (ambiguous) {
168  // This deals with ambiguities where the process is not specified
170  } else if (!h.isValid()) {
171  return makeFailToGetException(kindOfType, id, token);
172  }
173  return h;
174  }
175 
177  InputTag const& tag,
178  ModuleCallingContext const* mcc) const {
180  }
181 
183  std::string const& label,
184  std::string const& instance,
185  std::string const& process,
186  ModuleCallingContext const* mcc) const {
188  return h;
189  }
190 
193  ModuleCallingContext const* mcc) const {
195  }
196 
198 
200  std::string const& productInstanceName) const {
201  std::ostringstream str;
202  for (auto branchDescription : principal_.productRegistry().allBranchDescriptions()) {
203  if (branchDescription->moduleLabel() == md_.moduleLabel() and
204  branchDescription->processName() == md_.processName()) {
205  str << *branchDescription << "-----\n";
206  }
207  }
209  << "Illegal attempt to 'put' an unregistered product.\n"
210  << "No product is registered for\n"
211  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
212  << " module label: '" << md_.moduleLabel() << "'\n"
213  << " product instance name: '" << productInstanceName << "'\n"
214  << " process name: '" << md_.processName() << "'\n"
215 
216  << "The following data products are registered for production by " << md_.moduleLabel() << ":\n"
217  << str.str() << '\n'
218  << "To correct the problem:\n"
219  " 1) make sure the proper 'produce' call is being made in the module's constructor,\n"
220  " 2) if 'produce' exists and uses a product instance name make sure that same name is used during the "
221  "'put' call.";
222  }
223 
225  std::string const& productInstanceName) const {
226  ProductResolverIndexHelper const& productResolverIndexHelper = principal_.productLookup();
227  ProductResolverIndex index = productResolverIndexHelper.index(
228  PRODUCT_TYPE, type, md_.moduleLabel().c_str(), productInstanceName.c_str(), md_.processName().c_str());
230  throwUnregisteredPutException(type, productInstanceName);
231  }
233  assert(phb != nullptr);
234  return phb->branchDescription();
235  }
236 
237  BranchDescription const& PrincipalGetAdapter::getBranchDescription(unsigned int iPutTokenIndex) const {
238  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
240  assert(phb != nullptr);
241  return phb->branchDescription();
242  }
243 
244  ProductID const& PrincipalGetAdapter::getProductID(unsigned int iPutTokenIndex) const {
245  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
247  assert(phb != nullptr);
248  auto prov = phb->stableProvenance();
249  assert(prov != nullptr);
250  return prov->productID();
251  }
252 
254  if (LIKELY(principal().branchType() == InEvent)) {
255  return Transition::Event;
256  }
257  if (principal().branchType() == InRun) {
258  if (isComplete()) {
259  return Transition::EndRun;
260  } else {
261  return Transition::BeginRun;
262  }
263  }
264  if (isComplete()) {
266  }
268  //Must be lumi
269  }
270 
272  std::string const& productInstanceName) const {
273  auto tran = transition();
274  size_t index = 0;
275  for (auto const& tl : prodBase_->typeLabelList()) {
276  if ((tran == tl.transition_) and (type == tl.typeID_) and (productInstanceName == tl.productInstanceName_)) {
277  return index;
278  }
279  ++index;
280  }
281  throwUnregisteredPutException(type, productInstanceName);
283  }
284 
286  return prodBase_->typeLabelList()[iToken.index()].productInstanceName_;
287  }
288 
290  return prodBase_->typeLabelList()[index].typeID_;
291  }
292 
293  std::vector<edm::ProductResolverIndex> const& PrincipalGetAdapter::putTokenIndexToProductResolverIndex() const {
295  }
296 
297  std::vector<bool> const& PrincipalGetAdapter::recordProvenanceList() const {
299  }
300 
302 } // namespace edm
Likely.h
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
edm::Principal::processBlockIndex
virtual unsigned int processBlockIndex(std::string const &processName) const
Definition: Principal.cc:567
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:240
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:297
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Transition::Event
edm::PrincipalGetAdapter::getManyByType_
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:191
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:293
edm::EDConsumerBase::itemsToGetFrom
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
Definition: EDConsumerBase.h:91
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
edm::PrincipalGetAdapter::md_
ModuleDescription const & md_
Definition: PrincipalGetAdapter.h:244
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:224
edm::PrincipalGetAdapter::makeFailToGetException
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
Definition: PrincipalGetAdapter.cc:92
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:199
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:151
edm::EDPutToken
Definition: EDPutToken.h:38
edm::PrincipalGetAdapter::prodBase_
ProducerBase const * prodBase_
Definition: PrincipalGetAdapter.h:248
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:53
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:137
edm::errors::InsertFailure
Definition: EDMException.h:35
edm::PrincipalGetAdapter::transition
Transition transition() const
Definition: PrincipalGetAdapter.cc:253
edm::InEvent
Definition: BranchType.h:11
h
edm::Transition::BeginLuminosityBlock
edm::PrincipalGetAdapter::consumer_
EDConsumerBase const * consumer_
Definition: PrincipalGetAdapter.h:246
ProducerBase.h
edm::PrincipalGetAdapter::numberOfProductsConsumed
size_t numberOfProductsConsumed() const
Definition: PrincipalGetAdapter.cc:82
edm::PrincipalGetAdapter::prodGetter
EDProductGetter const * prodGetter() const
Definition: PrincipalGetAdapter.cc:301
edm::Principal::productRegistry
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
edm::ProducerBase::recordProvenanceList
std::vector< bool > const & recordProvenanceList() const
Definition: ProductRegistryHelper.h:91
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
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
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:289
edm::PrincipalGetAdapter::productInstanceLabel
std::string const & productInstanceLabel(EDPutToken) const
Definition: PrincipalGetAdapter.cc:285
edm::ProductRegistry::allBranchDescriptions
std::vector< BranchDescription const * > allBranchDescriptions() const
Definition: ProductRegistry.cc:199
edm::EDGetToken
Definition: EDGetToken.h:35
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::PrincipalGetAdapter::getProductID
ProductID const & getProductID(unsigned int iPutTokenIndex) const
Definition: PrincipalGetAdapter.cc:244
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
edm::ProductResolverIndexAmbiguous
Definition: ProductResolverIndex.h:18
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
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:613
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:649
edm::PrincipalGetAdapter::getPutTokenIndex
EDPutToken::value_type getPutTokenIndex(TypeID const &type, std::string const &productInstanceName) const
Definition: PrincipalGetAdapter.cc:271
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:247
edm::PrincipalGetAdapter::processBlockIndex
unsigned int processBlockIndex(std::string const &processName) const
Definition: PrincipalGetAdapter.cc:88
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:571
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:120
cms::Exception
Definition: Exception.h:70
edm::PrincipalGetAdapter::getMatchingSequenceByLabel_
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: PrincipalGetAdapter.cc:176
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:197
edm::PrincipalGetAdapter::branchType
BranchType const & branchType() const
Definition: PrincipalGetAdapter.cc:135
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316