/usr/include/root/TMVA/Option.h is in libroot-tmva-dev 5.34.19+dfsg-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | // @(#)root/tmva $Id$
// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss
/**********************************************************************************
* Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
* Package: TMVA *
* Class : Option *
* Web : http://tmva.sourceforge.net *
* *
* Description: *
* Option container *
* *
* Authors (alphabetical): *
* Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
* Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
* Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
* *
* Copyright (c) 2005: *
* CERN, Switzerland *
* U. of Victoria, Canada *
* MPI-K Heidelberg, Germany *
* LAPP, Annecy, France *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted according to the terms listed in LICENSE *
* (http://mva.sourceforge.net/license.txt) *
**********************************************************************************/
#ifndef ROOT_TMVA_Option
#define ROOT_TMVA_Option
//////////////////////////////////////////////////////////////////////////
// //
// Option //
// //
// Class for TMVA-option handling //
// //
//////////////////////////////////////////////////////////////////////////
#include <iomanip>
#include <sstream>
#include <vector>
#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TList
#include "TList.h"
#endif
#ifndef ROOT_TMVA_MsgLogger
#include "TMVA/MsgLogger.h"
#endif
namespace TMVA {
class Configurable;
class OptionBase : public TObject {
public:
friend class Configurable;
OptionBase( const TString& name, const TString& desc );
virtual ~OptionBase() {}
virtual const char* GetName() const { return fNameAllLower.Data(); }
virtual const char* TheName() const { return fName.Data(); }
virtual TString GetValue(Int_t i=-1) const = 0;
Bool_t IsSet() const { return fIsSet; }
virtual Bool_t IsArrayOpt() const = 0;
const TString& Description() const { return fDescription; }
virtual Bool_t IsPreDefinedVal(const TString&) const = 0;
virtual Bool_t HasPreDefinedVal() const = 0;
virtual Int_t GetArraySize() const = 0;
virtual Bool_t SetValue( const TString& vs, Int_t i=-1 );
using TObject::Print;
virtual void Print( std::ostream&, Int_t levelofdetail=0 ) const = 0;
private:
virtual void SetValueLocal(const TString& vs, Int_t i=-1) = 0;
const TString fName; // name of variable
TString fNameAllLower; // name of variable
const TString fDescription; // its description
Bool_t fIsSet; // set by user ?
protected:
static MsgLogger* fgLogger; // message logger
};
// ---------------------------------------------------------------------------
template <class T>
class Option : public OptionBase {
public:
Option( T& ref, const TString& name, const TString& desc ) :
OptionBase(name, desc), fRefPtr(&ref) {}
virtual ~Option() {}
// getters
virtual TString GetValue( Int_t i=-1 ) const;
virtual const T& Value ( Int_t i=-1 ) const;
virtual Bool_t HasPreDefinedVal() const { return (fPreDefs.size()!=0); }
virtual Bool_t IsPreDefinedVal( const TString& ) const;
virtual Bool_t IsArrayOpt() const { return kFALSE; }
virtual Int_t GetArraySize() const { return 0; }
// setters
virtual void AddPreDefVal(const T&);
using OptionBase::Print;
virtual void Print ( std::ostream&, Int_t levelofdetail=0 ) const;
virtual void PrintPreDefs( std::ostream&, Int_t levelofdetail=0 ) const;
protected:
T& Value(Int_t=-1);
virtual void SetValueLocal( const TString& val, Int_t i=-1 );
virtual Bool_t IsPreDefinedValLocal( const T& ) const;
T* fRefPtr;
std::vector<T> fPreDefs; // templated vector
};
template<typename T>
class Option<T*> : public Option<T> {
public:
Option( T*& ref, Int_t size, const TString& name, const TString& desc ) :
Option<T>(*ref,name, desc), fVRefPtr(&ref), fSize(size) {}
virtual ~Option() {}
TString GetValue( Int_t i ) const {
std::stringstream str;
str << std::scientific << Value(i);
return str.str();
}
const T& Value( Int_t i ) const { return (*fVRefPtr)[i]; }
virtual Bool_t IsArrayOpt() const { return kTRUE; }
virtual Int_t GetArraySize() const { return fSize; }
using Option<T>::Print;
virtual void Print( std::ostream&, Int_t levelofdetail=0 ) const;
virtual Bool_t SetValue( const TString& val, Int_t i=0 );
T& Value(Int_t i) { return (*fVRefPtr)[i]; }
T ** fVRefPtr;
Int_t fSize;
};
} // namespace
namespace TMVA {
//______________________________________________________________________
template<class T>
inline const T& TMVA::Option<T>::Value( Int_t ) const {
return *fRefPtr;
}
template<class T>
inline T& TMVA::Option<T>::Value( Int_t ) {
return *fRefPtr;
}
template<class T>
inline TString TMVA::Option<T>::GetValue( Int_t ) const {
std::stringstream str;
str << std::scientific << this->Value();
return str.str();
}
template<>
inline TString TMVA::Option<Bool_t>::GetValue( Int_t ) const {
return Value() ? "True" : "False";
}
template<>
inline TString TMVA::Option<Bool_t*>::GetValue( Int_t i ) const {
return Value(i) ? "True" : "False";
}
template<class T>
inline Bool_t TMVA::Option<T>::IsPreDefinedVal( const TString& val ) const
{
// template
T tmpVal;
std::stringstream str(val.Data());
str >> tmpVal;
return IsPreDefinedValLocal(tmpVal);
}
template<class T>
inline Bool_t TMVA::Option<T>::IsPreDefinedValLocal(const T& val) const
{
// template
if (fPreDefs.size()==0) return kTRUE; // if nothing pre-defined then allow everything
typename std::vector<T>::const_iterator predefIt;
predefIt = fPreDefs.begin();
for (;predefIt!=fPreDefs.end(); predefIt++)
if ( (*predefIt)==val ) return kTRUE;
return kFALSE;
}
template<>
inline Bool_t TMVA::Option<TString>::IsPreDefinedValLocal( const TString& val ) const
{
// template specialization for Bool_t
TString tVal(val);
tVal.ToLower();
if (fPreDefs.size()==0) return kFALSE; // if nothing pre-defined then allow everything
Bool_t foundPreDef = kFALSE;
std::vector<TString>::const_iterator predefIt;
predefIt = fPreDefs.begin();
for (;predefIt!=fPreDefs.end(); predefIt++) {
TString s(*predefIt);
s.ToLower();
if (s==tVal) { foundPreDef = kTRUE; break; }
}
return foundPreDef;
}
//______________________________________________________________________
template<class T>
inline void TMVA::Option<T>::AddPreDefVal( const T& val )
{
// template
fPreDefs.push_back(val);
}
template<>
inline void TMVA::Option<Bool_t>::AddPreDefVal( const Bool_t& )
{
// template specialization for Bool_t
*fgLogger << kFATAL << "<AddPreDefVal> predefined values for Option<Bool_t> don't make sense"
<< Endl;
}
template<>
inline void TMVA::Option<Float_t>::AddPreDefVal( const Float_t& )
{
// template specialization for Float_t
*fgLogger << kFATAL << "<AddPreDefVal> predefined values for Option<Float_t> don't make sense"
<< Endl;
}
template<class T>
inline void TMVA::Option<T>::Print( std::ostream& os, Int_t levelofdetail ) const
{
// template specialization for TString printing
os << TheName() << ": " << "\"" << GetValue() << "\"" << " [" << Description() << "]";
this->PrintPreDefs(os,levelofdetail);
}
template<class T>
inline void TMVA::Option<T*>::Print( std::ostream& os, Int_t levelofdetail ) const
{
// template specialization for TString printing
for (Int_t i=0; i<fSize; i++) {
if (i==0)
os << this->TheName() << "[" << i << "]: " << "\"" << this->GetValue(i) << "\"" << " [" << this->Description() << "]";
else
os << " " << this->TheName() << "[" << i << "]: " << "\"" << this->GetValue(i) << "\"";
if (i!=fSize-1) os << std::endl;
}
this->PrintPreDefs(os,levelofdetail);
}
//______________________________________________________________________
template<class T>
inline void TMVA::Option<T>::PrintPreDefs( std::ostream& os, Int_t levelofdetail ) const
{
// template specialization for TString printing
if (HasPreDefinedVal() && levelofdetail>0) {
os << std::endl << "PreDefined - possible values are:" << std::endl;
typename std::vector<T>::const_iterator predefIt;
predefIt = fPreDefs.begin();
for (;predefIt!=fPreDefs.end(); predefIt++) {
os << " ";
os << " - " << (*predefIt) << std::endl;
}
}
}
//______________________________________________________________________
template<class T>
inline Bool_t TMVA::Option<T*>::SetValue( const TString& val, Int_t ind )
{
// template
if (ind >= fSize) return kFALSE;
std::stringstream str(val.Data());
if (ind < 0) {
str >> Value(0);
for (Int_t i=1; i<fSize; i++) Value(i) = Value(0);
}
else {
str >> Value(ind);
}
return kTRUE;
}
template<class T>
inline void TMVA::Option<T>::SetValueLocal( const TString& val, Int_t i )
{
// template
std::stringstream str(val.Data());
str >> Value(i);
}
template<>
inline void TMVA::Option<TString>::SetValueLocal( const TString& val, Int_t )
{
// set TString value
TString valToSet(val);
if (fPreDefs.size()!=0) {
TString tVal(val);
tVal.ToLower();
std::vector<TString>::const_iterator predefIt;
predefIt = fPreDefs.begin();
for (;predefIt!=fPreDefs.end(); predefIt++) {
TString s(*predefIt);
s.ToLower();
if (s==tVal) { valToSet = *predefIt; break; }
}
}
std::stringstream str(valToSet.Data());
str >> Value(-1);
}
template<>
inline void TMVA::Option<Bool_t>::SetValueLocal( const TString& val, Int_t )
{
// set Bool_t value
TString valToSet(val);
valToSet.ToLower();
if (valToSet=="1" || valToSet=="true" || valToSet=="ktrue" || valToSet=="t") {
this->Value() = true;
}
else if (valToSet=="0" || valToSet=="false" || valToSet=="kfalse" || valToSet=="f") {
this->Value() = false;
}
else {
*fgLogger << kFATAL << "<SetValueLocal> value \'" << val
<< "\' can not be interpreted as boolean" << Endl;
}
}
}
#endif
|