source: Sophya/trunk/SophyaPI/PIext/pawexecut.cc@ 1076

Last change on this file since 1076 was 1076, checked in by ercodmgr, 25 years ago

des details cmv 20/7/00

File size: 38.3 KB
Line 
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 "histos.h"
9#include "histos2.h"
10#include "hisprof.h"
11#include "ntuple.h"
12
13#include "pawexecut.h"
14#include "nobjmgr.h"
15#include "servnobjm.h"
16#include "pistdimgapp.h"
17
18#ifdef SANS_EVOLPLANCK
19#include "cvector.h"
20#include "matrix.h"
21#else
22#include "tmatrix.h"
23#include "tvector.h"
24#endif
25
26/* Reza + cmv 13/10/99 */
27
28uint_4 PAWExecutor::autoc_counter_ = 0;
29
30/* methode */
31PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app)
32: mApp(app)
33{
34string kw, usage;
35string hgrp = "pawCmd";
36
37kw = "reset";
38usage = "Reset histograms vectors or matrix";
39usage += "\n reset nameobj";
40piac->RegisterCommand(kw,usage,this,hgrp);
41
42kw = "n/plot";
43usage = "Plot NTuple variables a la paw";
44usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
45usage += "\n n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]";
46usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]";
47usage += "\n for default use ! , loop=i1[:i2[:di]]";
48usage += "\n Related commands: plot2dw plot3d";
49piac->RegisterCommand(kw,usage,this,hgrp);
50
51kw = "n/proj";
52usage = "Project NTuple in histogram (1D or 2D) a la paw";
53usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
54usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [loop] [gratt]";
55usage += "\n for default use ! , loop=i1[:i2[:di]]";
56usage += "\n Related commands: projh1d projh2d projprof";
57piac->RegisterCommand(kw,usage,this,hgrp);
58
59kw = "h/integ";
60usage = "Integrate a 1D histogram";
61usage += "\n h/integ nameh1d [norm]";
62usage += "\n Related commands: h/deriv";
63piac->RegisterCommand(kw,usage,this,hgrp);
64
65kw = "h/deriv";
66usage = "Derivate a 1D histogram";
67usage += "\n h/deriv nameh1d";
68usage += "\n Related commands: h/integ";
69piac->RegisterCommand(kw,usage,this,hgrp);
70
71kw = "h/rebin";
72usage = "Rebin a 1D histogram or profile";
73usage += "\n h/rebin nameh1d nbin";
74piac->RegisterCommand(kw,usage,this,hgrp);
75
76kw = "h/cadd";
77usage = "Add a constant to an histogram, a vector or a matrix";
78usage += "\n h/cadd namehisto val";
79usage += "\n Related commands: h/cmult h/oper";
80piac->RegisterCommand(kw,usage,this,hgrp);
81
82kw = "h/cmult";
83usage = "Multiply an histogram, a vector or a matrix by a constant";
84usage += "\n h/cmult namehisto val";
85usage += "\n Related commands: h/cadd h/oper";
86piac->RegisterCommand(kw,usage,this,hgrp);
87
88kw = "h/oper";
89usage = "Operation on histograms vectors or matrices";
90usage += "\n h/oper @ h1 h2 hres";
91usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)";
92usage += "\n For vectors and matrices, operations are elements by elements";
93usage += "\n Related commands: h/cadd h/cmult";
94piac->RegisterCommand(kw,usage,this,hgrp);
95
96kw = "h/plot/2d";
97usage = "Specific plot for 2D histogrammes";
98usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme";
99usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme";
100usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection";
101usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection";
102usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n";
103usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n";
104usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n";
105usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n";
106usage += "\n n < 0 means Show Info";
107piac->RegisterCommand(kw,usage,this,hgrp);
108
109kw = "h/put_vec";
110usage = "Put content of vector (matrix) into content of histogram 1D or 2D";
111usage += "\n h/put_vec nameh1d namevector [cont,err2]";
112usage += "\n h/put_vec nameh2d namematrix [cont,err2]";
113usage += "\n cont : put into histogramme content";
114usage += "\n err2 : put into histogramme error^2";
115usage += "\n Related commands: h/get_vec";
116piac->RegisterCommand(kw,usage,this,hgrp);
117
118kw = "h/get_vec";
119usage = "Get content of histogram 1D profile or 2D into vector (matrix)";
120usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]";
121usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]";
122usage += "\n cont : get histogramme content";
123usage += "\n err2 : get histogramme error^2";
124usage += "\n absc : get histogramme low bin abscissa (1D only)";
125usage += "\n proj :";
126usage += "\n show : show available projections for Histo2D";
127usage += "\n px : get X projection";
128usage += "\n py : get Y projection";
129usage += "\n bx n : get X band number n";
130usage += "\n by n : get Y band number n";
131usage += "\n sx n : get X slice number n";
132usage += "\n sy n : get Y slice number n";
133usage += "\n Related commands: h/put_vec";
134piac->RegisterCommand(kw,usage,this,hgrp);
135
136kw = "h/copy";
137usage = "Copy content of object1 into object2";
138usage += "\n objects are Vector,Matrix,Histo,Histo2D";
139usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
140usage += "\n copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)";
141usage += "\n copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)";
142usage += "\n Warning: elements from i1 to i2 included are copied";
143usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1";
144usage += "\n or obj2Dto with size i2-i1+1,j2-j1+1";
145usage += "\n The adressed content of obj?Dfrom is overwritten";
146usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
147usage += "\n Related commands: copy";
148piac->RegisterCommand(kw,usage,this,hgrp);
149
150}
151
152/* methode */
153PAWExecutor::~PAWExecutor()
154{
155}
156
157/* methode */
158int PAWExecutor::Execute(string& kw, vector<string>& tokens)
159{
160if(kw == "reset") {
161 reset(tokens); return(0);
162} else if(kw == "n/plot") {
163 n_plot(tokens); return(0);
164} else if(kw == "n/proj") {
165 n_proj(tokens); return(0);
166} else if(kw == "h/integ") {
167 h_integ(tokens); return(0);
168} else if(kw == "h/deriv") {
169 h_deriv(tokens); return(0);
170} else if(kw == "h/rebin") {
171 h_rebin(tokens); return(0);
172} else if(kw == "h/cadd") {
173 h_cadd(tokens); return(0);
174} else if(kw == "h/cmult") {
175 h_cmult(tokens); return(0);
176} else if(kw == "h/oper") {
177 h_oper(tokens); return(0);
178} else if(kw == "h/plot/2d") {
179 h_plot_2d(tokens); return(0);
180} else if(kw == "h/put_vec") {
181 h_put_vec(tokens); return(0);
182} else if(kw == "h/get_vec") {
183 h_get_vec(tokens); return(0);
184} else if(kw == "h/copy") {
185 h_copy(tokens); return(0);
186} else return(1);
187}
188
189/* methode */
190void PAWExecutor::reset(vector<string>& tokens)
191// Reset d'histogrammes, vecteurs et matrices
192{
193if(tokens.size() < 1)
194 {cout<<"Usage: reset nameobj"<<endl; return;}
195NamedObjMgr omg;
196AnyDataObj* mobj = omg.GetObj(tokens[0]);
197if(mobj == NULL)
198 {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
199 return;}
200string ctyp = typeid(*mobj).name();
201
202#ifdef SANS_EVOLPLANCK
203if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
204else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
205#else
206 if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
207// ob->DataBlock().Reset(0.);}
208 else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
209//ob->DataBlock().Reset(0.);}
210#endif
211else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
212else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
213else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
214else {
215 cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
216 return;
217}
218
219return;
220}
221
222/* methode */
223void PAWExecutor::n_plot(vector<string>& tokens)
224// Equivalent n/plot de paw
225// Plot 1D
226// n/plot nameobj.x_exp [cut] [w_exp] [gratt]
227// Plot 2D (plot2dw)
228// n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
229// Plot 3D (plot3d)
230// n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
231{
232if(tokens.size() < 1) {
233 cout
234 <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
235 <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
236 <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
237 <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
238 return;
239}
240string nameobj,expx,expy,expz;
241int nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
242string expcut = "1"; string expwt = "1."; string loop = "";
243string dopt = ""; string nameproj="";
244if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
245
246NamedObjMgr omg;
247Services2NObjMgr* srvo = omg.GetServiceObj();
248
249if(nvar<=0) {
250 cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
251} else if(nvar==1) { // c'est un plot 1D
252 if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
253 if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
254 if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
255 if(tokens.size()>=6) nameproj = tokens[5];
256 if(nameproj.length()<=0 || nameproj=="!") {
257 nameproj = "/autoc/paw_n_plot1D_";
258 AnyDataObj* mobj = omg.GetObj(nameproj);
259 if(mobj!=NULL) {
260 char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
261 nameproj += buff;
262 }
263 }
264 srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
265} else if(nvar==2) { // c'est un plot 2D
266 if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
267 if(tokens.size()>=4) dopt = tokens[3];
268 string err = "";
269 srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
270} else { // c'est un plot 3D
271 if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
272 if(tokens.size()>=4) dopt = tokens[3];
273 srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
274}
275
276return;
277}
278
279/* methode */
280void PAWExecutor::n_proj(vector<string>& tokens)
281// Equivalent n/proj de paw
282// Project NTuple in histogram a la paw
283// Dans un Histo 1D
284// n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
285// Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
286// n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
287{
288if(tokens.size()<2)
289 {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
290 <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
291string nameproj = tokens[0];
292string nameobj,expx,expy,expz;
293int nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
294string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
295if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
296if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
297if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
298if(tokens.size()>=6) dopt = tokens[5];
299
300NamedObjMgr omg;
301Services2NObjMgr* srvo = omg.GetServiceObj();
302
303if(nvar==1) {
304 // c'est une projection dans un histo 1D
305 srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
306} else if(nvar==2) {
307 // c'est une projection dans un histo2D
308 // OU un HProf si nameproj est un HProf un deja defini
309 AnyDataObj* mobj = omg.GetObj(nameproj);
310 if(mobj==NULL)
311 srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
312 else if(dynamic_cast<HProf*>(mobj))
313 srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
314 else
315 srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
316} else {
317 cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<" nvar="<<nvar<<endl;
318}
319
320return;
321}
322
323/* methode */
324void PAWExecutor::h_integ(vector<string>& tokens)
325// Pour remplacer le contenu d'un histo 1D par son integrale
326{
327if(tokens.size()<1)
328 {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
329NamedObjMgr omg;
330AnyDataObj* mobj = omg.GetObj(tokens[0]);
331if(mobj==NULL)
332 {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
333 return;}
334double norm = 1.;
335if(tokens.size()>=2) norm = atof(tokens[1].c_str());
336// attention: dynamic_cast<Histo*>(HProf)=Vrai!
337Histo* h1 = dynamic_cast<Histo*>(mobj);
338HProf* hp = dynamic_cast<HProf*>(mobj);
339if(hp || !h1)
340 {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl;
341 return;}
342h1->HInteg(norm);
343}
344
345/* methode */
346void PAWExecutor::h_deriv(vector<string>& tokens)
347// Pour remplacer le contenu d'un histo 1D par sa derivee
348{
349if(tokens.size()<1)
350 {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
351NamedObjMgr omg;
352AnyDataObj* mobj = omg.GetObj(tokens[0]);
353if(mobj==NULL)
354 {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
355 return;}
356// attention: dynamic_cast<Histo*>(HProf)=Vrai!
357Histo* h1 = dynamic_cast<Histo*>(mobj);
358HProf* hp = dynamic_cast<HProf*>(mobj);
359if(hp || !h1)
360 {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl;
361 return;}
362h1->HDeriv();
363}
364
365/* methode */
366void PAWExecutor::h_rebin(vector<string>& tokens)
367// Pour re-binner un histogramme 1D
368{
369if(tokens.size()<2)
370 {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
371NamedObjMgr omg;
372AnyDataObj* mobj = omg.GetObj(tokens[0]);
373if(mobj==NULL)
374 {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
375 return;}
376int nbin = atoi(tokens[1].c_str());
377Histo* h1 = dynamic_cast<Histo*>(mobj);
378// Ca marche aussi pour les HProf, HRebin a ete passe virtuel
379//HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
380if(!h1)
381 {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
382 return;}
383h1->HRebin(nbin);
384}
385
386/* methode */
387void PAWExecutor::h_cadd(vector<string>& tokens)
388// Additionne une constante a un histogramme
389{
390if(tokens.size()<2)
391 {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
392NamedObjMgr omg;
393AnyDataObj* mobj = omg.GetObj(tokens[0]);
394if(mobj==NULL)
395 {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
396 return;}
397double val = atof(tokens[1].c_str());
398Histo* h1 = dynamic_cast<Histo*>(mobj);
399HProf* hp = dynamic_cast<HProf*>(mobj);
400Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
401Vector* v = dynamic_cast<Vector*>(mobj);
402Matrix* m = dynamic_cast<Matrix*>(mobj);
403if(h1 && !hp) *h1 += val;
404else if(h2) *h2 += val;
405else if(v) *v += val;
406else if(m) *m += val;
407else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl;
408}
409
410/* methode */
411void PAWExecutor::h_cmult(vector<string>& tokens)
412// Multiplie un histogramme par une constante
413{
414if(tokens.size()<2)
415 {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
416NamedObjMgr omg;
417AnyDataObj* mobj = omg.GetObj(tokens[0]);
418if(mobj==NULL)
419 {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
420 return;}
421double val = atof(tokens[1].c_str());
422Histo* h1 = dynamic_cast<Histo*>(mobj);
423HProf* hp = dynamic_cast<HProf*>(mobj);
424Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
425Vector* v = dynamic_cast<Vector*>(mobj);
426Matrix* m = dynamic_cast<Matrix*>(mobj);
427if(h1 && !hp) *h1 *= val;
428else if(h2) *h2 *= val;
429else if(v) *v += val;
430else if(m) *m += val;
431else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl;
432}
433
434/* methode */
435void PAWExecutor::h_oper(vector<string>& tokens)
436// Equivalent h/oper/add sub,mul,div de paw
437// Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices
438// h/oper @ h1 h2 hres
439// hres = h1 @ h2 with @ = (+,-,*,/)
440// Pour les vecteurs et les matrices, il sagit d'operations elements a elements
441{
442if(tokens.size()<4)
443 {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl;
444 return;}
445
446// Decode arguments
447const char * oper = tokens[0].c_str();
448if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
449 {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
450 return;}
451string h1name = tokens[1];
452string h2name = tokens[2];
453string h3name = tokens[3];
454
455// Get objects
456NamedObjMgr omg;
457AnyDataObj* mobjh1 = omg.GetObj(h1name);
458AnyDataObj* mobjh2 = omg.GetObj(h2name);
459if( mobjh1==NULL || mobjh2==NULL )
460 {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
461 return;}
462AnyDataObj* mobjh3 = omg.GetObj(h3name);
463
464// Operations on HProf, only + is working
465if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
466 if( oper[0]!='+' )
467 { cout<<"PAWExecutor::h_oper Error: operation "<<oper
468 <<" not implemented for HProf"<<endl; return;}
469 if( dynamic_cast<HProf*>(mobjh2) == NULL )
470 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
471 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
472 return;}
473 HProf* h1 =(HProf*) mobjh1;
474 HProf* h2 =(HProf*) mobjh2;
475 if( h1->NBins() != h2->NBins() )
476 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
477 <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
478 HProf* h3 = NULL;
479 if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
480 {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
481 h3 = dynamic_cast<HProf*>(mobjh3);
482 if(h3 == NULL) // ce n'est pas un HProf
483 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
484 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
485 if(h1->NBins() != h3->NBins())
486 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
487 <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
488 *h3 = *h1 + *h2;
489 h3->UpdateHisto();
490
491// Operations on Histo
492} else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
493 if( dynamic_cast<Histo*>(mobjh2) == NULL )
494 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
495 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
496 return;}
497 Histo* h1 =(Histo*) mobjh1;
498 Histo* h2 =(Histo*) mobjh2;
499 if( h1->NBins() != h2->NBins() )
500 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
501 <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
502 Histo* h3 = NULL;
503 if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
504 {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
505 h3 = dynamic_cast<Histo*>(mobjh3);
506 if(h3 == NULL) // ce n'est pas un Histo
507 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
508 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
509 if(h1->NBins() != h3->NBins())
510 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
511 <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
512 if( oper[0]=='+') *h3 = *h1 + *h2;
513 else if( oper[0]=='-') *h3 = *h1 - *h2;
514 else if( oper[0]=='*') *h3 = *h1 * *h2;
515 else if( oper[0]=='/') *h3 = *h1 / *h2;
516
517// Operations on Histo2D
518} else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
519 if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
520 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
521 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
522 return;}
523 Histo2D* h1 =(Histo2D*) mobjh1;
524 Histo2D* h2 =(Histo2D*) mobjh2;
525 if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
526 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
527 <<h1->NBinX()<<","<<h1->NBinY()<<" "
528 <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
529 Histo2D* h3 = NULL;
530 if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
531 {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
532 h3 = dynamic_cast<Histo2D*>(mobjh3);
533 if(h3 == NULL) // ce n'est pas un Histo2D
534 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
535 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
536 if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
537 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
538 <<h1->NBinX()<<","<<h1->NBinY()<<" "
539 <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
540 if( oper[0]=='+') *h3 = *h1 + *h2;
541 else if( oper[0]=='-') *h3 = *h1 - *h2;
542 else if( oper[0]=='*') *h3 = *h1 * *h2;
543 else if( oper[0]=='/') *h3 = *h1 / *h2;
544
545// Operations on Vector
546} else if( dynamic_cast<Vector*>(mobjh1) != NULL ) {
547 if( dynamic_cast<Vector*>(mobjh2) == NULL )
548 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
549 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
550 return;}
551 Vector* h1 =(Vector*) mobjh1;
552 Vector* h2 =(Vector*) mobjh2;
553 if( h1->NElts() != h2->NElts() )
554 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
555 <<h1->NElts()<<" "<<h2->NElts()<<endl; return;}
556 Vector* h3 = NULL;
557 if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
558#ifdef SANS_EVOLPLANCK
559 h3 = new Vector(*h1);
560#else
561 h3 = new Vector(*h1,false);
562#endif
563 *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
564 }
565 h3 = dynamic_cast<Vector*>(mobjh3);
566 if(h3 == NULL) // ce n'est pas un Vector
567 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
568 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
569 if(h1->NElts() != h3->NElts())
570 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
571 <<h1->NElts()<<" "<<h3->NElts()<<endl; return;}
572 if( oper[0]=='+') *h3 = *h1 + *h2;
573 else if( oper[0]=='-') *h3 = *h1 - *h2;
574#ifdef SANS_EVOLPLANCK
575 else if(oper[0]=='*' || oper[0]=='/')
576 cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
577 <<" not implemented for Vector in Peida"<<endl;
578#else
579 else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
580 else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
581#endif
582
583// Operations on Matrix
584} else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) {
585 if( dynamic_cast<Matrix*>(mobjh2) == NULL )
586 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
587 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
588 return;}
589 Matrix* h1 =(Matrix*) mobjh1;
590 Matrix* h2 =(Matrix*) mobjh2;
591 if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() )
592 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
593 <<h1->NRows()<<","<<h1->NCol()<<" "
594 <<h2->NRows()<<","<<h2->NCol()<<endl; return;}
595 Matrix* h3 = NULL;
596 if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
597#ifdef SANS_EVOLPLANCK
598 h3 = new Matrix(*h1);
599#else
600 h3 = new Matrix(*h1,false);
601#endif
602 *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
603 }
604 h3 = dynamic_cast<Matrix*>(mobjh3);
605 if(h3 == NULL) // ce n'est pas un Matrix
606 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
607 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
608 if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() )
609 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
610 <<h1->NRows()<<","<<h1->NCol()<<" "
611 <<h3->NRows()<<","<<h3->NCol()<<endl; return;}
612 if( oper[0]=='+') *h3 = *h1 + *h2;
613 else if( oper[0]=='-') *h3 = *h1 - *h2;
614#ifdef SANS_EVOLPLANCK
615 else if(oper[0]=='*' || oper[0]=='/')
616 cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
617 <<" not implemented for Vector in Peida"<<endl;
618#else
619 else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
620 else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
621#endif
622
623// Doesn't work for other objects
624} else {
625 cout<<"PAWExecutor::h_oper Error: not implemented for "
626 <<typeid(*mobjh1).name()<<endl;
627 return;
628}
629
630return;
631}
632
633/* methode */
634void PAWExecutor::h_plot_2d(vector<string>& tokens)
635// plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
636{
637if(tokens.size()<1)
638 {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
639string proj = "h"; if(tokens.size()>1) proj = tokens[1];
640NamedObjMgr omg;
641AnyDataObj* mobj = omg.GetObj(tokens[0]);
642if(mobj==NULL)
643 {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
644 return;}
645Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
646if(!h2)
647 {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
648 return;}
649
650Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
651
652string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
653if(proj == "show") {
654 h2->ShowProj();
655 h2->ShowBand(2);
656 h2->ShowSli(2);
657 return;
658} else if(proj == "h") {
659 nametoplot = tokens[0];
660} else if(proj == "px") {
661 if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
662 else {h2->ShowProj(); return;}
663} else if(proj == "py") {
664 if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
665 else {h2->ShowProj(); return;}
666} else {
667 if(tokens.size()<3)
668 {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
669 int n = atoi(tokens[2].c_str());
670 dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
671 if(proj == "bx") {
672 if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
673 else {h2->ShowBand(); return;}
674 } else if(proj == "by") {
675 if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
676 else {h2->ShowBand(); return;}
677 } else if(proj == "sx") {
678 if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
679 else {h2->ShowSli(); return;}
680 } else if(proj == "sy") {
681 if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
682 else {h2->ShowSli(); return;}
683 }
684}
685
686omg.DisplayObj(nametoplot,dopt);
687}
688
689/* methode */
690int PAWExecutor::decodepawstring(string tokens,string& nameobj
691 ,string& xexp,string& yexp,string& zexp)
692// Decodage general de "nameobj.xexp"
693// "nameobj.yexp%xexp"
694// "nameobj.zexp%yexp%xexp"
695// Return: nombre de variables trouvees, -1 si probleme
696{
697nameobj = ""; xexp= ""; yexp= ""; zexp= "";
698
699int lt = (int) tokens.length();
700if(lt<=0) return -1;
701
702// decodage de la chaine de type PAW.
703char *str = new char[lt+2];
704strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
705//cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
706char *c[3] = {NULL,NULL,NULL};
707int i, np=0; bool namefound = false;
708for(i=0;i<lt;i++) {
709 if(!namefound && str[i]=='.') {
710 str[i]='\0';
711 namefound=true;
712 c[np] = str+i+1; np++;
713 }
714 if( namefound && str[i]=='%') {
715 str[i]='\0';
716 if(np<3) {c[np] = str+i+1; np++;}
717 }
718}
719//cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
720
721// Remplissage du nom et des variables
722nameobj = str;
723if(np==1) xexp=c[0];
724if(np==2) {yexp=c[0]; xexp=c[1];}
725if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
726//cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
727delete [] str;
728
729// Comptage des variables
730np = -1;
731if(nameobj.length()>0)
732 {np = 0; if(xexp.length()>0)
733 {np++; if(yexp.length()>0)
734 {np++; if(zexp.length()>0) np++;}}}
735cout<<"pawstring["<<np<<"] name="<<nameobj
736 <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
737return np;
738}
739
740/* methode */
741void PAWExecutor::h_put_vec(vector<string>& tokens)
742// Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice
743// L'histogramme doit deja exister. Le nombre de bins remplit
744// depend des tailles respectives des 2 objets.
745// tokens[2] = "cont" : on remplit les valeurs de l'histogramme (ou "!")
746// = "err2" : on remplit les erreurs de l'histogramme
747{
748if(tokens.size()<2)
749 {cout<<"Usage: h/put_vec namehisto namevector"<<endl;
750 return;}
751string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
752if(toput=="!") toput = "cont";
753if(toput!="cont" && toput!="err2")
754 {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
755 return;}
756string hname = tokens[0];
757string vname = tokens[1];
758
759// Get objects
760NamedObjMgr omg;
761AnyDataObj* mobjh = omg.GetObj(hname);
762AnyDataObj* mobjv = omg.GetObj(vname);
763if( mobjh==NULL || mobjv==NULL )
764 {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl;
765 return;}
766
767// Fill Histo from Vector
768if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) {
769 Histo* h = dynamic_cast<Histo*>(mobjh);
770 Vector* v = dynamic_cast<Vector*>(mobjv);
771 if(toput=="cont") h->PutValue(*v);
772 else if(toput=="err2") h->PutError2(*v);
773
774// Fill Histo2D from Matrix
775} else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) {
776 Histo2D* h = dynamic_cast<Histo2D*>(mobjh);
777 Matrix* v = dynamic_cast<Matrix*>(mobjv);
778 if(toput=="cont") h->PutValue(*v);
779 else if(toput=="err2") h->PutError2(*v);
780
781} else {
782 cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n"
783 <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl;
784 return;
785}
786
787}
788
789/* methode */
790void PAWExecutor::h_get_vec(vector<string>& tokens)
791// Pour copier un histo dans un vecteur ou une matrice
792// Si le vecteur (matrice) n'existe pas, il est cree.
793// Le vecteur ou la matrice est re-dimensionne correctement.
794// tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!")
795// = "err2" : on copie les erreurs de l'histogramme
796// = "absc" : on copie les erreurs de l'histogramme (1D only)
797// tokens[3[,4]] = show : show available projections for Histo2D
798// px : get X projection
799// py : get Y projection
800// bx n : get X band number n
801// by n : get Y band number n
802// sx n : get X slice number n
803// sy n : get Y slice number n
804{
805if(tokens.size()<2)
806 {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
807 return;}
808string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
809if(toget=="!") toget = "cont";
810if(toget!="cont" && toget!="err2" && toget!="absc")
811 {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
812 return;}
813string proj = "h"; if(tokens.size()>3) proj = tokens[3];
814int nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
815string hname = tokens[0];
816string vname = tokens[1];
817
818// Get objects
819NamedObjMgr omg;
820AnyDataObj* mobjh = omg.GetObj(hname);
821AnyDataObj* mobjv = omg.GetObj(vname);
822if( mobjh==NULL)
823 {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
824 return;}
825
826// Copy Histo/Histo2D/Projection to Vector/Matrix
827Histo* h = dynamic_cast<Histo*>(mobjh);
828Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
829if( h != NULL ) { // Histo ou HProf
830 HProf* hp = dynamic_cast<HProf*>(mobjh);
831 if(hp!=NULL) if(!(hp->IsOk())) hp->UpdateHisto();
832 Vector* v = NULL;
833 if(mobjv==NULL) // le vecteur n'existe pas
834 {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
835 if(typeid(*mobjv) != typeid(Vector))
836 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
837 <<typeid(*mobjv).name()<<endl; return;}
838 v = dynamic_cast<Vector*>(mobjv);
839 if(toget=="cont") h->GetValue(*v);
840 else if(toget=="err2") h->GetError2(*v);
841 else if(toget=="absc") h->GetAbsc(*v);
842
843} else if( h2 != NULL) { // Histo2D
844
845 if(proj == "h") { // On veut les valeurs de l'histogramme 2D
846 Matrix* v = NULL;
847 if(mobjv==NULL) // la matrice n'existe pas
848 {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
849 if(typeid(*mobjv) != typeid(Matrix))
850 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
851 <<typeid(*mobjv).name()<<endl; return;}
852 v = dynamic_cast<Matrix*>(mobjv);
853 if(toget=="cont") h2->GetValue(*v);
854 else if(toget=="err2") h2->GetError2(*v);
855 else
856 {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl;
857 return;}
858
859 } else { // On veut les valeurs d'une projection de l'histo 2D
860 h = NULL;
861 if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);}
862 else if(proj == "px") h = h2->HProjX();
863 else if(proj == "py") h = h2->HProjY();
864 else if(proj == "bx") h = h2->HBandX(nproj);
865 else if(proj == "by") h = h2->HBandY(nproj);
866 else if(proj == "sx") h = h2->HSliX(nproj);
867 else if(proj == "sy") h = h2->HSliY(nproj);
868 if(h==NULL)
869 {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj
870 <<" number "<<nproj<<endl; return;}
871 Vector* v = NULL;
872 if(mobjv==NULL) // le vecteur n'existe pas
873 {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
874 if(typeid(*mobjv) != typeid(Vector))
875 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
876 <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;}
877 v = dynamic_cast<Vector*>(mobjv);
878 if(toget=="cont") h->GetValue(*v);
879 else if(toget=="err2") h->GetError2(*v);
880 else if(toget=="absc") h->GetAbsc(*v);
881 }
882
883} else {
884 cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n"
885 <<typeid(*mobjh).name()<<endl;
886 return;
887}
888
889}
890
891/* methode */
892void PAWExecutor::h_copy(vector<string>& tokens)
893// Pour copier un object dans un object
894// objects are Vector,Matrix,Histo,Histo2D
895// h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]
896// copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)
897// copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)
898// Attention: elements depuis i1 jusqu'a i2 COMPRIS
899// Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1
900// ou obj2Dto avec une taille i2-i1+1,j2-j1+1
901// Le contenu de obj?Dfrom adresse est surecrit
902// Le contenu de obj?Dfrom non adresse reste le meme
903{
904 int tks = tokens.size();
905if(tks<2)
906 {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
907 return;}
908
909NamedObjMgr omg;
910AnyDataObj* mobjv1 = omg.GetObj(tokens[0]);
911if( mobjv1==NULL)
912 {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
913 return;}
914AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
915
916int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2;
917
918// Cas d'un Vector
919if(typeid(*mobjv1) == typeid(Vector)) {
920 Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts();
921 i2=nx1-1;
922 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
923 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
924 if(i2<i1)
925 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
926 <<nx1<<endl; return;}
927 Vector* v2 = NULL;
928 if(mobjv2==NULL)
929 {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
930 if(typeid(*mobjv2) != typeid(Vector))
931 {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
932 <<typeid(*mobjv2).name()<<endl; return;}
933 v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts();
934 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
935 if(ic1<0) ic1=0;
936 if(ic1>=nx2)
937 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts="
938 <<nx2<<endl; return;}
939 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
940 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i);
941 return;
942}
943
944// Cas d'un Histo
945if(typeid(*mobjv1) == typeid(Histo)) {
946 Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins();
947 i2=nx1-1;
948 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
949 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
950 if(i2<i1)
951 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
952 <<nx1<<endl; return;}
953 Histo* v2 = NULL;
954 if(mobjv2==NULL)
955 {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1);
956 omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
957 if(typeid(*mobjv2) != typeid(Histo))
958 {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
959 <<typeid(*mobjv2).name()<<endl; return;}
960 v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins();
961 if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
962 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
963 if(ic1<0) ic1=0;
964 if(ic1>=nx2)
965 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins="
966 <<nx2<<endl; return;}
967 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
968 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
969 {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);}
970 return;
971}
972
973// Cas d'une Matrix
974if(typeid(*mobjv1) == typeid(Matrix)) {
975 Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol();
976 i2=nx1-1; j2=ny1-1;
977 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
978 if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
979 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
980 if(i2<i1 || j2<j1)
981 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
982 <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
983 <<nx1<<" , "<<ny1<<endl; return;}
984 Matrix* v2 = NULL;
985 if(mobjv2==NULL)
986 {v2 = new Matrix(i2-i1+1,j2-j1+1);
987 omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
988 if(typeid(*mobjv2) != typeid(Matrix))
989 {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
990 <<typeid(*mobjv2).name()<<endl; return;}
991 v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol();
992 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
993 if(ic1<0) ic1=0; if(jc1<0) jc1=0;
994 if(ic1>=nx2 || jc1>=ny2)
995 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
996 <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;}
997 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
998 <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
999 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
1000 for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
1001 return;
1002}
1003
1004// Cas d'un Histo2D
1005if(typeid(*mobjv1) == typeid(Histo2D)) {
1006 Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY();
1007 i2=nx1-1; j2=ny1-1;
1008 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
1009 if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
1010 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
1011 if(i2<i1 || j2<j1)
1012 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
1013 <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
1014 <<nx1<<" , "<<ny1<<endl; return;}
1015 Histo2D* v2 = NULL;
1016 if(mobjv2==NULL)
1017 {v2 = new Histo2D(0.,(float)(i2-i1+1),i2-i1+1,0.,(float)(j2-j1+1),j2-j1+1);
1018 omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
1019 if(typeid(*mobjv2) != typeid(Histo2D))
1020 {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
1021 <<typeid(*mobjv2).name()<<endl; return;}
1022 v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY();
1023 if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
1024 if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
1025 if(ic1<0) ic1=0; if(jc1<0) jc1=0;
1026 if(ic1>=nx2 || jc1>=ny2)
1027 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
1028 <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;}
1029 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
1030 <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
1031 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
1032 for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++)
1033 {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);}
1034 return;
1035}
1036
1037// Cas non prevu
1038cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n"
1039 <<typeid(*mobjv1).name()<<endl;
1040return;
1041}
Note: See TracBrowser for help on using the repository browser.