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 Event::getByLabel<GenericObject>(std::string const& label,
129  std::string const& productInstanceName,
131 
132  template <>
133  bool Event::getByLabel<GenericObject>(InputTag const& tag, Handle<GenericObject>& result) const;
134 
136  template <>
137  bool Event::getByToken<GenericObject>(EDGetToken token, Handle<GenericObject>& result) const;
138 
139 } // namespace edm
140 #endif
void setWhyFailedFactory(std::shared_ptr< HandleExceptionFactory const > const &iWhyFailed)
Handle(Handle< GenericObject > const &h)
Definition: GenericHandle.h:62
Handle(ObjectWithDict const &prod, Provenance const *prov, ProductID const &)
Definition: GenericHandle.h:65
ObjectWithDict const & operator*() const
Definition: GenericHandle.h:98
T const * product() const
Definition: Handle.h:70
ProductID const & productID() const
Definition: Provenance.h:79
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
ObjectWithDict const * product() const
Definition: GenericHandle.h:91
assert(be >=bs)
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:86
bool failedToGet() const
Definition: HandleBase.h:72
char const * label
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Handle< GenericObject > GenericHandle
Provenance const * prov_
TypeWithDict const & type() const
Handle< GenericObject > & operator=(Handle< GenericObject > const &rhs)
Definition: GenericHandle.h:82
Provenance const * provenance() const
void swap(HandleBase &other)
Definition: HandleBase.h:57
std::shared_ptr< HandleExceptionFactory const > whyFailedFactory_
Definition: HandleBase.h:110
Handle< T > convert_handle(BasicHandle &&bh) noexcept(true)
Definition: ConvertHandle.h:22
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.
Provenance const * prov_
Definition: HandleBase.h:109
std::shared_ptr< HandleExceptionFactory const > whyFailedFactory_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4