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 Framework_GenericHandle_h
2 #define 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 // system include files
30 #include <string>
31 
32 // user include files
33 #include "Reflex/Object.h"
35 
36 // forward declarations
37 namespace edm {
40 {
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& pid):
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 
96  {
97  // use unqualified swap for user defined classes
98  using std::swap;
99  swap(type_, other.type_);
100  std::swap(prod_, other.prod_);
101  swap(prov_, other.prov_);
102  swap(whyFailed_, other.whyFailed_);
103  }
104 
105 
107  {
109  this->swap(temp);
110  return *this;
111  }
112 
113  bool isValid() const {
114  return prod_ && 0!= prov_;
115  }
116 
117  bool failedToGet() const {
118  return 0 != whyFailed_.get();
119  }
120  Reflex::Object const* product() const {
121  if(this->failedToGet()) {
122  whyFailed_->raise();
123  }
124  return &prod_;
125  }
126  Reflex::Object const* operator->() const {return this->product();}
127  Reflex::Object const& operator*() const {return *(this->product());}
128 
129  Reflex::Type const& type() const {return type_;}
130  Provenance const* provenance() const {return prov_;}
131 
132  ProductID id() const {return prov_->productID();}
133 
134  void clear() { prov_ = 0; whyFailed_.reset();}
135 
136  void setWhyFailed(boost::shared_ptr<cms::Exception> const& iWhyFailed) {
137  whyFailed_=iWhyFailed;
138  }
139 private:
141  Reflex::Object prod_;
142  Provenance const* prov_;
143  boost::shared_ptr<cms::Exception> whyFailed_;
144 
145 };
146 
148 
150 void convert_handle(BasicHandle const& orig,
152 
153 
155 template<>
156 bool
157 edm::Event::getByLabel<GenericObject>(std::string const& label,
158  std::string const& productInstanceName,
160 
161 template <>
162 bool
164 
165 }
166 #endif
Handle(Handle< GenericObject > const &h)
Definition: GenericHandle.h:77
Handle(Reflex::Object const &prod, Provenance const *prov, ProductID const &pid)
Definition: GenericHandle.h:84
Provenance const * provenance() const
const std::string & label
Definition: MVAComputer.cc:186
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="")
Definition: EDMException.cc:81
boost::shared_ptr< cms::Exception > whyFailed_
Definition: HandleBase.h:101
void convert_handle(BasicHandle const &orig, Handle< T > &result)
Definition: ConvertHandle.h:17
Reflex::Object const * product() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
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:355
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
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:39
T const * product() const
Definition: Handle.h:74
Provenance const * prov_
Definition: HandleBase.h:100
ProductID const & productID() const
Definition: Provenance.h:88
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
boost::shared_ptr< cms::Exception > whyFailed_