Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MsgLogger.h
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Attila Krasznahorkay, Andreas Hoecker, Joerg Stelzer, Eckhard von Toerne
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : MsgLogger *
8 * Web : http://tmva.sourceforge.net *
9 * *
10 * Description: *
11 * TMVA output logger class producing nicely formatted log messages *
12 * *
13 * Author: *
14 * Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch> - CERN, Switzerland *
15 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
16 * Joerg Stelzer <stelzer@cern.ch> - DESY, Germany *
17 * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
18 * *
19 * Copyright (c) 2005-2011: *
20 * CERN, Switzerland *
21 * U. of Victoria, Canada *
22 * MPI-K Heidelberg, Germany *
23 * U. of Bonn, Germany *
24 * *
25 * Redistribution and use in source and binary forms, with or without *
26 * modification, are permitted according to the terms listed in LICENSE *
27 * (http://tmva.sourceforge.net/LICENSE) *
28 **********************************************************************************/
29
30#ifndef ROOT_TMVA_MsgLogger
31#define ROOT_TMVA_MsgLogger
32
33//////////////////////////////////////////////////////////////////////////
34// //
35// MsgLogger //
36// //
37// ostringstream derivative to redirect and format output //
38// //
39//////////////////////////////////////////////////////////////////////////
40
41// STL include(s):
42#include <string>
43#include <sstream>
44#include <iostream>
45#include <map>
46#include <atomic>
47
48// ROOT include(s)
49#include "TObject.h"
50
51#include "TMVA/Types.h"
52
53// Local include(s):
54
55namespace TMVA {
56
57 class MsgLogger : public std::ostringstream, public TObject {
58
59 public:
60
61 MsgLogger( const TObject* source, EMsgType minType = kINFO );
62 MsgLogger( const std::string& source, EMsgType minType = kINFO );
63 MsgLogger( EMsgType minType = kINFO );
64 MsgLogger( const MsgLogger& parent );
65 ~MsgLogger();
66
67 // Accessors
68 void SetSource ( const std::string& source ) { fStrSource = source; }
69 EMsgType GetMinType() const { return fMinType; }
70 void SetMinType( EMsgType minType ) { fMinType = minType; }
71 std::string GetSource() const { return fStrSource; }
72 std::string GetPrintedSource() const;
73 std::string GetFormattedSource() const;
74
75 static UInt_t GetMaxSourceSize();
76
77 // Needed for copying
78 MsgLogger& operator= ( const MsgLogger& parent );
79
80 // Stream modifier(s)
81 static MsgLogger& Endmsg( MsgLogger& logger );
82
83 // Accept stream modifiers
84 MsgLogger& operator<< ( MsgLogger& ( *_f )( MsgLogger& ) );
85 MsgLogger& operator<< ( std::ostream& ( *_f )( std::ostream& ) );
86 MsgLogger& operator<< ( std::ios& ( *_f )( std::ios& ) );
87
88 // Accept message type specification
89 MsgLogger& operator<< ( EMsgType type );
90
91 // For all the "conventional" inputs
92 template <class T> MsgLogger& operator<< ( T arg ) {
93 *(std::ostringstream*)this << arg;
94 return *this;
95 }
96
97 // Temporally disables all the loggers (Caution! Use with care !)
98 static void InhibitOutput();
99 static void EnableOutput();
100
101 private:
102
103 // private utility routines
104 void Send();
105 void InitMaps();
106 void WriteMsg( EMsgType type, const std::string& line ) const;
107
108 const TObject* fObjSource; ///< the source TObject (used for name)
109 std::string fStrSource; ///< alternative string source
110 static const std::string fgPrefix; ///< the prefix of the source name
111 static const std::string fgSuffix; ///< suffix following source name
112 EMsgType fActiveType; ///< active type
113 static const UInt_t fgMaxSourceSize; ///< maximum length of source name
114 static std::atomic<Bool_t> fgOutputSupressed; ///< disable the output globally (used by generic booster)
115 static std::atomic<Bool_t> fgInhibitOutput; ///< flag to suppress all output
116
117 static std::atomic<const std::map<EMsgType, std::string>*> fgTypeMap; ///< matches output types with strings
118 static std::atomic<const std::map<EMsgType, std::string>*> fgColorMap; ///< matches output types with terminal colors
119 EMsgType fMinType; ///< minimum type for output
120
121 ClassDef(MsgLogger,0) // Ostringstream derivative to redirect and format logging output
122 }; // class MsgLogger
123
125 {
126 return (_f)(*this);
127 }
128
129 inline MsgLogger& MsgLogger::operator<< ( std::ostream& (*_f)( std::ostream& ) )
130 {
131 (_f)(*this);
132 return *this;
133 }
134
135 inline MsgLogger& MsgLogger::operator<< ( std::ios& ( *_f )( std::ios& ) )
136 {
137 (_f)(*this);
138 return *this;
139 }
140
142 {
144 return *this;
145 }
146
147 // Shortcut
148 inline MsgLogger& Endl(MsgLogger& ml) { return MsgLogger::Endmsg(ml); }
149
150}
151
152#endif // TMVA_MsgLogger
unsigned int UInt_t
Definition RtypesCore.h:46
#define ClassDef(name, id)
Definition Rtypes.h:337
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
void SetMinType(EMsgType minType)
Definition MsgLogger.h:70
static const UInt_t fgMaxSourceSize
maximum length of source name
Definition MsgLogger.h:113
static const std::string fgPrefix
the prefix of the source name
Definition MsgLogger.h:110
~MsgLogger()
destructor
void SetSource(const std::string &source)
Definition MsgLogger.h:68
MsgLogger & operator=(const MsgLogger &parent)
assignment operator
std::string GetPrintedSource() const
the full logger prefix
std::string fStrSource
alternative string source
Definition MsgLogger.h:109
static std::atomic< Bool_t > fgOutputSupressed
disable the output globally (used by generic booster)
Definition MsgLogger.h:114
static std::atomic< const std::map< EMsgType, std::string > * > fgColorMap
matches output types with terminal colors
Definition MsgLogger.h:118
MsgLogger & operator<<(MsgLogger &(*_f)(MsgLogger &))
Definition MsgLogger.h:124
static UInt_t GetMaxSourceSize()
returns the maximum source size
static void InhibitOutput()
Definition MsgLogger.cxx:67
const TObject * fObjSource
the source TObject (used for name)
Definition MsgLogger.h:108
static const std::string fgSuffix
suffix following source name
Definition MsgLogger.h:111
static void EnableOutput()
Definition MsgLogger.cxx:68
EMsgType fMinType
minimum type for output
Definition MsgLogger.h:119
static std::atomic< const std::map< EMsgType, std::string > * > fgTypeMap
matches output types with strings
Definition MsgLogger.h:117
std::string GetSource() const
Definition MsgLogger.h:71
std::string GetFormattedSource() const
make sure the source name is no longer than fgMaxSourceSize:
void InitMaps()
Create the message type and color maps.
EMsgType fActiveType
active type
Definition MsgLogger.h:112
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
static MsgLogger & Endmsg(MsgLogger &logger)
end line
static std::atomic< Bool_t > fgInhibitOutput
flag to suppress all output
Definition MsgLogger.h:115
void Send()
activates the logger writer
EMsgType GetMinType() const
Definition MsgLogger.h:69
EMsgType
Definition Types.h:55
Mother of all ROOT objects.
Definition TObject.h:41
TLine * line
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148