44#ifndef ALICEO2_ITS_SEGMENTATION_H_
55#define ALICEO2_ITS_SEGMENTATION_H_
66
7+ #include < exception>
8+ #include < sstream>
9+
710#include < TObject.h>
811
912class TF1 ;
@@ -18,6 +21,116 @@ namespace ITS {
1821class Segmentation : public TObject {
1922
2023public:
24+ // / Error handling in case a point in local coordinates
25+ // / exceeds limits in any direction
26+ class OutOfActiveAreaException : public std ::exception {
27+ public:
28+ // / Definition of direction in which the boundary is exceeded
29+ enum Direction {
30+ kX = 0 , // /< Local X
31+ kZ = 1 // /< Local Z
32+ };
33+ // / Constructor
34+ // / Settting necessary information for the error handling
35+ // / @param dir Direction in which the range exception happened
36+ // / @param val Value of the exception
37+ // / @param lower Lower limit in the direction
38+ // / @param upper Upper limit in the direction
39+ OutOfActiveAreaException (Direction dir, Double_t val, Double_t lower, Double_t upper) :
40+ fErrorMessage (), fDirection (dir), fValue (val), fLower (lower), fUpper (upper)
41+ {
42+ std::stringstream errormessage;
43+ errormessage << " Range exceeded in " << (fDirection == kX ? " x" : " z" ) << " -direction, value " << fValue << " , limits [" << fLower << " |" << fUpper << " ]" ;
44+ fErrorMessage = errormessage.str ();
45+ }
46+ // / Destructor
47+ virtual ~OutOfActiveAreaException () throw () {}
48+
49+ // / Get the value for which the exception was raised
50+ // / @return Value (point in one direction)
51+ Double_t GetValue () const { return fValue ; }
52+ // / Get the lower limit in direction for which the exception
53+ // / was raised
54+ // / @return Lower limit of the direction
55+ Double_t GetLowerLimit () const { return fLower ; }
56+ // / Get the upper limit in direction for which the exception
57+ // / was raised
58+ // / @return Upper limit of the direction
59+ Double_t GetUpperLimit () const { return fUpper ; }
60+ // / Check whether exception was raised in x-directon
61+ // / @return True if exception was raised in x-direction, false otherwise
62+ Bool_t IsX () const { return fDirection == kX ; }
63+ // / Check whether exception was raised in z-direction
64+ // / @return True if exception was raised in z-direction, false otherwise
65+ Bool_t IsZ () const { return fDirection == kZ ; }
66+
67+ // / Provide error message string containing direction,
68+ // / value of the point, and limits
69+ // / @return Error message
70+ const char *what () const noexcept {
71+ return fErrorMessage .c_str ();
72+ }
73+
74+ private:
75+ std::string fErrorMessage ; // /< Error message connected to the exception
76+ Direction fDirection ; // /< Direction in which the exception was raised
77+ Double_t fValue ; // /< Value which exceeds limit
78+ Double_t fLower ; // /< Lower limit in direction
79+ Double_t fUpper ; // /< Upper limit in direction
80+ };
81+
82+ // / Error handling in case of access to an invalid pixel ID
83+ // / (pixel ID in direction which exceeds the range of valid pixel IDs)
84+ class InvalidPixelException : public std ::exception{
85+ public:
86+ // / Definition of direction in which the boundary is exceeded
87+ enum Direction {
88+ kX = 0 , // /< Local X
89+ kZ = 1 // /< Local Z
90+ };
91+ // / Constructor
92+ // / Setting necessary information for the error handling
93+ // / @param dir Direction in which the exception occurs
94+ // / @param pixelID Index of the pixel (in direction) which is out of scope
95+ // / @param maxPixelID Maximum amount of pixels in direction
96+ InvalidPixelException (Direction dir, Int_t pixelID, Int_t maxPixelID):
97+ fErrorMessage (), fDirection (dir), fValue (pixelID), fMaxPixelID (maxPixelID)
98+ {
99+ std::stringstream errormessage;
100+ errormessage << " Obtained " << (fDirection == kX ? " row" : " col" ) << " " << fValue << " is not in range [0:" << fMaxPixelID << " )" ;
101+ fErrorMessage = errormessage.str ();
102+ }
103+
104+ // / Destructor
105+ virtual ~InvalidPixelException () {}
106+
107+ // / Get the ID of the pixel which raised the exception
108+ // / @return ID of the pixel
109+ Int_t GetPixelID () const { return fValue ; }
110+ // / Get the maximum number of pixels in a given direction
111+ // / @return Max. number of pixels
112+ Int_t GetMaxNumberOfPixels () const { return fMaxPixelID ; }
113+ // / Check whether exception was raised in x-directon
114+ // / @return True if exception was raised in x-direction, false otherwise
115+ Bool_t IsX () const { return fDirection == kX ; }
116+ // / Check whether exception was raised in z-direction
117+ // / @return True if exception was raised in z-direction, false otherwise
118+ Bool_t IsZ () const { return fDirection == kZ ; }
119+
120+ // / Provide error message string containing direction,
121+ // / index of the pixel out of range, and the maximum pixel ID
122+ const char *what () const noexcept {
123+ return fErrorMessage .c_str ();
124+ }
125+
126+ private:
127+ std::string fErrorMessage ; // /< Error message connected to this exception
128+ Direction fDirection ; // /< Direction in which the pixel index is out of range
129+ Int_t fValue ; // /< Value of the pixel ID which is out of range
130+ Int_t fMaxPixelID ; // /< Maximum amount of pixels in direction;
131+ };
132+
133+
21134 // / Default constructor
22135 Segmentation ();
23136
@@ -101,10 +214,12 @@ class Segmentation : public TObject {
101214
102215 // / Transformation from Geant cm detector center local coordinates
103216 // / to detector segmentation/cell coordiantes starting from (0,0).
104- virtual Bool_t localToDetector (Float_t, Float_t, Int_t&, Int_t&) const = 0;
217+ // / @throw OutOfActiveAreaException if the point is outside the active area in any of the directions
218+ virtual void localToDetector (Float_t, Float_t, Int_t&, Int_t&) const = 0;
105219
106220 // / Transformation from detector segmentation/cell coordiantes starting
107221 // / from (0,0) to Geant cm detector center local coordinates.
222+ // / @throw InvalidPixelException in case the pixel ID in any direction is out of range
108223 virtual void detectorToLocal (Int_t, Int_t, Float_t&, Float_t&) const = 0;
109224
110225 // / Initialisation
0 commit comments