QError.hh

Go to the documentation of this file.
00001 
00010 #ifndef _Q_ERR_HH_
00011 #define _Q_ERR_HH_
00012 
00013 #include <iostream>
00014 #include <string>
00015 #include <map>
00016 
00017 #include "QCuore.hh"
00018 
00022 enum QError_ {
00023   
00024   // generic errors
00025   QERR_SUCCESS,
00026   QERR_OUT_OF_RANGE,
00027   QERR_OVERFLOW ,
00028   QERR_UNDERFLOW ,
00029   QERR_SIZE_NOT_MATCH,
00030   QERR_FILE_NOT_FOUND,
00031   QERR_CANNOT_OPEN_FILE,
00032   QERR_UNDEFINED_NUMBER,
00033   QERR_TYPE_CONVERSION,
00034   QERR_GSL_ERROR,
00035   
00036   
00037   // Apollo: general errors
00038   QERR_UNDEFINED_LG,
00039   QERR_UNDEFINED_ID,
00040   QERR_UNDEFINED_TYPE,
00041   QERR_UNDEFINED_STATUS,
00042   QERR_UNDEFINED_PARAMETER,
00043   QERR_UNDEFINED_COMMAND,
00044   QERR_UNDEFINED_DEVICE,
00045   QERR_UNDEFINED_INTERFACE,
00046   QERR_UNDEFINED_TARGET,
00047 
00048   // National Instruments error codes
00049   QERR_NI,
00050 
00051   // Slow Control: specific error codes
00052   QERR_UNDEFINED_MODE,
00053   QERR_UNDEFINED_BASKET,
00054   QERR_UNDEFINED_CRATE, 
00055   QERR_UNDEFINED_BOARD, 
00056   QERR_UNDEFINED_CHANNEL,
00057 
00058   // Slow Control Error (Front-End, Bessel, Pulser, Backplane)
00059   QERR_ELE_UNDEFINED_REGISTER,
00060   QERR_ELE_GENERIC_ERR,
00061   QERR_ELE_NO_ACKNOLDGEMENT,
00062   QERR_ELE_FE_WRITE,
00063   QERR_ELE_BACKPLANE_WRITE,
00064   QERR_ELE_BESSEL_WRITE,
00065   QERR_ELE_PULSER_ATT_WRITE,
00066   QERR_ELE_PULSER_STATUS_WRITE,
00067   QERR_ELE_FE_READ,
00068   QERR_ELE_BACKPLANE_READ,
00069   QERR_ELE_BESSEL_READ,
00070   QERR_ELE_PULSER_ATT_READ,
00071   QERR_ELE_PULSER_STATUS_READ,
00072 
00073   // vme related errors
00074   QERR_VME_OPEN,
00075   QERR_VME_WRITE,
00076   QERR_VME_READ,
00077 
00078   // GPIB Errors
00079   QERR_GPIB_GENERAL,
00080 
00081   // Network communication errors
00082   QERR_NET_UNKNOWN_HOST,
00083   QERR_NET_CONNECTION_FAILED,
00084   QERR_NET_IO_FAILED,
00085   QERR_NET_WRITE_FAILED,
00086   QERR_NET_READ_FAILED,
00087   QERR_NET_PROTOCOL,
00088 
00089   // shared memory related errors
00090   QERR_SHMEM_INVALID_INDEX,
00091   QERR_SHMEM_INVALID_ID,
00092 
00093   // DataBase errors
00094   QERR_DB_INCONSISTENCY,
00095   QERR_DB_CONN_FAILED,
00096   QERR_DB_QUERY_FAILED,
00097   QERR_DB_NULL_RESULT,
00098   QERR_DB_MAXLINES_EXCEEDED,
00099 
00100   // Unknown Errors
00101   QERR_UNKNOWN_ERR,
00102   QERR_NOT_IMPLEMENTED
00103 };
00104 
00108 class QError {
00109 
00110         public:
00112                 QError();
00113 
00115                 QError(QError_ err);
00116 
00118                 QError(QError_ err, const std::string& descr);
00119         
00121                 QError(QError_ err, const std::string& file, const int line, const std::string& descr);
00122 
00124                 QError(const QError& err);
00125 
00127                 virtual ~QError() {};
00128 
00130                 const QError& operator = (const QError_ &e); 
00131 
00133                 const QError& operator = (const QError &e);
00134 
00136                 void SetDescription(const std::string& descr) {fDescr = descr;}
00137         
00139                 void SetDescription(const std::string& file, const int line, const std::string& descr);
00140 
00142                 std::string GetDescription() const;
00143 
00145                 QError_ GetCode() const {return fErr;}
00146 
00148                 const std::string& ToString() const;
00149 
00151                 bool operator == (const QError_& e) const {return fErr == e;}
00152 
00154                 bool operator == (const QError& e)  const {return fErr == e.fErr;}
00155 
00157                 bool operator != (const QError_& e) const {return fErr != e;}
00158 
00160                 bool operator != (const QError &e)  const {return fErr != e.fErr;}
00161 
00163                 void Set(QError_ e=QERR_SUCCESS, const std::string &descr="");
00164 
00165                 void Set(QError_ e, const std::string& file, const int line, const std::string &descr = "");
00166 
00167 
00168         private:
00169 
00171                 QError_ fErr;
00172 
00174                 std::string fDescr;
00175         
00177                 std::string fFile;
00178         
00180                 int fLine;
00181 
00183                 static void Init();
00184 
00186                 static std::map<QError_, std::string> fMap;
00187 
00189                 friend  std::ostream& operator<<(std::ostream &s , const QError &err); 
00190 
00191 };
00192 
00194 std::ostream& operator<<(std::ostream &s , const QError &err); 
00195 
00196 #endif

Generated on Tue Nov 16 10:49:55 2010 for CUORE Software by  doxygen 1.5.6