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
EDPutToken::value_type getPutTokenIndex(TypeID const &type, std::string const &productInstanceName) const
SharedResourcesAcquirer * resourcesAcquirer_
std::vector< BranchDescription const * > allBranchDescriptions() const
unsigned int ProductResolverIndex
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductResolverIndex index, bool skipCurrentProcess, bool &ambiguous, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:621
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
static PFTauRenderPlugin instance
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
void throwOnPutOfUninitializedToken(char const *principalType, std::type_info const &productType)
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag, ModuleCallingContext const *mcc) const
std::vector< bool > const & recordProvenanceList() const
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
EDProductGetter const * prodGetter() const
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
#define LIKELY(x)
Definition: Likely.h:20
EDConsumerBase const * consumer_
ProducerBase const * prodBase_
assert(be >=bs)
ProcessHistory const & processHistory() const
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:657
BranchType
Definition: BranchType.h:11
std::string const & productInstanceLabel(EDPutToken) const
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
virtual unsigned int processBlockIndex(std::string const &processName) const
Definition: Principal.cc:575
std::vector< bool > const & recordProvenanceList() const
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
char const * label
BranchType const & branchType() const
BasicHandle getByToken_(TypeID const &id, KindOfType kindOfType, EDGetToken token, ModuleCallingContext const *mcc) const
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
ProductID const & getProductID(unsigned int iPutTokenIndex) const
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
Principal const & principal() const
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=nullptr) const
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
unsigned int value_type
Definition: EDPutToken.h:42
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:579
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
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
Definition: ProducerBase.h:101
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md, bool isComplete)
constexpr value_type index() const noexcept
Definition: EDPutToken.h:50
ProcessHistory const & processHistory() const
Definition: Principal.h:140
std::string const & processName() const
BranchDescription const & branchDescription() const
unsigned int processBlockIndex(std::string const &processName) const
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
HLT enums.
size_t numberOfProductsConsumed() const
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
results
Definition: mysort.py:8
StableProvenance const * stableProvenance() const
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:148
ModuleDescription const & md_
#define UNLIKELY(x)
Definition: Likely.h:21
Log< level::Warning, false > LogWarning
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
#define str(s)
std::string const & moduleLabel() const
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:570
TypeID const & getTypeIDForPutTokenIndex(EDPutToken::value_type index) const
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
BranchType const & branchType() const
Definition: Principal.h:181
std::vector< BasicHandle > BasicHandleVec