Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooMsgService.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooMsgService.h,v 1.2 2007/07/13 21:50:24 wouter Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_MSG_SERVICE
0017 #define ROO_MSG_SERVICE
0018 
0019 #include <RooCmdArg.h>
0020 #include <RooGlobalFunc.h>
0021 
0022 #include <TObject.h>
0023 
0024 #include <cstddef>
0025 #include <string>
0026 #include <vector>
0027 #include <stack>
0028 #include <map>
0029 
0030 class RooAbsArg ;
0031 class RooWorkspace ;
0032 
0033 // Shortcut definitions
0034 #define coutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
0035 #define coutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a)
0036 #define coutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
0037 #define coutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
0038 #define coutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
0039 
0040 // Skip the message prefix
0041 #define ccoutD(a) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,true)
0042 #define ccoutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,true)
0043 #define ccoutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a,true)
0044 #define ccoutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,true)
0045 #define ccoutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,true)
0046 #define ccoutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,true)
0047 
0048 // Message from given object instead of "this"
0049 #define oocoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
0050 #define oocoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a)
0051 #define oocoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
0052 #define oocoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a)
0053 #define oocoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
0054 
0055 // Message from given object instead of "this" and skip message prefix
0056 #define ooccoutD(o,a) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,true)
0057 #define ooccoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,true)
0058 #define ooccoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a,true)
0059 #define ooccoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,true)
0060 #define ooccoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,true)
0061 #define ooccoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,true)
0062 
0063 #ifndef _WIN32
0064 #define ANYDEBUG (RooMsgService::_debugCount>0)
0065 #else
0066 #define ANYDEBUG (RooMsgService::anyDebug())
0067 #endif
0068 
0069 #define dologD(a) (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG))
0070 #define dologI(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO))
0071 #define dologP(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS))
0072 #define dologW(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING))
0073 #define dologE(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR))
0074 #define dologF(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL))
0075 
0076 #define oodologD(o,a) (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG))
0077 #define oodologI(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO))
0078 #define oodologP(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS))
0079 #define oodologW(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING))
0080 #define oodologE(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR))
0081 #define oodologF(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL))
0082 
0083 // Shortcuts definitions with conditional execution of print expression -- USE WITH CAUTION
0084 
0085 #define cxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a)
0086 #define ccxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,true)
0087 #define oocxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a)
0088 #define ooccxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,true)
0089 #define cxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
0090 #define ccxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,true)
0091 #define oocxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
0092 #define ooccxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,true)
0093 #define cxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a)
0094 #define ccxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a,true)
0095 #define oocxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a)
0096 #define ooccxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a,true)
0097 #define cxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
0098 #define ccxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,true)
0099 #define oocxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
0100 #define ooccxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,true)
0101 #define cxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
0102 #define ccxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,true)
0103 #define oocxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a)
0104 #define ooccxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,true)
0105 #define cxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
0106 #define ccxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,true)
0107 #define oocxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
0108 #define ooccxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,true)
0109 
0110 class RooMsgService : public TObject {
0111 public:
0112 
0113   ~RooMsgService() override ;
0114 
0115   struct StreamConfig {
0116     public:
0117 
0118     void addTopic(RooFit::MsgTopic newTopic) {
0119       topic |= newTopic ;
0120     }
0121 
0122     void removeTopic(RooFit::MsgTopic oldTopic) {
0123       topic &= ~oldTopic ;
0124     }
0125 
0126 
0127     friend class RooMsgService ;
0128 
0129     bool match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const RooAbsArg* obj) ;
0130     bool match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const TObject* obj) ;
0131 
0132     inline bool match(RooFit::MsgLevel level, RooFit::MsgTopic facility, std::nullptr_t obj)
0133     {
0134        return match(level, facility, static_cast<TObject const *>(obj));
0135     }
0136 
0137     bool active ;
0138     bool universal ;
0139 
0140     RooFit::MsgLevel minLevel ;
0141     Int_t    topic ;
0142     std::string objectName ;
0143     std::string className ;
0144     std::string baseClassName ;
0145     std::string tagName ;
0146     Color_t color ;
0147     bool prefix ;
0148 
0149     std::ostream* os ;
0150 
0151   } ;
0152 
0153   // Access to instance
0154   static RooMsgService& instance();
0155   static bool anyDebug() ;
0156 
0157   // User interface -- Add or delete reporting streams ;
0158   Int_t addStream(RooFit::MsgLevel level, const RooCmdArg& arg1={}, const RooCmdArg& arg2={}, const RooCmdArg& arg3={},
0159                           const RooCmdArg& arg4={}, const RooCmdArg& arg5={}, const RooCmdArg& arg6={});
0160   void deleteStream(Int_t id) ;
0161   StreamConfig& getStream(Int_t id) { return _streams[id] ; }
0162 
0163   Int_t numStreams() const { return _streams.size() ; }
0164   void setStreamStatus(Int_t id, bool active) ;
0165   bool getStreamStatus(Int_t id) const ;
0166 
0167   void reset();
0168 
0169   void setGlobalKillBelow(RooFit::MsgLevel level) { _globMinLevel = level ; }
0170   RooFit::MsgLevel globalKillBelow() const { return _globMinLevel ; }
0171 
0172   void Print(Option_t *options= nullptr) const override ;
0173   void showPid(bool flag) { _showPid = flag ; }
0174 
0175   // Back end -- Send message or check if particular logging configuration is active
0176   std::ostream& log(const RooAbsArg* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false) ;
0177   std::ostream& log(const TObject* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false) ;
0178   // Overload to resolve the ambiguity when passing a `nullptr`. Without this,
0179   // one would have to explicitly cast the `nullptr` to TObject* or RooAbsArg*.
0180   inline std::ostream& log(std::nullptr_t, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false) {
0181       return log(static_cast<TObject*>(nullptr), level, facility, forceSkipPrefix);
0182   }
0183 
0184   /// Check if logging is active for given object/topic/RooFit::%MsgLevel combination.
0185   template <class T>
0186   bool isActive(T self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
0187   {
0188      return activeStream(self, topic, level) >= 0;
0189   }
0190 
0191   static Int_t _debugCount ;
0192   std::map<int,std::string> _levelNames ;
0193   std::map<int,std::string> _topicNames ;
0194 
0195   // Print level support for RooFit-related messages that are not routed through RooMsgService (such as Minuit printouts)
0196   bool silentMode() const { return _silentMode ; }
0197   void setSilentMode(bool flag) { _silentMode = flag ; }
0198 
0199   Int_t errorCount() const { return _errorCount ; }
0200   void clearErrorCount() { _errorCount = 0 ; }
0201 
0202   void saveState() ;
0203   void restoreState() ;
0204 
0205   RooWorkspace* debugWorkspace() ;
0206 
0207   Int_t& debugCode() { return _debugCode ; }
0208 
0209 protected:
0210 
0211   /// Find appropriate logging stream for message from given object with given topic and message level.
0212   template <class T>
0213   Int_t activeStream(T self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
0214   {
0215      if (level < _globMinLevel)
0216         return -1;
0217      for (UInt_t i = 0; i < _streams.size(); i++) {
0218         if (_streams[i].match(level, topic, self)) {
0219            return i;
0220         }
0221      }
0222      return -1;
0223   }
0224 
0225   std::vector<StreamConfig> _streams ;
0226   std::stack<std::vector<StreamConfig> > _streamsSaved ;
0227   std::unique_ptr<std::ofstream> _devnull ;
0228 
0229   std::map<std::string,std::unique_ptr<std::ostream>> _files ;
0230   RooFit::MsgLevel _globMinLevel ;
0231   RooFit::MsgLevel _lastMsgLevel ;
0232 
0233   bool _silentMode ;
0234   bool _showPid ;
0235 
0236   Int_t _errorCount ;
0237 
0238   // Private constructor -- singleton class
0239   RooMsgService() ;
0240   RooMsgService(const RooMsgService&) ;
0241 
0242   std::unique_ptr<RooWorkspace> _debugWorkspace;
0243 
0244   Int_t _debugCode ;
0245 
0246   ClassDefOverride(RooMsgService,0) // RooFit Message Service Singleton class
0247 };
0248 
0249 #endif