64#pragma warning ( disable : 4355 )
71:
TNamed(
"Configurable",
"Configurable"),
72 fOptions ( theOption ),
73 fLooseOptionCheckingEnabled (
kTRUE ),
74 fLastDeclaredOption ( 0 ),
75 fConfigDescription (
"No description" ),
76 fReferenceFile (
"None" ),
100 while (splitOpt.
Length()>0) {
108 splitOpt = splitOpt(splitOpt.
First(
':')+1,splitOpt.
Length());
130 Log() << kVERBOSE <<
"Parsing option string: " <<
Endl;
131 TString optionsWithoutTilde(fOptions);
133 Log() << kVERBOSE <<
"... \"" << optionsWithoutTilde <<
"\"" <<
Endl;
140 SplitOptions(fOptions, loo);
144 std::map<TString, std::vector<std::pair<Int_t, TString> > > arrayTypeOptions;
159 Bool_t preserveTilde =
s.BeginsWith(
'~');
163 if (
s.Contains(
'=')) {
165 TString optval =
s(
s.First(
'=')+1,
s.Length());
173 if (decOpt==0 && optname.
Contains(
'[')) {
178 std::stringstream str(st.
Data());
187 Log() << kWARNING <<
"Value for option " << decOpt->
GetName()
188 <<
" was previously set to " << decOpt->
GetValue() <<
Endl;
199 Log() << kFATAL <<
"Index " << idx <<
" too large for option " << decOpt->
TheName()
205 Log() << kFATAL <<
"Option " << decOpt->
TheName()
206 <<
" is not an array, but you specified an index" <<
Endl;
211 else Log() << kFATAL <<
"Option " << decOpt->
TheName()
212 <<
" does not have predefined value: \"" << optval <<
"\"" <<
Endl;
221 if (
s.BeginsWith(
"!")) {
s.Remove(0,1); preserveNotSign = hasNotSign =
kTRUE; }
229 if (predOptName == optname) optionExists =
kTRUE;
231 if (predOptName == optname)
break;
236 decOpt->
SetValue( hasNotSign ?
"0" :
"1" );
240 if (optionExists && hasNotSign) {
241 Log() << kFATAL <<
"Negating a non-boolean variable " << optname
242 <<
", please check the options for method: " <<
GetName() <<
Endl;
248 if (!paramParsed && LooseOptionCheckingEnabled()) {
253 if (decOpt->HasPreDefinedVal() && decOpt->IsPreDefinedVal(
s) ) {
254 paramParsed = decOpt->SetValue(
s);
260 if (fOptions!=
"") fOptions +=
":";
261 if (paramParsed || preserveTilde) fOptions +=
'~';
262 if (preserveNotSign) fOptions +=
'!';
268 if (
gConfig().WriteOptionsReference()) WriteOptionsReferenceToFile();
281 SplitOptions(theOpt, loo);
288 if (!
s.BeginsWith(
'~')) {
289 if (unusedOptions !=
"") unusedOptions +=
':';
293 if (unusedOptions !=
"") {
295 <<
"The following options were specified, but could not be interpreted: \'"
296 << unusedOptions <<
"\', please check!" <<
Endl;
305 Log() << kVERBOSE <<
"The following options are set:" <<
Endl;
308 Log() << kVERBOSE <<
"- By User:" <<
Endl;
312 Log() << kVERBOSE <<
" ";
313 std::ostringstream oss;
318 if (!found)
Log() << kVERBOSE <<
" <none>" <<
Endl;
321 Log() << kVERBOSE <<
"- Default:" <<
Endl;
325 Log() << kVERBOSE <<
" ";
326 std::ostringstream oss;
331 if (!found)
Log() << kVERBOSE <<
" <none>" <<
Endl;
340 o << prefix <<
"# Set by User:" << std::endl;
342 if (opt->IsSet()) { o << prefix; opt->Print(o); o << std::endl; }
344 o << prefix <<
"# Default:" << std::endl;
346 if (!opt->IsSet()) { o << prefix; opt->Print(o); o << std::endl; }
347 o << prefix <<
"##" << std::endl;
360 if (opt->IsArrayOpt()) {
361 std::stringstream
s(
"");
363 for(
Int_t i=0; i<opt->GetArraySize(); i++) {
365 s << std::scientific << opt->GetValue(i);
373 if (opt->IsArrayOpt()) {
376 gTools().
AddAttr(optnode,
"modified", (opt->IsSet()?
"Yes":
"No") );
388 if (fOptions.Length()!=0) fOptions +=
":";
391 std::stringstream
s(
"");
393 if (
gTools().HasAttr(opt,
"size")) {
397 for(
UInt_t i=0; i<size; i++) {
399 s << std::scientific << optName <<
"[" << i <<
"]=" << values[i];
403 s << std::scientific << optName <<
"=" << optValue;
405 fOptions +=
s.str().c_str();
417 fReferenceFile = dir +
"/" + GetConfigName() +
"_optionsRef.txt";
418 std::ofstream o( fReferenceFile );
420 Log() << kFATAL <<
"<WriteOptionsToInfoFile> Unable to open output file: " << fReferenceFile <<
Endl;
424 o <<
"# List of options:" << std::endl;
425 o <<
"# Configurable: " << GetConfigName() << std::endl;
426 o <<
"# Description: " << GetConfigDescription() << std::endl;
429 o << std::endl <<
"# ------------------------------------------------" << std::endl;
433 Log() << kVERBOSE <<
"Wrote options reference file: \"" << fReferenceFile <<
"\"" <<
Endl;
447 istr.getline(buf,512);
449 while (istr.good() && !istr.eof() && !(buf[0]==
'#' && buf[1]==
'#')) {
451 while (*p==
' ' || *p==
'\t') p++;
452 if (*p==
'#' || *p==
'\0') {
453 istr.getline(buf,512);
456 std::stringstream sstr(buf);
457 sstr >> stropt >> strval;
460 if (fOptions.Length()!=0) fOptions +=
":";
463 istr.getline(buf,512);
R__EXTERN TSystem * gSystem
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void Reset()
Reset list iterator.
virtual void Add(TObject *obj)
TString fOptionsReferenceFileDir
void ReadOptionsFromXML(void *node)
void ResetSetFlag()
resets the IsSet flag for all declare options to be called before options are read from stream
virtual ~Configurable()
default destructor
void WriteOptionsReferenceToFile()
write complete options to output stream
void WriteOptionsToStream(std::ostream &o, const TString &prefix) const
write options to output stream (e.g. in writing the MVA weight files
Configurable(const TString &theOption="")
constructor
TList fListOfOptions
last declared option
virtual void ParseOptions()
options parser
void PrintOptions() const
prints out the options set in the options string and the defaults
void CheckForUnusedOptions() const
checks for unused options in option string
void SplitOptions(const TString &theOpt, TList &loo) const
splits the option string at ':' and fills the list 'loo' with the primitive strings
void ReadOptionsFromStream(std::istream &istr)
read option back from the weight file
void AddOptionsXMLTo(void *parent) const
write options to XML file
ostringstream derivative to redirect and format output
void SetMinType(EMsgType minType)
Class for TMVA-option handling.
virtual const char * TheName() const
virtual Bool_t SetValue(const TString &vs, Int_t i=-1)
set value for option
virtual Bool_t IsPreDefinedVal(const TString &) const =0
virtual Bool_t IsArrayOpt() const =0
virtual Bool_t HasPreDefinedVal() const =0
virtual const char * GetName() const
Returns name of object.
virtual Int_t GetArraySize() const =0
virtual TString GetValue(Int_t i=-1) const =0
The TNamed class is the base class for all named ROOT classes.
Collectable string class.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
void ToLower()
Change string to lower-case.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
TString & Remove(Ssiz_t pos)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual int MakeDirectory(const char *name)
Make a directory.
std::string GetName(const std::string &scope_name)
static constexpr double s
MsgLogger & Endl(MsgLogger &ml)