BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TrkErrCode.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkErrCode.cxx,v 1.1.1.1 2005/04/21 06:01:42 zhangy Exp $
4//
5// Description:
6//
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author(s): Steve Schaffner
12//
13// Revision History:
14// 20000420 M. Kelsey -- Remove terminating endl in print().
15//------------------------------------------------------------------------
16#include "TrkBase/TrkErrCode.h"
17#include <algorithm>
18#include <iostream>
19using std::ostream;
20
21std::string TrkErrCode::_nullStr( "" );
22
23TrkErrCode::TrkErrCode( TrkSuccess succ, int code, const char* str ) : _string( 0 ) {
24 setMessage( str );
25 if ( succ )
26 {
27 _failure = 0;
28 _success = code;
29 }
30 else
31 {
32 _success = 0;
33 _failure = code;
34 }
35}
36
38 : _failure( theCode._failure ), _success( theCode._success ) {
39 if ( theCode._string != 0 ) { _string = new std::string( *theCode._string ); }
40 else { _string = 0; }
41}
42
44 if ( _string != 0 )
45 {
46 delete _string;
47 _string = 0;
48 }
49}
50
52 _failure = theCode._failure;
53 _success = theCode._success;
54
55 if ( theCode._string != 0 )
56 {
57 if ( _string != 0 ) { *_string = *theCode._string; }
58 else { _string = new std::string( *theCode._string ); }
59 }
60 else
61 {
62 if ( _string != 0 ) delete _string;
63 _string = 0;
64 }
65
66 return *this;
67}
68
69void TrkErrCode::print( ostream& ostr ) const {
70 const char* pstatus = 0;
71 int code;
72 if ( success() )
73 {
74 pstatus = "succeeded";
75 code = success();
76 }
77 else
78 {
79 pstatus = "failed";
80 code = failure();
81 }
82 std::string pstring;
83 static const std::string failed[4] = { "Arithmetic error.", "Failed to converge.",
84 "Failed because parallel.", "Undefined error." };
85
86 static const std::string succeeded[4] = { "Normal completion.", "Didn't converge.",
87 "Parallel.", "Undefined success state." };
88
89 if ( code > 0 && code < 10 )
90 {
91 if ( failure() ) { pstring = failed[std::min( code - 1, 3 )]; }
92 else if ( success() ) { pstring = succeeded[std::min( code - 1, 3 )]; }
93 }
94 else if ( _string == 0 ) { pstring = "Unknown error."; }
95 else { pstring = *_string; }
96
97 ostr << "TrkErrCode: " << pstatus << ", code " << code << ". Status: " << pstring.c_str();
98}
99
100ostream& operator<<( ostream& os, const TrkErrCode& trkerr ) {
101 trkerr.print( os );
102 return os;
103}
ostream & operator<<(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)