AliRoot Core  3dc7879 (3dc7879)
AliParser Class Reference

Class provides flexibility static methods for tokenizing strings. You can find explanation, details and examples in description of each function. More...

#include <AliParser.h>

Static Public Member Functions

static std::vector< TString > ExtractBetween (const char *inputString, const char *startStr, const char *endStr, Int_t verbose=0)
 Extracts content between specified patterns (startStr, endStr). More...
 
static std::vector< TString > Split (const char *inputString, const char delimiter=',', Int_t verbose=0)
 Splits input string to array according to specified char delimiter. More...
 
static std::vector< TString > ExtractSurroundingBy (const char *inputString, const char begin='(', const char end= ')', Int_t verbose=0)
 Extracts content from specified parentheses. More...
 
static std::map< TString, TString > Parse (const char *inputString, Int_t verbose=0, std::vector< TString > defKeys=std::vector< TString >{})
 Parses string with named arguments. More...
 
static std::vector< Int_t > Slice2IArray (const char *inputString)
 Returns array according with python-like interface. More...
 
static TMatrixD Slice2Matrix (const char *inputString, Int_t verbose=0)
 Returns TMatrixD from input string. More...
 
static void Map2Array (std::vector< Double_t > &array, std::map< Int_t, std::vector< Double_t > > iRanges, Int_t *indexes, Int_t cnt)
 
static void FillFloatFlagArray (std::vector< Double_t > &, TString)
 

Detailed Description

Class provides flexibility static methods for tokenizing strings. You can find explanation, details and examples in description of each function.

Author
Marian Ivanov, Boris Rumyantsev

Definition at line 21 of file AliParser.h.

Member Function Documentation

std::vector< TString > AliParser::ExtractBetween ( const char *  str,
const char *  startStr,
const char *  endStr,
Int_t  verbose = 0 
)
static

Extracts content between specified patterns (startStr, endStr).

The analogue of this method exists in matlab

Parameters
str- input string
startStr- start pattern
endStr- end pattern
verbose
Returns
- vector of TString with content between startStr and endStr

Example usage:

root[] AliParser::ExtractBetween("{\nmarker-style:25,21,22,23; \nmarker-color:1,2,4,5; \n}", "marker-style:", ";")
(std::vector<TString>) { "25,21,22,23" }
root [] AliParser::ExtractBetween("3*<mean>-<max>/2,<rms>*10+<min>", "<", ">")
(std::vector<TString>) { "mean", "max", "rms", "mean" }

Definition at line 40 of file AliParser.cxx.

Referenced by AliParserTest_ExtractBetween(), and AliPainter::GetStatVal().

std::vector< TString > AliParser::ExtractSurroundingBy ( const char *  inpString,
const char  begin = '(',
const char  end = ')',
Int_t  verbose = 0 
)
static

Extracts content from specified parentheses.

The similar method exist in java library from google - guava Template of input string: <(content1)(content2(content3))> ==> {content1,content2(content3)} This function very similar to AliParser::ExtractBetween. The differences:

  1. In AliParser::ExtractBetween separators could be any length;
  2. In case such string "abc<1>+..." will be input string of both methods, that all elements of returned arrays from AliParser::ExtractBetween and AliParser::ExtractSurroundingBy will be the same except first element. AliParser::ExtractBetween(...)[0] will be "1"(!), but AliParser::ExtractSurroundingBy(...)[0] will be "abc"(!).
    Parameters
    inpString
    begin- by default - '('
    end- by default - ')'
    verbose
    Returns
    - arrays with contents of parentheses
    Example usage:
    root [] AliParser::ExtractSurroundingBy("(a(1,2,3))(b[1,2,3])(c{1,2,3})")
    (std::vector<TString>) { "a(1,2,3)", "b[1,2,3]", "c{1,2,3}" }
    AliParser::ExtractSurroundingBy("nameOfSomething(param1,param2)(param3,param4)(functionName(arg1,arg2))")
    (std::vector<TString>) { "nameOfSomething", "param1,param2", "param3,param4", "functionName(arg1,arg2)" }

Definition at line 132 of file AliParser.cxx.

Referenced by AliParserTest_ExtractSurroundingBy(), AliPainter::DrawHistogram(), and AliPainter::PrepareHistogram().

void AliParser::FillFloatFlagArray ( std::vector< Double_t > &  floatFlagArray,
TString  str 
)
static
Parameters
floatFlagArray
str

Definition at line 381 of file AliParser.cxx.

Referenced by Slice2Matrix().

void AliParser::Map2Array ( std::vector< Double_t > &  array,
std::map< Int_t, std::vector< Double_t > >  iRanges,
Int_t *  indexes,
Int_t  cnt 
)
static
Parameters
array
iRanges
indexes
cnt

