LCOV - code coverage report
Current view: top level - TEvtGen/Photos/src/utilities - Log.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 158 1.3 %
Date: 2016-06-14 17:26:59 Functions: 3 15 20.0 %

          Line data    Source code
       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             : void (*PHOERR)(int,const char*,double) = Log::PHOERR;
      14             : void (*PHOREP)()                       = Log::PHOREP;
      15             : 
      16             : list<Log::Pointer*> *Log::PointerList = NULL;
      17             : 
      18          12 : streambuf   *Log::bCout=cout.rdbuf(),*Log::bCerr=cerr.rdbuf();
      19             : ostream     *Log::out=&cout;
      20           6 : stringstream Log::buf;
      21             : int  Log::warnLimit=100;
      22             : int  Log::decays[4] = {0};
      23             : int  Log::dCount =0,Log::dRangeS =65535,Log::dRangeE =65534;
      24             : int  Log::faCount=0,Log::faRangeS=65535,Log::faRangeE=65534;
      25             : int  Log::iCount =0,Log::wCount =0,Log::eCount =0,Log::asCount=0, Log::asFailedCount=0;
      26             : bool Log::iAction=1,Log::wAction=1,Log::eAction=1,Log::asAction=1,Log::rAction=1;
      27             : 
      28             : void Log::AddDecay(int type)
      29             : {
      30           0 :         decays[type]++;
      31           0 : }
      32             : 
      33             : ostream& Log::Debug(unsigned short int code, bool count)
      34             : {
      35           0 :         if(count) ++dCount;
      36           0 :         if(code>=dRangeS && code<=dRangeE ) return *out<<"DEBUG("<<code<<") from PHOTOS:"<<endl;
      37           0 :         return buf.seekp(0);
      38           0 : }
      39             : 
      40             : 
      41             : ostream& Log::Info(bool count)
      42             : {
      43           0 :         if(count) ++iCount;
      44           0 :         if(iAction) return *out<<"INFO from PHOTOS:"<<endl;
      45           0 :         return buf.seekp(0);
      46           0 : }
      47             : 
      48             : 
      49             : ostream& Log::Warning(bool count)
      50             : {
      51           0 :         if(count) ++wCount;
      52           0 :         if(warnLimit>0 && wCount>=warnLimit)
      53             :         {
      54           0 :                 if(wAction)
      55             :                 {
      56           0 :                         *out<<"WARNING from PHOTOS:"<<endl<<"Limit reached ("<<warnLimit<<"). Warnings suppressed."<<endl;
      57           0 :                         wAction=false;
      58           0 :                 }
      59           0 :                 return buf.seekp(0);
      60             :         }
      61           0 :         if(wAction && count) return *out<<"WARNING from PHOTOS:"<<endl;
      62           0 :         if(wAction)          return *out;
      63           0 :         return buf.seekp(0);
      64           0 : }
      65             : 
      66             : 
      67             : ostream& Log::Error(bool count)
      68             : {
      69           0 :         if(count) ++eCount;
      70           0 :         if(eAction) return *out<<"ERROR from PHOTOS:"<<endl;
      71           0 :         buf.seekp(0);
      72           0 :         return buf;
      73           0 : }
      74             : 
      75             : void Log::Assert(bool check, char *text)
      76             : {
      77           0 :         ++asCount;
      78           0 :         if(check) return;
      79           0 :         ++asFailedCount;
      80           0 :         if(text==NULL)  *out<<"ASSERT from PHOTOS:"<<endl<<"Assertion failed. "<<endl;
      81           0 :         else *out<<"ASSERT from PHOTOS:"<<endl<<"Assertion failed: "<<text<<endl;
      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 PHOTOS:"<<endl<<"Terminated by a call to Log::Exit();"<<endl;
      89           0 :         else *out<<"FATAL ERROR from PHOTOS: "<<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<<"---------------------------- Photos Log Summary ------------------------------"<<endl;
     116           0 :         *out<<" Debug:   \t";
     117           0 :         if(dRangeS>dRangeE) *out<<"(OFF)";
     118           0 :         *out<<"\t\t"<<dCount<<"\t";
     119           0 :         if(dRangeS<=dRangeE) *out<<"Debug range: "<<dRangeS<<" - "<<dRangeE;
     120           0 :         *out<<endl;
     121           0 :         *out<<" Info:    \t";
     122           0 :         if(!iAction) *out<<"(OFF)";
     123           0 :         *out<<"\t\t"<<iCount<<"\t"<<endl;
     124           0 :         *out<<" Warnings:\t";
     125           0 :         if(!wAction) if(warnLimit>0 && wCount>warnLimit) *out<<"(SUPP.)"; else *out<<"(OFF)";
     126           0 :         *out<<"\t\t"<<wCount<<"\t"<<endl;
     127           0 :         *out<<" Errors:  \t";
     128           0 :         if(!eAction) *out<<"(OFF)";
     129           0 :         *out<<"\t\t"<<eCount<<"\t"<<endl;
     130           0 :         if(asCount || !asAction || faRangeS<faRangeE) cout<<"-----------------------------------"<<endl;
     131           0 :         if(asCount>0) *out<<" Asserts:\t\t\t"<<asCount<<endl;
     132           0 :         if(!asAction) *out<<" Failed asserts ignored:\t"<<asFailedCount<<endl;
     133           0 :         if(faRangeS<=faRangeE) *out<<" Fatal errors ignored:  \t"<<faCount<<endl;
     134           0 :         cout<<"-----------------------------------"<<endl;
     135           0 :         if(decays[3]) cout<<" Normal decays:                        "<<decays[3]<<endl;
     136           0 :         if(decays[2]) cout<<" Decays without mother:                "<<decays[2]<<endl;
     137           0 :         if(decays[1]) cout<<" Decays without mother & grandmothers: "<<decays[1]<<endl;
     138           0 :         if(decays[0]) cout<<" Decayed using Tauola gun:             "<<decays[0]<<endl;
     139           0 :         *out<<"------------------------------------------------------------------------------"<<endl;
     140           0 : }
     141             : 
     142             : 
     143             : //----------------------------------------------------------------------
     144             : //
     145             : //    PHOTOS:   PHOton radiation in decays ERRror handling
     146             : //
     147             : //    Purpose:  Inform user  about (fatal) errors and warnings generated
     148             : //              by either the user or the program.
     149             : //
     150             : //    Input Parameters:   IMES, TEXT, DATA
     151             : //
     152             : //    Output Parameters:  None
     153             : //
     154             : //    Author(s):  B. van Eijk                     Created at:  29/11/89
     155             : //                                                Last Update: 18/06/13
     156             : //
     157             : //----------------------------------------------------------------------
     158             : void Log::PHOERR(int IMES,const char *TEXT,double DATA){
     159             : 
     160             :   static int IERROR=0;
     161             :   double  SDATA;
     162             :   static int PHOMES=10;
     163             :   static int i=1;
     164           0 :   char star80[81]= "********************************************************************************";
     165             : 
     166           0 :   if (IMES<=PHOMES) phosta_.status[IMES-i]=phosta_.status[IMES-i]+1;
     167             : // 
     168             : //    Count number of non-fatal errors...
     169           0 :   if ((IMES ==  6) && (phosta_.status[IMES-i]>=2)) return;
     170           0 :   if ((IMES == 10) && (phosta_.status[IMES-i]>=2)) return;
     171             :   SDATA=DATA;
     172             :   //  int PHLUN=(int)pholun_.phlun;
     173           0 :   bool IFSTOP=phosta_.ifstop;
     174           0 :   FILE *PHLUN = stdout;
     175             :   int furthA=0;
     176           0 :   fprintf(PHLUN,"%s\n",star80);
     177           0 :   fprintf(PHLUN,"*\n");  //9120
     178             :   //      GOTO (10,20,30,40,50,60,70,80,90,100),IMES
     179             : 
     180           0 :   switch(IMES){
     181             :   case 1:
     182           0 :     fprintf(PHLUN,"* %s: Too many charged Particles, NCHARG = %6i\n", TEXT,(int)SDATA);   //I6
     183             :     furthA= 110;
     184           0 :     break;
     185             :   case 2:
     186           0 :     fprintf(PHLUN,"* %s: Too much Bremsstrahlung required, PRSOFT = %15.6f\n", TEXT,SDATA);//F15.6
     187             :     furthA= 110;
     188           0 :     break;
     189             :   case 3:
     190           0 :     fprintf(PHLUN,"* %s: Combined Weight is exceeding 1., Weight = %15.6f\n", TEXT,SDATA);   //F15.6
     191             :     furthA= 110;
     192           0 :     break;
     193             :   case 4:
     194           0 :     fprintf(PHLUN,"* %s: Error in Rescaling charged and neutral Vectors\n", TEXT);
     195             :     furthA= 110;
     196           0 :     break;
     197             :   case 5:
     198           0 :     fprintf(PHLUN,"* %s: Non matching charged Particle Pointer, NCHARG = %5i\n", TEXT,(int)SDATA);  //I5
     199             :     furthA= 110;
     200           0 :     break;
     201             :   case 6:
     202           0 :     fprintf(PHLUN,"* %s: Do you really work with a Particle of Spin: %4.1f\n", TEXT,SDATA);   //F4.1
     203             :     furthA= 130;
     204           0 :     break;
     205             :   case 7:
     206           0 :     fprintf(PHLUN,"* %s: Stack Length exceeded, NSTACK = %5i\n", TEXT,(int)(SDATA));//I5
     207             :     furthA= 110;
     208           0 :     break;
     209             :   case 8:
     210           0 :     fprintf(PHLUN,"* %s: Random Number Generator Seed(1) out of Range: %8i\n", TEXT,(int)SDATA);//I8
     211             :     furthA= 110;
     212           0 :     break;
     213             :   case 9:
     214           0 :     fprintf(PHLUN,"* %s: Random Number Generator Seed(2) out of Range: %8i\n", TEXT,(int)SDATA);//I8
     215             :     furthA= 110;
     216           0 :     break;
     217             :   case 10:
     218           0 :     fprintf(PHLUN,"* %s: Available Phase Space below Cut-off: %15.6f GeV/c^2\n", TEXT,SDATA);//F15.6
     219             :     furthA= 130;
     220           0 :     break;
     221             :   default:
     222           0 :     fprintf(PHLUN,"* Funny Error Message: %4i ! What to do ?\n", IMES);//I4
     223             :     furthA= 120;
     224           0 :     break;
     225             :   }
     226             : 
     227           0 :  switch(furthA){
     228             :  case 110:
     229           0 :    fprintf(PHLUN,"* Fatal Error Message, I stop this Run !\n");
     230           0 :    fprintf(PHLUN,"*\n"); //9120
     231           0 :    fprintf(PHLUN,"%s\n",star80);
     232           0 :    if (IFSTOP){ 
     233           0 :      exit(-1);
     234             :    }
     235             :    else{
     236           0 :      fprintf(PHLUN,"*\n"); //9120
     237           0 :      fprintf(PHLUN,"%s\n",star80);
     238           0 :      break;
     239             :    }      
     240             :  case 120:
     241           0 :    IERROR=IERROR+1;
     242           0 :    if (IERROR>=10){
     243           0 :      fprintf(PHLUN,"* 10 Error Messages generated, I stop this Run !\n");
     244           0 :      fprintf(PHLUN,"*\n");//9120
     245           0 :      fprintf(PHLUN,"%s\n",star80);
     246           0 :      if (IFSTOP){
     247           0 :        exit(-1);
     248             :      }
     249             :      else{
     250           0 :        fprintf(PHLUN,"*\n"); //9120
     251           0 :        fprintf(PHLUN,"%s\n",star80);
     252           0 :        break;
     253             :      }
     254             :    }  
     255             :  case 130:
     256           0 :   fprintf(PHLUN,"*\n");  //9120
     257           0 :   fprintf(PHLUN,"%s\n",star80);
     258           0 :   break;
     259             :  }
     260             :  return;
     261             : 
     262             : 
     263             :  //9120 FORMAT(1H ,'*',T81,'*')
     264             :  // 9140 FORMAT(1H ,'* Fatal Error Message, I stop this Run !',T81,'*')
     265             :  // 9150 FORMAT(1H ,'* 10 Error Messages generated, I stop this Run !',T81,
     266             :  //     &'*')
     267           0 : }
     268             : 
     269             : 
     270             : //----------------------------------------------------------------------
     271             : //
     272             : //    PHOTOS:   PHOton radiation in decays run summary REPort
     273             : //
     274             : //    Purpose:  Inform user about success and/or restrictions of PHOTOS
     275             : //              encountered during execution.
     276             : //
     277             : //    Input Parameters:   Common /PHOSTA/
     278             : //
     279             : //    Output Parameters:  None
     280             : //
     281             : //    Author(s):  B. van Eijk                     Created at:  10/01/92
     282             : //                                                Last Update: 18/06/13
     283             : //
     284             : //----------------------------------------------------------------------
     285             : void Log::PHOREP(){
     286             :   static int PHOMES=10;
     287             :   int I;
     288             :   bool ERROR=false;
     289             :   //  int PHLUN=(int)pholun_.phlun;
     290           0 :   char star80[81]= "********************************************************************************";
     291           0 :   char X26[27] = "                          ";
     292           0 :   char EQ25[26]= "=========================";
     293           0 :   char X30[31] = "                              ";
     294           0 :   char X22[23] = "                      ";
     295           0 :   char X23[24 ]= "                       ";
     296           0 :   char X16[17] = "                ";
     297           0 :   FILE *PHLUN = stdout;
     298           0 :   fprintf(PHLUN," \n");
     299           0 :   fprintf(PHLUN,"%s\n",star80);
     300           0 :   fprintf(PHLUN,"*\n");
     301           0 :   fprintf(PHLUN,"* %s %s\n",X26,EQ25);
     302           0 :   fprintf(PHLUN,"* %s PHOTOS Run Summary\n",X30);
     303           0 :   fprintf(PHLUN,"* %s %s\n",X26,EQ25);
     304           0 :   fprintf(PHLUN,"*\n");
     305           0 :   for(I=1;I<=PHOMES;I++){
     306             : 
     307           0 :     if (phosta_.status[I-1] == 0) break;
     308           0 :     if ((I == 6)|| (I == 10)){
     309           0 :       fprintf(PHLUN,"* %s Warning # %2i  occured %6i times\n",X22, I,phosta_.status[I-1]); // I2 I6 
     310           0 :     }
     311             :     else{
     312             :       ERROR=true;
     313           0 :       fprintf(PHLUN,"* %s Error # %2i occured %6i  times\n",X23, I,phosta_.status[I-1]);// I2 I6
     314             :     }         
     315             :   }
     316             : 
     317           0 :   if (!ERROR) fprintf(PHLUN,"* %s PHOTOS Execution has successfully terminated\n",X16);
     318           0 :   fprintf(PHLUN,"*\n");
     319           0 :   fprintf(PHLUN,"%s\n",star80);
     320             :   return;
     321             : 
     322             : //      RETURN
     323             : // 9000 FORMAT(1H1)
     324             : // 9010 FORMAT(1H ,80('*'))
     325             : // 9020 FORMAT(1H ,'*',T81,'*')
     326             : // 9030 FORMAT(1H ,'*',26X,25('='),T81,'*')
     327             : // 9040 FORMAT(1H ,'*',30X,'PHOTOS Run Summary',T81,'*')
     328             : // 9050 FORMAT(1H ,'*',22X,'Warning #',I2,' occured',I6,' times',T81,'*')
     329             : // 9060 FORMAT(1H ,'*',23X,'Error #',I2,' occured',I6,' times',T81,'*')
     330             : // 9070 FORMAT(1H ,'*',16X,'PHOTOS Execution has successfully terminated',
     331             : //     &T81,'*')
     332           0 : }
     333             : 
     334             : 
     335             : 
     336             : 
     337             : 
     338             : } // namespace Photospp

Generated by: LCOV version 1.11