CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputHandle.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_OutputHandle_h
2 #define DataFormats_Common_OutputHandle_h
3 
4 /*----------------------------------------------------------------------
5 
6 Handle: Non-owning "smart pointer" for reference to EDProducts and
7 their Provenances.
8 
9 This is a very preliminary version, and lacks safety features and
10 elegance.
11 
12 If the pointed-to object or provenance destroyed, use of the
13 Handle becomes undefined. There is no way to query the Handle to
14 discover if this has happened.
15 
16 Handles can have:
17  -- Product and Provenance pointers both null;
18  -- Both pointers valid
19 
20 To check validity, one can use the isValid() function.
21 
22 If failedToGet() returns true then the requested data is not available
23 If failedToGet() returns false but isValid() is also false then no attempt
24  to get data has occurred
25 
26 ----------------------------------------------------------------------*/
27 
29 
30 #include "boost/shared_ptr.hpp"
31 
32 namespace cms {
33  class Exception;
34 }
35 
36 namespace edm {
37  class ConstBranchDescription;
38  class EDProduct;
39  class OutputHandle {
40  public:
42  wrap_(0),
43  desc_(0),
45 
47  wrap_(h.wrap_),
48  desc_(h.desc_),
51 
52  OutputHandle(EDProduct const* prod, ConstBranchDescription const* desc, boost::shared_ptr<ProductProvenance> productProvenance) :
53  wrap_(prod),
54  desc_(desc),
55  productProvenance_(productProvenance) {}
56 
58  OutputHandle(boost::shared_ptr<cms::Exception> const& iWhyFailed):
59  wrap_(0),
60  desc_(0),
62  whyFailed_(iWhyFailed) {}
63 
65 
66  void swap(OutputHandle& other) {
67  using std::swap;
68  std::swap(wrap_, other.wrap_);
69  std::swap(desc_, other.desc_);
71  swap(whyFailed_,other.whyFailed_);
72  }
73 
74 
76  OutputHandle temp(rhs);
77  this->swap(temp);
78  return *this;
79  }
80 
81  bool isValid() const {
82  return wrap_ && desc_ &&productProvenance_;
83  }
84 
85  bool failedToGet() const {
86  return 0 != whyFailed_.get();
87  }
88 
89  EDProduct const* wrapper() const {
90  return wrap_;
91  }
92 
93  boost::shared_ptr<cms::Exception> whyFailed() const {
94  return whyFailed_;
95  }
96 
98  return productProvenance_.get();
99  }
100 
101  boost::shared_ptr<ProductProvenance> productProvenanceSharedPtr() const {
102  return productProvenance_;
103  }
104 
105  ConstBranchDescription const* desc() const {
106  return desc_;
107  }
108 
109  private:
110  EDProduct const* wrap_;
112  boost::shared_ptr<ProductProvenance> productProvenance_;
113  boost::shared_ptr<cms::Exception> whyFailed_;
114  };
115 
116  // Free swap function
117  inline
118  void
120  a.swap(b);
121  }
122 }
123 
124 #endif
bool isValid() const
Definition: OutputHandle.h:81
boost::shared_ptr< ProductProvenance > productProvenanceSharedPtr() const
Definition: OutputHandle.h:101
ConstBranchDescription const * desc() const
Definition: OutputHandle.h:105
ProductProvenance const * productProvenance() const
Definition: OutputHandle.h:97
EDProduct const * wrap_
Definition: OutputHandle.h:110
OutputHandle(EDProduct const *prod, ConstBranchDescription const *desc, boost::shared_ptr< ProductProvenance > productProvenance)
Definition: OutputHandle.h:52
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
ConstBranchDescription const * desc_
Definition: OutputHandle.h:111
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
OutputHandle(boost::shared_ptr< cms::Exception > const &iWhyFailed)
Used when the attempt to get the data failed.
Definition: OutputHandle.h:58
OutputHandle & operator=(OutputHandle const &rhs)
Definition: OutputHandle.h:75
bool failedToGet() const
Definition: OutputHandle.h:85
double b
Definition: hdecay.h:120
EDProduct const * wrapper() const
Definition: OutputHandle.h:89
double a
Definition: hdecay.h:121
boost::shared_ptr< ProductProvenance > productProvenance_
Definition: OutputHandle.h:112
void swap(OutputHandle &other)
Definition: OutputHandle.h:66
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
OutputHandle(OutputHandle const &h)
Definition: OutputHandle.h:46
boost::shared_ptr< cms::Exception > whyFailed() const
Definition: OutputHandle.h:93
boost::shared_ptr< cms::Exception > whyFailed_
Definition: OutputHandle.h:113