LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
OutputHandle.h
Go to the documentation of this file.
1 #ifndef art_Framework_Principal_OutputHandle_h
2 #define art_Framework_Principal_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 
32 #include "cetlib/exempt_ptr.h"
33 #include "cetlib_except/exception.h"
34 
35 #include <memory>
36 
37 namespace art {
38  class EDProduct;
39  class OutputHandle {
40  public:
41  OutputHandle(EDProduct const* prod,
42  BranchDescription const* desc,
43  cet::exempt_ptr<ProductProvenance const> productProvenance,
44  RangeSet const& rs)
45  : wrap_{prod}
46  , desc_{desc}
48  , rangeOfValidity_{rs}
49  {}
50 
51  static OutputHandle
53  {
55  }
56 
59 
60  // use compiler-generated copy c'tor, copy assignment, and d'tor
61 
62  void
64  {
65  using std::swap;
66  swap(wrap_, other.wrap_);
67  swap(desc_, other.desc_);
69  }
70 
71  bool
72  isValid() const
73  {
74  return wrap_ && desc_ && productProvenance_;
75  }
76 
77  RangeSet const&
79  {
80  return rangeOfValidity_;
81  }
82 
83  EDProduct const*
84  wrapper() const
85  {
86  return wrap_;
87  }
88 
89  ProductProvenance const*
91  {
92  return productProvenance_.get();
93  }
94 
95  BranchDescription const*
96  desc() const
97  {
98  return desc_;
99  }
100 
101  private:
102  EDProduct const* wrap_{nullptr};
103  BranchDescription const* desc_{nullptr};
104  cet::exempt_ptr<ProductProvenance const> productProvenance_{nullptr};
106  };
107 
108  // Free swap function
109  inline void
111  {
112  a.swap(b);
113  }
114 }
115 
116 #endif /* art_Framework_Principal_OutputHandle_h */
117 
118 // Local Variables:
119 // mode: c++
120 // End:
ProductProvenance const * productProvenance() const
Definition: OutputHandle.h:90
BranchDescription const * desc() const
Definition: OutputHandle.h:96
RangeSet const & rangeOfValidity() const
Definition: OutputHandle.h:78
void swap(OutputHandle &other)
Definition: OutputHandle.h:63
bool isValid() const
Definition: OutputHandle.h:72
OutputHandle(RangeSet const &rs)
Used when the attempt to get the data failed.
Definition: OutputHandle.h:58
OutputHandle(EDProduct const *prod, BranchDescription const *desc, cet::exempt_ptr< ProductProvenance const > productProvenance, RangeSet const &rs)
Definition: OutputHandle.h:41
RangeSet const & rangeOfValidity_
Definition: OutputHandle.h:105
EDProduct const * wrapper() const
Definition: OutputHandle.h:84
BranchDescription const * desc_
Definition: OutputHandle.h:103
EDProduct const * wrap_
Definition: OutputHandle.h:102
cet::exempt_ptr< ProductProvenance const > productProvenance_
Definition: OutputHandle.h:104
void swap(OutputHandle &a, OutputHandle &b)
Definition: OutputHandle.h:110
static RangeSet invalid()
Definition: RangeSet.cc:46
HLT enums.
static OutputHandle invalid()
Definition: OutputHandle.h:52