Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
Config.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Fredrik Tegenfeldt, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : Config *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * GLobal configuration settings (singleton) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16  * Fredrik Tegenfeldt <Fredrik.Tegenfeldt@cern.ch> - Iowa State U., USA *
17  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, GER *
18  * *
19  * Copyright (c) 2006: *
20  * CERN, Switzerland *
21  * Iowa State U., USA *
22  * MPI-K Heidelberg, Germany *
23  * *
24  * Redistribution and use in source and binary forms, with or without *
25  * modification, are permitted according to the terms listed in LICENSE *
26  * (http://mva.sourceforge.net/license.txt) *
27  **********************************************************************************/
28 
29 #ifndef ROOT_TMVA_Config
30 #define ROOT_TMVA_Config
31 
32 //////////////////////////////////////////////////////////////////////////
33 // //
34 // Config //
35 // //
36 // Singleton class for global configuration settings used by TMVA //
37 // //
38 //////////////////////////////////////////////////////////////////////////
39 #if __cplusplus > 199711L
40 #include <atomic>
41 #endif
42 #include "Rtypes.h"
43 #include "TString.h"
44 
45 #include "Executor.h"
46 
47 namespace TMVA {
48 
49  class MsgLogger;
50 
51  class Config {
52  protected:
53 
54  Executor fExecutor; // Executor for multi-thread or serial execution
55 
56  public:
57 
58  static Config& Instance();
59  static void DestroyInstance();
60 
61  Bool_t UseColor() const { return fUseColoredConsole; }
62  void SetUseColor( Bool_t uc ) { fUseColoredConsole = uc; }
63 
64  Bool_t IsSilent() const { return fSilent; }
65  void SetSilent( Bool_t s ) { fSilent = s; }
66 
67  Bool_t WriteOptionsReference() const { return fWriteOptionsReference; }
68  void SetWriteOptionsReference( Bool_t w ) { fWriteOptionsReference = w; }
69 
70  Bool_t DrawProgressBar() const { return fDrawProgressBar; }
71  void SetDrawProgressBar( Bool_t d ) { fDrawProgressBar = d; }
72  UInt_t GetNCpu() { return fExecutor.GetPoolSize(); }
73 
74  UInt_t GetNumWorkers() const { return fNWorkers; }
75  void SetNumWorkers(UInt_t n) { fNWorkers = n; }
76 
77 #ifdef R__USE_IMT
78  ROOT::TThreadExecutor &GetMultiThreadExecutor() { return *(fExecutor.GetMultiThreadExecutor()); }
79 // ROOT::TSequentialExecutor &GetSeqExecutor() { return *fSeqfPool; }
80 #endif
81  /// Get executor class for multi-thread usage
82  /// In case when MT is not enabled will return a serial executor
83  Executor & GetThreadExecutor() { return fExecutor; }
84 
85  /// Enable MT in TMVA (by default is on when ROOT::EnableImplicitMT() is set
86  void EnableMT(int numthreads = 0) { fExecutor = Executor(numthreads); }
87 
88  /// Force disabling MT running and release the thread pool by using instead seriaql execution
89  void DisableMT() { fExecutor = Executor(1); }
90 
91  ///Check if IMT is enabled
92  Bool_t IsMTEnabled() const { return fExecutor.GetPoolSize() > 1; }
93 
94  public:
95 
96  class VariablePlotting;
97  class IONames;
98 
99  VariablePlotting& GetVariablePlotting() { return fVariablePlotting; }
100  IONames& GetIONames() { return fIONames; }
101 
102  // publicly accessible global settings
103  class VariablePlotting {
104  // data collection class to configure plotting of variables
105  public:
106 
107  Float_t fTimesRMS;
108  Int_t fNbins1D;
109  Int_t fNbins2D;
110  Int_t fMaxNumOfAllowedVariables;
111  Int_t fMaxNumOfAllowedVariablesForScatterPlots;
112  Int_t fNbinsMVAoutput;
113  Int_t fNbinsXOfROCCurve;
114  Bool_t fUsePaperStyle;
115 
116  } fVariablePlotting; // Customisable plotting properties
117 
118  // for file names and similar
119  class IONames {
120 
121  public:
122  // this is name of weight file directory
123  TString fWeightFileDirPrefix;
124  TString fWeightFileDir;
125  TString fWeightFileExtension;
126  TString fOptionsReferenceFileDir;
127  } fIONames; // Customisable weight file properties
128 
129 
130  private:
131 
132  // private constructor
133  Config();
134  Config( const Config& );
135  Config& operator=( const Config&);
136  virtual ~Config();
137 #if __cplusplus > 199711L
138  static std::atomic<Config*> fgConfigPtr;
139 #else
140  static Config* fgConfigPtr;
141 #endif
142  private:
143 
144 #if __cplusplus > 199711L
145  std::atomic<Bool_t> fDrawProgressBar; // draw progress bar to indicate training evolution
146  std::atomic<UInt_t> fNWorkers; // Default number of workers for multi-process jobs
147  std::atomic<Bool_t> fUseColoredConsole; // coloured standard output
148  std::atomic<Bool_t> fSilent; // no output at all
149  std::atomic<Bool_t> fWriteOptionsReference; // if set true: Configurable objects write file with option reference
150 #else
151  Bool_t fDrawProgressBar; // draw progress bar to indicate training evolution
152  UInt_t fNWorkers; // Default number of workers for multi-process jobs
153  Bool_t fUseColoredConsole; // coloured standard output
154  Bool_t fSilent; // no output at all
155  Bool_t fWriteOptionsReference; // if set true: Configurable objects write file with option reference
156 #endif
157  mutable MsgLogger* fLogger; // message logger
158  MsgLogger& Log() const { return *fLogger; }
159 
160  ClassDef(Config,0); // Singleton class for global configuration settings
161  };
162 
163  // global accessor
164  Config& gConfig();
165 }
166 
167 #endif