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