CMS 3D CMS Logo

FWGenericHandle.h
Go to the documentation of this file.
1 #ifndef Fireworks_FWGenericHandle_h
2 #define Fireworks_FWGenericHandle_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : FWGenericHandle
7 //
28 //
29 // Original Author: Chris Jones
30 // Created: Sat Jan 7 15:40:43 EST 2006
31 //
32 
33 // system include files
34 #include <string>
35 
36 // user include files
41 
42 // forward declarations
43 namespace edm {
45  struct FWGenericObject {};
46 
47  template <>
49  public:
51  Handle(std::string const& iName) : type_(edm::TypeWithDict::byName(iName)), prod_(), prov_(nullptr) {
52  if (type_ == edm::TypeWithDict()) {
54  "Handle<FWGenericObject> told to use uknown type '",
55  iName.c_str(),
56  "'.\n Please check spelling or that a module uses this type in the job.");
57  }
58  }
59 
61  Handle(edm::TypeWithDict const& iType) : type_(iType), prod_(), prov_(nullptr) {
62  if (iType == edm::TypeWithDict()) {
63  Exception::throwThis(errors::NotFound, "Handle<FWGenericObject> given an invalid edm::TypeWithDict");
64  }
65  }
66 
68  : type_(h.type_), prod_(h.prod_), prov_(h.prov_), whyFailed_(h.whyFailed_) {}
69 
70  Handle(edm::ObjectWithDict const& prod, Provenance const* prov, ProductID const& pid)
71  : type_(prod.typeOf()), prod_(prod), prov_(prov) {
72  assert(prod_);
73  assert(prov_);
74  // assert(prov_->productID() != ProductID());
75  }
76 
77  //~Handle();
78 
80  // use unqualified swap for user defined classes
81  using std::swap;
82  swap(type_, other.type_);
83  std::swap(prod_, other.prod_);
84  swap(prov_, other.prov_);
85  swap(whyFailed_, other.whyFailed_);
86  }
87 
90  this->swap(temp);
91  return *this;
92  }
93 
94  bool isValid() const { return prod_ && nullptr != prov_; }
95 
96  bool failedToGet() const { return nullptr != whyFailed_.get(); }
97  edm::ObjectWithDict const* product() const {
98  if (this->failedToGet()) {
99  whyFailed_->raise();
100  }
101  return &prod_;
102  }
103  edm::ObjectWithDict const* operator->() const { return this->product(); }
104  edm::ObjectWithDict const& operator*() const { return *(this->product()); }
105 
106  edm::TypeWithDict const& type() const { return type_; }
107  Provenance const* provenance() const { return prov_; }
108 
109  ProductID id() const { return prov_->productID(); }
110 
111  void clear() {
112  prov_ = nullptr;
113  whyFailed_.reset();
114  }
115 
116  void setWhyFailed(std::shared_ptr<cms::Exception> const& iWhyFailed) { whyFailed_ = iWhyFailed; }
117 
118  private:
122  std::shared_ptr<cms::Exception> whyFailed_;
123  };
124 
126 
129 
131  template <>
133 
134 } // namespace edm
135 #endif
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
edm::ObjectWithDict const * product() const
void setWhyFailed(std::shared_ptr< cms::Exception > const &iWhyFailed)
edm::ObjectWithDict const * operator->() const
edm::TypeWithDict const & type() const
#define nullptr
Handle(edm::TypeWithDict const &iType)
Throws exception if iType is invalid.
void swap(Handle< FWGenericObject > &other)
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
Handle< FWGenericObject > & operator=(Handle< FWGenericObject > const &rhs)
Handle(edm::ObjectWithDict const &prod, Provenance const *prov, ProductID const &pid)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Handle< T > convert_handle(BasicHandle &&bh)(true)
Definition: ConvertHandle.h:22
Provenance const * provenance() const
This class is just a &#39;tag&#39; used to allow a specialization of edm::Handle.
Handle(std::string const &iName)
Throws exception if iName is not a known C++ class type.
std::shared_ptr< cms::Exception > whyFailed_
edm::ObjectWithDict const & operator*() const
Handle(Handle< FWGenericObject > const &h)
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
HLT enums.
Handle< FWGenericObject > FWGenericHandle