CMS 3D CMS Logo

PrincipalGetAdapter.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <algorithm>
5 
15 
17 
18 namespace edm {
19 
21  ModuleDescription const& md) :
22  //putProducts_(),
23  principal_(pcpl),
24  md_(md),
25  consumer_(nullptr),
26  resourcesAcquirer_(nullptr)
27  {
28  }
29 
31  }
32 
33  void
35  char const* principalType,
36  TypeID const& productType,
37  std::string const& productInstanceName) {
39  << principalType
40  << "::put: A null unique_ptr was passed to 'put'.\n"
41  << "The pointer is of type "
42  << productType
43  << ".\nThe specified productInstanceName was '"
44  << productInstanceName
45  << "'.\n";
46  }
47 
48  void
50  char const* principalType,
51  TypeID const& productType,
52  std::string const& moduleLabel,
53  std::string const& productInstanceName) {
54  //throw Exception(errors::LogicError)
55  LogWarning("LogicError")
56  << "::getByLabel: An attempt was made to read a "
57  << principalType
58  << " product before end"
59  << principalType
60  << "() was called.\n"
61  << "The product is of type '"
62  << productType
63  << "'.\nThe specified ModuleLabel was '"
64  << moduleLabel
65  << "'.\nThe specified productInstanceName was '"
66  << productInstanceName
67  << "'.\n";
68  }
69 
70  void
72  char const* principalType,
73  TypeID const& productType) {
74  //throw Exception(errors::LogicError)
75  LogWarning("LogicError")
76  << "::getManyByType: An attempt was made to read a "
77  << principalType
78  << " product before end"
79  << principalType
80  << "() was called.\n"
81  << "The product is of type '"
82  << productType
83  << "'.\n";
84  }
85 
86  void
88  char const* principalType,
89  TypeID const& productType,
90  EDGetToken token) {
92  << "::getByToken: An attempt was made to read a "
93  << principalType
94  << " product before end"
95  << principalType
96  << "() was called.\n"
97  << "The index of the token was "<<token.index()<<".\n";
98  }
99 
100  void
102  consumer_->labelsForToken(iToken,oLabels);
103  }
104 
107  TypeID const& productType,
108  EDGetToken token) const {
110  consumer_->labelsForToken(token,labels);
111  //no need to copy memory since the exception will no occur after the
112  // const char* have been deleted
113  return BasicHandle(makeHandleExceptionFactory([labels,kindOfType,productType]()->std::shared_ptr<cms::Exception> {
114  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
115  if (kindOfType == PRODUCT_TYPE) {
116  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: " << productType << "\n"
117  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
118  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
119  } else {
120  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container with elements of type: " << productType << "\n"
121  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
122  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
123  }
124  return exception;
125  }));
126  }
127 
128  void
130  EDGetToken token) const {
132  consumer_->labelsForToken(token,labels);
133  cms::Exception exception("AmbiguousProduct");
134  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with elements of type: " << productType << "\n"
135  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
136  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
137  << "This can only occur with get function calls using a Handle<View> argument.\n"
138  << "Try a get not using a View or change the instance name of one of the products";
139  throw exception;
140  }
141 
142  BranchType const&
144  return principal_.branchType();
145  }
146 
149  InputTag const& tag,
150  ModuleCallingContext const* mcc) const {
151  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
152  }
153 
156  std::string const& label,
157  std::string const& instance,
158  std::string const& process,
159  ModuleCallingContext const* mcc) const {
160  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process, consumer_, resourcesAcquirer_, mcc);
161  }
162 
165  ModuleCallingContext const* mcc) const {
168  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
169  if( unlikely(index == ProductResolverIndexInvalid)) {
170  return makeFailToGetException(kindOfType,id,token);
171  } else if( unlikely(index == ProductResolverIndexAmbiguous)) {
172  // This deals with ambiguities where the process is specified
173  throwAmbiguousException(id, token);
174  }
175  bool ambiguous = false;
176  BasicHandle h = principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, resourcesAcquirer_, mcc);
177  if (ambiguous) {
178  // This deals with ambiguities where the process is not specified
179  throwAmbiguousException(id, token);
180  } else if(!h.isValid()) {
181  return makeFailToGetException(kindOfType,id,token);
182  }
183  return h;
184  }
185 
188  InputTag const& tag,
189  ModuleCallingContext const* mcc) const {
190  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag, consumer_, resourcesAcquirer_, mcc);
191  }
192 
195  std::string const& label,
196  std::string const& instance,
197  std::string const& process,
198  ModuleCallingContext const* mcc) const {
200  typeID,
201  label,
202  instance,
203  process,
204  consumer_,
206  mcc);
207  return h;
208  }
209 
210  void
213  ModuleCallingContext const* mcc) const {
215  }
216 
217  ProcessHistory const&
219  return principal_.processHistory();
220  }
221 
222  BranchDescription const&
224  std::string const& productInstanceName) const {
225  ProductResolverIndexHelper const& productResolverIndexHelper = principal_.productLookup();
226  ProductResolverIndex index = productResolverIndexHelper.index(PRODUCT_TYPE, type, md_.moduleLabel().c_str(),productInstanceName.c_str(), md_.processName().c_str());
227  if(index == ProductResolverIndexInvalid) {
228  std::ostringstream str;
229  for(auto branchDescription: principal_.productRegistry().allBranchDescriptions()) {
230  if (branchDescription->moduleLabel() == md_.moduleLabel() and branchDescription->processName() == md_.processName()) {
231  str << *branchDescription<< "-----\n";
232  }
233  }
235  << "Illegal attempt to 'put' an unregistered product.\n"
236  << "No product is registered for\n"
237  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
238  << " module label: '" << md_.moduleLabel() << "'\n"
239  << " product instance name: '" << productInstanceName << "'\n"
240  << " process name: '" << md_.processName() << "'\n"
241 
242  << "The following data products are registered for production by "<<md_.moduleLabel()<<":\n"
243  << str.str()
244  << '\n'
245  << "To correct the problem:\n"
246  " 1) make sure the proper 'produce' call is being made in the module's constructor,\n"
247  " 2) if 'produce' exists and uses a product instance name make sure that same name is used during the 'put' call.";
248  }
250  assert(phb != nullptr);
251  return phb->branchDescription();
252  }
253 
254  EDProductGetter const*
256  return principal_.prodGetter();
257  }
258 
259  bool
261  return principal_.isComplete();
262  }
263 }
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:145
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
unsigned int ProductResolverIndex
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag, ModuleCallingContext const *mcc) const
std::string const & processName() const
static PFTauRenderPlugin instance
bool isComplete() const
Definition: Principal.h:194
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md)
EDConsumerBase const * consumer_
#define nullptr
std::string const & moduleLabel() const
ProcessHistory const & processHistory() const
Definition: Principal.h:135
BranchType
Definition: BranchType.h:11
char const * process
Definition: ProductLabels.h:7
#define unlikely(x)
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:449
BranchType const & branchType() const
EDProductGetter const * prodGetter() const
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
BranchType const & branchType() const
Definition: Principal.h:172
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
std::vector< BranchDescription const * > allBranchDescriptions() const
char const * module
Definition: ProductLabels.h:5
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
ProductResolverIndex productResolverIndex() const
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:147
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
char const * productInstance
Definition: ProductLabels.h:6
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=0) const
HLT enums.
BranchDescription const & branchDescription() const
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:442
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:485
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
EDProductGetter const * prodGetter() const
Definition: Principal.h:88
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
unsigned int index() const
Definition: EDGetToken.h:46
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:518
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
std::vector< BasicHandle > BasicHandleVec
std::string friendlyClassName() const
Definition: TypeID.cc:67