BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Reconstruction/MdcPatRec/TrkBase/include/TrkBase/TrkErrCode.h
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkErrCode.h,v 1.1.1.1 2005/04/21 06:01:42 zhangy Exp $
4//
5// Description:
6// Encapsulate error/success status of tracking operations.
7// Either failure() or success() will be non-zero, but not both.
8// Failure => no valid answer available.
9// Success => a valid answer has been
10// provided, even if it wasn't exactly what you asked for. The
11// value of failure() or success() distinguishes different
12// failure/success modes. A string describing the success/failure
13// mode can also be provided, and printed by the user.
14//
15// Note that if this string is provided by the called function,
16// it _must_ be a pointer to a statically stored string (which includes
17// string literals). E.g.
18// TrkErrCode err;
19// err.setFailure(10,"Forgot to tie my shoelaces.");
20// return err;
21// is valid.
22//
23// Several codes have predefined meanings and strings; strings
24// supplied for them will be ignored. Strings for codes >= 10
25// can be supplied by users. Predefined:
26// failure = 1 -- "Arithmetic error."
27// = 2 -- "Failed to converge."
28// = 3 -- "Failed because parallel."
29// = 4-9 -- reserved until I think of some more standard codes
30// success = 1 -- "Normal completion."
31// = 2 -- "Didn't converge."
32// = 3 -- "Parallel"
33// = 4-9 -- reserved
34//
35// Environment:
36// Software developed for the BaBar Detector at the SLAC B-Factory.
37//
38// Authors: (Steve Schaffner) -- initial implementation stolen from A. Snyder
39//
40//------------------------------------------------------------------------
41#ifndef TRKERRCODE_HH
42#define TRKERRCODE_HH
43
44#include <iosfwd>
45#include <string>
46
47// Class interface //
48class TrkErrCode {
49public:
51
52 TrkErrCode( TrkSuccess = succeed, int code = 1, const char* str = 0 );
54
55 // Copy constructors
58
59 // access
60 int failure() const { return _failure; }
61 int success() const { return _success; }
62 const std::string& message() const { return ( _string != 0 ) ? *_string : _nullStr; }
63 void print( std::ostream& ostr ) const;
64
65 // set
66 void setMessage( const char* str = 0 ) {
67 if ( _string != 0 ) delete _string;
68 if ( str != 0 ) { _string = new std::string( str ); }
69 else { _string = 0; }
70 }
71 void setFailure( int i, const char* str = 0 ) {
72 setMessage( str );
73 _failure = ( i == 0 ? 1 : i );
74 _success = 0;
75 }
76 void setSuccess( int i, const char* str = 0 ) {
77 setMessage( str );
78 _success = ( i == 0 ? 1 : i );
79 _failure = 0;
80 }
81
82private:
83 // Data
84 int _failure;
85 int _success;
86 std::string* _string;
87 static std::string _nullStr;
88};
89
90std::ostream& operator<<( std::ostream& os, const TrkErrCode& trkerr );
91
92#endif
std::ostream & operator<<(std::ostream &os, const TrkErrCode &trkerr)
void print(std::ostream &ostr) const
TrkErrCode & operator=(const TrkErrCode &)
TrkErrCode(TrkSuccess=succeed, int code=1, const char *str=0)
TrkErrCode(const TrkErrCode &)