Exceptions.h
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/Exceptions.h
3  * @brief Collection of exceptions for Geometry system
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date November 24, 2016
6  *
7  * This is currently a header-only library.
8  *
9  * It offers:
10  * - InvalidWireError (for bad wire numbers)
11  * - InvalidWireIDError (deprecated in favor of the former)
12  *
13  */
14 
15 #ifndef LARCOREALG_GEOMETRY_EXCEPTIONS_H
16 #define LARCOREALG_GEOMETRY_EXCEPTIONS_H
17 
18 
19 // LArSoft libraries
20 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::PlaneID, ...
21 
22 // Framework libraries
23 #include "cetlib_except/exception.h"
24 
25 // C/C++ standard library
26 #include <limits> // std::numeric_limits<>
27 
28 
29 namespace geo {
30 
31  /** **************************************************************************
32  * @brief Exception thrown on invalid wire number
33  *
34  * This class is thrown, e.g., by Geometry::NearestWireID().
35  * It contains the erroneous wire number, a suggestion of which one might be
36  * the right one, and a plane ID.
37  *
38  * The wire numbers are signed.
39  *
40  *
41  */
43  public:
44 
45  /// Value used to represent an invalid wire number
46  static constexpr int InvalidWireNo = std::numeric_limits<int>::max();
47 
48 
49  /// Constructor: we don't have any information
50  /// @deprecated Specify at least the wrong wire number!
52 
53  /// Constructor with the complete information
55  std::string cat,
56  geo::PlaneID const& planeID,
57  int badWireNo,
58  int betterWireNo
59  )
60  : cet::exception(cat)
61  , fPlaneID(planeID)
62  , fWireNumber(badWireNo)
63  , fBetterWireNo(betterWireNo)
64  {}
65 
66  /// Constructor: no wire suggestions
68  (std::string cat, geo::PlaneID const& planeID, int badWireNo)
69  : cet::exception(cat)
70  , fPlaneID(planeID)
71  , fWireNumber(badWireNo)
72  {}
73 
74  /// Constructor: no plane information
76  std::string cat,
77  int badWireNo,
78  int betterWireNo
79  )
80  : cet::exception(cat)
81  , fWireNumber(badWireNo)
82  , fBetterWireNo(betterWireNo)
83  {}
84 
85  /// Constructor: no plane information and no suggestion
87  std::string cat,
88  int badWireNo
89  )
90  : cet::exception(cat)
91  , fWireNumber(badWireNo)
92  {}
93 
94 
95  /// @{
96  /// @name Access to bad wire
97 
98  /// Returns whether we known the bad wire number
99  bool hasBadWire() const { return fWireNumber != InvalidWireNo; }
100 
101  /// Returns the bad wire number
102  int badWire() const { return fWireNumber; }
103 
104  /// Returns the bad wire ID
106 
107  /// @}
108 
109 
110  /// @{
111  /// @name Access to suggested wire
112 
113  /// Returns whether we known a better wire number
114  bool hasSuggestedWire() const { return fBetterWireNo != InvalidWireNo; }
115 
116  /// Returns a better wire number
117  int suggestedWire() const { return fBetterWireNo; }
118 
119  /// Returns a better wire ID
121 
122  /// @}
123 
124 
125  /// @{
126  /// @name Plane access
127 
128  /// Return whether a plane is recorded with the exception
129  bool hasPlane() const { return fPlaneID.isValid; }
130 
131  /// Return the plane ID recorded with the exception
132  geo::PlaneID const& planeID() const { return fPlaneID; }
133 
134  /// @}
135 
136  private:
137  geo::PlaneID fPlaneID; ///< plane the wire belongs to
138 
139  /// the invalid wire number
141 
142  /// a suggestion for a good wire number
144 
145  /// Transform a wire number into wire ID
146  geo::WireID makeWireID(int wireNo) const
147  { return { fPlaneID, (geo::WireID::WireID_t) wireNo }; }
148 
149 
150  }; // class InvalidWireError
151 
152 
153  /** **************************************************************************
154  * @brief Exception thrown on invalid wire number (e.g. NearestWireID())
155  *
156  * @deprecated Use InvalidWireError instead
157  */
159  public:
161 
162  InvalidWireIDError(std::string cat, int bad_wire, int better_wire = -1):
163  cet::exception(cat),
164  wire_number(bad_wire), better_wire_number(better_wire)
165  {}
166 
167  int wire_number = -1; ///< the invalid wire number
168  int better_wire_number = -1; ///< a suggestion for a good wire number
169  }; // class InvalidWireIDError
170 
171 
172 } // namespace geo
173 
174 #endif // LARCOREALG_GEOMETRY_EXCEPTIONS_H
int suggestedWire() const
Returns a better wire number.
Definition: Exceptions.h:117
std::string string
Definition: nybbler.cc:12
bool hasBadWire() const
Returns whether we known the bad wire number.
Definition: Exceptions.h:99
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:211
int badWire() const
Returns the bad wire number.
Definition: Exceptions.h:102
InvalidWireError(std::string cat, int badWireNo, int betterWireNo)
Constructor: no plane information.
Definition: Exceptions.h:75
int fBetterWireNo
a suggestion for a good wire number
Definition: Exceptions.h:143
InvalidWireIDError(std::string cat, int bad_wire, int better_wire=-1)
Definition: Exceptions.h:162
InvalidWireError(std::string cat, int badWireNo)
Constructor: no plane information and no suggestion.
Definition: Exceptions.h:86
InvalidWireError(std::string cat, geo::PlaneID const &planeID, int badWireNo, int betterWireNo)
Constructor with the complete information.
Definition: Exceptions.h:54
geo::PlaneID fPlaneID
plane the wire belongs to
Definition: Exceptions.h:137
geo::PlaneID const & planeID() const
Return the plane ID recorded with the exception.
Definition: Exceptions.h:132
static int max(int a, int b)
Definition of data types for geometry description.
InvalidWireIDError(std::string cat)
Definition: Exceptions.h:160
geo::WireID badWireID() const
Returns the bad wire ID.
Definition: Exceptions.h:105
InvalidWireError(std::string cat)
Definition: Exceptions.h:51
static constexpr int InvalidWireNo
Value used to represent an invalid wire number.
Definition: Exceptions.h:46
bool hasPlane() const
Return whether a plane is recorded with the exception.
Definition: Exceptions.h:129
geo::WireID makeWireID(int wireNo) const
Transform a wire number into wire ID.
Definition: Exceptions.h:146
Exception thrown on invalid wire number.
Definition: Exceptions.h:42
unsigned int WireID_t
Type for the ID number.
Definition: geo_types.h:561
Exception thrown on invalid wire number (e.g. NearestWireID())
Definition: Exceptions.h:158
geo::WireID suggestedWireID() const
Returns a better wire ID.
Definition: Exceptions.h:120
LArSoft geometry interface.
Definition: ChannelGeo.h:16
bool hasSuggestedWire() const
Returns whether we known a better wire number.
Definition: Exceptions.h:114
int fWireNumber
the invalid wire number
Definition: Exceptions.h:140
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33