1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <ctype.h>
|
---|
4 | #include <iostream.h>
|
---|
5 | #include <typeinfo>
|
---|
6 |
|
---|
7 | #include "strutil.h"
|
---|
8 | #include "cvector.h"
|
---|
9 | #include "matrix.h"
|
---|
10 | #include "histos.h"
|
---|
11 | #include "histos.h"
|
---|
12 | #include "histos2.h"
|
---|
13 | #include "hisprof.h"
|
---|
14 | #include "ntuple.h"
|
---|
15 |
|
---|
16 | #include "pawexecut.h"
|
---|
17 | #include "nobjmgr.h"
|
---|
18 | #include "servnobjm.h"
|
---|
19 | #include "pistdimgapp.h"
|
---|
20 |
|
---|
21 | /* Reza + cmv 13/10/99 */
|
---|
22 |
|
---|
23 | /* methode */
|
---|
24 | PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app)
|
---|
25 | : mApp(app)
|
---|
26 | {
|
---|
27 | string kw, usage;
|
---|
28 | string hgrp = "pawCmd";
|
---|
29 |
|
---|
30 | kw = "reset";
|
---|
31 | usage = "Reset histograms vectors or matrix";
|
---|
32 | usage += "\n reset nameobj";
|
---|
33 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
34 |
|
---|
35 | kw = "n/plot";
|
---|
36 | usage = "Plot NTuple variable a la paw";
|
---|
37 | usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [gratt]";
|
---|
38 | usage += "\n n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]";
|
---|
39 | usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]";
|
---|
40 | usage += "\n Related commands: plot2dw plot3d";
|
---|
41 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
42 |
|
---|
43 | kw = "n/proj";
|
---|
44 | usage = "Project NTuple in histogram (1D or 2D) a la paw";
|
---|
45 | usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]";
|
---|
46 | usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]";
|
---|
47 | usage += "\n Related commands: projh1d projh2d projprof";
|
---|
48 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
49 |
|
---|
50 | kw = "h/integ";
|
---|
51 | usage = "Integrate a 1D histogram or profile";
|
---|
52 | usage += "\n h/integ nameh1d [norm]";
|
---|
53 | usage += "\n Related commands: h/deriv";
|
---|
54 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
55 |
|
---|
56 | kw = "h/deriv";
|
---|
57 | usage = "Derivate a 1D histogram or profile";
|
---|
58 | usage += "\n h/deriv nameh1d";
|
---|
59 | usage += "\n Related commands: h/integ";
|
---|
60 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
61 |
|
---|
62 | kw = "h/rebin";
|
---|
63 | usage = "Rebin a 1D histogram or profile";
|
---|
64 | usage += "\n h/rebin nbin";
|
---|
65 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
66 |
|
---|
67 | kw = "h/cadd";
|
---|
68 | usage = "Add a constant to an histogramme";
|
---|
69 | usage += "\n h/cadd val";
|
---|
70 | usage += "\n Related commands: h/cmult";
|
---|
71 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
72 |
|
---|
73 | kw = "h/cmult";
|
---|
74 | usage = "Multiply an histogramme by a constant";
|
---|
75 | usage += "\n h/cmult val";
|
---|
76 | usage += "\n Related commands: h/cadd";
|
---|
77 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
78 |
|
---|
79 | kw = "h/plot/2d";
|
---|
80 | usage = "Specific plot for 2D histogrammes";
|
---|
81 | usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme";
|
---|
82 | usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme";
|
---|
83 | usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection";
|
---|
84 | usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection";
|
---|
85 | usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n";
|
---|
86 | usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n";
|
---|
87 | usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n";
|
---|
88 | usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n";
|
---|
89 | usage += "\n n < 0 means Show Info";
|
---|
90 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /* methode */
|
---|
94 | PAWExecutor::~PAWExecutor()
|
---|
95 | {
|
---|
96 | }
|
---|
97 |
|
---|
98 | /* methode */
|
---|
99 | int PAWExecutor::Execute(string& kw, vector<string>& tokens)
|
---|
100 | {
|
---|
101 | if(kw == "reset") {
|
---|
102 | reset(tokens); return(0);
|
---|
103 | } else if(kw == "n/plot") {
|
---|
104 | n_plot(tokens); return(0);
|
---|
105 | } else if(kw == "n/proj") {
|
---|
106 | n_proj(tokens); return(0);
|
---|
107 | } else if(kw == "h/integ") {
|
---|
108 | h_integ(tokens); return(0);
|
---|
109 | } else if(kw == "h/deriv") {
|
---|
110 | h_deriv(tokens); return(0);
|
---|
111 | } else if(kw == "h/rebin") {
|
---|
112 | h_rebin(tokens); return(0);
|
---|
113 | } else if(kw == "h/cadd") {
|
---|
114 | h_cadd(tokens); return(0);
|
---|
115 | } else if(kw == "h/cmult") {
|
---|
116 | h_cmult(tokens); return(0);
|
---|
117 | } else if(kw == "h/plot/2d") {
|
---|
118 | h_plot_2d(tokens); return(0);
|
---|
119 | } else return(1);
|
---|
120 | }
|
---|
121 |
|
---|
122 | /* methode */
|
---|
123 | void PAWExecutor::reset(vector<string>& tokens)
|
---|
124 | // Reset d'histogrammes, vecteurs et matrices
|
---|
125 | {
|
---|
126 | if(tokens.size() < 1)
|
---|
127 | {cout<<"Usage: reset nameobj"<<endl;
|
---|
128 | return;}
|
---|
129 | NamedObjMgr omg;
|
---|
130 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
131 | if(mobj == NULL)
|
---|
132 | {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
133 | return;}
|
---|
134 | string ctyp = typeid(*mobj).name();
|
---|
135 |
|
---|
136 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
|
---|
137 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
|
---|
138 | else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
|
---|
139 | else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
|
---|
140 | else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
|
---|
141 | else {
|
---|
142 | cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
|
---|
143 | return;
|
---|
144 | }
|
---|
145 |
|
---|
146 | return;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /* methode */
|
---|
150 | void PAWExecutor::n_plot(vector<string>& tokens)
|
---|
151 | // Equivalent n/plot de paw
|
---|
152 | // Plot 1D
|
---|
153 | // n/plot nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
154 | // Plot 2D (plot2dw)
|
---|
155 | // n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
156 | // Plot 3D (plot3d)
|
---|
157 | // n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
|
---|
158 | {
|
---|
159 | if(tokens.size() < 1) {
|
---|
160 | cout
|
---|
161 | <<"Usage: n/plot nameobj.[z_exp%y_exp%]x_exp [cut] [w_exp] [gratt]"<<endl
|
---|
162 | <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]"<<endl;
|
---|
163 | return;
|
---|
164 | }
|
---|
165 | string nameobj,expx,expy,expz;
|
---|
166 | int nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
|
---|
167 | string expcut = "1";
|
---|
168 | string expwt = "1.";
|
---|
169 | string dopt = "";
|
---|
170 | string loop = "";
|
---|
171 | if(tokens.size()>=2) expcut = tokens[1];
|
---|
172 | if(tokens.size()>=3) expwt = tokens[2];
|
---|
173 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
174 |
|
---|
175 |
|
---|
176 | NamedObjMgr omg;
|
---|
177 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
178 |
|
---|
179 | if(nvar<=0) {
|
---|
180 | cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
|
---|
181 | } else if(nvar==1) { // c'est un plot 1D
|
---|
182 | string nameproj = "/autoc/paw_n_plot1D";
|
---|
183 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
184 | if(mobj!=NULL) omg.DelObj(nameproj);
|
---|
185 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
186 | } else if(nvar==2) { // c'est un plot 2D
|
---|
187 | srvo->DisplayPoints2DW(nameobj,expx,expy,expwt,expcut,dopt,loop);
|
---|
188 | } else { // c'est un plot 3D
|
---|
189 | srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
|
---|
190 | }
|
---|
191 |
|
---|
192 | return;
|
---|
193 | }
|
---|
194 |
|
---|
195 | /* methode */
|
---|
196 | void PAWExecutor::n_proj(vector<string>& tokens)
|
---|
197 | // Equivalent n/proj de paw
|
---|
198 | // Project NTuple in histogram a la paw
|
---|
199 | // Dans un Histo 1D
|
---|
200 | // n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
201 | // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
|
---|
202 | // n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
203 | {
|
---|
204 | if(tokens.size()<2)
|
---|
205 | {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [gratt]"<<endl;
|
---|
206 | return;}
|
---|
207 | string nameproj = tokens[0];
|
---|
208 | string nameobj,expx,expy,expz;
|
---|
209 | int nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
|
---|
210 | string expcut = "1";
|
---|
211 | string expwt = "1.";
|
---|
212 | string dopt = "";
|
---|
213 | string loop = "";
|
---|
214 | if(tokens.size()>=3) expcut = tokens[2];
|
---|
215 | if(tokens.size()>=4) expwt = tokens[3];
|
---|
216 | if(tokens.size()>=5) dopt = tokens[4];
|
---|
217 |
|
---|
218 | NamedObjMgr omg;
|
---|
219 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
220 |
|
---|
221 | if(nvar<=0) {
|
---|
222 | cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<endl;
|
---|
223 | } else if(nvar==1) {
|
---|
224 | // c'est une projection dans un histo 1D
|
---|
225 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
226 | } else {
|
---|
227 | // c'est une projection dans un histo2D
|
---|
228 | // OU un HProf si nameproj est HProf un deja defini
|
---|
229 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
230 | if(mobj==NULL)
|
---|
231 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
232 | else if(dynamic_cast<HProf*>(mobj))
|
---|
233 | srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
234 | else
|
---|
235 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
236 | }
|
---|
237 |
|
---|
238 | return;
|
---|
239 | }
|
---|
240 |
|
---|
241 | /* methode */
|
---|
242 | void PAWExecutor::h_integ(vector<string>& tokens)
|
---|
243 | // Pour remplacer le contenu d'un histo 1D par son integrale
|
---|
244 | {
|
---|
245 | if(tokens.size()<1)
|
---|
246 | {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
|
---|
247 | NamedObjMgr omg;
|
---|
248 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
249 | if(mobj==NULL)
|
---|
250 | {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
251 | return;}
|
---|
252 | double norm = 1.;
|
---|
253 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
254 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
255 | // Le HProf se fait tout seul avec Histo: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
256 | //HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
257 | if(h1) h1->HInteg(norm);
|
---|
258 | //else if(hp) hp->HInteg(norm);
|
---|
259 | else cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
260 | }
|
---|
261 |
|
---|
262 | /* methode */
|
---|
263 | void PAWExecutor::h_deriv(vector<string>& tokens)
|
---|
264 | // Pour remplacer le contenu d'un histo 1D par sa derivee
|
---|
265 | {
|
---|
266 | if(tokens.size()<1)
|
---|
267 | {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
|
---|
268 | NamedObjMgr omg;
|
---|
269 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
270 | if(mobj==NULL)
|
---|
271 | {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
272 | return;}
|
---|
273 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
274 | //HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
275 | if(h1) h1->HDeriv();
|
---|
276 | //else if(hp) hp->HDeriv();
|
---|
277 | else cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
278 | }
|
---|
279 |
|
---|
280 | /* methode */
|
---|
281 | void PAWExecutor::h_rebin(vector<string>& tokens)
|
---|
282 | // Pour re-binner un histogramme 1D
|
---|
283 | {
|
---|
284 | if(tokens.size()<2)
|
---|
285 | {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
|
---|
286 | NamedObjMgr omg;
|
---|
287 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
288 | if(mobj==NULL)
|
---|
289 | {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
|
---|
290 | return;}
|
---|
291 | int nbin = atoi(tokens[1].c_str());
|
---|
292 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
293 | //HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
294 | if(h1) h1->HRebin(nbin);
|
---|
295 | //else if(hp) hp->HRebin(nbin);
|
---|
296 | else cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
297 | }
|
---|
298 |
|
---|
299 | /* methode */
|
---|
300 | void PAWExecutor::h_cadd(vector<string>& tokens)
|
---|
301 | // Additionne une constante a un histogramme
|
---|
302 | {
|
---|
303 | if(tokens.size()<2)
|
---|
304 | {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
|
---|
305 | NamedObjMgr omg;
|
---|
306 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
307 | if(mobj==NULL)
|
---|
308 | {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
|
---|
309 | return;}
|
---|
310 | double val = atof(tokens[1].c_str());
|
---|
311 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
312 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
313 | if(h1) *h1 += val;
|
---|
314 | else if(h2) *h2 += val;
|
---|
315 | else cout<<"PAWExecutor::h_cadd Error: "<<tokens[0]<<" not an Histo/HProf/Histo2D"<<endl;
|
---|
316 | }
|
---|
317 |
|
---|
318 | /* methode */
|
---|
319 | void PAWExecutor::h_cmult(vector<string>& tokens)
|
---|
320 | // Multiplie un histogramme par une constante
|
---|
321 | {
|
---|
322 | if(tokens.size()<2)
|
---|
323 | {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
|
---|
324 | NamedObjMgr omg;
|
---|
325 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
326 | if(mobj==NULL)
|
---|
327 | {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
|
---|
328 | return;}
|
---|
329 | double val = atof(tokens[1].c_str());
|
---|
330 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
331 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
332 | if(h1) *h1 *= val;
|
---|
333 | else if(h2) *h2 *= val;
|
---|
334 | else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0]
|
---|
335 | <<" not an Histo/HProf/Histo2D"<<endl;
|
---|
336 | }
|
---|
337 |
|
---|
338 | /* methode */
|
---|
339 | void PAWExecutor::h_plot_2d(vector<string>& tokens)
|
---|
340 | // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
|
---|
341 | {
|
---|
342 | if(tokens.size()<2)
|
---|
343 | {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
|
---|
344 | NamedObjMgr omg;
|
---|
345 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
346 | if(mobj==NULL)
|
---|
347 | {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
|
---|
348 | return;}
|
---|
349 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
350 | if(!h2)
|
---|
351 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
|
---|
352 | return;}
|
---|
353 |
|
---|
354 | Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
|
---|
355 | AnyDataObj* mobjh1 = omg.GetObj(nametoplot);
|
---|
356 | if(mobjh1!=NULL) omg.DelObj(nametoplot);
|
---|
357 |
|
---|
358 | string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
|
---|
359 | if(tokens[1] == "show") {
|
---|
360 | h2->ShowProj();
|
---|
361 | h2->ShowBand(2);
|
---|
362 | h2->ShowSli(2);
|
---|
363 | return;
|
---|
364 | } else if(tokens[1] == "h") {
|
---|
365 | nametoplot = tokens[0];
|
---|
366 | } else if(tokens[1] == "px") {
|
---|
367 | if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
368 | else {h2->ShowProj(); return;}
|
---|
369 | } else if(tokens[1] == "py") {
|
---|
370 | if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
371 | else {h2->ShowProj(); return;}
|
---|
372 | } else {
|
---|
373 | if(tokens.size()<3)
|
---|
374 | {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
|
---|
375 | int n = atoi(tokens[2].c_str());
|
---|
376 | dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
|
---|
377 | if(tokens[1] == "bx") {
|
---|
378 | if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
379 | else {h2->ShowBand(); return;}
|
---|
380 | } else if(tokens[1] == "by") {
|
---|
381 | if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
382 | else {h2->ShowBand(); return;}
|
---|
383 | } else if(tokens[1] == "sx") {
|
---|
384 | if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
385 | else {h2->ShowSli(); return;}
|
---|
386 | } else if(tokens[1] == "sy") {
|
---|
387 | if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
388 | else {h2->ShowSli(); return;}
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | omg.DisplayObj(nametoplot,dopt);
|
---|
393 | }
|
---|
394 |
|
---|
395 | /* methode */
|
---|
396 | int PAWExecutor::decodepawstring(string tokens,string& nameobj
|
---|
397 | ,string& xexp,string& yexp,string& zexp)
|
---|
398 | // Decodage general de "nameobj.xexp"
|
---|
399 | // "nameobj.yexp%xexp"
|
---|
400 | // "nameobj.zexp%yexp%xexp"
|
---|
401 | // Return: nombre de variables trouvees, -1 si probleme
|
---|
402 | {
|
---|
403 | nameobj = ""; xexp= ""; yexp= ""; zexp= "";
|
---|
404 |
|
---|
405 | int lt = (int) tokens.length();
|
---|
406 | if(lt<=0) return -1;
|
---|
407 |
|
---|
408 | // decodage de la chaine de type PAW.
|
---|
409 | char *str = new char[lt+2];
|
---|
410 | strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
|
---|
411 | //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
|
---|
412 | char *c[3] = {NULL,NULL,NULL};
|
---|
413 | int i, np=0; bool namefound = false;
|
---|
414 | for(int i=0;i<lt;i++) {
|
---|
415 | if(!namefound && str[i]=='.') {
|
---|
416 | str[i]='\0';
|
---|
417 | namefound=true;
|
---|
418 | c[np] = str+i+1; np++;
|
---|
419 | }
|
---|
420 | if( namefound && str[i]=='%') {
|
---|
421 | str[i]='\0';
|
---|
422 | if(np<3) {c[np] = str+i+1; np++;}
|
---|
423 | }
|
---|
424 | }
|
---|
425 | //cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
|
---|
426 |
|
---|
427 | // Remplissage du nom et des variables
|
---|
428 | nameobj = str;
|
---|
429 | if(np==1) xexp=c[0];
|
---|
430 | if(np==2) {yexp=c[0]; xexp=c[1];}
|
---|
431 | if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
|
---|
432 | //cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
|
---|
433 | delete [] str;
|
---|
434 |
|
---|
435 | // Comptage des variables
|
---|
436 | np = -1;
|
---|
437 | if(nameobj.length()>0)
|
---|
438 | {np = 0; if(xexp.length()>0)
|
---|
439 | {np++; if(yexp.length()>0)
|
---|
440 | {np++; if(zexp.length()>0) np++;}}}
|
---|
441 | cout<<"pawstring["<<np<<"] name="<<nameobj
|
---|
442 | <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
|
---|
443 | return np;
|
---|
444 | }
|
---|