00001 // @(#)root/mathcore:$Id: DistSamplerOptions.cxx 37419 2010-12-08 21:19:45Z moneta $ 00002 // Author: L. Moneta Fri Aug 15 2008 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2008 LCG ROOT Math Team, CERN/PH-SFT * 00007 * * 00008 * * 00009 **********************************************************************/ 00010 00011 #include "Math/DistSamplerOptions.h" 00012 00013 #include "Math/GenAlgoOptions.h" 00014 00015 00016 #include <iomanip> 00017 00018 namespace ROOT { 00019 00020 00021 namespace Math { 00022 00023 namespace Sampler { 00024 static std::string gDefaultSampler = "Unuran"; 00025 static std::string gDefaultAlgorithm1D = "auto"; 00026 static std::string gDefaultAlgorithmND = "vnrou"; 00027 static int gDefaultPrintLevel = 0; 00028 } 00029 00030 00031 void DistSamplerOptions::SetDefaultSampler(const char * type ) { 00032 // set the default minimizer type and algorithm 00033 if (type) Sampler::gDefaultSampler = std::string(type); 00034 } 00035 void DistSamplerOptions::SetDefaultAlgorithm1D(const char * algo ) { 00036 // set the default minimizer type and algorithm 00037 if (algo) Sampler::gDefaultAlgorithm1D = std::string(algo); 00038 } 00039 void DistSamplerOptions::SetDefaultAlgorithmND(const char * algo ) { 00040 // set the default minimizer type and algorithm 00041 if (algo) Sampler::gDefaultAlgorithmND = std::string(algo); 00042 } 00043 void DistSamplerOptions::SetDefaultPrintLevel(int level) { 00044 // set the default printing level 00045 Sampler::gDefaultPrintLevel = level; 00046 } 00047 00048 const std::string & DistSamplerOptions::DefaultAlgorithm1D() { return Sampler::gDefaultAlgorithm1D; } 00049 const std::string & DistSamplerOptions::DefaultAlgorithmND() { return Sampler::gDefaultAlgorithmND; } 00050 int DistSamplerOptions::DefaultPrintLevel() { return Sampler::gDefaultPrintLevel; } 00051 00052 const std::string & DistSamplerOptions::DefaultSampler() 00053 { 00054 // return default minimizer 00055 // if is "" (no default is set) read from etc/system.rootrc 00056 // use form /etc/ ?? 00057 00058 return Sampler::gDefaultSampler; 00059 } 00060 00061 00062 DistSamplerOptions::DistSamplerOptions(int dim): 00063 fLevel( Sampler::gDefaultPrintLevel), 00064 fExtraOptions(0) 00065 { 00066 // constructor using the default options 00067 00068 fSamplerType = DistSamplerOptions::DefaultSampler(); 00069 00070 if (dim == 1) 00071 fAlgoType = DistSamplerOptions::DefaultAlgorithm1D(); 00072 else if (dim >1) 00073 fAlgoType = DistSamplerOptions::DefaultAlgorithmND(); 00074 else 00075 // not specified - keep null string 00076 fAlgoType = std::string(); 00077 00078 // check if extra options exists (copy them if needed) 00079 if (!fExtraOptions) { 00080 IOptions * gopts = FindDefault( fSamplerType.c_str() ); 00081 if (gopts) fExtraOptions = gopts->Clone(); 00082 } 00083 } 00084 00085 00086 DistSamplerOptions::DistSamplerOptions(const DistSamplerOptions & opt) : fExtraOptions(0) { 00087 // copy constructor 00088 (*this) = opt; 00089 } 00090 00091 DistSamplerOptions & DistSamplerOptions::operator=(const DistSamplerOptions & opt) { 00092 // assignment operator 00093 if (this == &opt) return *this; // self assignment 00094 fLevel = opt.fLevel; 00095 fSamplerType = opt.fSamplerType; 00096 fAlgoType = opt.fAlgoType; 00097 00098 if (fExtraOptions) delete fExtraOptions; 00099 fExtraOptions = 0; 00100 if (opt.fExtraOptions) fExtraOptions = (opt.fExtraOptions)->Clone(); 00101 return *this; 00102 } 00103 00104 DistSamplerOptions::~DistSamplerOptions() { 00105 if (fExtraOptions) delete fExtraOptions; 00106 } 00107 00108 void DistSamplerOptions::SetExtraOptions(const IOptions & opt) { 00109 // set extra options (clone the passed one) 00110 if (fExtraOptions) delete fExtraOptions; 00111 fExtraOptions = opt.Clone(); 00112 } 00113 00114 void DistSamplerOptions::Print(std::ostream & os) const { 00115 //print all the options 00116 os << std::setw(25) << "DistSampler Type" << " : " << std::setw(15) << fSamplerType << std::endl; 00117 os << std::setw(25) << "DistSampler Algorithm" << " : " << std::setw(15) << fAlgoType << std::endl; 00118 os << std::setw(25) << "Print Level" << " : " << std::setw(15) << fLevel << std::endl; 00119 00120 if (ExtraOptions()) { 00121 os << fSamplerType << " specific options :" << std::endl; 00122 ExtraOptions()->Print(os); 00123 } 00124 } 00125 00126 IOptions & DistSamplerOptions::Default(const char * name) { 00127 // create default extra options for the given algorithm type 00128 return GenAlgoOptions::Default(name); 00129 } 00130 00131 IOptions * DistSamplerOptions::FindDefault(const char * name) { 00132 // find extra options for the given algorithm type 00133 return GenAlgoOptions::FindDefault(name); 00134 } 00135 00136 void DistSamplerOptions::PrintDefault(const char * name, std::ostream & os) { 00137 //print default options 00138 os << "Default DistSampler options " << std::endl; 00139 os << std::setw(25) << "Default Type" << " : " << std::setw(15) << DistSamplerOptions::DefaultSampler() << std::endl; 00140 os << std::setw(25) << "Default Algorithm 1D" << " : " << std::setw(15) << DistSamplerOptions::DefaultAlgorithm1D() << std::endl; 00141 os << std::setw(25) << "Default Algorithm ND" << " : " << std::setw(15) << DistSamplerOptions::DefaultAlgorithmND() << std::endl; 00142 os << std::setw(25) << "Default Print Level" << " : " << std::setw(15) << DistSamplerOptions::DefaultPrintLevel() << std::endl; 00143 IOptions * opt = FindDefault(name); 00144 if (opt) { 00145 os << "Specific default options for " << name << std::endl; 00146 opt->Print(os); 00147 } 00148 } 00149 00150 00151 00152 00153 } // end namespace Math 00154 00155 } // end namespace ROOT 00156