Belle II Software  release-06-02-00
Log.cc
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  void (*PHOERR)(int, const char*, double) = Log::PHOERR;
13  void (*PHOREP)() = Log::PHOREP;
14 
15  list<Log::Pointer*>* Log::PointerList = NULL;
16 
17  streambuf* Log::bCout = cout.rdbuf(), *Log::bCerr = cerr.rdbuf();
18  ostream* Log::out = &cout;
19  stringstream Log::buf;
20  int Log::warnLimit = 100;
21  int Log::decays[4] = {0};
22  int Log::dCount = 0, Log::dRangeS = 65535, Log::dRangeE = 65534;
23  int Log::faCount = 0, Log::faRangeS = 65535, Log::faRangeE = 65534;
24  int Log::iCount = 0, Log::wCount = 0, Log::eCount = 0, Log::asCount = 0, Log::asFailedCount = 0;
25  bool Log::iAction = 1, Log::wAction = 1, Log::eAction = 1, Log::asAction = 1, Log::rAction = 1;
26 
27  void Log::AddDecay(int type)
28  {
29  decays[type]++;
30  }
31 
32  ostream& Log::Debug(unsigned short int code, bool count)
33  {
34  if (count) ++dCount;
35  if (code >= dRangeS && code <= dRangeE) return *out << "DEBUG(" << code << ") from PHOTOS:" << endl;
36  return buf.seekp(0);
37  }
38 
39 
40  ostream& Log::Info(bool count)
41  {
42  if (count) ++iCount;
43  if (iAction) return *out << "INFO from PHOTOS:" << endl;
44  return buf.seekp(0);
45  }
46 
47 
48  ostream& Log::Warning(bool count)
49  {
50  if (count) ++wCount;
51  if (warnLimit > 0 && wCount >= warnLimit) {
52  if (wAction) {
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 
64  ostream& Log::Error(bool count)
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 
102  void Log::RedirectOutput(ostream& where)
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 
140 //----------------------------------------------------------------------
141 //
142 // PHOTOS: PHOton radiation in decays ERRror handling
143 //
144 // Purpose: Inform user about (fatal) errors and warnings generated
145 // by either the user or the program.
146 //
147 // Input Parameters: IMES, TEXT, DATA
148 //
149 // Output Parameters: None
150 //
151 // Author(s): B. van Eijk Created at: 29/11/89
152 // Last Update: 18/06/13
153 //
154 //----------------------------------------------------------------------
155  void Log::PHOERR(int IMES, const char* TEXT, double DATA)
156  {
157 
158  static int IERROR = 0;
159  double SDATA;
160  static int PHOMES = 10;
161  static int i = 1;
162  char star80[81] = "********************************************************************************";
163 
164  if (IMES <= PHOMES) phosta.status[IMES - i] = phosta.status[IMES - i] + 1;
165 //
166 // Count number of non-fatal errors...
167  if ((IMES == 2) && (phosta.status[IMES - i] >= 2)) return; // Too much bremsstrahlung happens for e-e+ pair emissions [SwB]
168  if ((IMES == 3) && (phosta.status[IMES - i] >= 2)) return; // Overweighted events happens for e-e+ pair emissions [SwB]
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  } else {
235  fprintf(PHLUN, "*\n"); //9120
236  fprintf(PHLUN, "%s\n", star80);
237  break;
238  }
239  case 120:
240  IERROR = IERROR + 1;
241  if (IERROR >= 10) {
242  fprintf(PHLUN, "* 10 Error Messages generated, I stop this Run !\n");
243  fprintf(PHLUN, "*\n"); //9120
244  fprintf(PHLUN, "%s\n", star80);
245  if (IFSTOP) {
246  exit(-1);
247  } else {
248  fprintf(PHLUN, "*\n"); //9120
249  fprintf(PHLUN, "%s\n", star80);
250  break;
251  }
252  }
253  case 130:
254  fprintf(PHLUN, "*\n"); //9120
255  fprintf(PHLUN, "%s\n", star80);
256  break;
257  }
258  return;
259 
260 
261 //9120 FORMAT(1H ,'*',T81,'*')
262 // 9140 FORMAT(1H ,'* Fatal Error Message, I stop this Run !',T81,'*')
263 // 9150 FORMAT(1H ,'* 10 Error Messages generated, I stop this Run !',T81,
264 // &'*')
265  }
266 
267 
268 //----------------------------------------------------------------------
269 //
270 // PHOTOS: PHOton radiation in decays run summary REPort
271 //
272 // Purpose: Inform user about success and/or restrictions of PHOTOS
273 // encountered during execution.
274 //
275 // Input Parameters: Common /PHOSTA/
276 //
277 // Output Parameters: None
278 //
279 // Author(s): B. van Eijk Created at: 10/01/92
280 // Last Update: 18/06/13
281 //
282 //----------------------------------------------------------------------
283  void Log::PHOREP()
284  {
285  static int PHOMES = 10;
286  int I;
287  bool ERROR = false;
288  // int PHLUN=(int)pholun.phlun;
289  char star80[81] = "********************************************************************************";
290  char X26[27] = " ";
291  char EQ25[26] = "=========================";
292  char X30[31] = " ";
293  char X22[23] = " ";
294  char X23[24 ] = " ";
295  char X16[17] = " ";
296  FILE* PHLUN = stdout;
297  fprintf(PHLUN, " \n");
298  fprintf(PHLUN, "%s\n", star80);
299  fprintf(PHLUN, "*\n");
300  fprintf(PHLUN, "* %s %s\n", X26, EQ25);
301  fprintf(PHLUN, "* %s PHOTOS Run Summary\n", X30);
302  fprintf(PHLUN, "* %s %s\n", X26, EQ25);
303  fprintf(PHLUN, "*\n");
304  for (I = 1; I <= PHOMES; I++) {
305 
306  if (phosta.status[I - 1] == 0) break;
307  if ((I == 6) || (I == 10)) {
308  fprintf(PHLUN, "* %s Warning # %2i occured %6i times\n", X22, I, phosta.status[I - 1]); // I2 I6
309  } else {
310  ERROR = true;
311  fprintf(PHLUN, "* %s Error # %2i occured %6i times\n", X23, I, phosta.status[I - 1]); // I2 I6
312  }
313  }
314 
315  if (!ERROR) fprintf(PHLUN, "* %s PHOTOS Execution has successfully terminated\n", X16);
316  fprintf(PHLUN, "*\n");
317  fprintf(PHLUN, "%s\n", star80);
318  return;
319 
320 // RETURN
321 // 9000 FORMAT(1H1)
322 // 9010 FORMAT(1H ,80('*'))
323 // 9020 FORMAT(1H ,'*',T81,'*')
324 // 9030 FORMAT(1H ,'*',26X,25('='),T81,'*')
325 // 9040 FORMAT(1H ,'*',30X,'PHOTOS Run Summary',T81,'*')
326 // 9050 FORMAT(1H ,'*',22X,'Warning #',I2,' occured',I6,' times',T81,'*')
327 // 9060 FORMAT(1H ,'*',23X,'Error #',I2,' occured',I6,' times',T81,'*')
328 // 9070 FORMAT(1H ,'*',16X,'PHOTOS Execution has successfully terminated',
329 // &T81,'*')
330  }
331 
332 
333 
334 
335 
336 } // namespace Photospp
static ostream & Debug(unsigned short int code=0, bool count=true)
Four logging entries.
Definition: Log.cc:32
static void AddDecay(int type)
Adds the decay to the counter.
Definition: Log.cc:27
static void Assert(bool check, char *text=NULL)
Asserts logical value.
Definition: Log.cc:72
static void RedirectOutput(void(*func)(), ostream &where= *out)
Redirects output to log.
Definition: Log.cc:90
static void Fatal(string text, unsigned short int code=0)
Terminates the program with added default message or 'text'.
static void PHOREP()
Final report of warnings from internal part of PHOTOS (originally in F77)
Definition: Log.cc:283
static void PHOERR(int IMES, const char *TEXT, double DATA)
Warnings on errors from internal part of PHOTOS (originally in F77)
Definition: Log.cc:155
static void Summary()
Shows the summary of all messages.
Definition: Log.cc:110