CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  {
27  }
28 
30  }
31 
32  void
34  char const* principalType,
35  TypeID const& productType,
36  std::string const& productInstanceName) {
38  << principalType
39  << "::put: A null auto_ptr was passed to 'put'.\n"
40  << "The pointer is of type "
41  << productType
42  << ".\nThe specified productInstanceName was '"
43  << productInstanceName
44  << "'.\n";
45  }
46 
47  void
49  char const* principalType,
50  TypeID const& productType,
51  std::string const& moduleLabel,
52  std::string const& productInstanceName) {
53  //throw Exception(errors::LogicError)
54  LogWarning("LogicError")
55  << "::getByLabel: An attempt was made to read a "
56  << principalType
57  << " product before end"
58  << principalType
59  << "() was called.\n"
60  << "The product is of type '"
61  << productType
62  << "'.\nThe specified ModuleLabel was '"
63  << moduleLabel
64  << "'.\nThe specified productInstanceName was '"
65  << productInstanceName
66  << "'.\n";
67  }
68 
69  void
71  char const* principalType,
72  TypeID const& productType) {
73  //throw Exception(errors::LogicError)
74  LogWarning("LogicError")
75  << "::getManyByType: An attempt was made to read a "
76  << principalType
77  << " product before end"
78  << principalType
79  << "() was called.\n"
80  << "The product is of type '"
81  << productType
82  << "'.\n";
83  }
84 
85  void
87  char const* principalType,
88  TypeID const& productType,
89  EDGetToken token) {
91  << "::getByToken: An attempt was made to read a "
92  << principalType
93  << " product before end"
94  << principalType
95  << "() was called.\n"
96  << "The index of the token was "<<token.index()<<".\n";
97  }
98 
101  TypeID const& productType,
102  EDGetToken token) const {
104  consumer_->labelsForToken(token,labels);
105  //no need to copy memory since the exception will no occur after the
106  // const char* have been deleted
107  return BasicHandle(makeHandleExceptionFactory([labels,kindOfType,productType]()->std::shared_ptr<cms::Exception> {
108  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
109  if (kindOfType == PRODUCT_TYPE) {
110  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: " << productType << "\n"
111  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
112  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
113  } else {
114  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container with elements of type: " << productType << "\n"
115  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
116  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
117  }
118  return exception;
119  }));
120  }
121 
122  void
124  EDGetToken token) const {
126  consumer_->labelsForToken(token,labels);
127  cms::Exception exception("AmbiguousProduct");
128  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with elements of type: " << productType << "\n"
129  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
130  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
131  << "This can only occur with get function calls using a Handle<View> argument.\n"
132  << "Try a get not using a View or change the instance name of one of the products";
133  throw exception;
134  }
135 
136  BranchType const&
138  return principal_.branchType();
139  }
140 
143  InputTag const& tag,
144  ModuleCallingContext const* mcc) const {
145  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag, consumer_, mcc);
146  }
147 
150  std::string const& label,
151  std::string const& instance,
152  std::string const& process,
153  ModuleCallingContext const* mcc) const {
154  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process, consumer_, mcc);
155  }
156 
159  ModuleCallingContext const* mcc) const {
160  ProductHolderIndexAndSkipBit indexAndBit = consumer_->indexFrom(token,branchType(),id);
162  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
163  if( unlikely(index == ProductHolderIndexInvalid)) {
164  return makeFailToGetException(kindOfType,id,token);
165  } else if( unlikely(index == ProductHolderIndexAmbiguous)) {
166  // This deals with ambiguities where the process is specified
167  throwAmbiguousException(id, token);
168  }
169  bool ambiguous = false;
170  BasicHandle h = principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, mcc);
171  if (ambiguous) {
172  // This deals with ambiguities where the process is not specified
173  throwAmbiguousException(id, token);
174  } else if(!h.isValid()) {
175  return makeFailToGetException(kindOfType,id,token);
176  }
177  return h;
178  }
179 
182  InputTag const& tag,
183  ModuleCallingContext const* mcc) const {
184  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag, consumer_, mcc);
185  }
186 
189  std::string const& label,
190  std::string const& instance,
191  std::string const& process,
192  ModuleCallingContext const* mcc) const {
194  typeID,
195  label,
196  instance,
197  process,
198  consumer_,
199  mcc);
200  return h;
201  }
202 
203  void
206  ModuleCallingContext const* mcc) const {
207  principal_.getManyByType(tid, results, consumer_, mcc);
208  }
209 
210  ProcessHistory const&
212  return principal_.processHistory();
213  }
214 
215  BranchDescription const&
217  std::string const& productInstanceName) const {
218  ProductHolderIndexHelper const& productHolderIndexHelper = principal_.productLookup();
219  ProductHolderIndex index = productHolderIndexHelper.index(PRODUCT_TYPE, type, md_.moduleLabel().c_str(),productInstanceName.c_str(), md_.processName().c_str());
220  if(index == ProductHolderIndexInvalid) {
222  << "Illegal attempt to 'put' an unregistered product.\n"
223  << "No product is registered for\n"
224  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
225  << " module label: '" << md_.moduleLabel() << "'\n"
226  << " product instance name: '" << productInstanceName << "'\n"
227  << " process name: '" << md_.processName() << "'\n"
228 
229  << "The ProductRegistry contains:\n"
231  << '\n';
232  }
234  assert(phb != nullptr);
235  return phb->branchDescription();
236  }
237 
238  EDProductGetter const*
240  return principal_.prodGetter();
241  }
242 
243  bool
245  return principal_.isComplete();
246  }
247 }
ProcessHistory const & processHistory() const
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:147
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag, ModuleCallingContext const *mcc) const
std::string const & processName() const
PrincipalGetAdapter(Principal &pcpl, ModuleDescription const &md)
static PFTauRenderPlugin instance
bool isComplete() const
Definition: Principal.h:193
ProductHolderIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=0) const
assert(m_qm.get())
ProductHolderIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
EDConsumerBase const * consumer_
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, ModuleCallingContext const *mcc) const
Definition: Principal.cc:521
unsigned int ProductHolderIndex
#define nullptr
std::string const & moduleLabel() const
ProcessHistory const & processHistory() const
Definition: Principal.h:137
BranchType
Definition: BranchType.h:11
#define unlikely(x)
BranchType const & branchType() const
EDProductGetter const * prodGetter() const
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductHolderIndex index, bool skipCurrentProcess, bool &ambiguous, ModuleCallingContext const *mcc) const
Definition: Principal.cc:489
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:90
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:448
BranchType const & branchType() const
Definition: Principal.h:165
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
bool isValid() const
Definition: BasicHandle.h:90
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, ModuleCallingContext const *mcc) const
Definition: Principal.cc:455
ModuleDescription const & md_
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
tuple process
Definition: LaserDQM_cfg.py:3
EDProductGetter const * prodGetter() const
Definition: Principal.h:93
ProductHolderIndex productHolderIndex() const
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
unsigned int index() const
Definition: EDGetToken.h:46
std::vector< BasicHandle > BasicHandleVec
ProductHolderIndexHelper const & productLookup() const
Definition: Principal.h:149
std::string friendlyClassName() const
Definition: TypeID.cc:67