Definition at line 354 of file AliParser.cxx.

Referenced by Slice2Matrix().

std::map< TString, TString > AliParser::Parse ( const char *  iStr,
Int_t  verbose = 0,
std::vector< TString >  defKeys = std::vector<TString>{} 
)
static

Parses string with named arguments.

Template of input string: <nameOfArg1=value1,nameOfArg2=value2,nameOfArg3=[value3.1,value3.2]...> In some cases could be useful usage of named parameters. You can study more information in python argparse module.

Parameters
optionsStr- input string
verbose
defKeys- the list of predefined keys, if parsed key will not found in this list - warning'll be generate.
Returns

Example usage:

root[] AliParser::Parse("name=gaus, strategy=misac(10,20),xlim=[10,20],class=Abc",4)
(std::map<TString, TString>) { "name" => "gaus", "strategy" => "misac(10,20)", "xlim" => "[10,20]", "class" => "Abc" }

Definition at line 190 of file AliParser.cxx.

Referenced by AliParserTest_Parse(), AliPainter::DrawHistogram(), and AliPainter::PrepareHistogram().

std::vector< Int_t > AliParser::Slice2IArray ( const char *  inputString)
static

Returns array according with python-like interface.

In python for getting values from array, you can use ":" see python docs Here we provide the same functionality, but output array will generate from string.

Parameters
range
Returns

Example usage:

root [] AliParser::Slice2IArray("10:40:10:10")
(std::vector<Int_t>) { 10, 20, 20, 30, 30, 40 }
(std::vector<Int_t>) { 1, 2, 2, 3, 3, 4 }
root [] AliParser::Slice2IArray("1:4:1:0")
(std::vector<Int_t>) { 1, 1, 2, 2, 3, 3, 4, 4 }

Definition at line 228 of file AliParser.cxx.

Referenced by AliParserTest_Slice2IArray(), and Slice2Matrix().

TMatrixD AliParser::Slice2Matrix ( const char *  iStr,
Int_t  verbose = 0 
)
static

Returns TMatrixD from input string.

The idea is providing method for generating values of ranges with slicer: Such string "10,20,30:60:10:10,70:110:10:10" should be transform to the next map:

axisNum 0 1 2
values 10 30 70
20 40 80
40 80
50 90
50 90
60 100
100
110

And then such map will be transform to the matrix:

nCols - (count of axes) * 2

nRows - 1 + multiplication of sizes of each array from map divided by 2

last row - floatFlag of each column. In case float flag is 1 SetRangeUser will be applied else SetRange

x0Minx0Maxx1Minx1Maxx2Minx2Max
10 20 30 40 70 80
10 20 30 40 80 90
10 20 30 40 90 100
10 20 30 40 100110
10 20 40 50 70 80
10 20 40 50 80 90
10 20 40 50 90 100
10 20 40 50 100110
10 20 50 60 70 80
10 20 50 60 80 90
10 20 50 60 90 100
10 20 50 60 100110
0 0 0 0 0 0
Parameters
inputString- string for transforming
verbose
Returns
matrix of parsed values

Example usage:

/*
auto m = AliParser::Slice2Matrix("10,20,30:60:10:10,70:110:10:10")
{
for(auto i=0;i<m.GetNrows();++i) {
for(auto j=0;j<m.GetNcols();++j) {
std::cout << " " << TMatrixDRow(m,i)[j];
}
std::cout << std::endl;
}
}
*/
*

Definition at line 300 of file AliParser.cxx.

Referenced by AliParserTest_Slice2Matrix(), and AliPainter::SliceHistogram().

std::vector< TString > AliParser::Split ( const char *  inputExpr,
const char  del = ',',
Int_t  verbose = 0 
)
static

Splits input string to array according to specified char delimiter.

Widespread function in popular languages like python, or javascript. The main difference our method from aforementioned is ignoring specified delimiter inside of such - "(){}[]<>" brackets. Template of input string: <value1|delimiter|value2(value2.1|delimiter|value2.2)> ==> {value1,value2(value2.1|delimiter|value2.2)}

Parameters
inputExpr- input string
del- delimiter. by default - ','
verbose
Returns
- array with parsed content

Example usage:

root [] AliParser::Split("a(1,2,3),b[1,2,3],c{1,2,3}")
(std::vector<TString>) { "a(1,2,3)", "b[1,2,3]", "c{1,2,3}"}
root [] AliParser::Split("1,2,3,4,5")
(std::vector<TString>) { "1", "2", "3", "4", "5"}

Definition at line 81 of file AliParser.cxx.

Referenced by AliParserTest_Split(), AliPainter::FitHistogram(), Parse(), AliPainter::SetProjections(), Slice2IArray(), and Slice2Matrix().


The documentation for this class was generated from the following files: