CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  return principal_.processBlockIndex(processName);
90  }
91 
93  TypeID const& productType,
94  EDGetToken token) const {
96  consumer_->labelsForToken(token, labels);
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 
122  consumer_->labelsForToken(token, labels);
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 {
140  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
141  }
142 
144  std::string const& label,
145  std::string const& instance,
146  std::string const& process,
147  ModuleCallingContext const* mcc) const {
148  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process, consumer_, resourcesAcquirer_, mcc);
149  }
150 
152  KindOfType kindOfType,
154  ModuleCallingContext const* mcc) const {
155  ProductResolverIndexAndSkipBit indexAndBit = consumer_->indexFrom(token, branchType(), id);
157  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
158  if (UNLIKELY(index == ProductResolverIndexInvalid)) {
159  return makeFailToGetException(kindOfType, id, token);
160  } else if (UNLIKELY(index == ProductResolverIndexAmbiguous)) {
161  // This deals with ambiguities where the process is specified
162  throwAmbiguousException(id, token);
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
169  throwAmbiguousException(id, token);
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 {
179  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
180  }
181 
183  std::string const& label,
184  std::string const& instance,
185  std::string const& process,
186  ModuleCallingContext const* mcc) const {
187  auto h = principal_.getByLabel(ELEMENT_TYPE, typeID, label, instance, process, consumer_, resourcesAcquirer_, mcc);
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());
229  if (UNLIKELY(index == ProductResolverIndexInvalid)) {
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
ProcessHistory const & processHistory() const
SharedResourcesAcquirer * resourcesAcquirer_
BasicHandle getByToken_(TypeID const &id, KindOfType kindOfType, EDGetToken token, ModuleCallingContext const *mcc) const
unsigned int processBlockIndex(std::string const &processName) const
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
constexpr unsigned int index() const noexcept
Definition: EDGetToken.h:50
size_t numberOfProductsConsumed() const
unsigned int ProductResolverIndex
Transition transition() const
Principal const & principal() const
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
dictionary results
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:99
ProducerBase const * prodBase_
assert(be >=bs)
std::string const & moduleLabel() const
ProcessHistory const & processHistory() const
Definition: Principal.h:140
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:571
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:181
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
bool isValid() const noexcept(true)
Definition: BasicHandle.h:69
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md, bool isComplete)
constexpr value_type index() const noexcept
Definition: EDPutToken.h:50
virtual unsigned int processBlockIndex(std::string const &processName) const
Definition: Principal.cc:567
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
BranchDescription const & branchDescription() const
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:562
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:613
#define UNLIKELY(x)
Definition: Likely.h:21
Log< level::Warning, false > LogWarning
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
tuple process
Definition: LaserDQM_cfg.py:3
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)
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
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:649
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
std::vector< BasicHandle > BasicHandleVec
std::string friendlyClassName() const
Definition: TypeID.cc:59