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 {
92  consumer_->labelsForToken(token, labels);
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 
116  void PrincipalGetAdapter::throwAmbiguousException(TypeID const& productType, EDGetToken token) const {
118  consumer_->labelsForToken(token, labels);
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 {
136  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
137  }
138 
140  std::string const& label,
141  std::string const& instance,
142  std::string const& process,
143  ModuleCallingContext const* mcc) const {
144  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process, consumer_, resourcesAcquirer_, mcc);
145  }
146 
148  KindOfType kindOfType,
149  EDGetToken token,
150  ModuleCallingContext const* mcc) const {
151  ProductResolverIndexAndSkipBit indexAndBit = consumer_->indexFrom(token, branchType(), id);
153  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
154  if (UNLIKELY(index == ProductResolverIndexInvalid)) {
155  return makeFailToGetException(kindOfType, id, token);
156  } else if (UNLIKELY(index == ProductResolverIndexAmbiguous)) {
157  // This deals with ambiguities where the process is specified
158  throwAmbiguousException(id, token);
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
165  throwAmbiguousException(id, token);
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 {
175  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
176  }
177 
179  std::string const& label,
180  std::string const& instance,
181  std::string const& process,
182  ModuleCallingContext const* mcc) const {
183  auto h = principal_.getByLabel(ELEMENT_TYPE, typeID, label, instance, process, consumer_, resourcesAcquirer_, mcc);
184  return h;
185  }
186 
188  BasicHandleVec& results,
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());
225  if (UNLIKELY(index == ProductResolverIndexInvalid)) {
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
ProcessHistory const & processHistory() const
SharedResourcesAcquirer * resourcesAcquirer_
BasicHandle getByToken_(TypeID const &id, KindOfType kindOfType, EDGetToken token, ModuleCallingContext const *mcc) const
type
Definition: HCALResponse.h:21
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
size_t numberOfProductsConsumed() const
unsigned int ProductResolverIndex
bool isValid() const (true)
Definition: BasicHandle.h:74
Transition transition() const
Principal const & principal() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void throwUnregisteredPutException(TypeID const &type, std::string const &productInstanceLabel) const
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag, ModuleCallingContext const *mcc) const
std::vector< bool > const & recordProvenanceList() const
std::string const & processName() const
static PFTauRenderPlugin instance
void throwOnPutOfUninitializedToken(char const *principalType, std::type_info const &productType)
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
#define nullptr
TypeID const & getTypeIDForPutTokenIndex(EDPutToken::value_type index) const
#define LIKELY(x)
Definition: Likely.h:20
EDConsumerBase const * consumer_
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
Definition: ProducerBase.h:93
ProducerBase const * prodBase_
std::string const & moduleLabel() const
ProcessHistory const & processHistory() const
Definition: Principal.h:140
value_type index() const
Definition: EDPutToken.h:50
BranchType
Definition: BranchType.h:11
StableProvenance const * stableProvenance() const
char const * process
Definition: ProductLabels.h:7
char const * label
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:540
BranchType const & branchType() const
EDProductGetter const * prodGetter() const
ProductID const & getProductID(unsigned int iPutTokenIndex) const
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
BranchType const & branchType() const
Definition: Principal.h:180
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
unsigned int value_type
Definition: EDPutToken.h:42
Transition
Definition: Transition.h:12
std::vector< BranchDescription const * > allBranchDescriptions() const
void throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
char const * module
Definition: ProductLabels.h:5
std::vector< bool > const & recordProvenanceList() const
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md, bool isComplete)
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
ProductResolverIndex productResolverIndex() const
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:148
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
std::string const & productInstanceLabel(EDPutToken) const
EDPutToken::value_type getPutTokenIndex(TypeID const &type, std::string const &productInstanceName) const
char const * productInstance
Definition: ProductLabels.h:6
HLT enums.
BranchDescription const & branchDescription() const
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:535
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
ModuleDescription const & md_
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductResolverIndex index, bool skipCurrentProcess, bool &ambiguous, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:578
#define UNLIKELY(x)
Definition: Likely.h:21
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
#define str(s)
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
unsigned int index() const
Definition: EDGetToken.h:45
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=nullptr) const
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:614
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
std::vector< BasicHandle > BasicHandleVec
std::string friendlyClassName() const
Definition: TypeID.cc:62