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 
14 
16 
17 namespace edm {
18 
20  ModuleDescription const& md) :
21  //putProducts_(),
22  principal_(pcpl),
23  md_(md) {
24  }
25 
27  }
28 
29 
30  void
31  principal_get_adapter_detail::deleter::operator()(std::pair<WrapperOwningHolder, ConstBranchDescription const*> const p) const {
32  WrapperOwningHolder* edp = const_cast<WrapperOwningHolder*>(&p.first);
33  edp->reset();
34  }
35 
36  void
38  char const* principalType,
39  TypeID const& productType,
40  std::string const& productInstanceName) {
42  << principalType
43  << "::put: A null auto_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
53  char const* principalType,
54  TypeID const& productType,
55  std::string const& moduleLabel,
56  std::string const& productInstanceName) {
57  //throw Exception(errors::LogicError)
58  LogWarning("LogicError")
59  << "::getByLabel: An attempt was made to read a "
60  << principalType
61  << " product before end"
62  << principalType
63  << "() was called.\n"
64  << "The product is of type '"
65  << productType
66  << "'.\nThe specified ModuleLabel was '"
67  << moduleLabel
68  << "'.\nThe specified productInstanceName was '"
69  << productInstanceName
70  << "'.\n";
71  }
72 
73  void
75  char const* principalType,
76  TypeID const& productType) {
77  //throw Exception(errors::LogicError)
78  LogWarning("LogicError")
79  << "::getManyByType: An attempt was made to read a "
80  << principalType
81  << " product before end"
82  << principalType
83  << "() was called.\n"
84  << "The product is of type '"
85  << productType
86  << "'.\n";
87  }
88 
89  void
91  char const* principalType,
92  TypeID const& productType,
93  EDGetToken token) {
95  << "::getByToken: An attempt was made to read a "
96  << principalType
97  << " product before end"
98  << principalType
99  << "() was called.\n"
100  << "The index of the token was "<<token.index()<<".\n";
101  }
102 
105  TypeID const& productType,
106  EDGetToken token) const {
108  consumer_->labelsForToken(token,labels);
109  boost::shared_ptr<cms::Exception> exception(new Exception(errors::ProductNotFound));
110  if (kindOfType == PRODUCT_TYPE) {
111  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: " << productType << "\n"
112  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
113  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
114  } else {
115  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container with elements of 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  }
119  return BasicHandle(exception);
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) const {
144  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag);
145  }
146 
149  std::string const& label,
150  std::string const& instance,
151  std::string const& process) const {
152  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process);
153  }
154 
156  PrincipalGetAdapter::getByToken_(TypeID const& id, KindOfType kindOfType, EDGetToken token) const {
157  ProductHolderIndex index = consumer_->indexFrom(token,InEvent,id);
158  if( unlikely(index == ProductHolderIndexInvalid)) {
159  return makeFailToGetException(kindOfType,id,token);
160  } else if( unlikely(index == ProductHolderIndexAmbiguous)) {
161  // This deals with ambiguities where the process is specified
162  throwAmbiguousException(id, token);
163  }
164  bool ambiguous = false;
165  BasicHandle h = principal_.getByToken(kindOfType,id,index, token.willSkipCurrentProcess(), ambiguous);
166  if (ambiguous) {
167  // This deals with ambiguities where the process is not specified
168  throwAmbiguousException(id, token);
169  } else if(!h.isValid()) {
170  return makeFailToGetException(kindOfType,id,token);
171  }
172  return h;
173  }
174 
177  InputTag const& tag) const {
178  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag);
179  }
180 
183  std::string const& label,
184  std::string const& instance,
185  std::string const& process) const {
186  return principal_.getByLabel(ELEMENT_TYPE,
187  typeID,
188  label,
189  instance,
190  process);
191  }
192 
193  void
195  BasicHandleVec& results) const {
196  principal_.getManyByType(tid, results);
197  }
198 
199  ProcessHistory const&
201  return principal_.processHistory();
202  }
203 
206  std::string const& productInstanceName) const {
207  ProductHolderIndexHelper const& productHolderIndexHelper = principal_.productLookup();
208  ProductHolderIndex index = productHolderIndexHelper.index(PRODUCT_TYPE, type, md_.moduleLabel().c_str(),productInstanceName.c_str(), md_.processName().c_str());
209  if(index == ProductHolderIndexInvalid) {
211  << "Illegal attempt to 'put' an unregistered product.\n"
212  << "No product is registered for\n"
213  << " process name: '" << md_.processName() << "'\n"
214  << " module label: '" << md_.moduleLabel() << "'\n"
215  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
216  << " product instance name: '" << productInstanceName << "'\n"
217 
218  << "The ProductRegistry contains:\n"
219  << principal_.productRegistry()
220  << '\n';
221  }
222  ProductHolderBase const* phb = principal_.getProductByIndex(index, false, false);
223  assert(phb != nullptr);
224  return phb->branchDescription();
225  }
226 
227  EDProductGetter const*
229  return principal_.prodGetter();
230  }
231 
232  bool
234  return principal_.isComplete();
235  }
236 }
ProcessHistory const & processHistory() const
type
Definition: HCALResponse.h:21
void getManyByType_(TypeID const &tid, BasicHandleVec &results) const
PrincipalGetAdapter(Principal &pcpl, ModuleDescription const &md)
static PFTauRenderPlugin instance
ConstBranchDescription const & branchDescription() const
Definition: ProductHolder.h:93
ProductHolderIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=0) const
unsigned int ProductHolderIndex
BranchType
Definition: BranchType.h:11
static void throwAmbiguousException(const char *where, TypeID const &productType, std::string const &label, std::string const &instance, std::string const &process)
Definition: Principal.cc:84
#define unlikely(x)
Definition: Likely.h:21
BranchType const & branchType() const
EDProductGetter const * prodGetter() const
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag) const
void operator()(std::pair< WrapperOwningHolder, ConstBranchDescription const * > const p) const
bool willSkipCurrentProcess() const
Definition: EDGetToken.h:48
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
bool isValid() const
Definition: BasicHandle.h:90
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag) const
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
ConstBranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
tuple process
Definition: LaserDQM_cfg.py:3
BasicHandle getByToken_(TypeID const &id, KindOfType kindOfType, EDGetToken token) const
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
unsigned int index() const
Definition: EDGetToken.h:47
std::vector< BasicHandle > BasicHandleVec
std::string friendlyClassName() const
Definition: TypeID.cc:63