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 
68  TypeID const& productType,
69  EDGetToken token) {
70  throw Exception(errors::LogicError) << "::getByToken: An attempt was made to read a " << principalType
71  << " product before end" << principalType << "() was called.\n"
72  << "The index of the token was " << token.index() << ".\n";
73  }
74 
76 
77  void PrincipalGetAdapter::labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const {
78  consumer_->labelsForToken(iToken, oLabels);
79  }
80 
83  }
84 
86  TypeID const& productType,
87  EDGetToken token) const {
90  //no need to copy memory since the exception will no occur after the
91  // const char* have been deleted
92  return BasicHandle(
93  makeHandleExceptionFactory([labels, kindOfType, productType]() -> std::shared_ptr<cms::Exception> {
94  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
95  if (kindOfType == PRODUCT_TYPE) {
96  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: "
97  << productType << "\n"
98  << "Looking for module label: " << labels.module << "\n"
99  << "Looking for productInstanceName: " << labels.productInstance << "\n"
100  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
101  } else {
102  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container "
103  "with elements of 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  }
109  return exception;
110  }));
111  }
112 
116  cms::Exception exception("AmbiguousProduct");
117  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with "
118  "elements of type: "
119  << productType << "\n"
120  << "Looking for module label: " << labels.module << "\n"
121  << "Looking for productInstanceName: " << labels.productInstance << "\n"
122  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
123  << "This can only occur with get function calls using a Handle<View> argument.\n"
124  << "Try a get not using a View or change the instance name of one of the products";
125  throw exception;
126  }
127 
129 
131  InputTag const& tag,
132  ModuleCallingContext const* mcc) const {
134  }
135 
137  std::string const& label,
138  std::string const& instance,
139  std::string const& process,
140  ModuleCallingContext const* mcc) const {
142  }
143 
145  KindOfType kindOfType,
147  ModuleCallingContext const* mcc) const {
150  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
152  return makeFailToGetException(kindOfType, id, token);
154  // This deals with ambiguities where the process is specified
156  }
157  bool ambiguous = false;
158  BasicHandle h =
159  principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, resourcesAcquirer_, mcc);
160  if (ambiguous) {
161  // This deals with ambiguities where the process is not specified
163  } else if (!h.isValid()) {
164  return makeFailToGetException(kindOfType, id, token);
165  }
166  return h;
167  }
168 
170  InputTag const& tag,
171  ModuleCallingContext const* mcc) const {
173  }
174 
176  std::string const& label,
177  std::string const& instance,
178  std::string const& process,
179  ModuleCallingContext const* mcc) const {
181  return h;
182  }
183 
185 
187  std::string const& productInstanceName) const {
188  std::ostringstream str;
189  for (auto branchDescription : principal_.productRegistry().allBranchDescriptions()) {
190  if (branchDescription->moduleLabel() == md_.moduleLabel() and
191  branchDescription->processName() == md_.processName()) {
192  str << *branchDescription << "-----\n";
193  }
194  }
196  << "Illegal attempt to 'put' an unregistered product.\n"
197  << "No product is registered for\n"
198  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
199  << " module label: '" << md_.moduleLabel() << "'\n"
200  << " product instance name: '" << productInstanceName << "'\n"
201  << " process name: '" << md_.processName() << "'\n"
202 
203  << "The following data products are registered for production by " << md_.moduleLabel() << ":\n"
204  << str.str() << '\n'
205  << "To correct the problem:\n"
206  " 1) make sure the proper 'produce' call is being made in the module's constructor,\n"
207  " 2) if 'produce' exists and uses a product instance name make sure that same name is used during the "
208  "'put' call.";
209  }
210 
212  std::string const& productInstanceName) const {
213  ProductResolverIndexHelper const& productResolverIndexHelper = principal_.productLookup();
214  ProductResolverIndex index = productResolverIndexHelper.index(
215  PRODUCT_TYPE, type, md_.moduleLabel().c_str(), productInstanceName.c_str(), md_.processName().c_str());
217  throwUnregisteredPutException(type, productInstanceName);
218  }
220  assert(phb != nullptr);
221  return phb->branchDescription();
222  }
223 
224  BranchDescription const& PrincipalGetAdapter::getBranchDescription(unsigned int iPutTokenIndex) const {
225  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
227  assert(phb != nullptr);
228  return phb->branchDescription();
229  }
230 
231  ProductID const& PrincipalGetAdapter::getProductID(unsigned int iPutTokenIndex) const {
232  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
234  assert(phb != nullptr);
235  auto prov = phb->stableProvenance();
236  assert(prov != nullptr);
237  return prov->productID();
238  }
239 
241  if (LIKELY(principal().branchType() == InEvent)) {
242  return Transition::Event;
243  }
244  if (principal().branchType() == InRun) {
245  if (isComplete()) {
246  return Transition::EndRun;
247  } else {
248  return Transition::BeginRun;
249  }
250  }
251  if (isComplete()) {
253  }
255  //Must be lumi
256  }
257 
259  std::string const& productInstanceName) const {
260  auto tran = transition();
261  size_t index = 0;
262  for (auto const& tl : prodBase_->typeLabelList()) {
263  if ((tran == tl.transition_) and (type == tl.typeID_) and (productInstanceName == tl.productInstanceName_)) {
264  return index;
265  }
266  ++index;
267  }
268  throwUnregisteredPutException(type, productInstanceName);
270  }
271 
273  return prodBase_->typeLabelList()[iToken.index()].productInstanceName_;
274  }
275 
277  return prodBase_->typeLabelList()[index].typeID_;
278  }
279 
280  std::vector<edm::ProductResolverIndex> const& PrincipalGetAdapter::putTokenIndexToProductResolverIndex() const {
282  }
283 
284  std::vector<bool> const& PrincipalGetAdapter::recordProvenanceList() const {
286  }
287 
289 } // 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:614
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
static PFTauRenderPlugin instance
ProductRegistry const & productRegistry() const
Definition: Principal.h:140
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
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:568
std::vector< bool > const & recordProvenanceList() 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:572
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:134
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)
StableProvenance const * stableProvenance() const
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:142
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:563
TypeID const & getTypeIDForPutTokenIndex(EDPutToken::value_type index) const
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
BranchType const & branchType() const
Definition: Principal.h:175