CMS 3D CMS Logo

GenericHandle.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_GenericHandle_h
2 #define FWCore_Framework_GenericHandle_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : GenericHandle
7 //
24 //
25 // Original Author: Chris Jones
26 // Created: Sat Jan 7 15:40:43 EST 2006
27 //
28 
29 // user include files
33 
34 // system include files
35 #include <string>
36 
37 // forward declarations
38 namespace edm {
40  struct GenericObject {};
41 
42  template <>
44  public:
46  Handle(std::string const& iName) : type_(TypeWithDict::byName(iName)), prod_(), prov_(nullptr) {
47  if (!bool(type_)) {
49  "Handle<GenericObject> told to use uknown type '",
50  iName.c_str(),
51  "'.\n Please check spelling or that a module uses this type in the job.");
52  }
53  }
54 
56  Handle(TypeWithDict const& iType) : type_(iType), prod_(), prov_(nullptr) {
57  if (!bool(iType)) {
58  Exception::throwThis(errors::NotFound, "Handle<GenericObject> given an invalid type");
59  }
60  }
61 
63  : type_(h.type_), prod_(h.prod_), prov_(h.prov_), whyFailedFactory_(h.whyFailedFactory_) {}
64 
65  Handle(ObjectWithDict const& prod, Provenance const* prov, ProductID const&)
66  : type_(prod.typeOf()), prod_(prod), prov_(prov) {
67  assert(prod_);
68  assert(prov_);
69  }
70 
71  //~Handle();
72 
74  // use unqualified swap for user defined classes
75  using std::swap;
76  swap(type_, other.type_);
77  std::swap(prod_, other.prod_);
78  swap(prov_, other.prov_);
79  swap(whyFailedFactory_, other.whyFailedFactory_);
80  }
81 
84  this->swap(temp);
85  return *this;
86  }
87 
88  bool isValid() const { return prod_ && nullptr != prov_; }
89 
90  bool failedToGet() const { return bool(whyFailedFactory_); }
91  ObjectWithDict const* product() const {
92  if (this->failedToGet()) {
93  whyFailedFactory_->make()->raise();
94  }
95  return &prod_;
96  }
97  ObjectWithDict const* operator->() const { return this->product(); }
98  ObjectWithDict const& operator*() const { return *(this->product()); }
99 
100  TypeWithDict const& type() const { return type_; }
101  Provenance const* provenance() const { return prov_; }
102 
103  ProductID id() const { return prov_->productID(); }
104 
105  void clear() {
106  prov_ = nullptr;
107  whyFailedFactory_ = nullptr;
108  }
109 
110  void setWhyFailedFactory(std::shared_ptr<HandleExceptionFactory const> const& iWhyFailed) {
111  whyFailedFactory_ = iWhyFailed;
112  }
113 
114  private:
118  std::shared_ptr<HandleExceptionFactory const> whyFailedFactory_;
119  };
120 
122 
125 
127  template <>
128  bool edm::Event::getByLabel<GenericObject>(std::string const& label,
129  std::string const& productInstanceName,
131 
132  template <>
134 
135 } // namespace edm
136 #endif
electrons_cff.bool
bool
Definition: electrons_cff.py:393
edm::Handle< GenericObject >::whyFailedFactory_
std::shared_ptr< HandleExceptionFactory const > whyFailedFactory_
Definition: GenericHandle.h:118
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::Handle< GenericObject >::prov_
Provenance const * prov_
Definition: GenericHandle.h:117
edm::BasicHandle
Definition: BasicHandle.h:43
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Handle< GenericObject >::setWhyFailedFactory
void setWhyFailedFactory(std::shared_ptr< HandleExceptionFactory const > const &iWhyFailed)
Definition: GenericHandle.h:110
edm::ObjectWithDict
Definition: ObjectWithDict.h:17
edm::Provenance::productID
ProductID const & productID() const
Definition: Provenance.h:79
edm::Handle< GenericObject >::swap
void swap(Handle< GenericObject > &other)
Definition: GenericHandle.h:73
cms::cuda::assert
assert(be >=bs)
edm::Handle< GenericObject >::isValid
bool isValid() const
Definition: GenericHandle.h:88
TypeWithDict.h
edm::errors::NotFound
Definition: EDMException.h:57
edm::Handle
Definition: AssociativeIterator.h:50
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::convert_handle
Handle< T > convert_handle(BasicHandle &&bh) noexcept(true)
Definition: ConvertHandle.h:22
ObjectWithDict.h
edm::Handle< GenericObject >::type_
TypeWithDict type_
Definition: GenericHandle.h:115
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
edm::Handle< GenericObject >::operator*
ObjectWithDict const & operator*() const
Definition: GenericHandle.h:98
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
trackingPlots.other
other
Definition: trackingPlots.py:1467
edm::GenericHandle
Handle< GenericObject > GenericHandle
Definition: GenericHandle.h:121
h
edm::HandleBase::swap
void swap(HandleBase &other)
Definition: HandleBase.h:57
edm::Event::getByLabel
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:492
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Handle< GenericObject >::operator->
ObjectWithDict const * operator->() const
Definition: GenericHandle.h:97
edm::TypeWithDict
Definition: TypeWithDict.h:38
edm::HandleBase::failedToGet
bool failedToGet() const
Definition: HandleBase.h:72
Event.h
edm::Handle< GenericObject >::id
ProductID id() const
Definition: GenericHandle.h:103
edm::Handle< GenericObject >::Handle
Handle(Handle< GenericObject > const &h)
Definition: GenericHandle.h:62
edm::HandleBase::whyFailedFactory_
std::shared_ptr< HandleExceptionFactory const > whyFailedFactory_
Definition: HandleBase.h:110
edm::Handle< GenericObject >::Handle
Handle(std::string const &iName)
Throws exception if iName is not a known C++ class type.
Definition: GenericHandle.h:46
edm::HandleBase::prov_
Provenance const * prov_
Definition: HandleBase.h:109
diMuonSkim_cfi.byName
byName
Definition: diMuonSkim_cfi.py:9
edm::Handle< GenericObject >::Handle
Handle(ObjectWithDict const &prod, Provenance const *prov, ProductID const &)
Definition: GenericHandle.h:65
edm::Handle< GenericObject >::operator=
Handle< GenericObject > & operator=(Handle< GenericObject > const &rhs)
Definition: GenericHandle.h:82
edm::Handle< GenericObject >::failedToGet
bool failedToGet() const
Definition: GenericHandle.h:90
edm::Handle< GenericObject >::product
ObjectWithDict const * product() const
Definition: GenericHandle.h:91
edm::GenericObject
This class is just a 'tag' used to allow a specialization of edm::Handle.
Definition: GenericHandle.h:40
edm::Handle< GenericObject >::provenance
Provenance const * provenance() const
Definition: GenericHandle.h:101
edm::Handle< GenericObject >::Handle
Handle(TypeWithDict const &iType)
Throws exception if iType is invalid.
Definition: GenericHandle.h:56
edm::Handle< GenericObject >::prod_
ObjectWithDict prod_
Definition: GenericHandle.h:116
edm::Exception::throwThis
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
mps_fire.result
result
Definition: mps_fire.py:311
edm::Handle< GenericObject >::clear
void clear()
Definition: GenericHandle.h:105
edm::Provenance
Definition: Provenance.h:34
edm::Handle< GenericObject >::type
TypeWithDict const & type() const
Definition: GenericHandle.h:100
edm::Handle< GenericObject >
Definition: GenericHandle.h:43
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::ProductID
Definition: ProductID.h:27