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& iWhyFailed) {
111  whyFailedFactory_ = iWhyFailed;
112  }
113 
114  private:
118  std::shared_ptr<HandleExceptionFactory> 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
ObjectWithDict const & operator*() const
Definition: GenericHandle.h:98
Handle(Handle< GenericObject > const &h)
Definition: GenericHandle.h:62
Provenance const * provenance() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Handle(ObjectWithDict const &prod, Provenance const *prov, ProductID const &)
Definition: GenericHandle.h:65
#define nullptr
Handle(std::string const &iName)
Throws exception if iName is not a known C++ class type.
Definition: GenericHandle.h:46
ObjectWithDict const * operator->() const
Definition: GenericHandle.h:97
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:82
TypeWithDict const & type() const
char const * label
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Handle< T > convert_handle(BasicHandle &&bh)(true)
Definition: ConvertHandle.h:22
ObjectWithDict const * product() const
Definition: GenericHandle.h:91
Handle< GenericObject > GenericHandle
Provenance const * prov_
Handle< GenericObject > & operator=(Handle< GenericObject > const &rhs)
Definition: GenericHandle.h:82
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
void setWhyFailedFactory(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)
Handle(TypeWithDict const &iType)
Throws exception if iType is invalid.
Definition: GenericHandle.h:56
void swap(Handle< GenericObject > &other)
Definition: GenericHandle.h:73
This class is just a &#39;tag&#39; used to allow a specialization of edm::Handle.
Definition: GenericHandle.h:40
HLT enums.
std::shared_ptr< HandleExceptionFactory > whyFailedFactory_