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