rarStrParser Class Reference

String parser for RooRarFit. More...

#include <rarStrParser.hh>

List of all members.

Public Member Functions

 rarStrParser ()
 Trivial ctor.
 rarStrParser (const char *str)
 Ctor using char pointer.
 rarStrParser (const TString str)
 Ctor using TString object.
 rarStrParser (const rarStrParser &)
 Ctor for assignment using its own object.
virtual ~rarStrParser ()
void operator= (const char *str)
 Operator = with char pointer.
void operator= (const TString str)
 Operator = with TString object.
void operator= (const RooStringVar str)
 Operator = with RooStringVar object.
TString & operator[] (const Int_t idx)
 Get the indexed token.
void Remove (const Int_t idx=0)
 Remove the indexed token.
Int_t Index (const TString token)
 Get the index for a token.
Bool_t Have (const TString token)
 Check if have the token.
Int_t nArgs ()
 Return number of tokens.

Protected Member Functions

void init ()
 Initial function to parse a string.
TObjString * nextToken ()
 Get next token in the string from current position.

Protected Attributes

TString _str
 String to parse.
TList _strs
 List of parsed tokens.

Private Member Functions

 ClassDef (rarStrParser, 0)

Private Attributes

Int_t _idx
 Current char index used for string parsing.


Detailed Description

String parser for RooRarFit.

It is the string parser used widely by other RooRarFit classes to direct their actions through config items in config file. It breaks a string into tokens seperated by spaces. Characters inside quote(") are considered one token. Currently, quote (") can not be inside the parsed tokens.

Definition at line 27 of file rarStrParser.hh.


Constructor & Destructor Documentation

rarStrParser::rarStrParser (  ) 

Trivial ctor.

Definition at line 35 of file rarStrParser.cc.

References init().

00036   : _str("")
00037 {
00038   init();
00039 }

rarStrParser::rarStrParser ( const char *  str  ) 

Ctor using char pointer.

Parameters:
str String to parse

Definition at line 44 of file rarStrParser.cc.

References init().

00045   : _str(str)
00046 {
00047   init();
00048 }

rarStrParser::rarStrParser ( const TString  str  ) 

Ctor using TString object.

Parameters:
str String to parse

Definition at line 54 of file rarStrParser.cc.

References init().

00055   : _str(str)
00056 {
00057   init();
00058 }

rarStrParser::rarStrParser ( const rarStrParser aParser  ) 

Ctor for assignment using its own object.

Parameters:
aParser Source object

Definition at line 63 of file rarStrParser.cc.

References _str, and _strs.

00064   : TObject(aParser)
00065 {
00066   _str=aParser._str;
00067   // go through tokens and copy them
00068   for (Int_t i=0; i<((rarStrParser&)aParser).nArgs(); i++)
00069     _strs.Add(new TObjString(((rarStrParser&)aParser)[i]));
00070 }

rarStrParser::~rarStrParser (  )  [virtual]

Definition at line 72 of file rarStrParser.cc.

References _strs.

00073 {
00074   _strs.Delete();
00075 }


Member Function Documentation

rarStrParser::ClassDef ( rarStrParser  ,
 
) [private]

Bool_t rarStrParser::Have ( const TString  token  ) 

Check if have the token.

Parameters:
token Token to check
Returns:
true if found, false if not
It checks if the parser has the token

Definition at line 130 of file rarStrParser.cc.

References Index().

Referenced by rarBasePdf::doPdfFit(), rarBasePdf::doPdfPlot(), rarMLFitter::doSPlot(), rarMLFitter::getSnB(), rarConfig::getVarTNTU(), rarDatasets::isBlind(), rarBasePdf::isFracName(), rarBasePdf::matchCatType(), and rarMLFitter::run().

00130                                              {
00131   return (Index(token)<0) ? kFALSE : kTRUE;
00132 }

Int_t rarStrParser::Index ( const TString  token  ) 

Get the index for a token.

Parameters:
token Token to check
Returns:
the index of the give token, -1 if not found
It returns index for a given token, -1 if not found.

Definition at line 139 of file rarStrParser.cc.

References nArgs().

Referenced by rarMLFitter::doContourPlot(), rarMLFitter::doSPlot(), rarConfig::getVarTNTU(), Have(), and rarMLPdf::init().

00139                                              {
00140   Int_t index(-1);
00141   for (Int_t i=0; i<nArgs(); i++)
00142     if (token==operator[](i)) return i;
00143   return index;
00144 }

void rarStrParser::init (  )  [protected]

Initial function to parse a string.

It initializes _idx and _strs and calls nextToken to parse the string

Definition at line 150 of file rarStrParser.cc.

References _idx, _strs, and nextToken().

Referenced by operator=(), and rarStrParser().

00151 {
00152   // reset index and parsed string objs
00153   _idx=0;
00154   _strs.Delete();
00155   TObjString *objStr(0);
00156   while (objStr=nextToken()) {
00157     _strs.Add(objStr);
00158   }
00159 }

Int_t rarStrParser::nArgs (  )  [inline]

Return number of tokens.

Returns:
Number of tokens stored

Definition at line 45 of file rarStrParser.hh.

References _strs.

