Line data Source code
1 : #include <fstream>
2 : #include "TauolaLog.h"
3 : using std::streambuf;
4 : using std::stringstream;
5 : using std::ostream;
6 : using std::cout;
7 : using std::cerr;
8 : using std::endl;
9 :
10 : namespace Tauolapp
11 : {
12 :
13 : list<Log::Pointer*> *Log::PointerList = NULL;
14 :
15 12 : streambuf *Log::bCout=cout.rdbuf(),*Log::bCerr=cerr.rdbuf();
16 : ostream *Log::out=&cout;
17 6 : stringstream Log::buf;
18 : int Log::warnLimit=100;
19 : int Log::decays[4] = {0};
20 : int Log::dCount =0,Log::dRangeS =65535,Log::dRangeE =65534;
21 : int Log::faCount=0,Log::faRangeS=65535,Log::faRangeE=65534;
22 : int Log::iCount =0,Log::wCount =0,Log::eCount =0,Log::asCount=0, Log::asFailedCount=0;
23 : bool Log::iAction=1,Log::wAction=1,Log::eAction=1,Log::asAction=1,Log::rAction=1;
24 :
25 : void Log::AddDecay(int type)
26 : {
27 0 : decays[type]++;
28 0 : }
29 :
30 : ostream& Log::Debug(unsigned short int code, bool count)
31 : {
32 0 : if(count) ++dCount;
33 0 : if(code>=dRangeS && code<=dRangeE ) return *out<<"DEBUG("<<code<<") from TAUOLA:"<<endl;
34 0 : return buf.seekp(0);
35 0 : }
36 :
37 :
38 : ostream& Log::Info(bool count)
39 : {
40 0 : if(count) ++iCount;
41 0 : if(iAction) return *out<<"INFO from TAUOLA:"<<endl;
42 0 : return buf.seekp(0);
43 0 : }
44 :
45 :
46 : ostream& Log::Warning(bool count)
47 : {
48 0 : if(count) ++wCount;
49 :
50 0 : if(warnLimit>0 && wCount>=warnLimit)
51 : {
52 0 : if(wAction)
53 : {
54 0 : *out<<"WARNING from TAUOLA:"<<endl<<"Limit reached ("<<warnLimit<<"). Warnings suppressed."<<endl;
55 0 : wAction=false;
56 0 : }
57 0 : return buf.seekp(0);
58 : }
59 :
60 0 : if(wAction && count) return *out<<"WARNING from TAUOLA:"<<endl;
61 0 : if(wAction) return *out;
62 0 : return buf.seekp(0);
63 0 : }
64 :
65 :
66 : ostream& Log::Error(bool count)
67 : {
68 0 : if(count) ++eCount;
69 0 : if(eAction) return *out<<"ERROR from TAUOLA:"<<endl;
70 0 : return buf.seekp(0);
71 0 : }
72 :
73 : void Log::Assert(bool check, char *text)
74 : {
75 0 : ++asCount;
76 0 : if(check) return;
77 :
78 0 : ++asFailedCount;
79 0 : if(text==NULL) *out<<"ASSERT from TAUOLA:"<<endl<<"Assertion failed. "<<endl;
80 0 : else *out<<"ASSERT from TAUOLA:"<<endl<<"Assertion failed: "<<text<<endl;
81 :
82 0 : if(asAction) exit(-1);
83 0 : }
84 :
85 : void Log::Fatal(string text,unsigned short code)
86 : {
87 0 : ++faCount;
88 0 : if(text.size()==0) *out<<"FATAL ERROR from TAUOLA:"<<endl<<"Terminated by a call to Log::Exit();"<<endl;
89 0 : else *out<<"FATAL ERROR from TAUOLA:"<<endl<<text<<endl;
90 0 : if(code<faRangeS || code>faRangeE) exit(-1);
91 0 : }
92 :
93 : void Log::RedirectOutput(void (*func)(), ostream& where)
94 : {
95 :
96 0 : if(!rAction) { func(); return; }
97 0 : cout.rdbuf(where.rdbuf());
98 0 : cerr.rdbuf(where.rdbuf());
99 0 : where<<endl;
100 0 : func();
101 0 : cout.rdbuf(bCout);
102 0 : cerr.rdbuf(bCerr);
103 0 : }
104 :
105 : void Log::RedirectOutput(ostream& where)
106 : {
107 0 : if(!rAction) return;
108 0 : cout.rdbuf(where.rdbuf());
109 0 : cerr.rdbuf(where.rdbuf());
110 0 : where<<endl;
111 0 : }
112 :
113 : void Log::Summary()
114 : {
115 0 : *out<<"---------------------------- Tauola Log Summary ------------------------------"<<endl;
116 :
117 : // Debug
118 0 : *out<<" Debug: \t";
119 0 : if(dRangeS>dRangeE) *out<<"(OFF)";
120 0 : *out<<"\t\t"<<dCount<<"\t";
121 0 : if(dRangeS<=dRangeE) *out<<"Debug range: "<<dRangeS<<" - "<<dRangeE;
122 0 : *out<<endl;
123 :
124 : // Info
125 0 : *out<<" Info: \t";
126 0 : if(!iAction) *out<<"(OFF)";
127 0 : *out<<"\t\t"<<iCount<<"\t"<<endl;
128 :
129 : // Warnings
130 0 : *out<<" Warnings:\t";
131 0 : if(!wAction)
132 : {
133 0 : if(warnLimit>0 && wCount>warnLimit) *out<<"(SUPP.)";
134 0 : else *out<<"(OFF)";
135 : }
136 0 : *out<<"\t\t"<<wCount<<"\t"<<endl;
137 :
138 : // Errors
139 0 : *out<<" Errors: \t";
140 0 : if(!eAction) *out<<"(OFF)";
141 0 : *out<<"\t\t"<<eCount<<"\t"<<endl;
142 :
143 : // Counters
144 0 : if(asCount || !asAction || faRangeS<faRangeE) cout<<"-----------------------------------"<<endl;
145 0 : if(asCount>0) *out<<" Asserts: "<<asCount<<endl;
146 0 : if(!asAction) *out<<" Failed asserts ignored: "<<asFailedCount<<endl;
147 0 : if(faRangeS<=faRangeE) *out<<" Fatal errors ignored: "<<faCount<<endl;
148 :
149 0 : cout<<"-----------------------------------"<<endl;
150 0 : if(decays[3]) cout<<" Normal decays: "<<decays[3]<<endl;
151 0 : if(decays[2]) cout<<" Decays without mother: "<<decays[2]<<endl;
152 0 : if(decays[1]) cout<<" Decays without mother & grandmothers: "<<decays[1]<<endl;
153 0 : if(decays[0]) cout<<" Decayed using Tauola gun: "<<decays[0]<<endl;
154 0 : *out<<"------------------------------------------------------------------------------"<<endl;
155 0 : }
156 :
157 : } // namespace Tauolapp
|