Log.cxx
1#include <fstream>
2#include "Log.h"
3using std::streambuf;
4using std::stringstream;
5using std::ostream;
6using std::cout;
7using std::cerr;
8using std::endl;
9
10namespace Photospp
11{
12
13void (*PHOERR)(int,const char*,double) = Log::PHOERR;
14void (*PHOREP)() = Log::PHOREP;
15
16list<Log::Pointer*> *Log::PointerList = NULL;
17
18streambuf *Log::bCout=cout.rdbuf(),*Log::bCerr=cerr.rdbuf();
19ostream *Log::out=&cout;
20stringstream Log::buf;
21int Log::warnLimit=100;
22int Log::decays[4] = {0};
23int Log::dCount =0,Log::dRangeS =65535,Log::dRangeE =65534;
24int Log::faCount=0,Log::faRangeS=65535,Log::faRangeE=65534;
25int Log::iCount =0,Log::wCount =0,Log::eCount =0,Log::asCount=0, Log::asFailedCount=0;
26bool Log::iAction=1,Log::wAction=1,Log::eAction=1,Log::asAction=1,Log::rAction=1;
27
28void Log::AddDecay(int type)
29{
30 decays[type]++;
31}
32
33ostream& Log::Debug(unsigned short int code, bool count)
34{
35 if(count) ++dCount;
36 if(code>=dRangeS && code<=dRangeE ) return *out<<"DEBUG("<<code<<") from PHOTOS:"<<endl;
37 return buf.seekp(0);
38}
39
40
41ostream& Log::Info(bool count)
42{
43 if(count) ++iCount;
44 if(iAction) return *out<<"INFO from PHOTOS:"<<endl;
45 return buf.seekp(0);
46}
47
48
49ostream& Log::Warning(bool count)
50{
51 if(count) ++wCount;
52 if(warnLimit>0 && wCount>=warnLimit)
53 {
54 if(wAction)
55 {
56 *out<<"WARNING from PHOTOS:"<<endl<<"Limit reached ("<<warnLimit<<"). Warnings suppressed."<<endl;
57 wAction=false;
58 }
59 return buf.seekp(0);
60 }
61 if(wAction && count) return *out<<"WARNING from PHOTOS:"<<endl;
62 if(wAction) return *out;
63 return buf.seekp(0);
64}
65
66
67ostream& Log::Error(bool count)
68{
69 if(count) ++eCount;
70 if(eAction) return *out<<"ERROR from PHOTOS:"<<endl;
71 buf.seekp(0);
72 return buf;
73}
74
75void Log::Assert(bool check, char *text)
76{
77 ++asCount;
78 if(check) return;
79 ++asFailedCount;
80 if(text==NULL) *out<<"ASSERT from PHOTOS:"<<endl<<"Assertion failed. "<<endl;
81 else *out<<"ASSERT from PHOTOS:"<<endl<<"Assertion failed: "<<text<<endl;
82 if(asAction) exit(-1);
83}
84
85void Log::Fatal(string text,unsigned short code)
86{
87 ++faCount;
88 if(text.size()==0) *out<<"FATAL ERROR from PHOTOS:"<<endl<<"Terminated by a call to Log::Exit();"<<endl;
89 else *out<<"FATAL ERROR from PHOTOS: "<<endl<<text<<endl;
90 if(code<faRangeS || code>faRangeE) exit(-1);
91}
92
93void 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
105void Log::RedirectOutput(ostream& where)
106{
107 if(!rAction) return;
108 cout.rdbuf(where.rdbuf());
109 cerr.rdbuf(where.rdbuf());
110 where<<endl;
111}
112
114{
115 *out<<"---------------------------- Photos Log Summary ------------------------------"<<endl;
116 *out<<" Debug: \t";
117 if(dRangeS>dRangeE) *out<<"(OFF)";
118 *out<<"\t\t"<<dCount<<"\t";
119 if(dRangeS<=dRangeE) *out<<"Debug range: "<<dRangeS<<" - "<<dRangeE;
120 *out<<endl;
121 *out<<" Info: \t";
122 if(!iAction) *out<<"(OFF)";
123 *out<<"\t\t"<<iCount<<"\t"<<endl;
124 *out<<" Warnings:\t";
125 if(!wAction) { if(warnLimit>0 && wCount>warnLimit) *out<<"(SUPP.)"; else *out<<"(OFF)"; }
126 *out<<"\t\t"<<wCount<<"\t"<<endl;
127 *out<<" Errors: \t";
128 if(!eAction) *out<<"(OFF)";
129 *out<<"\t\t"<<eCount<<"\t"<<endl;
130 if(asCount || !asAction || faRangeS<faRangeE) cout<<"-----------------------------------"<<endl;
131 if(asCount>0) *out<<" Asserts:\t\t\t"<<asCount<<endl;
132 if(!asAction) *out<<" Failed asserts ignored:\t"<<asFailedCount<<endl;
133 if(faRangeS<=faRangeE) *out<<" Fatal errors ignored: \t"<<faCount<<endl;
134 cout<<"-----------------------------------"<<endl;
135 if(decays[3]) cout<<" Normal decays: "<<decays[3]<<endl;
136 if(decays[2]) cout<<" Decays without mother: "<<decays[2]<<endl;
137 if(decays[1]) cout<<" Decays without mother & grandmothers: "<<decays[1]<<endl;
138 if(decays[0]) cout<<" Decayed using Tauola gun: "<<decays[0]<<endl;
139 *out<<"------------------------------------------------------------------------------"<<endl;
140}
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//----------------------------------------------------------------------
158void 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 char star80[81]= "********************************************************************************";
165
166 if (IMES<=PHOMES) phosta.status[IMES-i]=phosta.status[IMES-i]+1;
167//
168// Count number of non-fatal errors...
169 if ((IMES == 6) && (phosta.status[IMES-i]>=2)) return;
170 if ((IMES == 10) && (phosta.status[IMES-i]>=2)) return;
171 SDATA=DATA;
172 // int PHLUN=(int)pholun.phlun;
173 bool IFSTOP=phosta.ifstop;
174 FILE *PHLUN = stdout;
175 int furthA=0;
176 fprintf(PHLUN,"%s\n",star80);
177 fprintf(PHLUN,"*\n"); //9120
178 // GOTO (10,20,30,40,50,60,70,80,90,100),IMES
179
180 switch(IMES){
181 case 1:
182 fprintf(PHLUN,"* %s: Too many charged Particles, NCHARG = %6i\n", TEXT,(int)SDATA); //I6
183 furthA= 110;
184 break;
185 case 2:
186 fprintf(PHLUN,"* %s: Too much Bremsstrahlung required, PRSOFT = %15.6f\n", TEXT,SDATA);//F15.6
187 furthA= 110;
188 break;
189 case 3:
190 fprintf(PHLUN,"* %s: Combined Weight is exceeding 1., Weight = %15.6f\n", TEXT,SDATA); //F15.6
191 furthA= 110;
192 break;
193 case 4:
194 fprintf(PHLUN,"* %s: Error in Rescaling charged and neutral Vectors\n", TEXT);
195 furthA= 110;
196 break;
197 case 5:
198 fprintf(PHLUN,"* %s: Non matching charged Particle Pointer, NCHARG = %5i\n", TEXT,(int)SDATA); //I5
199 furthA= 110;
200 break;
201 case 6:
202 fprintf(PHLUN,"* %s: Do you really work with a Particle of Spin: %4.1f\n", TEXT,SDATA); //F4.1
203 furthA= 130;
204 break;
205 case 7:
206 fprintf(PHLUN,"* %s: Stack Length exceeded, NSTACK = %5i\n", TEXT,(int)(SDATA));//I5
207 furthA= 110;
208 break;
209 case 8:
210 fprintf(PHLUN,"* %s: Random Number Generator Seed(1) out of Range: %8i\n", TEXT,(int)SDATA);//I8
211 furthA= 110;
212 break;
213 case 9:
214 fprintf(PHLUN,"* %s: Random Number Generator Seed(2) out of Range: %8i\n", TEXT,(int)SDATA);//I8
215 furthA= 110;
216 break;
217 case 10:
218 fprintf(PHLUN,"* %s: Available Phase Space below Cut-off: %15.6f GeV/c^2\n", TEXT,SDATA);//F15.6
219 furthA= 130;
220 break;
221 default:
222 fprintf(PHLUN,"* Funny Error Message: %4i ! What to do ?\n", IMES);//I4
223 furthA= 120;
224 break;
225 }
226
227 switch(furthA){
228 case 110:
229 fprintf(PHLUN,"* Fatal Error Message, I stop this Run !\n");
230 fprintf(PHLUN,"*\n"); //9120
231 fprintf(PHLUN,"%s\n",star80);
232 if (IFSTOP){
233 exit(-1);
234 }
235 else{
236 fprintf(PHLUN,"*\n"); //9120
237 fprintf(PHLUN,"%s\n",star80);
238 break;
239 }
240 case 120:
241 IERROR=IERROR+1;
242 if (IERROR>=10){
243 fprintf(PHLUN,"* 10 Error Messages generated, I stop this Run !\n");
244 fprintf(PHLUN,"*\n");//9120
245 fprintf(PHLUN,"%s\n",star80);
246 if (IFSTOP){
247 exit(-1);
248 }
249 else{
250 fprintf(PHLUN,"*\n"); //9120
251 fprintf(PHLUN,"%s\n",star80);
252 break;
253 }
254 }
255 case 130:
256 fprintf(PHLUN,"*\n"); //9120
257 fprintf(PHLUN,"%s\n",star80);
258 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}
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//----------------------------------------------------------------------
286 static int PHOMES=10;
287 int I;
288 bool ERROR=false;
289 // int PHLUN=(int)pholun.phlun;
290 char star80[81]= "********************************************************************************";
291 char X26[27] = " ";
292 char EQ25[26]= "=========================";
293 char X30[31] = " ";
294 char X22[23] = " ";
295 char X23[24 ]= " ";
296 char X16[17] = " ";
297 FILE *PHLUN = stdout;
298 fprintf(PHLUN," \n");
299 fprintf(PHLUN,"%s\n",star80);
300 fprintf(PHLUN,"*\n");
301 fprintf(PHLUN,"* %s %s\n",X26,EQ25);
302 fprintf(PHLUN,"* %s PHOTOS Run Summary\n",X30);
303 fprintf(PHLUN,"* %s %s\n",X26,EQ25);
304 fprintf(PHLUN,"*\n");
305 for(I=1;I<=PHOMES;I++){
306
307 if (phosta.status[I-1] == 0) break;
308 if ((I == 6)|| (I == 10)){
309 fprintf(PHLUN,"* %s Warning # %2i occured %6i times\n",X22, I,phosta.status[I-1]); // I2 I6
310 }
311 else{
312 ERROR=true;
313 fprintf(PHLUN,"* %s Error # %2i occured %6i times\n",X23, I,phosta.status[I-1]);// I2 I6
314 }
315 }
316
317 if (!ERROR) fprintf(PHLUN,"* %s PHOTOS Execution has successfully terminated\n",X16);
318 fprintf(PHLUN,"*\n");
319 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}
333
334
335
336
337
338} // namespace Photospp
static ostream & Debug(unsigned short int code=0, bool count=true)
Definition Log.cxx:33
static void AddDecay(int type)
Definition Log.cxx:28
static void Assert(bool check, char *text=NULL)
Definition Log.cxx:75
static void Fatal(string text, unsigned short int code=0)
static void PHOREP()
Definition Log.cxx:285
static void RedirectOutput(void(*func)(), ostream &where=*out)
Definition Log.cxx:93
static void PHOERR(int IMES, const char *TEXT, double DATA)
Definition Log.cxx:158
static void Summary()
Definition Log.cxx:113