Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TMsgLogger.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /**********************************************************************************
6  * Class : TMsgLogger *
7  * *
8  * Authors (alphabetical): *
9  * Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch> - CERN, Switzerland *
10  **********************************************************************************/
11 
12 #ifndef ROOT_Root_TMsgLogger
13 #define ROOT_Root_TMsgLogger
14 
16 // //
17 // TMsgLogger //
18 // //
19 // ostreamstream derivative to redirect and format output //
20 // //
22 
23 // STL include(s):
24 #include <string>
25 #include <sstream>
26 #include <map>
27 
28 // ROOT include(s)
29 #include "TObject.h"
30 #include "TString.h"
31 
32 // Local include(s):
33 
34 namespace Root {
35 
36  // define outside of class to facilite access
37  enum TMsgLevel {
38  kVERBOSE = 1,
39  kDEBUG = 2,
40  kINFO = 3,
41  kWARNING = 4,
42  kERROR = 5,
43  kFATAL = 6,
44  kALWAYS = 7
45  };
46 
47  class TMsgLogger : public std::ostringstream, public TObject {
48 
49  public:
50 
51  TMsgLogger( const TObject* source, TMsgLevel minLevel = kINFO );
52  TMsgLogger( const std::string& source, TMsgLevel minLevel = kINFO );
53  TMsgLogger( TMsgLevel minLevel = kINFO );
54  TMsgLogger( const TMsgLogger& parent );
55  virtual ~TMsgLogger();
56 
57  // Accessors
58  void SetSource( const char* source ) { m_strSource = source; }
59  void SetSource( const std::string& source ) { m_strSource = source; }
60  void SetSource( const TString& source ) { m_strSource = source.Data(); }
61  const std::string& GetSource() const { return m_strSource; }
62 
63  UInt_t GetMaxSourceSize() const { return (UInt_t)m_maxSourceSize; }
64  std::string GetPrintedSource() const;
65  std::string GetFormattedSource() const;
66 
67  TMsgLevel GetMinLevel() const { return m_minLevel; }
68  const std::string& GetMinLevelStr() const { return m_levelMap.find( m_minLevel )->second; }
69 
70  TMsgLevel MapLevel( const TString& instr ) const;
71 
72  // Needed for copying
74 
75  // Stream modifier(s)
76  static TMsgLogger& endmsg( TMsgLogger& logger );
77 
78  // Accept stream modifiers
80  TMsgLogger& operator<< ( std::ostream& ( *_f )( std::ostream& ) );
81  TMsgLogger& operator<< ( std::ios& ( *_f )( std::ios& ) );
82 
83  // Accept message level specification
85 
86  // For all the "conventional" inputs
87  template <class T> TMsgLogger& operator<< ( T arg ) {
88  *(std::ostringstream*)this << arg; return *this;
89  }
90 
91  static void SetMinLevel( TMsgLevel minLevel ) { m_minLevel = minLevel; }
92 
93  private:
94 
95  // the current minimum level is global for the whole Root
96  // it can only be changed by the central storage singleton object
97  // we make this atomic to suppress thread-checker warnings
98  static std::atomic<TMsgLevel> m_minLevel; // minimum level for logging output
99 
100  // private utility routines
101  void Send();
102  void InitMaps();
103  void WriteMsg( TMsgLevel level, const std::string& line ) const;
104 
105  const TObject* m_objSource; // the source TObject (used for name)
106  std::string m_strSource; // alternative string source
107  const std::string m_prefix; // the prefix of the source name
108  const std::string m_suffix; // suffix following source name
109  TMsgLevel m_activeLevel; // active level
110  const std::string::size_type m_maxSourceSize; // maximum length of source name
111 
112  std::map<TMsgLevel, std::string> m_levelMap; // matches output levels with strings
113  std::map<TMsgLevel, std::string> m_colorMap; // matches output levels with terminal colors
114 
115  //ClassDef(TMsgLogger,0)
116 
117  }; // class TMsgLogger
118 
120  {
121  return (_f)(*this);
122  }
123 
124  inline TMsgLogger& TMsgLogger::operator<< ( std::ostream& (*_f)( std::ostream& ) )
125  {
126  (_f)(*this);
127  return *this;
128  }
129 
130  inline TMsgLogger& TMsgLogger::operator<< ( std::ios& ( *_f )( std::ios& ) )
131  {
132  (_f)(*this);
133  return *this;
134  }
135 
137  {
139  return *this;
140  }
141 
142  // Although the proper definition of "Endl" as a function pointer
143  // would be nicer C++-wise, it introduces some "unused variable"
144  // warnings so let's use the #define definition after all...
145  // [ static TMsgLogger& ( *Endl )( TMsgLogger& ) = &TMsgLogger::endmsg; ]
146 #define GEndl TMsgLogger::endmsg
147 
148 }
149 
150 #endif // Root_TMsgLogger
Root::TMsgLogger::Send
void Send()
Definition: TMsgLogger.cxx:129
Root::TMsgLogger::m_suffix
const std::string m_suffix
Definition: TMsgLogger.h:113
Root::TMsgLogger::WriteMsg
void WriteMsg(TMsgLevel level, const std::string &line) const
Definition: TMsgLogger.cxx:160
Root::kWARNING
@ kWARNING
Definition: TMsgLogger.h:51
checkFileSG.line
line
Definition: checkFileSG.py:75
Root
Definition: GoodRunsListSelectorTool.h:30
Root::TMsgLogger::m_objSource
const TObject * m_objSource
Definition: TMsgLogger.h:110
Root::kERROR
@ kERROR
Definition: TMsgLogger.h:52
Root::TMsgLogger::GetPrintedSource
std::string GetPrintedSource() const
Definition: TMsgLogger.cxx:119
Root::TMsgLogger::GetMinLevel
TMsgLevel GetMinLevel() const
Definition: TMsgLogger.h:72
Root::kVERBOSE
@ kVERBOSE
Definition: TMsgLogger.h:48
Root::kALWAYS
@ kALWAYS
Definition: TMsgLogger.h:54
Root::TMsgLogger::GetMinLevelStr
const std::string & GetMinLevelStr() const
Definition: TMsgLogger.h:73
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
Root::TMsgLogger::m_prefix
const std::string m_prefix
Definition: TMsgLogger.h:112
Root::TMsgLogger::GetFormattedSource
std::string GetFormattedSource() const
Definition: TMsgLogger.cxx:104
Root::kDEBUG
@ kDEBUG
Definition: TMsgLogger.h:49
Root::TMsgLogger::MapLevel
TMsgLevel MapLevel(const TString &instr) const
Definition: TMsgLogger.cxx:190
Root::TMsgLogger::GetMaxSourceSize
UInt_t GetMaxSourceSize() const
Definition: TMsgLogger.h:68
Root::kINFO
@ kINFO
Definition: TMsgLogger.h:50
Root::TMsgLogger::m_strSource
std::string m_strSource
Definition: TMsgLogger.h:111
Root::TMsgLevel
TMsgLevel
Definition: TMsgLogger.h:42
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Root::TMsgLogger::~TMsgLogger
virtual ~TMsgLogger()
Definition: TMsgLogger.cxx:90
Root::TMsgLogger::operator<<
TMsgLogger & operator<<(TMsgLogger &(*_f)(TMsgLogger &))
Definition: TMsgLogger.h:124
Root::TMsgLogger::m_minLevel
static std::atomic< TMsgLevel > m_minLevel
Definition: TMsgLogger.h:103
Root::TMsgLogger::TMsgLogger
TMsgLogger(const TObject *source, TMsgLevel minLevel=kINFO)
Definition: TMsgLogger.cxx:42
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
Root::TMsgLogger::SetSource
void SetSource(const char *source)
Definition: TMsgLogger.h:63
Root::TMsgLogger::endmsg
static TMsgLogger & endmsg(TMsgLogger &logger)
Definition: TMsgLogger.cxx:183
Root::TMsgLogger::operator=
TMsgLogger & operator=(const TMsgLogger &parent)
Definition: TMsgLogger.cxx:93
Root::TMsgLogger::m_maxSourceSize
const std::string::size_type m_maxSourceSize
Definition: TMsgLogger.h:115
Root::TMsgLogger::InitMaps
void InitMaps()
Definition: TMsgLogger.cxx:207
Root::TMsgLogger::m_activeLevel
TMsgLevel m_activeLevel
Definition: TMsgLogger.h:114
copySelective.source
string source
Definition: copySelective.py:32
Root::TMsgLogger::GetSource
const std::string & GetSource() const
Definition: TMsgLogger.h:66
Root::TMsgLogger::m_colorMap
std::map< TMsgLevel, std::string > m_colorMap
Definition: TMsgLogger.h:118
Root::TMsgLogger
Definition: TMsgLogger.h:52
Root::TMsgLogger::m_levelMap
std::map< TMsgLevel, std::string > m_levelMap
Definition: TMsgLogger.h:117
Root::kFATAL
@ kFATAL
Definition: TMsgLogger.h:53
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
Root::TMsgLogger::SetMinLevel
static void SetMinLevel(TMsgLevel minLevel)
Definition: TMsgLogger.h:96