Log.cxx

00001 #include <fstream>
00002 #include "Log.h"
00003 using std::streambuf;
00004 using std::stringstream;
00005 using std::ostream;
00006 using std::cout;
00007 using std::cerr;
00008 using std::endl;
00009 
00010 namespace Tauolapp
00011 {
00012 
00013 list<Log::Pointer*> *Log::PointerList = NULL;
00014 
00015 streambuf   *Log::bCout=cout.rdbuf(),*Log::bCerr=cerr.rdbuf();
00016 ostream     *Log::out=&cout;
00017 stringstream Log::buf;
00018 int  Log::warnLimit=100;
00019 int  Log::decays[4] = {0};
00020 int  Log::dCount =0,Log::dRangeS =65535,Log::dRangeE =65534;
00021 int  Log::faCount=0,Log::faRangeS=65535,Log::faRangeE=65534;
00022 int  Log::iCount =0,Log::wCount =0,Log::eCount =0,Log::asCount=0, Log::asFailedCount=0;
00023 bool Log::iAction=1,Log::wAction=1,Log::eAction=1,Log::asAction=1,Log::rAction=1;
00024 
00025 void Log::AddDecay(int type)
00026 {
00027   decays[type]++;
00028 }
00029 
00030 ostream& Log::Debug(unsigned short int code, bool count)
00031 {
00032   if(count) ++dCount;
00033   if(code>=dRangeS && code<=dRangeE ) return *out<<"DEBUG("<<code<<") from TAUOLA:"<<endl;
00034   return buf.seekp(0);
00035 }
00036 
00037 
00038 ostream& Log::Info(bool count)
00039 {
00040   if(count) ++iCount;
00041   if(iAction) return *out<<"INFO from TAUOLA:"<<endl;
00042   return buf.seekp(0);
00043 }
00044 
00045 
00046 ostream& Log::Warning(bool count)
00047 {
00048   if(count) ++wCount;
00049 
00050   if(warnLimit>0 && wCount>=warnLimit)
00051   {
00052     if(wAction)
00053     {
00054       *out<<"WARNING from TAUOLA:"<<endl<<"Limit reached ("<<warnLimit<<"). Warnings suppressed."<<endl;
00055       wAction=false;
00056     }
00057     return buf.seekp(0);
00058   }
00059 
00060   if(wAction && count) return *out<<"WARNING from TAUOLA:"<<endl;
00061   if(wAction)          return *out;
00062   return buf.seekp(0);
00063 }
00064 
00065 
00066 ostream& Log::Error(bool count)
00067 {
00068   if(count) ++eCount;
00069   if(eAction) return *out<<"ERROR from TAUOLA:"<<endl;
00070   return buf.seekp(0);
00071 }
00072 
00073 void Log::Assert(bool check, char *text)
00074 {
00075   ++asCount;
00076   if(check) return;
00077 
00078   ++asFailedCount;
00079   if(text==NULL)  *out<<"ASSERT from TAUOLA:"<<endl<<"Assertion failed. "<<endl;
00080   else            *out<<"ASSERT from TAUOLA:"<<endl<<"Assertion failed: "<<text<<endl;
00081 
00082   if(asAction) exit(-1);
00083 }
00084 
00085 void Log::Fatal(string text,unsigned short code)
00086 {
00087   ++faCount;
00088   if(text.size()==0) *out<<"FATAL ERROR from TAUOLA:"<<endl<<"Terminated by a call to Log::Exit();"<<endl;
00089   else               *out<<"FATAL ERROR from TAUOLA:"<<endl<<text<<endl;
00090   if(code<faRangeS || code>faRangeE) exit(-1);
00091 }
00092 
00093 void Log::RedirectOutput(void (*func)(), ostream& where)
00094 {
00095 
00096   if(!rAction) { func(); return; }
00097   cout.rdbuf(where.rdbuf());
00098   cerr.rdbuf(where.rdbuf());
00099   where<<endl;
00100   func();
00101   cout.rdbuf(bCout);
00102   cerr.rdbuf(bCerr);
00103 }
00104 
00105 void Log::RedirectOutput(ostream& where)
00106 {
00107   if(!rAction) return;
00108   cout.rdbuf(where.rdbuf());
00109   cerr.rdbuf(where.rdbuf());
00110   where<<endl;
00111 }
00112 
00113 void Log::Summary()
00114 {
00115   *out<<"---------------------------- Tauola Log Summary ------------------------------"<<endl;
00116 
00117   // Debug
00118   *out<<" Debug:   \t";
00119   if(dRangeS>dRangeE)  *out<<"(OFF)";
00120   *out<<"\t\t"<<dCount<<"\t";
00121   if(dRangeS<=dRangeE) *out<<"Debug range: "<<dRangeS<<" - "<<dRangeE;
00122   *out<<endl;
00123 
00124   // Info
00125   *out<<" Info:    \t";
00126   if(!iAction) *out<<"(OFF)";
00127   *out<<"\t\t"<<iCount<<"\t"<<endl;
00128 
00129   // Warnings
00130   *out<<" Warnings:\t";
00131   if(!wAction)
00132   {
00133     if(warnLimit>0 && wCount>warnLimit) *out<<"(SUPP.)";
00134     else                                *out<<"(OFF)";
00135   }
00136   *out<<"\t\t"<<wCount<<"\t"<<endl;
00137 
00138   // Errors
00139   *out<<" Errors:  \t";
00140   if(!eAction) *out<<"(OFF)";
00141   *out<<"\t\t"<<eCount<<"\t"<<endl;
00142 
00143   // Counters
00144   if(asCount || !asAction || faRangeS<faRangeE) cout<<"-----------------------------------"<<endl;
00145   if(asCount>0)          *out<<" Asserts:                     "<<asCount<<endl;
00146   if(!asAction)          *out<<" Failed asserts ignored:      "<<asFailedCount<<endl;
00147   if(faRangeS<=faRangeE) *out<<" Fatal errors ignored:        "<<faCount<<endl;
00148 
00149   cout<<"-----------------------------------"<<endl;
00150   if(decays[3]) cout<<" Normal decays:                        "<<decays[3]<<endl;
00151   if(decays[2]) cout<<" Decays without mother:                "<<decays[2]<<endl;
00152   if(decays[1]) cout<<" Decays without mother & grandmothers: "<<decays[1]<<endl;
00153   if(decays[0]) cout<<" Decayed using Tauola gun:             "<<decays[0]<<endl;
00154   *out<<"------------------------------------------------------------------------------"<<endl;
00155 }
00156 
00157 } // namespace Tauolapp
Generated on Sun Oct 20 20:24:08 2013 for C++InterfacetoTauola by  doxygen 1.6.3