AliRoot Core  3dc7879 (3dc7879)
AliParserTest.C
Go to the documentation of this file.
1 /*
5 \code
6 .L $AliRoot_SRC/STAT/test/AliParserTest.C+
7 AliParserTest();
8 root.exe -b -q $AliRoot_SRC/STAT/test/AliParserTest.C+ 2>&1 | tee AliParserTest.log
9 \endcode
10 */
11 
12 #include "AliParser.h"
13 #include "TString.h"
14 #include "TMatrixD.h"
15 #include <vector>
16 #include <map>
17 #include "TError.h"
18 #include "Riostream.h"
19 #include "Rtypes.h"
20 #include "TSystem.h"
21 
22 void AliParserTest_Split();
25 void AliParserTest_Parse();
28 TString Vec2TString(std::vector<TString>);
29 TString Map2TString(std::map<TString, TString>);
30 TString VecD2TString(std::vector<Double_t> parsedVector);
31 TString VecI2TString(std::vector<Int_t> parsedVector);
32 TString TMatrixD2TString(TMatrixD matrix);
33 
34 
35 void AliParserTest() {
42 }
43 
44 TString Vec2TString(std::vector<TString> parsedVector) {
45  TString infoString = "";
46  for (std::vector<TString>::iterator it = parsedVector.begin(); it != parsedVector.end(); ++it)
47  infoString += *it + "|";
48  return infoString;
49 }
50 
51 TString VecD2TString(std::vector<Double_t> parsedVector) {
52  TString infoString = "";
53  for (std::vector<Double_t >::iterator it = parsedVector.begin(); it != parsedVector.end(); ++it)
54  infoString += TString::Format("%.2g|",*it);
55  return infoString;
56 }
57 
58 TString VecI2TString(std::vector<Int_t> parsedVector) {
59  TString infoString = "";
60  for (std::vector<Int_t >::iterator it = parsedVector.begin(); it != parsedVector.end(); ++it)
61  infoString += TString::Format("%d|",*it);
62  return infoString;
63 }
64 
65 TString TMatrixD2TString (TMatrixD matrix) {
66  TString infoString = "\n";
67  for(auto i=0;i<matrix.GetNrows();++i) {
68  for(auto j=0;j<matrix.GetNcols();++j) {
69  infoString += TString::Format("%d|", (Int_t) TMatrixDRow(matrix,i)[j]);
70  }
71  infoString += "\n";
72  }
73  return infoString;
74 }
75 
76 TString Map2TString(std::map<TString, TString> parsedMap) {
77  TString infoString = "";
78  for (std::map<TString, TString>::iterator it = parsedMap.begin(); it != parsedMap.end(); it++)
79  infoString += it->first + "=" + it->second + "|";
80  return infoString;
81 }
82 
84  TString input = "gaus,W,fitFunction(1,2,3),E,10,200";
85  if (Vec2TString(AliParser::Split(input.Data())) == TString("gaus|W|fitFunction(1,2,3)|E|10|200|"))
86  ::Info("AliParserTest", "AliParser::Split(\"%s\")- IsOK", input.Data());
87  else
88  ::Error("AliParserTest", "AliParser::Split(\"%s\")- FAILED", input.Data());
89 
90  input = "1,2,3,4";
91  if (Vec2TString(AliParser::Split(input.Data())) == TString("1|2|3|4|"))
92  ::Info("AliParserTest", "AliParser::Split(\"%s\")- IsOK", input.Data());
93  else
94  ::Error("AliParserTest", "AliParser::Split(\"%s\")- FAILED", input.Data());
95 
96  input = "a,b,c(1,2,3),d";
97  if (Vec2TString(AliParser::Split(input.Data())) == TString("a|b|c(1,2,3)|d|"))
98  ::Info("AliParserTest", "AliParser::Split(\"%s\")- IsOK", input.Data());
99  else
100  ::Error("AliParserTest", "AliParser::Split(\"%s\")- FAILED", input.Data());
101 
102  input = "a,b,c[1,2,3],d";
103  if (Vec2TString(AliParser::Split(input.Data())) == TString("a|b|c[1,2,3]|d|"))
104  ::Info("AliParserTest", "AliParser::Split(\"%s\")- IsOK", input.Data());
105  else
106  ::Error("AliParserTest", "AliParser::Split(\"%s\")- FAILED", input.Data());
107 
108  input = "(1,2,3),4,5,6";
109  if (Vec2TString(AliParser::Split(input.Data())) == TString("(1,2,3)|4|5|6|"))
110  ::Info("AliParserTest", "AliParser::Split(\"%s\")- IsOK", input.Data());
111  else
112  ::Error("AliParserTest", "AliParser::Split(\"%s\")- FAILED", input.Data());
113 
114 }
115 
117  TString input = "[1][2][3][4]";
118  if (Vec2TString(AliParser::ExtractSurroundingBy(input.Data(), '[', ']')) == TString("|1|2|3|4|"))
119  ::Info("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- IsOK", input.Data());
120  else
121  ::Error("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- FAILED", input.Data());
122 
123  input = "(1)(2)(3)(4)";
124  if (Vec2TString(AliParser::ExtractSurroundingBy(input.Data())) == TString("|1|2|3|4|"))
125  ::Info("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- IsOK", input.Data());
126  else
127  ::Error("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- FAILED", input.Data());
128 
129  input = "(a(1,2,3))(b)(c)(d(4,5,6))";
130  if (Vec2TString(AliParser::ExtractSurroundingBy(input.Data())) == TString("|a(1,2,3)|b|c|d(4,5,6)|"))
131  ::Info("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- IsOK", input.Data());
132  else
133  ::Error("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- FAILED", input.Data());
134 
135 
136  input = "((1,2,3))(2)(3)(4)";
137  if (Vec2TString(AliParser::ExtractSurroundingBy(input.Data())) == TString("|(1,2,3)|2|3|4|"))
138  ::Info("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- IsOK", input.Data());
139  else
140  ::Error("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- FAILED", input.Data());
141 
142  input = "abc(a)(b[10,20])(c[1,2,3])(d)";
143  if (Vec2TString(AliParser::ExtractSurroundingBy(input.Data())) == TString("abc|a|b[10,20]|c[1,2,3]|d|"))
144  ::Info("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- IsOK", input.Data());
145  else
146  ::Error("AliParserTest", "AliParser::ExtractSurroundingBy(\"%s\")- FAILED", input.Data());
147 
148 }
149 
151 
152  TString input = "pi*<max>+345*<min>";
153  if (Vec2TString(AliParser::ExtractBetween(input.Data(), "<", ">", 0)) == TString("max|min|"))
154  ::Info("AliParserTest", "AliParser::Split(\"%s\")- IsOK", input.Data());
155  else
156  ::Error("AliParserTest", "AliParser::Split(\"%s\")- FAILED", input.Data());
157 
158  input = "{marker-style:25,21,22,23; marker-color:1,2,4,5; }";
159  if (Vec2TString(AliParser::ExtractBetween(input.Data(), "marker-style:", ";", 0)) == TString("25,21,22,23|"))
160  ::Info("AliParserTest", "AliParser::ExtractBetween(\"%s\", \"marker-style:\")- IsOK", input.Data());
161  else
162  ::Error("AliParserTest", "AliParser::ExtractBetween(\"%s\", \"marker-style:\")- FAILED", input.Data());
163 
164  if (Vec2TString(AliParser::ExtractBetween(input.Data(), "marker-color:", ";", 0)) == TString("1,2,4,5|"))
165  ::Info("AliParserTest", "AliParser::ExtractBetween(\"%s\", \"marker-color:\")- IsOK", input.Data());
166  else
167  ::Error("AliParserTest", "AliParser::ExtractBetween(\"%s\", \"marker-color:\")- FAILED", input.Data());
168 
169  input = "{marker-style:25,21,22,23; marker-color:rgb(1,2,3),#f0f0f0,1; }";
170  if (Vec2TString(AliParser::ExtractBetween(input.Data(), "marker-color:", ";", 0)) == TString("rgb(1,2,3),#f0f0f0,1|"))
171  ::Info("AliParserTest", "AliParser::ExtractBetween(\"%s\")- IsOK", input.Data());
172  else
173  ::Error("AliParserTest", "AliParser::ExtractBetween(\"%s\")- FAILED", input.Data());
174 }
175 
177  TString input = "div=0";
178  if (Map2TString(AliParser::Parse(input.Data())) == TString("div=0|"))
179  ::Info("AliParserTest", "AliParser::Parse(\"%s\")- IsOK", input.Data());
180  else
181  ::Error("AliParserTest", "AliParser::Parse(\"%s\")- FAILED", input.Data());
182 
183  input = "class=[Mass,PtAll]";
184  if (Map2TString(AliParser::Parse(input.Data())) == TString("class=[Mass,PtAll]|"))
185  ::Info("AliParserTest", "AliParser::Parse(\"%s\")- IsOK", input.Data());
186  else
187  ::Error("AliParserTest", "AliParser::Parse(\"%s\")- FAILED", input.Data());
188 
189  input = "div=0, class=[Mass,PtAll], xlim=[10.123,20.435]";
190  if (Map2TString(AliParser::Parse(input.Data())) == TString("class=[Mass,PtAll]|div=0|xlim=[10.123,20.435]|"))
191  ::Info("AliParserTest", "AliParser::Parse(\"%s\")- IsOK", input.Data());
192  else
193  ::Error("AliParserTest", "AliParser::Parse(\"%s\")- FAILED", input.Data());
194 
195  input = "ylim=";
196  if (Map2TString(AliParser::Parse(input.Data())) == TString("ylim=|"))
197  ::Info("AliParserTest", "AliParser::Parse(\"%s\")- IsOK", input.Data());
198  else
199  ::Error("AliParserTest", "AliParser::Parse(\"%s\")- FAILED", input.Data());
200 
201  input = "zlim=[],xlim=[10.123,20.435],ylim=,class=Mass";
202  if (Map2TString(AliParser::Parse(input.Data())) == TString("class=Mass|xlim=[10.123,20.435]|ylim=|zlim=[]|"))
203  ::Info("AliParserTest", "AliParser::Parse(\"%s\")- IsOK", input.Data());
204  else
205  ::Error("AliParserTest", "AliParser::Parse(\"%s\")- FAILED", input.Data());
206  input = "zlim=(),xlim=(10.123,20.435),ylim=,class=Mass";
207  if (Map2TString(AliParser::Parse(input.Data())) == TString("class=Mass|xlim=(10.123,20.435)|ylim=|zlim=()|"))
208  ::Info("AliParserTest", "AliParser::Parse(\"%s\")- IsOK", input.Data());
209  else
210  ::Error("AliParserTest", "AliParser::Parse(\"%s\")- FAILED", input.Data());
211 }
212 
214  TString input = "10:40:10:10";
215  if (VecI2TString(AliParser::Slice2IArray(input.Data())) == TString("10|20|20|30|30|40|"))
216  ::Info("AliParserTest", "AliParser::Slice2IArray(\"%s\")- IsOK", input.Data());
217  else
218  ::Error("AliParserTest", "AliParser::Slice2IArray(\"%s\")- FAILED", input.Data());
219  input = "1:4";
220  if (VecI2TString(AliParser::Slice2IArray(input.Data())) == TString("1|2|2|3|3|4|"))
221  ::Info("AliParserTest", "AliParser::Slice2IArray(\"%s\")- IsOK", input.Data());
222  else
223  ::Error("AliParserTest", "AliParser::Slice2IArray(\"%s\")- FAILED", input.Data());
224  input = "1";
225  if (VecI2TString(AliParser::Slice2IArray(input.Data())) == TString())
226  ::Info("AliParserTest", "AliParser::Slice2IArray(\"%s\")- IsOK", input.Data());
227  else
228  ::Error("AliParserTest", "AliParser::Slice2IArray(\"%s\")- FAILED", input.Data());
229  input = "";
230  if (VecI2TString(AliParser::Slice2IArray(input.Data())) == TString())
231  ::Info("AliParserTest", "AliParser::Slice2IArray(\"%s\")- IsOK", input.Data());
232  else
233  ::Error("AliParserTest", "AliParser::Slice2IArray(\"%s\")- FAILED", input.Data());
234  input = "1:4:1:1:1:1:1";
235  if (VecI2TString(AliParser::Slice2IArray(input.Data())) == TString("1|2|2|3|3|4|"))
236  ::Info("AliParserTest", "AliParser::Slice2IArray(\"%s\")- IsOK", input.Data());
237  else
238  ::Error("AliParserTest", "AliParser::Slice2IArray(\"%s\")- FAILED", input.Data());
239  input = "1:4:1";
240  if (VecI2TString(AliParser::Slice2IArray(input.Data())) == TString("1|2|2|3|3|4|"))
241  ::Info("AliParserTest", "AliParser::Slice2IArray(\"%s\")- IsOK", input.Data());
242  else
243  ::Error("AliParserTest", "AliParser::Slice2IArray(\"%s\")- FAILED", input.Data());
244  input = "1:4:1:0";
245  if (VecI2TString(AliParser::Slice2IArray(input.Data())) == TString("1|1|2|2|3|3|4|4|"))
246  ::Info("AliParserTest", "AliParser::Slice2IArray(\"%s\")- IsOK", input.Data());
247  else
248  ::Error("AliParserTest", "AliParser::Slice2IArray(\"%s\")- FAILED", input.Data());
249  input = "1.2:4.3";
250  if (VecI2TString(AliParser::Slice2IArray(input.Data())) == TString("1|2|2|3|3|4|"))
251  ::Info("AliParserTest", "AliParser::Slice2IArray(\"%s\")- IsOK", input.Data());
252  else
253  ::Error("AliParserTest", "AliParser::Slice2IArray(\"%s\")- FAILED", input.Data());
254 
255 }
256 
258  TString input = "10,20,30:50:10:10,60,70";
259  if (TMatrixD2TString(AliParser::Slice2Matrix(input.Data())) == TString("\n10|20|30|40|60|70|\n10|20|40|50|60|70|\n0|0|0|0|0|0|\n"))
260  ::Info("AliParserTest", "AliParser::Slice2Matrix(\"%s\")- IsOK", input.Data());
261  else
262  ::Error("AliParserTest", "AliParser::Slice2Matrix(\"%s\")- FAILED", input.Data());
263  input = "10,20,30,50,60,70";
264  if (TMatrixD2TString(AliParser::Slice2Matrix(input.Data())) == TString("\n10|20|30|50|60|70|\n0|0|0|0|0|0|\n"))
265  ::Info("AliParserTest", "AliParser::Slice2Matrix(\"%s\")- IsOK", input.Data());
266  else
267  ::Error("AliParserTest", "AliParser::Slice2Matrix(\"%s\")- FAILED", input.Data());
268 // input = "";
269 // if (TMatrixD2TString(AliParser::Slice2Matrix(input.Data())) == TString("\n"))
270 // ::Info("AliParserTest", "AliParser::Slice2Matrix(\"%s\")- IsOK", input.Data());
271 // else
272 // ::Error("AliParserTest", "AliParser::Slice2Matrix(\"%s\")- FAILED", input.Data());
273 }
TString TMatrixD2TString(TMatrixD matrix)
Definition: AliParserTest.C:65
TString Map2TString(std::map< TString, TString >)
Definition: AliParserTest.C:76
void AliParserTest_Split()
test methods of AliParser Example usage
Definition: AliParserTest.C:83
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).
Definition: AliParser.cxx:40
void AliParserTest_Parse()
void AliParserTest_ExtractBetween()
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.
Definition: AliParser.cxx:81
static std::vector< TString > ExtractSurroundingBy(const char *inputString, const char begin='(', const char end= ')', Int_t verbose=0)
Extracts content from specified parentheses.
Definition: AliParser.cxx:132
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.
Definition: AliParser.cxx:190
TString Vec2TString(std::vector< TString >)
Definition: AliParserTest.C:44
void AliParserTest()
Definition: AliParserTest.C:35
TString VecD2TString(std::vector< Double_t > parsedVector)
Definition: AliParserTest.C:51
void AliParserTest_Slice2Matrix()
static TMatrixD Slice2Matrix(const char *inputString, Int_t verbose=0)
Returns TMatrixD from input string.
Definition: AliParser.cxx:300
void AliParserTest_Slice2IArray()
TString VecI2TString(std::vector< Int_t > parsedVector)
Definition: AliParserTest.C:58
static std::vector< Int_t > Slice2IArray(const char *inputString)
Returns array according with python-like interface.
Definition: AliParser.cxx:228
void AliParserTest_ExtractSurroundingBy()