CGEM BOSS 6.6.5.h
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 <iostream>
18#include <algorithm>
19using std::ostream;
20
21std::string TrkErrCode::_nullStr("");
22
23TrkErrCode::TrkErrCode(TrkSuccess succ, int code, const char* str)
24 : _string(0)
25{
26 setMessage(str);
27 if (succ) {
28 _failure = 0; _success = code;
29 } else {
30 _success = 0; _failure = code;
31 }
32}
33
34
36 : _failure(theCode._failure)
37 , _success(theCode._success)
38{
39 if (theCode._string != 0) {
40 _string = new std::string(*theCode._string);
41 }
42 else {
43 _string = 0;
44 }
45}
46
47
49 if (_string != 0) {
50 delete _string;
51 _string = 0;
52 }
53}
54
57{
58 _failure = theCode._failure;
59 _success = theCode._success;
60
61 if (theCode._string != 0) {
62 if (_string != 0) {
63 *_string = *theCode._string;
64 }
65 else {
66 _string = new std::string(*theCode._string);
67 }
68 }
69 else {
70 if (_string != 0) delete _string;
71 _string = 0;
72 }
73
74 return *this;
75}
76
77
78void
79TrkErrCode::print(ostream& ostr) const
80{
81 const char* pstatus = 0;
82 int code;
83 if (success()) {
84 pstatus = "succeeded";
85 code = success();
86 } else {
87 pstatus = "failed";
88 code = failure();
89 }
90 std::string pstring;
91 static const std::string failed[4] = { "Arithmetic error.",
92 "Failed to converge.",
93 "Failed because parallel.",
94 "Undefined error." };
95
96 static const std::string succeeded[4] = { "Normal completion.",
97 "Didn't converge.",
98 "Parallel.",
99 "Undefined success state."};
100
101 if (code > 0 && code < 10) {
102 if (failure()) {
103 pstring = failed[std::min(code-1,3) ];
104 } else if (success()) {
105 pstring = succeeded[std::min(code-1,3) ];
106 }
107 } else if (_string == 0 ) {
108 pstring = "Unknown error.";
109 } else {
110 pstring = *_string;
111 }
112
113 ostr << "TrkErrCode: " << pstatus << ", code " << code
114 << ". Status: " << pstring.c_str();
115}
116
117ostream&
118operator<<(ostream& os, const TrkErrCode& trkerr)
119{
120 trkerr.print(os);
121 return os;
122}
ostream & operator<<(ostream &os, const TrkErrCode &trkerr)
void print(std::ostream &ostr) const
int success() const
Definition TrkErrCode.h:62
TrkErrCode & operator=(const TrkErrCode &)
int failure() const
Definition TrkErrCode.h:61
TrkErrCode(TrkSuccess=succeed, int code=1, const char *str=0)
void setMessage(const char *str=0)
Definition TrkErrCode.h:70