CMS 3D CMS Logo

PrincipalGetAdapter.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <algorithm>
5 
16 
18 
19 namespace edm {
20 
22  ModuleDescription const& md, bool isComplete) :
23  //putProducts_(),
24  principal_(pcpl),
25  md_(md),
26  consumer_(nullptr),
27  resourcesAcquirer_(nullptr),
28  isComplete_(isComplete)
29  {
30  }
31 
33  }
34 
35  void
37  char const* principalType,
38  TypeID const& productType,
39  std::string const& productInstanceName) {
41  << principalType
42  << "::put: A null unique_ptr was passed to 'put'.\n"
43  << "The pointer is of type "
44  << productType
45  << ".\nThe specified productInstanceName was '"
46  << productInstanceName
47  << "'.\n";
48  }
49 
50  void
51  principal_get_adapter_detail::throwOnPutOfUninitializedToken(char const* principalType, std::type_info const& type) {
52  TypeID productType{type};
54  << principalType
55  << "::put: An uninitialized EDPutToken was passed to 'put'.\n"
56  << "The pointer is of type "
57  << productType
58  << ".\n";
59  }
60 
61  void
62  principal_get_adapter_detail::throwOnPutOfWrongType(std::type_info const& wrongType, TypeID const& rightType) {
63  TypeID wrongTypeID{wrongType};
65  << "The registered type for an EDPutToken does not match the put type.\n"
66  << "The expected type "
67  << rightType
68  << "\nThe put type "
69  << wrongTypeID
70  << ".\n";
71  }
72 
73  void
75  char const* principalType,
76  TypeID const& productType,
77  std::string const& moduleLabel,
78  std::string const& productInstanceName) {
79  //throw Exception(errors::LogicError)
80  LogWarning("LogicError")
81  << "::getByLabel: An attempt was made to read a "
82  << principalType
83  << " product before end"
84  << principalType
85  << "() was called.\n"
86  << "The product is of type '"
87  << productType
88  << "'.\nThe specified ModuleLabel was '"
89  << moduleLabel
90  << "'.\nThe specified productInstanceName was '"
91  << productInstanceName
92  << "'.\n";
93  }
94 
95  void
97  char const* principalType,
98  TypeID const& productType) {
99  //throw Exception(errors::LogicError)
100  LogWarning("LogicError")
101  << "::getManyByType: An attempt was made to read a "
102  << principalType
103  << " product before end"
104  << principalType
105  << "() was called.\n"
106  << "The product is of type '"
107  << productType
108  << "'.\n";
109  }
110 
111  void
113  char const* principalType,
114  TypeID const& productType,
115  EDGetToken token) {
117  << "::getByToken: An attempt was made to read a "
118  << principalType
119  << " product before end"
120  << principalType
121  << "() was called.\n"
122  << "The index of the token was "<<token.index()<<".\n";
123  }
124 
125  size_t
127  return consumer_->itemsToGetFrom(InEvent).size();
128  }
129 
130  void
132  consumer_->labelsForToken(iToken,oLabels);
133  }
134 
137  TypeID const& productType,
138  EDGetToken token) const {
140  consumer_->labelsForToken(token,labels);
141  //no need to copy memory since the exception will no occur after the
142  // const char* have been deleted
143  return BasicHandle(makeHandleExceptionFactory([labels,kindOfType,productType]()->std::shared_ptr<cms::Exception> {
144  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
145  if (kindOfType == PRODUCT_TYPE) {
146  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: " << productType << "\n"
147  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
148  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
149  } else {
150  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container with elements of type: " << productType << "\n"
151  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
152  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
153  }
154  return exception;
155  }));
156  }
157 
158  void
160  EDGetToken token) const {
162  consumer_->labelsForToken(token,labels);
163  cms::Exception exception("AmbiguousProduct");
164  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with elements of type: " << productType << "\n"
165  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
166  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
167  << "This can only occur with get function calls using a Handle<View> argument.\n"
168  << "Try a get not using a View or change the instance name of one of the products";
169  throw exception;
170  }
171 
172  BranchType const&
174  return principal_.branchType();
175  }
176 
179  InputTag const& tag,
180  ModuleCallingContext const* mcc) const {
181  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
182  }
183 
186  std::string const& label,
187  std::string const& instance,
188  std::string const& process,
189  ModuleCallingContext const* mcc) const {
190  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process, consumer_, resourcesAcquirer_, mcc);
191  }
192 
195  ModuleCallingContext const* mcc) const {
198  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
199  if( unlikely(index == ProductResolverIndexInvalid)) {
200  return makeFailToGetException(kindOfType,id,token);
201  } else if( unlikely(index == ProductResolverIndexAmbiguous)) {
202  // This deals with ambiguities where the process is specified
203  throwAmbiguousException(id, token);
204  }
205  bool ambiguous = false;
206  BasicHandle h = principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, resourcesAcquirer_, mcc);
207  if (ambiguous) {
208  // This deals with ambiguities where the process is not specified
209  throwAmbiguousException(id, token);
210  } else if(!h.isValid()) {
211  return makeFailToGetException(kindOfType,id,token);
212  }
213  return h;
214  }
215 
218  InputTag const& tag,
219  ModuleCallingContext const* mcc) const {
220  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
221  }
222 
225  std::string const& label,
226  std::string const& instance,
227  std::string const& process,
228  ModuleCallingContext const* mcc) const {
230  typeID,
231  label,
232  instance,
233  process,
234  consumer_,
236  mcc);
237  return h;
238  }
239 
240  void
243  ModuleCallingContext const* mcc) const {
245  }
246 
247  ProcessHistory const&
249  return principal_.processHistory();
250  }
251 
252  void
254  std::string const& productInstanceName) const {
255  std::ostringstream str;
256  for(auto branchDescription: principal_.productRegistry().allBranchDescriptions()) {
257  if (branchDescription->moduleLabel() == md_.moduleLabel() and branchDescription->processName() == md_.processName()) {
258  str << *branchDescription<< "-----\n";
259  }
260  }
262  << "Illegal attempt to 'put' an unregistered product.\n"
263  << "No product is registered for\n"
264  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
265  << " module label: '" << md_.moduleLabel() << "'\n"
266  << " product instance name: '" << productInstanceName << "'\n"
267  << " process name: '" << md_.processName() << "'\n"
268 
269  << "The following data products are registered for production by "<<md_.moduleLabel()<<":\n"
270  << str.str()
271  << '\n'
272  << "To correct the problem:\n"
273  " 1) make sure the proper 'produce' call is being made in the module's constructor,\n"
274  " 2) if 'produce' exists and uses a product instance name make sure that same name is used during the 'put' call.";
275  }
276 
277  BranchDescription const&
279  std::string const& productInstanceName) const {
280  ProductResolverIndexHelper const& productResolverIndexHelper = principal_.productLookup();
281  ProductResolverIndex index = productResolverIndexHelper.index(PRODUCT_TYPE, type, md_.moduleLabel().c_str(),productInstanceName.c_str(), md_.processName().c_str());
282  if(unlikely(index == ProductResolverIndexInvalid)) {
283  throwUnregisteredPutException(type, productInstanceName);
284  }
286  assert(phb != nullptr);
287  return phb->branchDescription();
288  }
289 
290  BranchDescription const&
291  PrincipalGetAdapter::getBranchDescription(unsigned int iPutTokenIndex) const {
292  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
294  assert(phb != nullptr);
295  return phb->branchDescription();
296  }
297 
298  ProductID const&
299  PrincipalGetAdapter::getProductID(unsigned int iPutTokenIndex) const {
300  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
302  assert(phb != nullptr);
303  auto prov = phb->stableProvenance();
304  assert(prov != nullptr);
305  return prov->productID();
306  }
307 
308  Transition
310  if(likely(principal().branchType() == InEvent)) {
311  return Transition::Event;
312  }
313  if(principal().branchType() == InRun) {
314  if(isComplete()) {
315  return Transition::EndRun;
316  } else {
317  return Transition::BeginRun;
318  }
319  }
320  if(isComplete()) {
322  }
324  //Must be lumi
325  }
326 
328  PrincipalGetAdapter::getPutTokenIndex(TypeID const& type, std::string const& productInstanceName) const {
329  auto tran = transition();
330  size_t index = 0;
331  for(auto const& tl : prodBase_->typeLabelList()) {
332  if((tran == tl.transition_) and (type == tl.typeID_)
333  and (productInstanceName == tl.productInstanceName_)) {
334  return index;
335  }
336  ++index;
337  }
338  throwUnregisteredPutException(type, productInstanceName);
340  }
341 
342 
343  std::string const&
345  return prodBase_->typeLabelList()[iToken.index()].productInstanceName_;
346  }
347 
348  TypeID const&
350  return prodBase_->typeLabelList()[index].typeID_;
351  }
352 
353 
354  std::vector<edm::ProductResolverIndex> const&
357  }
358 
359  std::vector<bool> const&
362  }
363 
364 
365  EDProductGetter const*
367  return principal_.prodGetter();
368  }
369 }
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:149
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
size_t numberOfProductsConsumed() const
unsigned int ProductResolverIndex
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
TypeID const & getTypeIDForPutTokenIndex(EDPutToken::value_type index) const
EDConsumerBase const * consumer_
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
Definition: ProducerBase.h:91
#define nullptr
ProducerBase const * prodBase_
std::string const & moduleLabel() const
ProcessHistory const & processHistory() const
Definition: Principal.h:139
value_type index() const
Definition: EDPutToken.h:47
BranchType
Definition: BranchType.h:11
StableProvenance const * stableProvenance() const
char const * process
Definition: ProductLabels.h:7
#define unlikely(x)
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
#define likely(x)
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:520
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:176
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
unsigned int value_type
Definition: EDPutToken.h:39
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:151
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
bool isValid() const
Definition: BasicHandle.h:82
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:513
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:557
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
EDProductGetter const * prodGetter() const
Definition: Principal.h:91
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
unsigned int index() const
Definition: EDGetToken.h:46
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:591
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
std::vector< BasicHandle > BasicHandleVec
std::string friendlyClassName() const
Definition: TypeID.cc:67