Diana Software
QError.cc
Go to the documentation of this file.
1 #include "QError.hh"
2 #include <sstream>
3 
4 using std::stringstream;
5 
6 
7 
8 
9 
10 std::map<QError_, std::string> QError::fMap;
11 
12 
13 //_____________________________________________________________________________
15 {
16  static bool initDone = false;
17  if(initDone) return;
18 
19  // Generic error code (Diana & Apollo)
20  fMap[QERR_SUCCESS] = "Success";
21  fMap[QERR_OUT_OF_RANGE] = "Out Of Range";
22  fMap[QERR_OVERFLOW] = "Overflow";
23  fMap[QERR_UNDERFLOW] = "Underflow";
24  fMap[QERR_SIZE_NOT_MATCH] = "Size not match";
25  fMap[QERR_FILE_NOT_FOUND] = "File not found";
26  fMap[QERR_CANNOT_OPEN_FILE] = "Cannot open file";
27  fMap[QERR_IO_FAILED] = "Input Output Failed";
28  fMap[QERR_UNDEFINED_NUMBER] = "Number not valid";
29  fMap[QERR_TYPE_CONVERSION] = "Type Conversion";
30  fMap[QERR_GSL_ERROR] = "GSL error";
31  fMap[QERR_TIMEOUT] = "Timemout elapsed";
32  fMap[QERR_EOF] = "Reached EOF";
33 
34  // Diana:
35  fMap[QERR_EVENT_GENERIC] = "Generic Event Error";
36  fMap[QERR_GLOBAL_GENERIC] = "Generic Global Objects Error";
37  fMap[QERR_EVENT_HANDLE] = "Event Handle Error";
38  fMap[QERR_GLOBAL_HANDLE] = "Global Handle Error";
39 
40 
41  // Apollo: general error codes
42  fMap[QERR_UNDEFINED_CHANNEL] = "Undefined Channel";
43  fMap[QERR_UNDEFINED_ID] = "Undefined Identification";
44  fMap[QERR_UNDEFINED_TYPE] = "Undefined Type";
45  fMap[QERR_UNDEFINED_STATUS] = "Undefined Status";
46  fMap[QERR_UNDEFINED_PARAMETER] = "Undefined Parameter";
47  fMap[QERR_UNDEFINED_COMMAND] = "Undefined Command";
48  fMap[QERR_UNDEFINED_DEVICE] = "Undefined Device";
49  fMap[QERR_UNDEFINED_INTERFACE] = "Undefined Interface";
50  fMap[QERR_UNDEFINED_TARGET] = "Undefined Target";
51  fMap[QERR_EXIT] = "Process status changed to Exit";
52 
53  // National Instruments error codes
54  fMap[QERR_NI] = "National Instruments error";
55 
56  // Slow Control: specific error codes
57  fMap[QERR_UNDEFINED_MODE] = "Undefined Mode";
58  fMap[QERR_UNDEFINED_BASKET] = "Setting Basket Not defined";
59  fMap[QERR_UNDEFINED_CRATE] = "Undefined Crate Address";
60  fMap[QERR_UNDEFINED_BOARD] = "Undefined Board Address";
61 
62 
63  // Slow Control: electronics error
64  fMap[QERR_ELE_UNDEFINED_REGISTER] = "Undefined Register";
65  fMap[QERR_ELE_GENERIC_ERR] = "Generic Error";
66  fMap[QERR_ELE_NO_ACKNOLDGEMENT] = "No Data Acknologement";
67  fMap[QERR_ELE_UNDEFINED_REGISTER] = "Register Not Defined";
68  fMap[QERR_ELE_FE_WRITE] = "Front End Write Error";
69  fMap[QERR_ELE_BACKPLANE_WRITE] = "Backplane Write Error";
70  fMap[QERR_ELE_BESSEL_WRITE] = "Bessel Write Error";
71  fMap[QERR_ELE_PULSER_ATT_WRITE] = "Pulser Attenuation Write Error";
72  fMap[QERR_ELE_PULSER_STATUS_WRITE] = "Pulser Status Write Error";
73  fMap[QERR_ELE_FE_READ] = "Front End Read Error";
74  fMap[QERR_ELE_BACKPLANE_READ] = "Backplane Read Error";
75  fMap[QERR_ELE_BESSEL_READ] = "Bessel Read Error";
76  fMap[QERR_ELE_PULSER_ATT_READ] = "Pulser Attenuation Read Errror";
77  fMap[QERR_ELE_PULSER_STATUS_READ] = "Pulser Status Read Error";
78 
79 
80  // Network communication errors
81  fMap[QERR_NET_UNKNOWN_HOST] = "Unknown Host";
82  fMap[QERR_NET_CONNECTION_FAILED] = "Connection Failed";
83  fMap[QERR_NET_PROTOCOL] = "Error in communication protocol";
84 
85  // shared memory related errors
86  fMap[QERR_SHMEM_INVALID_INDEX] = "Invalid index in shared memory buffer";
87  fMap[QERR_SHMEM_INVALID_ID] = "Invalid shared memory Id";
88 
89  // GPIB Error
90  fMap[QERR_GPIB_GENERAL] = "Error in GPIB Comunication";
91 
92  // vme related errors
93  fMap[QERR_VME_OPEN] = "Error opening VME environment";
94  fMap[QERR_VME_READ] = "Error reading from VME";
95  fMap[QERR_VME_WRITE] = "Error writing to VME";
96 
97  // DataBase errors
98  fMap[QERR_DB_INCONSISTENCY] = "Inconsistency found in db";
99  fMap[QERR_DB_CONN_FAILED] = "Connection to db failed";
100  fMap[QERR_DB_QUERY_FAILED] = "Error while executing query";
101  fMap[QERR_DB_NULL_RESULT] = "Null result while single expected";
102  fMap[QERR_DB_MAXLINES_EXCEEDED] = "Number of entries exceeded requested "
103  "limit";
104 
105 
106  // Unknown errors
107  fMap[QERR_UNKNOWN_ERR] = "Unknown error";
108  fMap[QERR_NOT_IMPLEMENTED] = "Not implemented";
109 
110  initDone = true;
111 }
112 
113 
114 //_____________________________________________________________________________
116  std::exception()
117 {
118  fErr = QERR_SUCCESS;
119  fDescr = "";
120  Init();
121 }
122 
123 
124 //_____________________________________________________________________________
126 {
127  fErr = err;
128  fDescr = "";
129  Init();
130 }
131 
132 
133 //_____________________________________________________________________________
134 QError::QError(QError_ err, const std::string& descr)
135 {
136  fErr = err;
137  fDescr = descr;
138  Init();
139 }
140 
141 QError::QError(QError_ err, const std::string& file, const int line, const std::string& descr)
142 {
143  fErr = err;
144  SetDescription(file,line,descr);
145  Init();
146 }
147 
149 {
150  *this = err;
151 }
152 
153 
154 
155 
156 //_____________________________________________________________________________
157 void QError::Set(QError_ err, const std::string& descr)
158 {
159  fErr = err;
160  fDescr = descr;
161 }
162 
163 void QError::Set(QError_ err, const std::string& file, const int line, const std::string& descr)
164 {
165  fErr = err;
166  SetDescription(file,line,descr);
167 }
168 
169 
170 
171 //_____________________________________________________________________________
172 
173 //_____________________________________________________________________________
175 {
176  fErr = e;
177  return *this;
178 }
179 
180 
181 //_____________________________________________________________________________
183 {
184  fErr = e.fErr;
185  fDescr = e.fDescr;
186  return *this;
187 }
188 
189 
190 const std::string& QError::GetDescription() const
191 {
192  return fDescr;
193 }
194 
195 void QError::SetDescription(const std::string& file, const int line, const std::string& descr)
196 {
197 
198  stringstream str;
199  str<<file<<":"<<line<<": "<<descr;
200  fDescr = str.str();
201 }
202 //_____________________________________________________________________________
203 const std::string& QError::ToString() const
204 {
205  return fMap[fErr];
206 }
207 
208 
209 //_____________________________________________________________________________
210 std::ostream& operator<<(std::ostream &s ,const QError &err)
211 {
212  s<<"Error: "<<err.fMap[err.fErr];
213  if(err.GetDescription().empty())
214  s << ". No description available";
215  else
216  s << ". Description: " << err.GetDescription();
217  return s;
218 }
219 
220 
221 //_____________________________________________________________________________
222 const char* QError::what() const throw()
223 {
224  std::stringstream s;
225  s << *this;
226  std::string ret1 = s.str();
227  const char* ret = ret1.c_str();
228  return ret;
229 }
err
Definition: CheckOF.C:114
std::ostream & operator<<(std::ostream &s, const QError &err)
error stream of string error and description
Definition: QError.cc:210
QError_
underlying enum with error types
Definition: QError.hh:24
@ QERR_SHMEM_INVALID_INDEX
Definition: QError.hh:97
@ QERR_EVENT_HANDLE
Definition: QError.hh:43
@ QERR_ELE_BESSEL_READ
Definition: QError.hh:79
@ QERR_UNDEFINED_STATUS
Definition: QError.hh:51
@ QERR_EVENT_GENERIC
Definition: QError.hh:42
@ QERR_UNDEFINED_COMMAND
Definition: QError.hh:53
@ QERR_ELE_PULSER_STATUS_WRITE
Definition: QError.hh:76
@ QERR_UNDEFINED_MODE
Definition: QError.hh:63
@ QERR_EXIT
Definition: QError.hh:57
@ QERR_UNDEFINED_NUMBER
Definition: QError.hh:35
@ QERR_UNDERFLOW
Definition: QError.hh:30
@ QERR_ELE_PULSER_ATT_READ
Definition: QError.hh:80
@ QERR_ELE_BACKPLANE_WRITE
Definition: QError.hh:73
@ QERR_NET_CONNECTION_FAILED
Definition: QError.hh:93
@ QERR_SHMEM_INVALID_ID
Definition: QError.hh:98
@ QERR_VME_READ
Definition: QError.hh:86
@ QERR_DB_INCONSISTENCY
Definition: QError.hh:101
@ QERR_UNDEFINED_CRATE
Definition: QError.hh:65
@ QERR_NET_PROTOCOL
Definition: QError.hh:94
@ QERR_ELE_GENERIC_ERR
Definition: QError.hh:70
@ QERR_FILE_NOT_FOUND
Definition: QError.hh:32
@ QERR_GLOBAL_GENERIC
Definition: QError.hh:44
@ QERR_ELE_BACKPLANE_READ
Definition: QError.hh:78
@ QERR_ELE_PULSER_STATUS_READ
Definition: QError.hh:81
@ QERR_IO_FAILED
Definition: QError.hh:34
@ QERR_VME_OPEN
Definition: QError.hh:84
@ QERR_TYPE_CONVERSION
Definition: QError.hh:36
@ QERR_GLOBAL_HANDLE
Definition: QError.hh:45
@ QERR_UNDEFINED_TYPE
Definition: QError.hh:50
@ QERR_TIMEOUT
Definition: QError.hh:38
@ QERR_UNKNOWN_ERR
Definition: QError.hh:108
@ QERR_GPIB_GENERAL
Definition: QError.hh:89
@ QERR_GSL_ERROR
Definition: QError.hh:37
@ QERR_UNDEFINED_CHANNEL
Definition: QError.hh:48
@ QERR_NI
Definition: QError.hh:60
@ QERR_NOT_IMPLEMENTED
Definition: QError.hh:109
@ QERR_UNDEFINED_INTERFACE
Definition: QError.hh:55
@ QERR_ELE_FE_READ
Definition: QError.hh:77
@ QERR_OVERFLOW
Definition: QError.hh:29
@ QERR_CANNOT_OPEN_FILE
Definition: QError.hh:33
@ QERR_UNDEFINED_TARGET
Definition: QError.hh:56
@ QERR_UNDEFINED_BASKET
Definition: QError.hh:64
@ QERR_NET_UNKNOWN_HOST
Definition: QError.hh:92
@ QERR_ELE_BESSEL_WRITE
Definition: QError.hh:74
@ QERR_UNDEFINED_DEVICE
Definition: QError.hh:54
@ QERR_VME_WRITE
Definition: QError.hh:85
@ QERR_ELE_UNDEFINED_REGISTER
Definition: QError.hh:69
@ QERR_ELE_NO_ACKNOLDGEMENT
Definition: QError.hh:71
@ QERR_DB_CONN_FAILED
Definition: QError.hh:102
@ QERR_DB_NULL_RESULT
Definition: QError.hh:104
@ QERR_ELE_FE_WRITE
Definition: QError.hh:72
@ QERR_UNDEFINED_BOARD
Definition: QError.hh:66
@ QERR_DB_QUERY_FAILED
Definition: QError.hh:103
@ QERR_ELE_PULSER_ATT_WRITE
Definition: QError.hh:75
@ QERR_SIZE_NOT_MATCH
Definition: QError.hh:31
@ QERR_OUT_OF_RANGE
Definition: QError.hh:28
@ QERR_EOF
Definition: QError.hh:39
@ QERR_UNDEFINED_PARAMETER
Definition: QError.hh:52
@ QERR_DB_MAXLINES_EXCEEDED
Definition: QError.hh:105
@ QERR_SUCCESS
Definition: QError.hh:27
@ QERR_UNDEFINED_ID
Definition: QError.hh:49
error class with error type and description
Definition: QError.hh:115
virtual const char * what() const
returns the same information as operator<<
Definition: QError.cc:222
void SetDescription(const std::string &descr)
set error description
Definition: QError.hh:147
void Set(QError_ e=QERR_SUCCESS, const std::string &descr="")
set to error code and description (default is SUCCESS)
Definition: QError.cc:157
const QError & operator=(const QError_ &e)
assignement operator
Definition: QError.cc:174
static void Init()
initialization of fMap
Definition: QError.cc:14
static std::map< QError_, std::string > fMap
map of string error
Definition: QError.hh:194
QError()
Default constructor.
Definition: QError.cc:115
std::string fDescr
error description
Definition: QError.hh:187
const std::string & GetDescription() const
get error description
Definition: QError.cc:190
QError_ fErr
underlying enum
Definition: QError.hh:184
const std::string & ToString() const
error type to string conversion
Definition: QError.cc:203