test
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  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 auto_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 {
166  ProductHolderIndexAndSkipBit indexAndBit = consumer_->indexFrom(token,branchType(),id);
168  bool skipCurrentProcess = indexAndBit.skipCurrentProcess();
169  if( unlikely(index == ProductHolderIndexInvalid)) {
170  return makeFailToGetException(kindOfType,id,token);
171  } else if( unlikely(index == ProductHolderIndexAmbiguous)) {
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  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  << " product friendly class name: '" << type.friendlyClassName() << "'\n"
232  << " module label: '" << md_.moduleLabel() << "'\n"
233  << " product instance name: '" << productInstanceName << "'\n"
234  << " process name: '" << md_.processName() << "'\n"
235 
236  << "The ProductRegistry contains:\n"
238  << '\n';
239  }
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
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:154
BasicHandle getMatchingSequenceByLabel_(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
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:210
ProductHolderIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=0) const
assert(m_qm.get())
PrincipalGetAdapter(Principal const &pcpl, ModuleDescription const &md)
ProductHolderIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
EDConsumerBase const * consumer_
unsigned int ProductHolderIndex
#define nullptr
std::string const & moduleLabel() const
ProcessHistory const & processHistory() const
Definition: Principal.h:144
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:476
BranchType const & branchType() const
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductHolderIndex index, bool skipCurrentProcess, bool &ambiguous, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:512
EDProductGetter const * prodGetter() const
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:93
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:469
BranchType const & branchType() const
Definition: Principal.h:179
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
tuple results
Definition: mps_update.py:44
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)
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:96
ProductHolderIndex productHolderIndex() const
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:545
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
std::vector< BasicHandle > BasicHandleVec
ProductHolderIndexHelper const & productLookup() const
Definition: Principal.h:156
std::string friendlyClassName() const
Definition: TypeID.cc:67