File indexing completed on 2025-01-18 10:11:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #ifndef ROOT_TMVA_MsgLogger
0031 #define ROOT_TMVA_MsgLogger
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 #include <string>
0043 #include <sstream>
0044 #include <iostream>
0045 #include <map>
0046 #include <atomic>
0047
0048
0049 #include "TObject.h"
0050
0051 #include "TMVA/Types.h"
0052
0053
0054
0055 namespace TMVA {
0056
0057 class MsgLogger : public std::ostringstream, public TObject {
0058
0059 public:
0060
0061 MsgLogger( const TObject* source, EMsgType minType = kINFO );
0062 MsgLogger( const std::string& source, EMsgType minType = kINFO );
0063 MsgLogger( EMsgType minType = kINFO );
0064 MsgLogger( const MsgLogger& parent );
0065 ~MsgLogger();
0066
0067
0068 void SetSource ( const std::string& source ) { fStrSource = source; }
0069 EMsgType GetMinType() const { return fMinType; }
0070 void SetMinType( EMsgType minType ) { fMinType = minType; }
0071 std::string GetSource() const { return fStrSource; }
0072 std::string GetPrintedSource() const;
0073 std::string GetFormattedSource() const;
0074
0075 static UInt_t GetMaxSourceSize();
0076
0077
0078 MsgLogger& operator= ( const MsgLogger& parent );
0079
0080
0081 static MsgLogger& Endmsg( MsgLogger& logger );
0082
0083
0084 MsgLogger& operator<< ( MsgLogger& ( *_f )( MsgLogger& ) );
0085 MsgLogger& operator<< ( std::ostream& ( *_f )( std::ostream& ) );
0086 MsgLogger& operator<< ( std::ios& ( *_f )( std::ios& ) );
0087
0088
0089 MsgLogger& operator<< ( EMsgType type );
0090
0091
0092 template <class T> MsgLogger& operator<< ( T arg ) {
0093 *(std::ostringstream*)this << arg;
0094 return *this;
0095 }
0096
0097
0098 static void InhibitOutput();
0099 static void EnableOutput();
0100
0101 private:
0102
0103
0104 void Send();
0105 void InitMaps();
0106 void WriteMsg( EMsgType type, const std::string& line ) const;
0107
0108 const TObject* fObjSource;
0109 std::string fStrSource;
0110 static const std::string fgPrefix;
0111 static const std::string fgSuffix;
0112 EMsgType fActiveType;
0113 static const UInt_t fgMaxSourceSize;
0114 static std::atomic<Bool_t> fgOutputSupressed;
0115 static std::atomic<Bool_t> fgInhibitOutput;
0116
0117 static std::atomic<const std::map<EMsgType, std::string>*> fgTypeMap;
0118 static std::atomic<const std::map<EMsgType, std::string>*> fgColorMap;
0119 EMsgType fMinType;
0120
0121 ClassDef(MsgLogger,0)
0122 };
0123
0124 inline MsgLogger& MsgLogger::operator<< ( MsgLogger& (*_f)( MsgLogger& ) )
0125 {
0126 return (_f)(*this);
0127 }
0128
0129 inline MsgLogger& MsgLogger::operator<< ( std::ostream& (*_f)( std::ostream& ) )
0130 {
0131 (_f)(*this);
0132 return *this;
0133 }
0134
0135 inline MsgLogger& MsgLogger::operator<< ( std::ios& ( *_f )( std::ios& ) )
0136 {
0137 (_f)(*this);
0138 return *this;
0139 }
0140
0141 inline MsgLogger& MsgLogger::operator<< ( EMsgType type )
0142 {
0143 fActiveType = type;
0144 return *this;
0145 }
0146
0147
0148 inline MsgLogger& Endl(MsgLogger& ml) { return MsgLogger::Endmsg(ml); }
0149
0150 }
0151
0152 #endif