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
31 
32 #include "Reflex/Object.h"
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_(Reflex::Type::ByName(iName)), prod_(), prov_(0) {
49  if(type_ == Reflex::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  if(type_.IsTypedef()){
56  //For a 'Reflex::Typedef' the 'toType' method returns the actual type
57  // this is needed since you are now allowed to 'invoke' methods of a 'Typedef'
58  // only for a 'real' class
59  type_ = type_.ToType();
60  }
61  }
62 
64  Handle(Reflex::Type const& iType) :
65  type_(iType), prod_(), prov_(0) {
66  if(iType == Reflex::Type()) {
67  Exception::throwThis(errors::NotFound, "Handle<GenericObject> given an invalid Reflex::Type");
68  }
69  if(type_.IsTypedef()){
70  //For a 'Reflex::Typedef' the 'toType' method returns the actual type
71  // this is needed since you are now allowed to 'invoke' methods of a 'Typedef'
72  // only for a 'real' class
73  type_ = type_.ToType();
74  }
75  }
76 
78  type_(h.type_),
79  prod_(h.prod_),
80  prov_(h.prov_),
82  }
83 
84  Handle(Reflex::Object const& prod, Provenance const* prov, ProductID const&):
85  type_(prod.TypeOf()),
86  prod_(prod),
87  prov_(prov) {
88  assert(prod_);
89  assert(prov_);
90  assert(prov_->productID() != ProductID());
91  }
92 
93  //~Handle();
94 
95  void swap(Handle<GenericObject>& other) {
96  // use unqualified swap for user defined classes
97  using std::swap;
98  swap(type_, other.type_);
99  std::swap(prod_, other.prod_);
100  swap(prov_, other.prov_);
101  swap(whyFailed_, other.whyFailed_);
102  }
103 
104 
107  this->swap(temp);
108  return *this;
109  }
110 
111  bool isValid() const {
112  return prod_ && 0!= prov_;
113  }
114 
115  bool failedToGet() const {
116  return 0 != whyFailed_.get();
117  }
118  Reflex::Object const* product() const {
119  if(this->failedToGet()) {
120  whyFailed_->raise();
121  }
122  return &prod_;
123  }
124  Reflex::Object const* operator->() const {return this->product();}
125  Reflex::Object const& operator*() const {return *(this->product());}
126 
127  Reflex::Type const& type() const {return type_;}
128  Provenance const* provenance() const {return prov_;}
129 
130  ProductID id() const {return prov_->productID();}
131 
132  void clear() { prov_ = 0; whyFailed_.reset();}
133 
134  void setWhyFailed(boost::shared_ptr<cms::Exception> const& iWhyFailed) {
135  whyFailed_=iWhyFailed;
136  }
137 private:
139  Reflex::Object prod_;
140  Provenance const* prov_;
141  boost::shared_ptr<cms::Exception> whyFailed_;
142 
143 };
144 
146 
148 void convert_handle(BasicHandle const& orig,
150 
151 
153 template<>
154 bool
155 edm::Event::getByLabel<GenericObject>(std::string const& label,
156  std::string const& productInstanceName,
158 
159 template <>
160 bool
162 
163 }
164 #endif
Handle(Handle< GenericObject > const &h)
Definition: GenericHandle.h:77
Provenance const * provenance() const
Handle(std::string const &iName)
Throws exception if iName is not a known C++ class type.
Definition: GenericHandle.h:47
Reflex::Object const & operator*() const
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
boost::shared_ptr< cms::Exception > whyFailed_
Definition: HandleBase.h:101
Reflex::Object const * product() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Handle(Reflex::Object const &prod, Provenance const *prov, ProductID const &)
Definition: GenericHandle.h:84
tuple result
Definition: query.py:137
Handle< GenericObject > GenericHandle
Provenance const * prov_
void setWhyFailed(boost::shared_ptr< cms::Exception > const &iWhyFailed)
Handle< GenericObject > & operator=(Handle< GenericObject > const &rhs)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
Reflex::Type const & type() const
void swap(HandleBase &other)
Definition: HandleBase.h:63
Handle(Reflex::Type const &iType)
Throws exception if iType is invalid.
Definition: GenericHandle.h:64
bool failedToGet() const
Definition: HandleBase.h:80
Reflex::Object const * operator->() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void convert_handle(BasicHandle const &bh, Handle< T > &result)
Definition: ConvertHandle.h:19
void swap(Handle< GenericObject > &other)
Definition: GenericHandle.h:95
This class is just a &#39;tag&#39; used to allow a specialization of edm::Handle.
Definition: GenericHandle.h:40
T const * product() const
Definition: Handle.h:74
Provenance const * prov_
Definition: HandleBase.h:100
ProductID const & productID() const
Definition: Provenance.h:88
boost::shared_ptr< cms::Exception > whyFailed_