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 
77  << "The getManyByType function is no longer supported. "
78  << "Consider upgrading to use GetterOfProducts instead or delete this function call.\n";
79  }
80 
82 
83  void PrincipalGetAdapter::labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const {
84  consumer_->labelsForToken(iToken, oLabels);
85  }
86 
89  }
90 
92  TypeID const& productType,
93  EDGetToken token) const {
96  //no need to copy memory since the exception will no occur after the
97  // const char* have been deleted
98  return BasicHandle(
99  makeHandleExceptionFactory([labels, kindOfType, productType]() -> std::shared_ptr<cms::Exception> {
100  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
101  if (kindOfType == PRODUCT_TYPE) {
102  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: "
103  << productType << "\n"
104  << "Looking for module label: " << labels.module << "\n"
105  << "Looking for productInstanceName: " << labels.productInstance << "\n"
106  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
107  } else {
108  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container "
109  "with elements of type: "
110  << productType << "\n"
111  << "Looking for module label: " << labels.module << "\n"
112  << "Looking for productInstanceName: " << labels.productInstance << "\n"
113  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
114  }
115  return exception;
116  }));
117  }
118 
122  cms::Exception exception("AmbiguousProduct");
123  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with "
124  "elements of type: "
125  << productType << "\n"
126  << "Looking for module label: " << labels.module << "\n"
127  << "Looking for productInstanceName: " << labels.productInstance << "\n"
128  << (0 == labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
129  << "This can only occur with get function calls using a Handle<View> argument.\n"
130  << "Try a get not using a View or change the instance name of one of the products";
131  throw exception;
132  }
133 
135 
137  InputTag const& tag,
138  ModuleCallingContext const* mcc) const {
140  }
141 
143  std::string const& label,
144  std::string const& instance,
145  std::string const& process,
146  ModuleCallingContext const* mcc) const {
148  }
149 
151  KindOfType kindOfType,
153  ModuleCallingContext const* mcc) const {
156  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
158  return makeFailToGetException(kindOfType, id, token);
160  // This deals with ambiguities where the process is specified
162  }
163  bool ambiguous = false;
164  BasicHandle h =
165  principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, resourcesAcquirer_, mcc);
166  if (ambiguous) {
167  // This deals with ambiguities where the process is not specified
169  } else if (!h.isValid()) {
170  return makeFailToGetException(kindOfType, id, token);
171  }
172  return h;
173  }
174 
176  InputTag const& tag,
177  ModuleCallingContext const* mcc) const {
179  }
180 
182  std::string const& label,
183  std::string const& instance,
184  std::string const& process,
185  ModuleCallingContext const* mcc) const {
187  return h;
188  }
189 
191 
193  std::string const& productInstanceName) const {
194  std::ostringstream str;
195  for (auto branchDescription : principal_.productRegistry().allBranchDescriptions()) {
196  if (branchDescription->moduleLabel() == md_.moduleLabel() and
197  branchDescription->processName() == md_.processName()) {
198  str << *branchDescription << "-----\n";
199  }
200  }
202  << "Illegal attempt to 'put' an unregistered product.\n"
203  << "No product is registered for\n"
204  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
205  << " module label: '" << md_.moduleLabel() << "'\n"
206  << " product instance name: '" << productInstanceName << "'\n"
207  << " process name: '" << md_.processName() << "'\n"
208 
209  << "The following data products are registered for production by " << md_.moduleLabel() << ":\n"
210  << str.str() << '\n'
211  << "To correct the problem:\n"
212  " 1) make sure the proper 'produce' call is being made in the module's constructor,\n"
213  " 2) if 'produce' exists and uses a product instance name make sure that same name is used during the "
214  "'put' call.";
215  }
216 
218  std::string const& productInstanceName) const {
219  ProductResolverIndexHelper const& productResolverIndexHelper = principal_.productLookup();
220  ProductResolverIndex index = productResolverIndexHelper.index(
221  PRODUCT_TYPE, type, md_.moduleLabel().c_str(), productInstanceName.c_str(), md_.processName().c_str());
223  throwUnregisteredPutException(type, productInstanceName);
224  }
226  assert(phb != nullptr);
227  return phb->branchDescription();
228  }
229 
230  BranchDescription const& PrincipalGetAdapter::getBranchDescription(unsigned int iPutTokenIndex) const {
231  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
233  assert(phb != nullptr);
234  return phb->branchDescription();
235  }
236 
237  ProductID const& PrincipalGetAdapter::getProductID(unsigned int iPutTokenIndex) const {
238  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
240  assert(phb != nullptr);
241  auto prov = phb->stableProvenance();
242  assert(prov != nullptr);
243  return prov->productID();
244  }
245 
247  if (LIKELY(principal().branchType() == InEvent)) {
248  return Transition::Event;
249  }
250  if (principal().branchType() == InRun) {
251  if (isComplete()) {
252  return Transition::EndRun;
253  } else {
254  return Transition::BeginRun;
255  }
256  }
257  if (isComplete()) {
259  }
261  //Must be lumi
262  }
263 
265  std::string const& productInstanceName) const {
266  auto tran = transition();
267  size_t index = 0;
268  for (auto const& tl : prodBase_->typeLabelList()) {
269  if ((tran == tl.transition_) and (type == tl.typeID_) and (productInstanceName == tl.productInstanceName_)) {
270  return index;
271  }
272  ++index;
273  }
274  throwUnregisteredPutException(type, productInstanceName);
276  }
277 
279  return prodBase_->typeLabelList()[iToken.index()].productInstanceName_;
280  }
281 
283  return prodBase_->typeLabelList()[index].typeID_;
284  }
285 
286  std::vector<edm::ProductResolverIndex> const& PrincipalGetAdapter::putTokenIndexToProductResolverIndex() const {
288  }
289 
290  std::vector<bool> const& PrincipalGetAdapter::recordProvenanceList() const {
292  }
293 
295 } // 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