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 
33  void
34  principal_get_adapter_detail::deleter::operator()(std::pair<WrapperOwningHolder, BranchDescription const*> const p) const {
35  WrapperOwningHolder* edp = const_cast<WrapperOwningHolder*>(&p.first);
36  edp->reset();
37  }
38 
39  void
41  char const* principalType,
42  TypeID const& productType,
43  std::string const& productInstanceName) {
45  << principalType
46  << "::put: A null auto_ptr was passed to 'put'.\n"
47  << "The pointer is of type "
48  << productType
49  << ".\nThe specified productInstanceName was '"
50  << productInstanceName
51  << "'.\n";
52  }
53 
54  void
56  char const* principalType,
57  TypeID const& productType,
58  std::string const& moduleLabel,
59  std::string const& productInstanceName) {
60  //throw Exception(errors::LogicError)
61  LogWarning("LogicError")
62  << "::getByLabel: An attempt was made to read a "
63  << principalType
64  << " product before end"
65  << principalType
66  << "() was called.\n"
67  << "The product is of type '"
68  << productType
69  << "'.\nThe specified ModuleLabel was '"
70  << moduleLabel
71  << "'.\nThe specified productInstanceName was '"
72  << productInstanceName
73  << "'.\n";
74  }
75 
76  void
78  char const* principalType,
79  TypeID const& productType) {
80  //throw Exception(errors::LogicError)
81  LogWarning("LogicError")
82  << "::getManyByType: 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  << "'.\n";
90  }
91 
92  void
94  char const* principalType,
95  TypeID const& productType,
96  EDGetToken token) {
98  << "::getByToken: An attempt was made to read a "
99  << principalType
100  << " product before end"
101  << principalType
102  << "() was called.\n"
103  << "The index of the token was "<<token.index()<<".\n";
104  }
105 
108  TypeID const& productType,
109  EDGetToken token) const {
111  consumer_->labelsForToken(token,labels);
112  //no need to copy memory since the exception will no occur after the
113  // const char* have been deleted
114  return BasicHandle(makeHandleExceptionFactory([labels,kindOfType,productType]()->std::shared_ptr<cms::Exception> {
115  std::shared_ptr<cms::Exception> exception(std::make_shared<Exception>(errors::ProductNotFound));
116  if (kindOfType == PRODUCT_TYPE) {
117  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: " << productType << "\n"
118  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
119  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
120  } else {
121  *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container with elements of type: " << productType << "\n"
122  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
123  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
124  }
125  return exception;
126  }));
127  }
128 
129  void
131  EDGetToken token) const {
133  consumer_->labelsForToken(token,labels);
134  cms::Exception exception("AmbiguousProduct");
135  exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with elements of type: " << productType << "\n"
136  << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
137  << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
138  << "This can only occur with get function calls using a Handle<View> argument.\n"
139  << "Try a get not using a View or change the instance name of one of the products";
140  throw exception;
141  }
142 
143  BranchType const&
145  return principal_.branchType();
146  }
147 
150  InputTag const& tag,
151  ModuleCallingContext const* mcc) const {
152  return principal_.getByLabel(PRODUCT_TYPE, typeID, tag, consumer_, mcc);
153  }
154 
157  std::string const& label,
158  std::string const& instance,
159  std::string const& process,
160  ModuleCallingContext const* mcc) const {
161  return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process, consumer_, mcc);
162  }
163 
166  ModuleCallingContext const* mcc) const {
167  ProductHolderIndexAndSkipBit indexAndBit = consumer_->indexFrom(token,branchType(),id);
169  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
170  if( unlikely(index == ProductHolderIndexInvalid)) {
171  return makeFailToGetException(kindOfType,id,token);
172  } else if( unlikely(index == ProductHolderIndexAmbiguous)) {
173  // This deals with ambiguities where the process is specified
174  throwAmbiguousException(id, token);
175  }
176  bool ambiguous = false;
177  BasicHandle h = principal_.getByToken(kindOfType, id, index, skipCurrentProcess, ambiguous, mcc);
178  if (ambiguous) {
179  // This deals with ambiguities where the process is not specified
180  throwAmbiguousException(id, token);
181  } else if(!h.isValid()) {
182  return makeFailToGetException(kindOfType,id,token);
183  }
184  return h;
185  }
186 
189  InputTag const& tag,
190  ModuleCallingContext const* mcc) const {
191  return principal_.getByLabel(ELEMENT_TYPE, typeID, tag, consumer_, mcc);
192  }
193 
196  std::string const& label,
197  std::string const& instance,
198  std::string const& process,
199  ModuleCallingContext const* mcc) const {
200  auto h= principal_.getByLabel(ELEMENT_TYPE,
201  typeID,
202  label,
203  instance,
204  process,
205  consumer_,
206  mcc);
207  return h;
208  }
209 
210  void
213  ModuleCallingContext const* mcc) const {
214  principal_.getManyByType(tid, results, consumer_, mcc);
215  }
216 
217  ProcessHistory const&
219  return principal_.processHistory();
220  }
221 
222  BranchDescription const&
224  std::string const& productInstanceName) const {
225  ProductHolderIndexHelper const& productHolderIndexHelper = principal_.productLookup();
226  ProductHolderIndex index = productHolderIndexHelper.index(PRODUCT_TYPE, type, md_.moduleLabel().c_str(),productInstanceName.c_str(), md_.processName().c_str());
227  if(index == ProductHolderIndexInvalid) {
229  << "Illegal attempt to 'put' an unregistered product.\n"
230  << "No product is registered for\n"
231  << " process name: '" << md_.processName() << "'\n"
232  << " module label: '" << md_.moduleLabel() << "'\n"
233  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
234  << " product instance name: '" << productInstanceName << "'\n"
235 
236  << "The ProductRegistry contains:\n"
237  << principal_.productRegistry()
238  << '\n';
239  }
240  ProductHolderBase const* phb = principal_.getProductHolderByIndex(index);
241  assert(phb != nullptr);
242  return phb->branchDescription();
243  }
244 
245  EDProductGetter const*
247  return principal_.prodGetter();
248  }
249 
250  bool
252  return principal_.isComplete();
253  }
254 }
ProcessHistory const & processHistory() const
BasicHandle getByToken_(TypeID const &id, KindOfType kindOfType, EDGetToken token, ModuleCallingContext const *mcc) const
type
Definition: HCALResponse.h:21
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
BasicHandle getByLabel_(TypeID const &tid, InputTag const &tag, ModuleCallingContext const *mcc) const
PrincipalGetAdapter(Principal &pcpl, ModuleDescription const &md)
static PFTauRenderPlugin instance
ProductHolderIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=0) const
#define nullptr
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:90
#define unlikely(x)
Definition: Likely.h:21
BranchType const & branchType() const
EDProductGetter const * prodGetter() const
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:95
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
BranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void getManyByType_(TypeID const &tid, BasicHandleVec &results, ModuleCallingContext const *mcc) const
BasicHandle makeFailToGetException(KindOfType, TypeID const &, EDGetToken) const
bool isValid() const
Definition: BasicHandle.h:98
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
void operator()(std::pair< WrapperOwningHolder, BranchDescription const * > const p) const
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
tuple process
Definition: LaserDQM_cfg.py:3
ProductHolderIndex productHolderIndex() const
void throwAmbiguousException(TypeID const &productType, EDGetToken token) const
unsigned int index() const
Definition: EDGetToken.h:46
std::vector< BasicHandle > BasicHandleVec
std::string friendlyClassName() const
Definition: TypeID.cc:60