FairRoot/PandaRoot
Log.cxx
Go to the documentation of this file.
1 #include <fstream>
2 #include "Log.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 Photospp
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;
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 PHOTOS:"<<endl;
34  return buf.seekp(0);
35 }
36 
37 
39 {
40  if(count) ++iCount;
41  if(iAction) return *out<<"INFO from PHOTOS:"<<endl;
42  return buf.seekp(0);
43 }
44 
45 
47 {
48  if(count) ++wCount;
49  if(warnLimit>0 && wCount>=warnLimit)
50  {
51  if(wAction)
52  {
53  *out<<"WARNING from PHOTOS:"<<endl<<"Limit reached ("<<warnLimit<<"). Warnings suppressed."<<endl;
54  wAction=false;
55  }
56  return buf.seekp(0);
57  }
58  if(wAction && count) return *out<<"WARNING from PHOTOS:"<<endl;
59  if(wAction) return *out;
60  return buf.seekp(0);
61 }
62 
63 
65 {
66  if(count) ++eCount;
67  if(eAction) return *out<<"ERROR from PHOTOS:"<<endl;
68  buf.seekp(0);
69  return buf;
70 }
71 
72 void Log::Assert(bool check, char *text)
73 {
74  ++asCount;
75  if(check) return;
76  ++asFailedCount;
77  if(text==NULL) *out<<"ASSERT from PHOTOS:"<<endl<<"Assertion failed. "<<endl;
78  else *out<<"ASSERT from PHOTOS:"<<endl<<"Assertion failed: "<<text<<endl;
79  if(asAction) exit(-1);
80 }
81 
82 void Log::Fatal(string text,unsigned short code)
83 {
84  ++faCount;
85  if(text.size()==0) *out<<"FATAL ERROR from PHOTOS:"<<endl<<"Terminated by a call to Log::Exit();"<<endl;
86  else *out<<"FATAL ERROR from PHOTOS: "<<endl<<text<<endl;
87  if(code<faRangeS || code>faRangeE) exit(-1);
88 }
89 
90 void Log::RedirectOutput(void (*func)(), ostream& where)
91 {
92 
93  if(!rAction) { func(); return; }
94  cout.rdbuf(where.rdbuf());
95  cerr.rdbuf(where.rdbuf());
96  where<<endl;
97  func();
98  cout.rdbuf(bCout);
99  cerr.rdbuf(bCerr);
100 }
101 
103 {
104  if(!rAction) return;
105  cout.rdbuf(where.rdbuf());
106  cerr.rdbuf(where.rdbuf());
107  where<<endl;
108 }
109 
111 {
112  *out<<"---------------------------- Photos Log Summary ------------------------------"<<endl;
113  *out<<" Debug: \t";
114  if(dRangeS>dRangeE) *out<<"(OFF)";
115  *out<<"\t\t"<<dCount<<"\t";
116  if(dRangeS<=dRangeE) *out<<"Debug range: "<<dRangeS<<" - "<<dRangeE;
117  *out<<endl;
118  *out<<" Info: \t";
119  if(!iAction) *out<<"(OFF)";
120  *out<<"\t\t"<<iCount<<"\t"<<endl;
121  *out<<" Warnings:\t";
122  if(!wAction) {if(warnLimit>0 && wCount>warnLimit) *out<<"(SUPP.)"; else *out<<"(OFF)";}
123  *out<<"\t\t"<<wCount<<"\t"<<endl;
124  *out<<" Errors: \t";
125  if(!eAction) *out<<"(OFF)";
126  *out<<"\t\t"<<eCount<<"\t"<<endl;
127  if(asCount || !asAction || faRangeS<faRangeE) cout<<"-----------------------------------"<<endl;
128  if(asCount>0) *out<<" Asserts:\t\t\t"<<asCount<<endl;
129  if(!asAction) *out<<" Failed asserts ignored:\t"<<asFailedCount<<endl;
130  if(faRangeS<=faRangeE) *out<<" Fatal errors ignored: \t"<<faCount<<endl;
131  cout<<"-----------------------------------"<<endl;
132  if(decays[3]) cout<<" Normal decays: "<<decays[3]<<endl;
133  if(decays[2]) cout<<" Decays without mother: "<<decays[2]<<endl;
134  if(decays[1]) cout<<" Decays without mother & grandmothers: "<<decays[1]<<endl;
135  if(decays[0]) cout<<" Decayed using Tauola gun: "<<decays[0]<<endl;
136  *out<<"------------------------------------------------------------------------------"<<endl;
137 }
138 
139 } // namespace Photospp
static int faRangeS
Definition: Log.h:119
static int wCount
Definition: Log.h:120
exit(0)
TF1 * func
static void Assert(bool check, char *text=NULL)
Definition: Log.cxx:72
static list< Pointer * > * PointerList
Definition: Log.h:134
static void AddDecay(int type)
Definition: Log.cxx:25
static int warnLimit
Definition: Log.h:117
static ostream & Info(bool count=true)
Definition: Log.cxx:38
static ostream & Debug(unsigned short int code=0, bool count=true)
Definition: Log.cxx:30
basic_ostream< char, char_traits< char > > ostream
static ostream * out
Definition: Log.h:115
static int decays[4]
Definition: Log.h:118
static int asFailedCount
Definition: Log.h:120
static int dRangeE
Definition: Log.h:119
static streambuf * bCout
Definition: Log.h:114
static int iCount
Definition: Log.h:120
static bool wAction
Definition: Log.h:121
static ostream & Warning(bool count=true)
Definition: Log.cxx:46
static stringstream buf
Definition: Log.h:116
static void Summary()
Definition: Log.cxx:110
static bool rAction
Definition: Log.h:121
static streambuf * bCerr
Definition: Log.h:114
static bool iAction
Definition: Log.h:121
static void Fatal(string text, unsigned short int code=0)
static int dRangeS
Definition: Log.h:119
static bool eAction
Definition: Log.h:121
static int faCount
Definition: Log.h:119
static bool asAction
Definition: Log.h:121
int count
static int eCount
Definition: Log.h:120
static int faRangeE
Definition: Log.h:119
static void RedirectOutput(void(*func)(), ostream &where=*out)
Definition: Log.cxx:90
static int asCount
Definition: Log.h:120
static ostream & Error(bool count=true)
Definition: Log.cxx:64
static int dCount
Definition: Log.h:119