51 const
UInt_t TMVA::MsgLogger::fgMaxSourceSize = 25;
53 const
std::
string TMVA::MsgLogger::fgPrefix = "--- ";
54 const
std::
string TMVA::MsgLogger::fgSuffix = ": ";
55 #if __cplusplus > 199711L
56 std::atomic<Bool_t> TMVA::MsgLogger::fgInhibitOutput{
kFALSE};
57 std::atomic<const std::map<TMVA::EMsgType, std::string>*> TMVA::MsgLogger::fgTypeMap{0};
58 std::atomic<const std::map<TMVA::EMsgType, std::string>*> TMVA::MsgLogger::fgColorMap{0};
61 const std::map<TMVA::EMsgType, std::string>* TMVA::MsgLogger::fgTypeMap = 0;
62 const std::map<TMVA::EMsgType, std::string>* TMVA::MsgLogger::fgColorMap = 0;
64 static std::auto_ptr<const std::map<TMVA::EMsgType, std::string> >
gOwnTypeMap;
65 static std::auto_ptr<const std::map<TMVA::EMsgType, std::string> >
gOwnColorMap;
74 : fObjSource ( source ),
87 fStrSource ( source ),
99 fStrSource (
"Unknown" ),
100 fActiveType(
kINFO ),
111 std::ostringstream(),
131 if (&parent !=
this) {
146 std::string source_name;
147 if (fObjSource) source_name = fObjSource->GetName();
148 else source_name = fStrSource;
150 if (source_name.size() > fgMaxSourceSize) {
151 source_name = source_name.substr( 0, fgMaxSourceSize - 3 );
152 source_name +=
"...";
163 std::string source_name = GetFormattedSource();
164 if (source_name.size() < fgMaxSourceSize)
165 for (std::string::size_type i=source_name.size(); i<fgMaxSourceSize; i++) source_name.push_back(
' ' );
167 return fgPrefix + source_name + fgSuffix;
176 std::string source_name = GetFormattedSource();
178 std::string
message = this->str();
179 std::string::size_type previous_pos = 0, current_pos = 0;
183 current_pos = message.find(
'\n', previous_pos );
184 std::string
line = message.substr( previous_pos, current_pos - previous_pos );
186 std::ostringstream message_to_send;
188 message_to_send.setf( std::ios::adjustfield, std::ios::left );
189 message_to_send.width( fgMaxSourceSize );
190 message_to_send << source_name << fgSuffix <<
line;
191 this->WriteMsg( fActiveType, message_to_send.str() );
193 if (current_pos == message.npos)
break;
194 previous_pos = current_pos + 1;
209 if ( (type < fMinType || fgInhibitOutput) && type!=
kFATAL )
return;
211 std::map<EMsgType, std::string>::const_iterator
stype;
213 if ((stype = fgTypeMap.load()->find( type )) != fgTypeMap.load()->end()) {
218 std::cout << fgPrefix << line << std::endl;
220 std::cout << fgColorMap.load()->find( type )->second << fgPrefix <<
"<"
221 << stype->second <<
"> " << line <<
"\033[0m" << std::endl;
224 if (type ==
kINFO) std::cout << fgPrefix << line << std::endl;
225 else std::cout << fgPrefix <<
"<" << stype->second <<
"> " << line << std::endl;
232 std::cout <<
"***> abort program execution" << std::endl;
253 std::map<TMVA::EMsgType, std::string>*tmp =
new std::map<TMVA::EMsgType, std::string>();
255 (*tmp)[
kVERBOSE] = std::string(
"VERBOSE");
256 (*tmp)[
kDEBUG] = std::string(
"DEBUG");
257 (*tmp)[
kINFO] = std::string(
"INFO");
258 (*tmp)[
kWARNING] = std::string(
"WARNING");
259 (*tmp)[
kERROR] = std::string(
"ERROR");
260 (*tmp)[
kFATAL] = std::string(
"FATAL");
261 (*tmp)[
kSILENT] = std::string(
"SILENT");
262 const std::map<TMVA::EMsgType, std::string>* expected=0;
263 if(fgTypeMap.compare_exchange_strong(expected,tmp)) {
265 gOwnTypeMap.reset(tmp);
273 std::map<TMVA::EMsgType, std::string>*tmp =
new std::map<TMVA::EMsgType, std::string>();
276 (*tmp)[
kDEBUG] = std::string(
"\033[34m");
277 (*tmp)[
kINFO] = std::string(
"");
278 (*tmp)[
kWARNING] = std::string(
"\033[1;31m");
279 (*tmp)[
kERROR] = std::string(
"\033[31m");
280 (*tmp)[
kFATAL] = std::string(
"\033[37;41;1m");
281 (*tmp)[
kSILENT] = std::string(
"\033[30m");
283 const std::map<TMVA::EMsgType, std::string>* expected=0;
284 if(fgColorMap.compare_exchange_strong(expected,tmp)) {
286 gOwnColorMap.reset(tmp);
void WriteMsg(EMsgType type, const std::string &line) const
putting the output string, the message type, and the color switcher together into a single string ...
void Send()
activates the logger writer
const TObject * fObjSource
static Bool_t fgInhibitOutput
static void InhibitOutput()
const char Int_t const char TProof Int_t stype
MsgLogger(const TObject *source, EMsgType minType=kINFO)
constructor
MsgLogger & operator=(const MsgLogger &parent)
assingment operator
std::string GetPrintedSource() const
the full logger prefix
void InitMaps()
Create the message type and color maps.
static std::auto_ptr< const std::map< TMVA::EMsgType, std::string > > gOwnColorMap
static MsgLogger & Endmsg(MsgLogger &logger)
end line
std::string GetFormattedSource() const
make sure the source name is no longer than fgMaxSourceSize:
Mother of all ROOT objects.
Abstract ClassifierFactory template that handles arbitrary types.
static void EnableOutput()
static std::auto_ptr< const std::map< TMVA::EMsgType, std::string > > gOwnTypeMap