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 
99  void
101  consumer_->labelsForToken(iToken,oLabels);
102  }
103 
106  TypeID const& productType,
107  EDGetToken token) const {
109  consumer_->labelsForToken(token,labels);
110  //no need to copy memory since the exception will no occur after the
111  // const char* have been deleted
112  return BasicHandle(makeHandleExceptionFactory([labels,kindOfType,productType]()->std::shared_ptr<cms::Exception> {
113  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
114  if (kindOfType == PRODUCT_TYPE) {
115  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: " << productType << "\n"
116  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
117  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
118  } else {
119  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container with elements of type: " << productType << "\n"
120  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
121  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
122  }
123  return exception;
124  }));
125  }
126 
127  void
129  EDGetToken token) const {
131  consumer_->labelsForToken(token,labels);
132  cms::Exception exception("AmbiguousProduct");
133  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with elements of type: " << productType << "\n"
134  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
135  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
136  << "This can only occur with get function calls using a Handle<View> argument.\n"
137  << "Try a get not using a View or change the instance name of one of the products";
138  throw exception;
139  }
140 
141  BranchType const&
143  return principal_.branchType();
144  }
145 
148  InputTag const& tag,
149  ModuleCallingContext const* mcc) const {
150  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag, consumer_, mcc);
151  }
152 
155  std::string const& label,
156  std::string const& instance,
157  std::string const& process,
158  ModuleCallingContext const* mcc) const {
159  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process, consumer_, mcc);
160  }
161 
164  ModuleCallingContext const* mcc) const {
165  ProductHolderIndexAndSkipBit indexAndBit = consumer_->indexFrom(token,branchType(),id);
167  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
168  if( unlikely(index == ProductHolderIndexInvalid)) {
169  return makeFailToGetException(kindOfType,id,token);
170  } else if( unlikely(index == ProductHolderIndexAmbiguous)) {
171  // This deals with ambiguities where the process is specified
172  throwAmbiguousException(id, token);
173  }
174  bool ambiguous = false;
175  BasicHandle h = principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, mcc);
176  if (ambiguous) {
177  // This deals with ambiguities where the process is not specified
178  throwAmbiguousException(id, token);
179  } else if(!h.isValid()) {
180  return makeFailToGetException(kindOfType,id,token);
181  }
182  return h;
183  }
184 
187  InputTag const& tag,
188  ModuleCallingContext const* mcc) const {
189  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag, consumer_, mcc);
190  }
191 
194  std::string const& label,
195  std::string const& instance,
196  std::string const& process,
197  ModuleCallingContext const* mcc) const {
199  typeID,
200  label,
201  instance,
202  process,
203  consumer_,
204  mcc);
205  return h;
206  }
207 
208  void
211  ModuleCallingContext const* mcc) const {
212  principal_.getManyByType(tid, results, consumer_, mcc);
213  }
214 
215  ProcessHistory const&
217  return principal_.processHistory();
218  }
219 
220  BranchDescription const&
222  std::string const& productInstanceName) const {
223  ProductHolderIndexHelper const& productHolderIndexHelper = principal_.productLookup();
224  ProductHolderIndex index = productHolderIndexHelper.index(PRODUCT_TYPE, type, md_.moduleLabel().c_str(),productInstanceName.c_str(), md_.processName().c_str());
225  if(index == ProductHolderIndexInvalid) {
227  << "Illegal attempt to 'put' an unregistered product.\n"
228  << "No product is registered for\n"
229  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
230  << " module label: '" << md_.moduleLabel() << "'\n"
231  << " product instance name: '" << productInstanceName << "'\n"
232  << " process name: '" << md_.processName() << "'\n"
233 
234  << "The ProductRegistry contains:\n"
236  << '\n';
237  }
239  assert(phb != nullptr);
240  return phb->branchDescription();
241  }
242 
243  EDProductGetter const*
245  return principal_.prodGetter();
246  }
247 
248  bool
250  return principal_.isComplete();
251  }
252 }
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:531
unsigned int ProductHolderIndex
#define nullptr
std::string const & moduleLabel() const
ProcessHistory const & processHistory() const
Definition: Principal.h:137
BranchType
Definition: BranchType.h:11
char const * process
Definition: ProductLabels.h:7
#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:499
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:90
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:458
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
char const * module
Definition: ProductLabels.h:5
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
char const * productInstance
Definition: ProductLabels.h:6
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:465
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
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
std::vector< BasicHandle > BasicHandleVec
ProductHolderIndexHelper const & productLookup() const
Definition: Principal.h:149
std::string friendlyClassName() const
Definition: TypeID.cc:67