BayesianAnalysisToolkit
0.9.3
Main Page
Namespaces
Classes
Files
File List
File Members
src
BCLog.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2007-2013, the BAT core developer team
3
* All rights reserved.
4
*
5
* For the licensing terms see doc/COPYING.
6
* For documentation see http://mpp.mpg.de/bat
7
*/
8
9
// ---------------------------------------------------------
10
11
#include "config.h"
12
13
#include "
BCLog.h
"
14
15
#include <TError.h>
16
#include <TROOT.h>
17
18
#include <fstream>
19
#include <iomanip>
20
21
22
std::ofstream
BCLog::fOutputStream
;
23
24
BCLog::LogLevel
BCLog::fMinimumLogLevelFile
=
BCLog::debug
;
25
26
BCLog::LogLevel
BCLog::fMinimumLogLevelScreen
=
BCLog::summary
;
27
28
bool
BCLog::fFirstOutputDone
=
false
;
29
30
const
char
*
BCLog::fVersion
= VERSION;
31
32
int
BCLog::fHindex
= 0;
33
34
// ---------------------------------------------------------
35
36
BCLog::BCLog
()
37
{
38
// suppress the ROOT Info printouts
39
gErrorIgnoreLevel=2000;
40
}
41
42
// ---------------------------------------------------------
43
44
BCLog::~BCLog
()
45
{}
46
47
// ---------------------------------------------------------
48
49
void
BCLog::OpenLog
(
const
char
* filename,
BCLog::LogLevel
loglevelfile,
BCLog::LogLevel
loglevelscreen)
50
{
51
// suppress the ROOT Info printouts
52
gErrorIgnoreLevel=2000;
53
54
// open log file
55
BCLog::fOutputStream
.open(filename);
56
57
if
(!
BCLog::fOutputStream
.is_open())
58
{
59
std::cerr <<
" Could not open log file "
<< filename <<
". "
<< std::endl;
60
return
;
61
}
62
63
// set log level
64
BCLog::SetLogLevelFile
(loglevelfile);
65
BCLog::SetLogLevelScreen
(loglevelscreen);
66
67
BCLog::Out
(
BCLog::summary
,
BCLog::summary
,Form(
"Opening logfile %s"
,filename));
68
}
69
70
// ---------------------------------------------------------
71
72
void
BCLog::OpenLog
(
const
char
* filename)
73
{
74
BCLog::OpenLog
(filename,
BCLog::debug
,
BCLog::summary
);
75
}
76
77
// ---------------------------------------------------------
78
79
void
BCLog::OpenLog
()
80
{
81
BCLog::OpenLog
(
"log.txt"
,
BCLog::debug
,
BCLog::summary
);
82
}
83
84
// ---------------------------------------------------------
85
86
bool
BCLog::IsOpen
()
87
{
88
return
BCLog::fOutputStream
.is_open();
89
}
90
91
// ---------------------------------------------------------
92
93
void
BCLog::CloseLog
()
94
{
95
BCLog::fOutputStream
.close();
96
}
97
98
// ---------------------------------------------------------
99
100
void
BCLog::Out
(
BCLog::LogLevel
loglevelfile,
BCLog::LogLevel
loglevelscreen,
const
char
* message)
101
{
102
// if this is the first call to Out(), call StartupInfo() first
103
if
(!
fFirstOutputDone
)
104
BCLog::StartupInfo
();
105
106
// open log file if not opened
107
if
(
BCLog::IsOpen
())
108
{
109
// write message in to log file
110
if
(loglevelfile >=
BCLog::fMinimumLogLevelFile
)
111
BCLog::fOutputStream
<<
BCLog::ToString
(loglevelfile) <<
" : "
<< message << std::endl;
112
}
113
114
// write message to screen
115
if
(loglevelscreen >=
BCLog::fMinimumLogLevelScreen
)
116
std::cout <<
BCLog::ToString
(loglevelscreen) <<
" : "
<< message << std::endl;
117
}
118
119
// ---------------------------------------------------------
120
121
void
BCLog::Out
(
const
char
* message)
122
{
123
BCLog::Out
(
BCLog::fMinimumLogLevelFile
,
BCLog::fMinimumLogLevelScreen
, message);
124
}
125
126
// ---------------------------------------------------------
127
128
void
BCLog::StartupInfo
()
129
{
130
char
* message = Form(
131
" +------------------------------------------------------+\n"
132
" | |\n"
133
" | BAT version %7s |\n"
134
" | Copyright (C) 2007-2013, the BAT core developer team |\n"
135
" | All rights reserved. |\n"
136
" | |\n"
137
" | For the licensing terms see doc/COPYING |\n"
138
" | For documentation see http://mpp.mpg.de/bat |\n"
139
" | |\n"
140
" +------------------------------------------------------+\n"
,
141
BCLog::fVersion
);
142
143
// write message to screen
144
if
(
BCLog::fMinimumLogLevelScreen
<
BCLog::nothing
)
145
std::cout << message << std::endl;
146
147
if
(
BCLog::IsOpen
() &&
BCLog::fMinimumLogLevelFile
<
BCLog::nothing
)
148
BCLog::fOutputStream
<< message;
149
150
fFirstOutputDone
=
true
;
151
}
152
153
// ---------------------------------------------------------
154
155
const
char
*
BCLog::ToString
(
BCLog::LogLevel
loglevel)
156
{
157
switch
(loglevel)
158
{
159
case
debug
:
160
return
"Debug "
;
161
case
detail
:
162
return
"Detail "
;
163
case
summary
:
164
return
"Summary"
;
165
case
warning
:
166
return
"Warning"
;
167
case
error
:
168
return
"Error "
;
169
default
:
170
return
""
;
171
}
172
}
173
174
// ---------------------------------------------------------
175
176
int
printBATUponLoading
()
177
{
178
/*
179
std::cout <<
180
" +------------------------------------------------------+\n"
181
" | |\n"
182
" | BAT version " << std::setw(7) << VERSION << " |\n"
183
" | Copyright (C) 2007-2013, the BAT core developer team |\n"
184
" | All rights reserved. |\n"
185
" | |\n"
186
" | For the licensing terms see doc/COPYING |\n"
187
" | For documentation see http://mpp.mpg.de/bat |\n"
188
" | |\n"
189
" +------------------------------------------------------+\n";
190
*/
191
return
0;
192
}
193
194
static
int
tmpvarPrint
=
printBATUponLoading
();
Generated by
1.8.4