Referenced by rarMLFitter::avgSysErrors(), rarConfig::createAbsVar(), rarConfig::createAbsVars(), rarConfig::createDataSet(), rarConfig::createPdf(), rarBasePdf::createPdfs(), rarMLFitter::doCombinePlot(), rarMLFitter::doLLRPlot(), rarBasePdf::doPdfFit(), rarBasePdf::doPdfPlot(), rarMLFitter::doProjPlot(), rarMLFitter::doScanPlot(), rarMLFitter::doSignf(), rarMLFitter::doSPlot(), rarMLFitter::doSysStudy(), rarMLFitter::doToyStudy(), rarMLFitter::generate(), rarBasePdf::getArgSet(), rarBasePdf::getControlBit(), rarMLFitter::getCorrMatrix(), rarDatasets::getData(), rarDatasetDef::getFormulaArgs(), rarBasePdf::getFormulaArgs(), rarMLFitter::getParamFileName(), rarBasePdf::getRange(), rarMLFitter::getSnB(), rarMLFitter::getSplitCat(), rarMLFitter::getSplitCatSet(), rarConfig::getVarTNTU(), Index(), rarStep::init(), rarProd::init(), rarMLPdf::init(), rarMLFitter::init(), rarDecay::init(), rarDatasets::init(), rarBinned::init(), rarDatasets::isBlind(), rarBasePdf::matchCatType(), rarMLFitter::run(), and rarBasePdf::setControlBits().

00045 {return _strs.GetSize();}

TObjString * rarStrParser::nextToken (  )  [protected]

Get next token in the string from current position.

Todo:
Make quote (") regular character with `\"'.
This is the actual parser. It ignores any blank characters at current position and return the sub-string until next blank character as the token. If current non-blank character is quote ("), it will take all characters after that until the next quote (") as token and return it. It return 0 (null) if current position, _idx, is out of range.

Definition at line 172 of file rarStrParser.cc.

References _idx, and _str.

Referenced by init().

00173 {
00174   Int_t nIdx(0);
00175   if (_idx>=_str.Length()) return 0;
00176   while (' '==_str[_idx] || '\t'==_str[_idx] || '\n'==_str[_idx]) {
00177     _idx++;
00178     if (_idx>=_str.Length()) return 0;
00179   }
00180   if ('"'==_str[_idx]) {
00181     _idx++;
00182     nIdx=_str.Index("\"", _idx);
00183     if(nIdx<0) return 0;
00184   } else {
00185     nIdx=_str.Index(" ", _idx);
00186     if(nIdx<0) nIdx=_str.Length();
00187   }
00188   //cout<<"in Parser "<<nIdx<<" "<<_idx<<" "<<_str(_idx, nIdx-_idx)<<endl;
00189   TString substr=_str(_idx, nIdx-_idx);
00190   TObjString *subStr=new TObjString(substr);
00191   _idx=nIdx;
00192   if (_idx<_str.Length())
00193     if ('"'==_str[_idx]) _idx++;
00194   
00195   return subStr;
00196 }

void rarStrParser::operator= ( const RooStringVar  str  ) 

Operator = with RooStringVar object.

Parameters:
str String to parse

Definition at line 97 of file rarStrParser.cc.

References operator=().

00098 {
00099   rarStrParser::operator=(str.getVal());
00100 }

void rarStrParser::operator= ( const TString  str  ) 

Operator = with TString object.

Parameters:
str String to parse

Definition at line 89 of file rarStrParser.cc.

References operator=().

00090 {
00091   rarStrParser::operator=(str.Data());
00092 }

void rarStrParser::operator= ( const char *  str  ) 

Operator = with char pointer.

Parameters:
str String to parse

Definition at line 80 of file rarStrParser.cc.

References _str, and init().

Referenced by operator=().

00081 {
00082   _str=str;
00083   init();
00084 }

TString & rarStrParser::operator[] ( const Int_t  idx  ) 

Get the indexed token.

Parameters:
idx Token index in _strs
Returns:
The indexed token

Definition at line 106 of file rarStrParser.cc.

References _str, and _strs.

00107 {
00108   TObjString *retVal=(TObjString*)_strs.At(idx);
00109   if (retVal) return retVal->String();
00110   return _str;
00111 }

void rarStrParser::Remove ( const Int_t  idx = 0  ) 

Remove the indexed token.

Parameters:
idx The index of token to be removed

Definition at line 116 of file rarStrParser.cc.

References _strs.

Referenced by rarConfig::createAbsVar(), rarConfig::createAbsVars(), rarConfig::createDataSet(), rarConfig::createPdf(), rarMLFitter::doContourPlot(), rarMLFitter::doLLRPlot(), rarBasePdf::doPdfFit(), rarBasePdf::doPdfPlot(), rarMLFitter::doProjPlot(), rarMLFitter::doScanPlot(), rarMLFitter::doSignf(), rarMLFitter::doSPlot(), rarMLFitter::doSysStudy(), rarMLFitter::doToyStudy(), rarMLFitter::generate(), rarBasePdf::getFormulaVal(), rarMLFitter::getParamFileName(), rarBasePdf::getRange(), rarMLFitter::getSplitCat(), rarConfig::getVarTNTU(), rarMLFitter::init(), rarGeneric::init(), rarBasePdf::init(), rarDatasets::isBlind(), and rarMLFitter::run().

00117 {
00118   TObject *val=_strs.At(idx);
00119   if (val) {
00120     _strs.Remove(val);
00121     delete val;
00122   }
00123 }


Member Data Documentation

Int_t rarStrParser::_idx [private]

Current char index used for string parsing.

Definition at line 55 of file rarStrParser.hh.

Referenced by init(), and nextToken().

TString rarStrParser::_str [protected]

String to parse.

Definition at line 51 of file rarStrParser.hh.

Referenced by nextToken(), operator=(), operator[](), and rarStrParser().

TList rarStrParser::_strs [protected]

List of parsed tokens.

Definition at line 52 of file rarStrParser.hh.

Referenced by init(), nArgs(), operator[](), rarStrParser(), Remove(), and ~rarStrParser().


The documentation for this class was generated from the following files:
Generated on 30 Oct 2013 for RooRarFit by  doxygen 1.4.7