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) :
23  //putProducts_(),
24  principal_(pcpl),
25  md_(md),
26  consumer_(nullptr),
27  resourcesAcquirer_(nullptr)
28  {
29  }
30 
32  }
33 
34  void
36  char const* principalType,
37  TypeID const& productType,
38  std::string const& productInstanceName) {
40  << principalType
41  << "::put: A null unique_ptr was passed to 'put'.\n"
42  << "The pointer is of type "
43  << productType
44  << ".\nThe specified productInstanceName was '"
45  << productInstanceName
46  << "'.\n";
47  }
48 
49  void
50  principal_get_adapter_detail::throwOnPutOfUninitializedToken(char const* principalType, std::type_info const& type) {
51  TypeID productType{type};
53  << principalType
54  << "::put: An uninitialized EDPutToken was passed to 'put'.\n"
55  << "The pointer is of type "
56  << productType
57  << ".\n";
58  }
59 
60  void
61  principal_get_adapter_detail::throwOnPutOfWrongType(std::type_info const& wrongType, TypeID const& rightType) {
62  TypeID wrongTypeID{wrongType};
64  << "The registered type for an EDPutToken does not match the put type.\n"
65  << "The expected type "
66  << rightType
67  << "\nThe put type "
68  << wrongTypeID
69  << ".\n";
70  }
71 
72  void
74  char const* principalType,
75  TypeID const& productType,
76  std::string const& moduleLabel,
77  std::string const& productInstanceName) {
78  //throw Exception(errors::LogicError)
79  LogWarning("LogicError")
80  << "::getByLabel: An attempt was made to read a "
81  << principalType
82  << " product before end"
83  << principalType
84  << "() was called.\n"
85  << "The product is of type '"
86  << productType
87  << "'.\nThe specified ModuleLabel was '"
88  << moduleLabel
89  << "'.\nThe specified productInstanceName was '"
90  << productInstanceName
91  << "'.\n";
92  }
93 
94  void
96  char const* principalType,
97  TypeID const& productType) {
98  //throw Exception(errors::LogicError)
99  LogWarning("LogicError")
100  << "::getManyByType: An attempt was made to read a "
101  << principalType
102  << " product before end"
103  << principalType
104  << "() was called.\n"
105  << "The product is of type '"
106  << productType
107  << "'.\n";
108  }
109 
110  void
112  char const* principalType,
113  TypeID const& productType,
114  EDGetToken token) {
116  << "::getByToken: An attempt was made to read a "
117  << principalType
118  << " product before end"
119  << principalType
120  << "() was called.\n"
121  << "The index of the token was "<<token.index()<<".\n";
122  }
123 
124  size_t
126  return consumer_->itemsToGetFrom(InEvent).size();
127  }
128 
129  void
131  consumer_->labelsForToken(iToken,oLabels);
132  }
133 
136  TypeID const& productType,
137  EDGetToken token) const {
139  consumer_->labelsForToken(token,labels);
140  //no need to copy memory since the exception will no occur after the
141  // const char* have been deleted
142  return BasicHandle(makeHandleExceptionFactory([labels,kindOfType,productType]()->std::shared_ptr<cms::Exception> {
143  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
144  if (kindOfType == PRODUCT_TYPE) {
145  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: " << productType << "\n"
146  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
147  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
148  } else {
149  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container with elements of type: " << productType << "\n"
150  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
151  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
152  }
153  return exception;
154  }));
155  }
156 
157  void
159  EDGetToken token) const {
161  consumer_->labelsForToken(token,labels);
162  cms::Exception exception("AmbiguousProduct");
163  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with elements of type: " << productType << "\n"
164  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
165  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
166  << "This can only occur with get function calls using a Handle<View> argument.\n"
167  << "Try a get not using a View or change the instance name of one of the products";
168  throw exception;
169  }
170 
171  BranchType const&
173  return principal_.branchType();
174  }
175 
178  InputTag const& tag,
179  ModuleCallingContext const* mcc) const {
180  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
181  }
182 
185  std::string const& label,
186  std::string const& instance,
187  std::string const& process,
188  ModuleCallingContext const* mcc) const {
189  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process, consumer_, resourcesAcquirer_, mcc);
190  }
191 
194  ModuleCallingContext const* mcc) const {
197  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
198  if( unlikely(index == ProductResolverIndexInvalid)) {
199  return makeFailToGetException(kindOfType,id,token);
200  } else if( unlikely(index == ProductResolverIndexAmbiguous)) {
201  // This deals with ambiguities where the process is specified
202  throwAmbiguousException(id, token);
203  }
204  bool ambiguous = false;
205  BasicHandle h = principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, resourcesAcquirer_, mcc);
206  if (ambiguous) {
207  // This deals with ambiguities where the process is not specified
208  throwAmbiguousException(id, token);
209  } else if(!h.isValid()) {
210  return makeFailToGetException(kindOfType,id,token);
211  }
212  return h;
213  }
214 
217  InputTag const& tag,
218  ModuleCallingContext const* mcc) const {
219  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
220  }
221 
224  std::string const& label,
225  std::string const& instance,
226  std::string const& process,
227  ModuleCallingContext const* mcc) const {
229  typeID,
230  label,
231  instance,
232  process,
233  consumer_,
235  mcc);
236  return h;
237  }
238 
239  void
242  ModuleCallingContext const* mcc) const {
244  }
245 
246  ProcessHistory const&
248  return principal_.processHistory();
249  }
250 
251  void
253  std::string const& productInstanceName) const {
254  std::ostringstream str;
255  for(auto branchDescription: principal_.productRegistry().allBranchDescriptions()) {
256  if (branchDescription->moduleLabel() == md_.moduleLabel() and branchDescription->processName() == md_.processName()) {
257  str << *branchDescription<< "-----\n";
258  }
259  }
261  << "Illegal attempt to 'put' an unregistered product.\n"
262  << "No product is registered for\n"
263  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
264  << " module label: '" << md_.moduleLabel() << "'\n"
265  << " product instance name: '" << productInstanceName << "'\n"
266  << " process name: '" << md_.processName() << "'\n"
267 
268  << "The following data products are registered for production by "<<md_.moduleLabel()<<":\n"
269  << str.str()
270  << '\n'
271  << "To correct the problem:\n"
272  " 1) make sure the proper 'produce' call is being made in the module's constructor,\n"
273  " 2) if 'produce' exists and uses a product instance name make sure that same name is used during the 'put' call.";
274  }
275 
276  BranchDescription const&
278  std::string const& productInstanceName) const {
279  ProductResolverIndexHelper const& productResolverIndexHelper = principal_.productLookup();
280  ProductResolverIndex index = productResolverIndexHelper.index(PRODUCT_TYPE, type, md_.moduleLabel().c_str(),productInstanceName.c_str(), md_.processName().c_str());
281  if(unlikely(index == ProductResolverIndexInvalid)) {
282  throwUnregisteredPutException(type, productInstanceName);
283  }
285  assert(phb != nullptr);
286  return phb->branchDescription();
287  }
288 
289  BranchDescription const&
290  PrincipalGetAdapter::getBranchDescription(unsigned int iPutTokenIndex) const {
291  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
293  assert(phb != nullptr);
294  return phb->branchDescription();
295  }
296 
297  ProductID const&
298  PrincipalGetAdapter::getProductID(unsigned int iPutTokenIndex) const {
299  auto index = prodBase_->putTokenIndexToProductResolverIndex()[iPutTokenIndex];
301  assert(phb != nullptr);
302  auto prov = phb->stableProvenance();
303  assert(prov != nullptr);
304  return prov->productID();
305  }
306 
307  Transition
309  if(likely(principal().branchType() == InEvent)) {
310  return Transition::Event;
311  }
312  if(principal().branchType() == InRun) {
313  if(principal().atEndTransition()) {
314  return Transition::EndRun;
315  } else {
316  return Transition::BeginRun;
317  }
318  }
319  if(principal().atEndTransition()) {
321  }
323  //Must be lumi
324  }
325 
327  PrincipalGetAdapter::getPutTokenIndex(TypeID const& type, std::string const& productInstanceName) const {
328  auto tran = transition();
329  size_t index = 0;
330  for(auto const& tl : prodBase_->typeLabelList()) {
331  if((tran == tl.transition_) and (type == tl.typeID_)
332  and (productInstanceName == tl.productInstanceName_)) {
333  return index;
334  }
335  ++index;
336  }
337  throwUnregisteredPutException(type, productInstanceName);
339  }
340 
341 
342  std::string const&
344  return prodBase_->typeLabelList()[iToken.index()].productInstanceName_;
345  }
346 
347  TypeID const&
349  return prodBase_->typeLabelList()[index].typeID_;
350  }
351 
352 
353  std::vector<edm::ProductResolverIndex> const&
356  }
357 
358  std::vector<bool> const&
361  }
362 
363 
364  EDProductGetter const*
366  return principal_.prodGetter();
367  }
368 
369  bool
371  return principal_.isComplete();
372  }
373 }
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:151
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
bool isComplete() const
Definition: Principal.h:200
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md)
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:141
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:505
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:178
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
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
ProductResolverIndex productResolverIndex() const
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:153
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:498
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:542
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
EDProductGetter const * prodGetter() const
Definition: Principal.h:94
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:575
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
std::vector< BasicHandle > BasicHandleVec
std::string friendlyClassName() const
Definition: TypeID.cc:67