CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_),
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 
82  void swap(Handle<GenericObject>& other) {
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_);
89  }
90 
91 
94  this->swap(temp);
95  return *this;
96  }
97 
98  bool isValid() const {
99  return prod_ && 0!= 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_ = 0; 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
assert(m_qm.get())
std::shared_ptr< HandleExceptionFactory > whyFailedFactory_
Definition: HandleBase.h:127
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
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
tuple result
Definition: query.py:137
Handle< GenericObject > GenericHandle
Provenance const * prov_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Handle< GenericObject > & operator=(Handle< GenericObject > const &rhs)
Definition: GenericHandle.h:92
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
void swap(HandleBase &other)
Definition: HandleBase.h:62
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
bool failedToGet() const
Definition: HandleBase.h:79
T const * product() const
Definition: Handle.h:81
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
Provenance const * prov_
Definition: HandleBase.h:126
ProductID const & productID() const
Definition: Provenance.h:78
std::shared_ptr< HandleExceptionFactory > whyFailedFactory_