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 <memory>
31 
32 namespace cms {
33  class Exception;
34 }
35 
36 namespace edm {
37  class BranchDescription;
38  class WrapperBase;
39  class OutputHandle {
40  public:
43  desc_(nullptr),
44  productProvenance_(0) {}
45 
47  product_(h.product_),
48  desc_(h.desc_),
51 
53  product_(product),
54  desc_(desc),
55  productProvenance_(productProvenance) {}
56 
58  OutputHandle(std::shared_ptr<cms::Exception> const& iWhyFailed):
60  desc_(nullptr),
62  whyFailed_(iWhyFailed) {}
63 
65 
66  void swap(OutputHandle& other) {
67  using std::swap;
68  std::swap(product_, other.product_);
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 product_ && desc_ &&productProvenance_;
83  }
84 
85  bool failedToGet() const {
86  return 0 != whyFailed_.get();
87  }
88 
89  WrapperBase const* wrapper() const {
90  return product_;
91  }
92 
93  std::shared_ptr<cms::Exception> whyFailed() const {
94  return whyFailed_;
95  }
96 
98  return productProvenance_;
99  }
100 
101  BranchDescription const* desc() const {
102  return desc_;
103  }
104 
105  private:
109  std::shared_ptr<cms::Exception> whyFailed_;
110  };
111 
112  // Free swap function
113  inline
114  void
116  a.swap(b);
117  }
118 }
119 
120 #endif
bool isValid() const
Definition: OutputHandle.h:81
std::shared_ptr< cms::Exception > whyFailed_
Definition: OutputHandle.h:109
WrapperBase const * wrapper() const
Definition: OutputHandle.h:89
OutputHandle(std::shared_ptr< cms::Exception > const &iWhyFailed)
Used when the attempt to get the data failed.
Definition: OutputHandle.h:58
ProductProvenance const * productProvenance() const
Definition: OutputHandle.h:97
#define nullptr
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
OutputHandle(WrapperBase const *product, BranchDescription const *desc, ProductProvenance *productProvenance)
Definition: OutputHandle.h:52
BranchDescription const * desc_
Definition: OutputHandle.h:107
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::shared_ptr< cms::Exception > whyFailed() const
Definition: OutputHandle.h:93
WrapperBase const * product_
Definition: OutputHandle.h:106
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
OutputHandle & operator=(OutputHandle const &rhs)
Definition: OutputHandle.h:75
bool failedToGet() const
Definition: OutputHandle.h:85
ProductProvenance * productProvenance_
Definition: OutputHandle.h:108
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void swap(OutputHandle &other)
Definition: OutputHandle.h:66
BranchDescription const * desc() const
Definition: OutputHandle.h:101
OutputHandle(OutputHandle const &h)
Definition: OutputHandle.h:46