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 
43 template<>
45 public:
47  Handle(std::string const& iName) :
48  type_(TypeWithDict::byName(iName)), prod_(), prov_(nullptr) {
49  if(!bool(type_)) {
51  "Handle<GenericObject> told to use uknown type '",
52  iName.c_str(),
53  "'.\n Please check spelling or that a module uses this type in the job.");
54  }
55  }
56 
58  Handle(TypeWithDict const& iType) :
59  type_(iType), prod_(), prov_(nullptr) {
60  if(!bool(iType)) {
61  Exception::throwThis(errors::NotFound, "Handle<GenericObject> given an invalid type");
62  }
63  }
64 
66  type_(h.type_),
67  prod_(h.prod_),
68  prov_(h.prov_),
69  whyFailedFactory_(h.whyFailedFactory_) {
70  }
71 
72  Handle(ObjectWithDict const& prod, Provenance const* prov, ProductID const&):
73  type_(prod.typeOf()),
74  prod_(prod),
75  prov_(prov) {
76  assert(prod_);
77  assert(prov_);
78  }
79 
80  //~Handle();
81 
83  // use unqualified swap for user defined classes
84  using std::swap;
85  swap(type_, other.type_);
86  std::swap(prod_, other.prod_);
87  swap(prov_, other.prov_);
88  swap(whyFailedFactory_, other.whyFailedFactory_);
89  }
90 
91 
94  this->swap(temp);
95  return *this;
96  }
97 
98  bool isValid() const {
99  return prod_ && nullptr!= prov_;
100  }
101 
102  bool failedToGet() const {
103  return bool(whyFailedFactory_);
104  }
105  ObjectWithDict const* product() const {
106  if(this->failedToGet()) {
107  whyFailedFactory_->make()->raise();
108  }
109  return &prod_;
110  }
111  ObjectWithDict const* operator->() const {return this->product();}
112  ObjectWithDict const& operator*() const {return *(this->product());}
113 
114  TypeWithDict const& type() const {return type_;}
115  Provenance const* provenance() const {return prov_;}
116 
117  ProductID id() const {return prov_->productID();}
118 
119  void clear() { prov_ = nullptr; whyFailedFactory_=nullptr;}
120 
121  void setWhyFailedFactory(std::shared_ptr<HandleExceptionFactory> const& iWhyFailed) {
122  whyFailedFactory_=iWhyFailed;
123  }
124 private:
127  Provenance const* prov_;
128  std::shared_ptr<HandleExceptionFactory> whyFailedFactory_;
129 
130 };
131 
133 
135 void convert_handle(BasicHandle && orig,
137 
138 
140 template<>
141 bool
142 edm::Event::getByLabel<GenericObject>(std::string const& label,
143  std::string const& productInstanceName,
145 
146 template <>
147 bool
149 
150 }
151 #endif
ObjectWithDict const & operator*() const
Handle(Handle< GenericObject > const &h)
Definition: GenericHandle.h:65
Provenance const * provenance() const
Handle(ObjectWithDict const &prod, Provenance const *prov, ProductID const &)
Definition: GenericHandle.h:72
Handle(std::string const &iName)
Throws exception if iName is not a known C++ class type.
Definition: GenericHandle.h:47
#define nullptr
ObjectWithDict const * operator->() const
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="")
TypeWithDict const & type() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ObjectWithDict const * product() const
Handle< GenericObject > GenericHandle
Provenance const * prov_
Handle< GenericObject > & operator=(Handle< GenericObject > const &rhs)
Definition: GenericHandle.h:92
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:464
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
void setWhyFailedFactory(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)
Handle(TypeWithDict const &iType)
Throws exception if iType is invalid.
Definition: GenericHandle.h:58
void swap(Handle< GenericObject > &other)
Definition: GenericHandle.h:82
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_