Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:01

0001 // @(#)root/tmva $Id$
0002 // Author: Attila Krasznahorkay, Andreas Hoecker, Joerg Stelzer, Eckhard von Toerne
0003 
0004 /**********************************************************************************
0005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
0006  * Package: TMVA                                                                  *
0007  * Class  : MsgLogger                                                             *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *      TMVA output logger class producing nicely formatted log messages          *
0012  *                                                                                *
0013  * Author:                                                                        *
0014  *      Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch> - CERN, Switzerland   *
0015  *      Andreas Hoecker       <Andreas.Hocker@cern.ch> - CERN, Switzerland        *
0016  *      Joerg Stelzer         <stelzer@cern.ch>        - DESY, Germany            *
0017  *      Eckhard v. Toerne     <evt@uni-bonn.de>        - U of Bonn, Germany       *
0018  *                                                                                *
0019  * Copyright (c) 2005-2011:                                                       *
0020  *      CERN, Switzerland                                                         *
0021  *      U. of Victoria, Canada                                                    *
0022  *      MPI-K Heidelberg, Germany                                                 *
0023  *      U. of Bonn, Germany                                                       *
0024  *                                                                                *
0025  * Redistribution and use in source and binary forms, with or without             *
0026  * modification, are permitted according to the terms listed in LICENSE           *
0027  * (see tmva/doc/LICENSE)                                          *
0028  **********************************************************************************/
0029 
0030 #ifndef ROOT_TMVA_MsgLogger
0031 #define ROOT_TMVA_MsgLogger
0032 
0033 //////////////////////////////////////////////////////////////////////////
0034 //                                                                      //
0035 // MsgLogger                                                            //
0036 //                                                                      //
0037 // ostringstream derivative to redirect and format output               //
0038 //                                                                      //
0039 //////////////////////////////////////////////////////////////////////////
0040 
0041 // STL include(s):
0042 #include <string>
0043 #include <sstream>
0044 #include <iostream>
0045 #include <map>
0046 #include <atomic>
0047 
0048 // ROOT include(s)
0049 #include "TObject.h"
0050 
0051 #include "TMVA/Types.h"
0052 
0053 // Local include(s):
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       // Accessors
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       // Needed for copying
0078       MsgLogger& operator= ( const MsgLogger& parent );
0079 
0080       // Stream modifier(s)
0081       static MsgLogger& Endmsg( MsgLogger& logger );
0082 
0083       // Accept stream modifiers
0084       MsgLogger& operator<< ( MsgLogger& ( *_f )( MsgLogger& ) );
0085       MsgLogger& operator<< ( std::ostream& ( *_f )( std::ostream& ) );
0086       MsgLogger& operator<< ( std::ios& ( *_f )( std::ios& ) );
0087 
0088       // Accept message type specification
0089       MsgLogger& operator<< ( EMsgType type );
0090 
0091       // For all the "conventional" inputs
0092       template <class T> MsgLogger& operator<< ( T arg ) {
0093          *(std::ostringstream*)this << arg;
0094          return *this;
0095       }
0096 
0097       // Temporally disables all the loggers (Caution! Use with care !)
0098       static void  InhibitOutput();
0099       static void  EnableOutput();
0100 
0101    private:
0102 
0103       // private utility routines
0104       void Send();
0105       void InitMaps();
0106       void WriteMsg( EMsgType type, const std::string& line ) const;
0107 
0108       const TObject*           fObjSource;        ///< the source TObject (used for name)
0109       std::string              fStrSource;        ///< alternative string source
0110       static const std::string fgPrefix;          ///< the prefix of the source name
0111       static const std::string fgSuffix;          ///< suffix following source name
0112       EMsgType                 fActiveType;       ///< active type
0113       static const UInt_t      fgMaxSourceSize;   ///< maximum length of source name
0114       static std::atomic<Bool_t> fgOutputSupressed; ///< disable the output globally (used by generic booster)
0115       static std::atomic<Bool_t> fgInhibitOutput;   ///< flag to suppress all output
0116 
0117       static std::atomic<const std::map<EMsgType, std::string>*> fgTypeMap;   ///< matches output types with strings
0118       static std::atomic<const std::map<EMsgType, std::string>*> fgColorMap;  ///< matches output types with terminal colors
0119       EMsgType                                fMinType;    ///< minimum type for output
0120 
0121       ClassDef(MsgLogger,0) // Ostringstream derivative to redirect and format logging output
0122    }; // class MsgLogger
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    // Shortcut
0148    inline MsgLogger& Endl(MsgLogger& ml) { return MsgLogger::Endmsg(ml); }
0149 
0150 }
0151 
0152 #endif // TMVA_MsgLogger