source: Sophya/trunk/SophyaPI/PIext/basexecut.cc@ 2933

Last change on this file since 2933 was 2933, checked in by ansari, 19 years ago

Suppression de toute reference a FITS (en particulier NObjMgrAdapter::ReadFits/SaveFits supprime) dans le module PIext - Makefile et smakefile refait , Reza 3 Avril 2006

File size: 50.8 KB
Line 
1#include "sopnamsp.h"
2#include "piacmd.h"
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <math.h>
7
8#include "basexecut.h"
9
10#include "pdlmgr.h"
11#include "ctimer.h"
12#include "strutilxx.h"
13
14#include "pistdimgapp.h"
15#include "nobjmgr.h"
16#include "servnobjm.h"
17#include "nomgadapter.h"
18
19#include "histos.h"
20#include "histos2.h"
21#include "hisprof.h"
22#include "ntuple.h"
23#include "generaldata.h"
24#include "datatable.h"
25
26#ifdef SANS_EVOLPLANCK
27#include "cvector.h"
28#else
29#include "tvector.h"
30#endif
31
32
33/* --Methode-- */
34PIABaseExecutor::PIABaseExecutor(PIACmd* piac, NamedObjMgr* omg, PIStdImgApp* app)
35{
36mpiac = piac;
37mObjMgr = omg;
38mImgApp = app;
39dynlink = NULL;
40dynlink2 = NULL;
41RegisterCommands();
42}
43
44PIABaseExecutor::~PIABaseExecutor()
45{
46 if (dynlink) delete dynlink;
47 if (dynlink2) delete dynlink2;
48}
49
50
51
52/* --Methode-- */
53int PIABaseExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
54{
55Services2NObjMgr* srvo = mObjMgr->GetServiceObj();
56// >>>>> Chargement de modules
57if (kw == "loadmodule") {
58 if (tokens.size() < 2) { cout << "Usage: loadmodule fnameso modulename" << endl; return(0); }
59 mpiac->LoadModule(tokens[0], tokens[1]);
60 }
61
62// >>>>>>>>>>> Link dynamique de fonctions C++
63else if (kw == "link" ) {
64 if (tokens.size() < 2) { cout << "Usage: link fnameso f1 [f2 f3]" << endl; return(0); }
65 string sph = "";
66 for(int gg=0; gg<5; gg++) tokens.push_back(sph);
67 int rc = LinkUserFuncs(tokens[0], tokens[1], tokens[2], tokens[3]);
68 if (rc == 0) cout << "PIABaseExecutor: Link from " << tokens[0] << " OK " << endl;
69}
70else if (kw == "linkff2" ) {
71 if (tokens.size() < 2) { cout << "Usage: linkff2 fnameso f1 [f2 f3]" << endl; return(0); }
72 string sph = "";
73 for(int gg=0; gg<5; gg++) tokens.push_back(sph);
74 int rc = LinkUserFuncs2(tokens[0], tokens[1], tokens[2], tokens[3]);
75 if (rc == 0) cout << "PIABaseExecutor: Link2 from " << tokens[0] << " OK " << endl;
76}
77else if (kw == "call" ) {
78 if (tokens.size() < 1) { cout << "Usage: call userf [arg1 arg2 ...]" << endl; return(0); }
79 UsFmap::iterator it;
80 UsFmap::iterator it1 = usfmap.find(tokens[0]);
81 UsFmap::iterator it2 = usfmap2.find(tokens[0]);
82 if ((it1 == usfmap.end()) && (it2 == usfmap2.end()) ) {
83 cerr << "PIABaseExecutor: No User Function " << tokens[0] << endl;
84 return(0);
85 }
86 if (it1 == usfmap.end()) it = it2;
87 else it = it1;
88 cout << "PIABaseExecutor: Call " << tokens[0] << "( ... )" << endl;
89// on est oblige de faire un cast etant donne qu'on
90// utilise donc des DlFunction (Reza 20/08/98) voir commentaire ds .h (pb g++)
91 DlUserProcFunction fuf = (DlUserProcFunction)(*it).second;
92/*DEL----- Plus besoin en multi-thread ? / Reza 06/01/2004
93// On redirige la sortie sur le terminal
94 bool red = mImgApp->HasRedirectedStdOutErr();
95 mImgApp->RedirectStdOutErr(false);
96 --------DEL */
97#ifdef SANS_EVOLPLANCK
98 TRY {
99 tokens.erase(tokens.begin());
100 fuf(tokens);
101 } CATCH(merr) {
102 fflush(stdout);
103 string es = PeidaExc(merr);
104 cerr << "\n PIABaseExecutor: Call UserFunc Exception :" << merr << es;
105 cout << endl;
106 }
107#else
108 try {
109 tokens.erase(tokens.begin());
110 fuf(tokens);
111 }
112 catch ( PThrowable & exc ) {
113 cerr << "\n PIABaseExecutor: Call / Catched Exception :"
114 << (string)typeid(exc).name() << " Msg= "
115 << exc.Msg() << endl;
116 cout << endl;
117 }
118 catch ( ... ) {
119 cerr << "\n PIABaseExecutor: Call / Catched Exception ... "
120 << endl;
121 cout << endl;
122 }
123#endif
124/*DEL----- Plus besoin en multi-thread ? / Reza 06/01/2004
125 mImgApp->RedirectStdOutErr(red);
126 --------DEL */
127}
128
129else if (kw == "openppf" ) {
130 if (tokens.size()<1) {cout<<"Usage: openppf file [objname1 objname2 ...]"<<endl; return(0); }
131 else if (tokens.size()==1) mObjMgr->ReadAll(tokens[0]);
132 else mObjMgr->ReadObj(tokens);
133}
134else if ((kw == "saveobjs") || (kw == "saveppf")) {
135 if (tokens.size() < 2) { cout << "Usage: saveobjs patt filename " << endl; return(0); }
136 mObjMgr->SaveObjects(tokens[0], tokens[1]);
137}
138else if (kw == "savelist") {
139 if (tokens.size() < 2) {
140 cout << "Usage: savelist objname1 [objname2 ...] filename "<<endl;
141 return(0);
142 }
143 mObjMgr->SaveListObjects(tokens);
144}
145else if (kw == "saveall" ) {
146 if (tokens.size() < 1) { cout << "Usage: saveall file " << endl; return(0); }
147 mObjMgr->SaveAll(tokens[0]);
148}
149else if (kw == "print" ) {
150 if (tokens.size() < 1) { cout << "Usage: print nameobj " << endl; return(0); }
151 mObjMgr->PrintObj(tokens[0]);
152}
153else if ( (kw == "rename" ) || (kw == "mv") ) {
154 if (tokens.size() < 2) { cout << "Usage: rename/mv nameobj namenew" << endl; return(0); }
155 mObjMgr->RenameObj(tokens[0], tokens[1]);
156}
157else if ( (kw == "del" ) || (kw == "rm") ) {
158 if (tokens.size() < 1) { cout << "Usage: del nameobj [nameobj2 ...]" << endl; return(0); }
159 if (tokens.size()>0)
160 for(uint_4 i=0;i<tokens.size();i++) mObjMgr->DelObj(tokens[i]);
161}
162else if (kw == "delobjs" ) {
163 if (tokens.size() < 1) { cout << "Usage: delobjs nomobjpattern (*,?) " << endl; return(0); }
164 mObjMgr->DelObjects(tokens[0]);
165}
166else if ( (kw == "listobjs") || (kw == "ls") ) {
167 if (tokens.size() < 1) tokens.push_back("*");
168 if (tokens.size() < 2) mObjMgr->ListObjs(tokens[0]);
169 else {
170 vector<string> olv;
171 mObjMgr->GetObjList(tokens[0], olv);
172 mpiac->SetVar(tokens[1], olv);
173 }
174}
175
176// Gestion des repertoires
177else if (kw == "mkdir" ) {
178 if (tokens.size() < 1) { cout << "Usage: mkdir dirname [true]" << endl; return(0); }
179 bool crd = mObjMgr->CreateDir(tokens[0]);
180 if ( crd && (tokens.size() > 1) && (tokens[1] == "true") )
181 mObjMgr->SetKeepOldDirAtt(tokens[0], true);
182 }
183else if (kw == "rmdir" ) {
184 if (tokens.size() < 1) { cout << "Usage: rmdir dirname " << endl; return(0); }
185 mObjMgr->DeleteDir(tokens[0]);
186 }
187else if (kw == "setdiratt" ) {
188 if (tokens.size() < 2) { cout << "Usage: setdiratt dirname true/false" << endl; return(0); }
189 if (tokens[1] == "true") mObjMgr->SetKeepOldDirAtt(tokens[0], true);
190 else mObjMgr->SetKeepOldDirAtt(tokens[0], false);
191}
192else if (kw == "cd") {
193 if (tokens.size() < 1) tokens.push_back("home");
194 mObjMgr->SetCurrentDir(tokens[0]);
195 }
196else if (kw == "pwd") {
197 string dirn;
198 mObjMgr->GetCurrentDir(dirn);
199 cout << "CurrentDirectory: " << dirn << endl;
200 }
201else if (kw == "listdirs") {
202 if (tokens.size() < 1) tokens.push_back("*");
203 mObjMgr->ListDirs(tokens[0]);
204 }
205
206// >>>>>>>>>>> Creation d'histos 1D-2D
207else if (kw == "newh1d") {
208 if (tokens.size() < 4) { cout << "Usage: newh1d name xmin xmax nbin" << endl; return(0); }
209 int_4 nbx = 100;
210 r_8 xmin = 0., xmax = 1.;
211 nbx = atoi(tokens[3].c_str());
212 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
213 Histo* h = new Histo(xmin, xmax, nbx);
214 mObjMgr->AddObj(h, tokens[0]);
215 }
216else if (kw == "newh2d") {
217 if (tokens.size() < 7) {
218 cout << "Usage: newh2d name xmin xmax nbinx ymin ymax nbiny" << endl;
219 return(0);
220 }
221 int_4 nbx = 50, nby = 50;
222 r_8 xmin = 0., xmax = 1.;
223 r_8 ymin = 0., ymax = 1.;
224 nbx = atoi(tokens[3].c_str());
225 nby = atoi(tokens[6].c_str());
226 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
227 ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str());
228 Histo2D* h = new Histo2D(xmin, xmax, nbx, ymin, ymax, nby);
229 mObjMgr->AddObj(h, tokens[0]);
230 }
231else if (kw == "newprof" || kw == "newprofe") {
232 if (tokens.size() < 4)
233 { cout << "Usage: newprof[e] name xmin xmax nbin [ymin ymax]" << endl; return(0); }
234 int_4 nbx = 100;
235 r_8 xmin = 0., xmax = 1., ymin = 1., ymax = -1.;
236 if(tokens.size() > 5)
237 {ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str());}
238 nbx = atoi(tokens[3].c_str());
239 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
240 HProf* h = new HProf(xmin, xmax, nbx, ymin, ymax);
241 if(kw == "newprofe") h->SetErrOpt(false);
242 mObjMgr->AddObj(h, tokens[0]);
243 }
244
245// Creation de NTuple
246else if (kw == "newnt") {
247 if(tokens.size() < 2)
248 {cout<<"Usage: newnt name v1 v2 ... vn / newnt name nvar"<<endl; return(0);}
249 vector<string> varname;
250 int nvar = 0;
251 const char *c = tokens[1].c_str();
252 if(isdigit(c[0])) {
253 nvar = atoi(tokens[1].c_str());
254 if(nvar<=0 || nvar>=10000)
255 {cout<<"newnt name nvar : nvar must be an positive integer<10000"<<endl;
256 return(0);}
257 for(int i=0;i<nvar;i++) {
258 char str[16]; sprintf(str,"%d",i);
259 string dum = "v"; dum += str;
260 varname.push_back(dum.c_str());
261 }
262 } else if( islower(c[0]) || isupper(c[0]) ) {
263 for(int i=1;i<(int)tokens.size();i++) {
264 varname.push_back(tokens[i].c_str());
265 nvar++;
266 }
267 } else {
268 cout<<"newnt name v1 v2 ... vn : name vi must begin by a letter"<<endl
269 <<"newnt name nvar : nvar must be an positive integer"<<endl;
270 return(0);
271 }
272 char **noms = new char*[nvar];
273 for(int i=0;i<nvar;i++) noms[i] = (char *)varname[i].c_str();
274 NTuple* nt = new NTuple(nvar,noms);
275 delete [] noms;
276 mObjMgr->AddObj(nt,tokens[0]);
277 }
278
279// Creation de DataTable
280else if (kw == "newdt") {
281 if(tokens.size() < 2)
282 {cout<<"Usage: newdt name v1:t1 v2:t2 ... vn:tn / newdt name nvar"<<endl; return(0);}
283 DataTable* dt = new DataTable();
284 const char *c = tokens[1].c_str();
285 if(isdigit(c[0])) {
286 int n = atoi(tokens[1].c_str());
287 if(n<=0 || n>=10000) {
288 cout<<"newdt name nvar : nvar="<<n<<" must be an positive integer<10000"<<endl;
289 delete dt; return(0);
290 }
291 for(int i=0;i<n;i++) {
292 char str[16]; sprintf(str,"v%d",i);
293 dt->AddDoubleColumn(str);
294 }
295 } else {
296 for(int i=1;i<tokens.size();i++) {
297 string vname = tokens[i];
298 uint_4 p = tokens[i].find(':');
299 if(p<tokens[i].size()) vname = vname.substr(0,p);
300 if(vname.size()<1) {
301 cout<<"Zero size name for variable: tokens["<<i<<"]="<<tokens[i]<<endl;
302 delete dt; return(0);
303 }
304 if (tokens[i].find(":r4")<tokens[i].size()) dt->AddFloatColumn(vname);
305 else if(tokens[i].find(":r8")<tokens[i].size()) dt->AddDoubleColumn(vname);
306 else if(tokens[i].find(":i4")<tokens[i].size()) dt->AddIntegerColumn(vname);
307 else if(tokens[i].find(":i8")<tokens[i].size()) dt->AddLongColumn(vname);
308 else if(tokens[i].find(":s") <tokens[i].size()) dt->AddStringColumn(vname);
309 else dt->AddDoubleColumn(vname);
310 }
311 }
312 mObjMgr->AddObj(dt,tokens[0]);
313}
314
315// Creation de GeneralFitData
316else if (kw == "newgfd") {
317 if (tokens.size() < 3)
318 { cout << "Usage: newgfd nvar nalloc [errx(0/1)]" << endl; return(0); }
319 int nvar, nalloc, errx=0;
320 if (tokens.size() > 3)
321 { errx = atoi(tokens[3].c_str()); if(errx>0) errx=1; else errx = 0;}
322 nvar = atoi(tokens[1].c_str()); nalloc = atoi(tokens[2].c_str());
323 if(nvar>0 && nalloc>0) {
324 GeneralFitData* gfd = new GeneralFitData(nvar,nalloc,errx);
325 mObjMgr->AddObj(gfd, tokens[0]);
326 }
327 }
328
329// Creation/remplissage de vecteur et de matrice
330else if (kw == "newvec") {
331 if (tokens.size() < 2) {
332 cout << "Usage: newvec name size [f(i) dopt] " << endl; return(0);
333 }
334 int n = atoi(tokens[1].c_str());
335 double xmin, xmax;
336 xmin = 0.; xmax = n;
337 if (tokens.size() < 3) {
338 Vector* v = new Vector(n);
339 mObjMgr->AddObj(v, tokens[0]);
340 }
341 else {
342 if (tokens.size() < 4) tokens.push_back("");
343 mObjMgr->GetServiceObj()->PlotFunc(tokens[2], tokens[0], xmin, xmax, n, tokens[3]);
344 }
345 }
346else if (kw == "newmtx") {
347 if (tokens.size() < 3) {
348 cout << "Usage: newmtx name sizeX(Col) sizeY(Lines) [f(i,j) dopt] " << endl; return(0);
349 }
350 int nx = atoi(tokens[1].c_str());
351 int ny = atoi(tokens[2].c_str());
352 double xmin, xmax, ymin, ymax;
353 xmin = 0.; xmax = nx;
354 ymin = 0.; ymax = ny;
355 if (tokens.size() < 4) {
356 Matrix* mtx = new Matrix(ny,nx);
357 mObjMgr->AddObj(mtx, tokens[0]);
358 }
359 else {
360 if (tokens.size() < 5) tokens.push_back("next");
361 mObjMgr->GetServiceObj()->PlotFunc2D(tokens[3], tokens[0], xmin, xmax, ymin, ymax,
362 nx, ny, tokens[4]);
363 }
364 }
365// ----- Vecteur/NTuple <> Lignes/variables interpreteur
366// Creation de vecteur depuis le contenu de la ligne
367else if (kw == "line2vec") {
368 if (tokens.size() < 2) {
369 cout << "Usage: line2vec vecname v0 v1 v2 ... " << endl; return(0);
370 }
371 int vsz = tokens.size()-1;
372 Vector* v = new Vector(vsz);
373 for(int kkv=0; kkv<vsz; kkv++) (*v)(kkv) = atof(tokens[kkv+1].c_str());
374 mObjMgr->AddObj(v, tokens[0]);
375 }
376// Remplissage de NTuple depuis la ligne
377else if (kw == "line2nt") {
378 if (tokens.size() < 2) {
379 cout << "Usage: line2nt ntname col0 col1 ..." << endl; return(0);
380 }
381 AnyDataObj* obj;
382 obj = mObjMgr->GetObj(tokens[0]);
383 if(obj == NULL) {
384 cerr << "line2nt Error , No such object " << tokens[0] << endl;
385 return(0);
386 }
387 NTuple* nt = dynamic_cast<NTuple *>(obj);
388 if(nt == NULL) {
389 cerr << "line2nt Error " << tokens[0] << " not an NTuple ! " << endl;
390 return(0);
391 }
392 if (nt->NbColumns() < 1) {
393 cerr << "line2nt Error: NbColumns < 1" << endl;
394 return(0);
395 }
396 r_4* xnt = new r_4[ nt->NbColumns() ];
397 int kkx;
398 for(kkx=0; kkx<nt->NbColumns(); kkx++) {
399 if (kkx < tokens.size()-1) xnt[kkx] = atof(tokens[kkx+1].c_str());
400 else xnt[kkx] = 0.;
401 }
402 nt->Fill(xnt);
403 delete[] xnt;
404}
405// Contenu du vecteur vers variable interpreteur
406#define MAXNWORDSO2V 32768
407else if (kw == "vec2var") {
408 if (tokens.size() < 2) {
409 cout << "Usage: vec2var vecname varname [loop_param start:end:step] " << endl; return(0);
410 }
411 AnyDataObj* obj;
412 obj = mObjMgr->GetObj(tokens[0]);
413 if(obj == NULL) {
414 cerr << "vec2var Error , No such object " << tokens[0] << endl;
415 return(0);
416 }
417 Vector* v = dynamic_cast<Vector *>(obj);
418 if(v == NULL) {
419 cerr << "vec2var Error " << tokens[0] << " not a Vector ! " << endl;
420 return(0);
421 }
422 int_8 kks = 0;
423 int_8 kke = v->NElts();
424 int_8 kkp = 1;
425 if (tokens.size() > 2) Services2NObjMgr::DecodeLoopParameters(tokens[2], kks, kke, kkp);
426 if (kks < 0) kks = 0;
427 if (kke > (int_8)v->NElts()) kke = v->NElts();
428 if (kkp < 1) kkp = 1;
429 int nelt = (kke-kks-1)/kkp;
430 if (nelt > MAXNWORDSO2V) {
431 nelt = MAXNWORDSO2V;
432 cout << "vec2var Warning: Only " << nelt
433 << " elements will be converted to string" << endl;
434 kke = kks+nelt*kkp;
435 }
436 string v2str;
437 char buff[64];
438 for(int kkv=kks; kkv<kke; kkv+=kkp) {
439 sprintf(buff, "%lg ", (*v)(kkv));
440 v2str += buff;
441 }
442
443 mObjMgr->SetVar(tokens[1], v2str);
444}
445// Une ligne du NTuple/NTupleInterface -> variable interpreteur
446else if ((kw == "ntline2var") || (kw == "ntcol2var")) {
447 if (tokens.size() < 3) {
448 cout << "Usage: ntline/col2var objname line_number varname" << endl;
449 return(0);
450 }
451 NObjMgrAdapter* oa = mObjMgr->GetObjAdapter(tokens[0]);
452 if(oa == NULL) {
453 cerr << "ntline/col2var Error , No such object " << tokens[0] << endl;
454 return(0);
455 }
456 bool adel = false;
457 NTupleInterface* nti = oa->GetNTupleInterface(adel);
458 if(nti == NULL) {
459 cerr << "ntline/col2var Error: objet" << tokens[0] << " has no NTupleInterface" << endl;
460 return(0);
461 }
462
463 if (nti->NbColumns() < 1 || nti->NbLines() < 1) {
464 cerr << "ntline/col2var Error: NbColumns or NbLines < 1" << endl;
465 return(0);
466 }
467 string v2str;
468 char buff[64];
469 if (kw == "ntline2var") {
470 int numline = atoi(tokens[1].c_str());
471 if ( (numline >= nti->NbLines()) || (numline < 0) ) {
472 cerr << "ntline2var Error: numline" << tokens[1] << " out of bounds" << endl;
473 return(0);
474 }
475 r_8* dline = nti->GetLineD(numline);
476 for(int kkv=0; kkv<nti->NbColumns(); kkv++) {
477 sprintf(buff, "%lg ", dline[kkv]);
478 v2str += buff;
479 }
480 }
481 else {
482 int numcol = atoi(tokens[1].c_str());
483 if ( (numcol >= nti->NbColumns()) || (numcol < 0) ) {
484 cerr << "ntcol2var Error: numcol" << tokens[1] << " out of bounds" << endl;
485 return(0);
486 }
487 int_8 kks = 0;
488 int_8 kke = nti->NbLines();
489 int_8 kkp = 1;
490 if (tokens.size() > 3) Services2NObjMgr::DecodeLoopParameters(tokens[3], kks, kke, kkp);
491 if (kks < 0) kks = 0;
492 if (kke > (int_8)nti->NbLines()) kke = nti->NbLines();
493 if (kkp < 1) kkp = 1;
494 int nelt = (kke-kks-1)/kkp;
495 if (nelt > MAXNWORDSO2V) {
496 nelt = MAXNWORDSO2V;
497 cout << "ntcol2var Warning: Only " << nelt
498 << " lines " << " will be converted to string" << endl;
499 kke = kks+nelt*kkp;
500 }
501 r_8* dline;
502 for(int kkl=kks; kkl<kke; kkl+=kkp) {
503 dline = nti->GetLineD(kkl);
504 sprintf(buff, "%lg ", dline[numcol]);
505 v2str += buff;
506 }
507 }
508 mObjMgr->SetVar(tokens[2], v2str);
509 if (adel) delete nti;
510}
511
512// -------------------------------------------------------
513// Copie d'objets
514else if ( (kw == "copy") || (kw == "cp") ) {
515 if(tokens.size()<2) {
516 cout<<"Usage: copy name_from name_to"<<endl;return(0);
517 }
518 mObjMgr->CopyObj(tokens[0],tokens[1]);
519}
520
521
522// >>>>>>>>>>> Trace de fonctions
523else if ( (kw == "func") ) {
524 if(tokens.size()<3) {cout<<"Usage: func f(x) xmin xmax [npt opt]"<<endl; return(0);}
525 int np = 100;
526 double xmin=0., xmax=1.;
527 string opt = "", nom = "";
528 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
529 if (tokens.size() > 3) np = atoi(tokens[3].c_str());
530 if (tokens.size() > 4) opt = tokens[4];
531 mObjMgr->GetServiceObj()->PlotFunc(tokens[0], nom, xmin, xmax, np, opt);
532 }
533else if ( (kw == "funcff") ) {
534 if (tokens.size()<4) {cout<<"Usage: funcff C-filename f(x)-name xmin xmax [npt opt]"<<endl; return(0);}
535 int np = 100;
536 double xmin=0., xmax=1.;
537 string opt = "", nom = "";
538 xmin = atof(tokens[2].c_str()); xmax = atof(tokens[3].c_str());
539 if(tokens.size()>4) np = atoi(tokens[4].c_str());
540 if(tokens.size()>5) opt = tokens[5];
541 mObjMgr->GetServiceObj()->PlotFuncFrCFile(tokens[0], tokens[1], nom, xmin, xmax, np, opt);
542 }
543else if ( (kw == "func2d") ) {
544 if (tokens.size() < 7) {
545 cout << "Usage: func2d f(x,y) xmin xmax nptx ymin ymax npty [opt]" << endl;
546 return(0);
547 }
548 int npx, npy;
549 double xmin, xmax;
550 double ymin, ymax;
551 npx = npy = 50;
552 xmin = 0.; xmax = 1.;
553 ymin = 0.; ymax = 1.;
554 npx = atoi(tokens[3].c_str());
555 npy = atoi(tokens[6].c_str());
556 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
557 ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str());
558 string opt = "";
559 if (tokens.size() > 7) opt = tokens[7];
560 string nom = "";
561 mObjMgr->GetServiceObj()->PlotFunc2D(tokens[0], nom, xmin, xmax, ymin, ymax, npx, npy, opt);
562 }
563else if ( (kw == "func2dff") ) {
564 if (tokens.size() < 8) {
565 cout << "Usage: func2d C-filename F(x,y)-name xmax nptx ymin ymax npty [opt]" << endl;
566 return(0);
567 }
568 int npx, npy;
569 double xmin, xmax;
570 double ymin, ymax;
571 npx = npy = 50;
572 xmin = 0.; xmax = 1.;
573 ymin = 0.; ymax = 1.;
574 npx = atoi(tokens[4].c_str());
575 npy = atoi(tokens[7].c_str());
576 xmin = atof(tokens[2].c_str()); xmax = atof(tokens[3].c_str());
577 ymin = atof(tokens[5].c_str()); ymax = atof(tokens[6].c_str());
578 string opt = "";
579 if (tokens.size() > 8) opt = tokens[8];
580 string nom = "";
581 mObjMgr->GetServiceObj()->PlotFunc2DFrCFile(tokens[0], tokens[1], nom, xmin, xmax, ymin, ymax, npx, npy, opt);
582 }
583
584// >>>>>>>>>>> Trace d'expressions de N_Tuple, StarList, etc ...
585else if (kw == "plot2d" ) {
586 if (tokens.size() < 3) {
587 cout << "Usage: plot2d nameobj expx expy [expcut opt loop_par]" << endl;
588 return(0);
589 }
590 string errx = ""; string erry = "";
591 if (tokens.size() < 4) tokens.push_back("1");
592 while (tokens.size() < 6) tokens.push_back("");
593 srvo->DisplayPoints2D(tokens[0],tokens[1],tokens[2],errx,erry,tokens[3],tokens[4],tokens[5]);
594 }
595
596else if (kw == "plot2de" ) { // Plot2D avec les erreurs
597 if (tokens.size() < 5) {
598 cout << "Usage: plot2de nameobj expx expy experrx experry [expcut opt loop_par]" << endl;
599 return(0);
600 }
601 if (tokens.size() < 6) tokens.push_back("1");
602 while (tokens.size() < 8) tokens.push_back("");
603 srvo->DisplayPoints2D(tokens[0],tokens[1],tokens[2],tokens[3],tokens[4],
604 tokens[5],tokens[6],tokens[7]);
605 }
606
607else if (kw == "plot2dw" ) { // Plot2d avec poids
608 if (tokens.size() < 4) {
609 cout << "Usage: plot2dw nomobj expx expy expwt [expcut opt loop_par]" << endl;
610 return(0);
611 }
612 if (tokens.size() < 5) tokens.push_back("1");
613 while (tokens.size() < 7) tokens.push_back("");
614 srvo->DisplayPoints2DW(tokens[0],tokens[1],tokens[2],tokens[3], tokens[4], tokens[5], tokens[6]);
615 }
616else if (kw == "plot3d" ) {
617 if (tokens.size() < 4) {
618 cout << "Usage: plot3d nomobj expx expy expz [expcut opt loop_par]" << endl;
619 return(0);
620 }
621 if (tokens.size() < 5) tokens.push_back("1");
622 while (tokens.size() < 7) tokens.push_back("");
623 srvo->DisplayPoints3D(tokens[0],tokens[1],tokens[2],tokens[3], tokens[4], tokens[5], tokens[6]);
624 }
625
626else if (kw == "projh1d" ) {
627 if (tokens.size() < 3) {
628 cout << "Usage: projh1d nomh1 nomobj expx [expwt expcut opt loop_par]" << endl;
629 return(0);
630 }
631 if (tokens.size() < 4) tokens.push_back("1.");
632 if (tokens.size() < 5) tokens.push_back("1");
633 while (tokens.size() < 7) tokens.push_back("");
634 srvo->ProjectH1(tokens[1], tokens[2], tokens[3], tokens[4], tokens[0], tokens[5], tokens[6] );
635 }
636
637
638// Projection dans histogrammes
639else if (kw == "projh2d" ) {
640 if (tokens.size() < 4) {
641 cout << "Usage: projh2d nomh2 nomobj expx expy [expwt expcut opt loop_par]" << endl;
642 return(0);
643 }
644 if (tokens.size() < 5) tokens.push_back("1.");
645 if (tokens.size() < 6) tokens.push_back("1");
646 while (tokens.size() < 8) tokens.push_back("");
647 srvo->ProjectH2(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5], tokens[0],
648 tokens[6], tokens[7] );
649 }
650
651else if (kw == "projprof" ) {
652 if (tokens.size() < 4) {
653 cout << "Usage: projprof nomprof nomobj expx expy [expwt expcut opt loop_par]" << endl;
654 return(0);
655 }
656 if (tokens.size() < 5) tokens.push_back("1.");
657 if (tokens.size() < 6) tokens.push_back("1");
658 while (tokens.size() < 8) tokens.push_back("");
659 srvo->ProjectHProf(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5], tokens[0],
660 tokens[6], tokens[7] );
661 }
662
663// Projection dans vector/matrix
664else if (kw == "fillvec" ) {
665 if (tokens.size() < 4) {
666 cout << "Usage: fillvec nomvec nomobj expx expv [expcut opt loop_par]" << endl;
667 return(0);
668 }
669 if (tokens.size() < 5) tokens.push_back("1");
670 while (tokens.size() < 7) tokens.push_back("");
671 srvo->FillVect(tokens[1], tokens[2], tokens[3], tokens[4], tokens[0], tokens[5], tokens[6] );
672 }
673
674else if (kw == "fillmtx" ) {
675 if (tokens.size() < 5) {
676 cout << "Usage: fillmtx nommtx nomobj expx expy expv [expcut opt loop_par]" << endl;
677 return(0);
678 }
679 if (tokens.size() < 6) tokens.push_back("1");
680 while (tokens.size() < 8) tokens.push_back("");
681 srvo->FillMatx(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5], tokens[0],
682 tokens[6], tokens[7] );
683 }
684
685// Remplissage NTuple,Vecteurs, ... , boucle de NTuple
686else if (kw == "ntfrascii" ) {
687 if(tokens.size() < 2) {
688 cout<<"Usage: ntfrascii nt_name file_name [def_init_val]"<<endl;
689 return(0);
690 }
691 double def_val = 0.;
692 if(tokens.size()>=3) def_val = atof(tokens[2].c_str());
693 srvo->NtFromASCIIFile(tokens[0],tokens[1],def_val);
694 }
695
696#ifndef SANS_EVOLPLANCK
697/* Lecture matrice/vecteur depuis fichier ASCII */
698else if ((kw == "mtxfrascii") || (kw == "vecfrascii") ) {
699 if(tokens.size() < 2) {
700 cout<<"Usage: mtxfrascii/vecfrascii mtx/vec_name file_name [CommLine Separator]"<<endl;
701 return(0);
702 }
703 TMatrix<r_8> mtx;
704 TVector<r_8> vec;
705 FILE* fip = fopen(tokens[1].c_str(), "r");
706 if (fip == NULL) {
707 cout << "vec/mtxfrascii: can not open file " << tokens[1] << endl;
708 return(0);
709 }
710 fclose(fip);
711 ifstream is(tokens[1].c_str());
712 sa_size_t nr, nc;
713 char clm = '#';
714 string sep = " \t";
715 if (tokens.size()>2) clm = tokens[2][0];
716 if (tokens.size()>3) sep = tokens[3];
717 if (kw == "mtxfrascii") {
718 mtx.ReadASCII(is, nr, nc, clm, sep.c_str());
719 mObjMgr->AddObj(mtx, tokens[0]);
720 cout << "mtxfrascii: TMatrix<r_8> " << tokens[0] << " read from file "
721 << tokens[1] << endl;
722 }
723 else {
724 vec.ReadASCII(is, nr, nc, clm, sep.c_str());
725 mObjMgr->AddObj(vec, tokens[0]);
726 cout << "vecfrascii: TVector<r_8> " << tokens[0] << " read from file "
727 << tokens[1] << endl;
728 }
729}
730else if (kw == "arrtoascii") {
731 if(tokens.size() < 2) {
732 cout<<"Usage: arrtoascii array_name file_name "<<endl;
733 return(0);
734 }
735
736 AnyDataObj* obj;
737 obj = mObjMgr->GetObj(tokens[0]);
738 if(obj == NULL) {
739 cerr << "arrtoascii Error , No such object " << tokens[0] << endl;
740 return(0);
741 }
742 BaseArray* ba = dynamic_cast<BaseArray *>(obj);
743 if(ba == NULL) {
744 cerr << "arrtoascii Error " << tokens[0] << " not a BaseArray ! " << endl;
745 return(0);
746 }
747 ofstream os(tokens[1].c_str());
748 ba->WriteASCII(os);
749 cout << "arrtoascii: Array " << tokens[0] << " written to file " << tokens[1] << endl;
750}
751
752#endif
753
754else if (kw == "fillnt" ) {
755 if (tokens.size() < 5) {
756 cout << "Usage: fillnt nameobj expx expy expz expt [expcut ntname loop_par]" << endl;
757 return(0);
758 }
759 while (tokens.size() < 8) tokens.push_back("");
760 srvo->FillNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6], tokens[7] );
761 }
762
763else if (kw == "ntloop" ) {
764 if (tokens.size() < 3) {
765 cout << "Usage: ntloop nameobj fname funcname [ntname loop_par ]" << endl;
766 return(0);
767 }
768 while (tokens.size() < 5) tokens.push_back("");
769 srvo->FillNTFrCFile(tokens[0],tokens[1], tokens[2], tokens[3], tokens[4]);
770 }
771
772else if (kw == "ntexpcfile" ) {
773 if (tokens.size() < 3) {
774 cout << "Usage: ntexpcfile nameobj fname funcname" << endl;
775 return(0);
776 }
777 srvo->PrepareNTExpressionCFile(tokens[0],tokens[1], tokens[2]);
778 }
779
780else if (kw == "expmeansig" ) {
781 if (tokens.size() < 2) {
782 cout << "Usage: expmeansig nameobj expx [expcut loop_par]" << endl;
783 return(0);
784 }
785 while (tokens.size() < 4) tokens.push_back("");
786 string dummy = "";
787 cout << " expmeansig: computing mean/sigma + min/max for " << tokens[0]
788 << "." << tokens[1] << endl;
789 srvo->ExpressionToVector(tokens[0],tokens[1],tokens[2],dummy,dummy,tokens[3]);
790 }
791
792else if (kw == "exptovec" ) {
793 if (tokens.size() < 3) {
794 cout << "Usage: exptovec nomvec nameobj expx [expcut opt loop_par]" << endl;
795 return(0);
796 }
797 while (tokens.size() < 6) tokens.push_back("");
798 srvo->ExpressionToVector(tokens[1],tokens[2],tokens[3],tokens[0],tokens[4],tokens[5]);
799 }
800
801else if (kw == "fillgd1" ) {
802 if (tokens.size() < 5) {
803 cout << "Usage: fillgd1 nomgfd nomobj expx expy experry [expcut loop_par] " << endl;
804 return(0);
805 }
806 if (tokens.size() < 6) tokens.push_back("1");
807 if (tokens.size() < 7) tokens.push_back("");
808 string expy = "";
809 srvo->FillGFD(tokens[1],tokens[2], expy, tokens[3], tokens[4], tokens[5], tokens[0]);
810 }
811
812else if (kw == "fillgd2" ) {
813 if (tokens.size() < 6) {
814 cout << "Usage: fillgd2 nomgfd nomobj expx expy expz experrz [expcut loop_par]" << endl;
815 return(0);
816 }
817 if (tokens.size() < 7) tokens.push_back("1");
818 if (tokens.size() < 8) tokens.push_back("");
819 srvo->FillGFD(tokens[1],tokens[2],tokens[3], tokens[4], tokens[5], tokens[6], tokens[0], tokens[7]);
820 }
821
822else if (kw == "gdfrvec" ) {
823 if(tokens.size()<3) {
824 cout<<"Usage: gdfrvec namegfd X Y\n"
825 <<" gdfrvec namegfd X Y"
826 <<" gdfrvec namegfd X Y ! EY\n"
827 <<" gdfrvec namegfd X Y Z\n"
828 <<" gdfrvec namegfd X Y Z EZ"<<endl;
829 return(0);
830 }
831 while(tokens.size()<5) tokens.push_back("!");
832 srvo->FillGFDfrVec(tokens[0],tokens[1],tokens[2],tokens[3],tokens[4]);
833 }
834
835// >>>>>>>>>>> Calcul d'expression arithmetique
836else if ( (kw == "eval") ) {
837 if(tokens.size()<2)
838 {cout<<"Usage: eval resultvarname arithmetic expression...."<<endl; return(0);}
839 string expval = "";
840 for(unsigned int i=1;i<tokens.size();i++) expval+=tokens[i];
841 string resultvarname = "";
842 if(isalpha(tokens[0][0])) resultvarname=tokens[0];
843 mObjMgr->GetServiceObj()->ExpVal(expval,resultvarname);
844 }
845
846else {
847 cerr << "PIABaseExecutor::Do() Erreur - Commande " << kw << " inconuue ! " << endl;
848 return(-1);
849 }
850
851return(0);
852}
853
854/* --Methode-- */
855bool PIABaseExecutor::IsThreadable(string const & keyw)
856{
857 if ( (keyw == "fillvec") || (keyw == "fillmtx") ||
858 (keyw == "fillnt") || (keyw == "ntloop") ) return true;
859 else if (keyw.substr(0,4) == "func") return true;
860 else {
861 string skw = keyw.substr(0,5);
862 if ( (skw == "plot2") || (skw == "plot3") || (skw == "projh") ) return true;
863 }
864 return false;
865}
866
867
868/* --Methode-- */
869void PIABaseExecutor::RegisterCommands()
870{
871string kw, usage, grp;
872//--------- Commandes du groupe modules externes
873grp = "External Modules";
874string gdesc = "Dynamic load (shared object modules) management command group";
875mpiac->AddHelpGroup(grp, gdesc);
876kw = "loadmodule";
877usage = "To load and initialize modules \n Usage: loadmodule fnameso modulename";
878usage += "\n Related commands: link";
879mpiac->RegisterCommand(kw, usage, this, grp);
880kw = "link";
881usage = "Dynamic linking of compiled user functions \n Usage: link fnameso f1 [f2 f3]";
882usage += "\n fnameso: Shared-object file name, f1,f2,f3 : User function names ";
883usage += "\n Related commands: call loadmodule linkff2";
884mpiac->RegisterCommand(kw, usage, this, grp);
885kw = "linkff2";
886usage = "Dynamic linking of compiled user functions (Set 2)\n Usage: linkff2 fnameso f1 [f2 f3]";
887usage += "\n fnameso: Shared-object file name, f1,f2,f3 : User function names ";
888usage += "\n Related commands: call link loadmodule";
889mpiac->RegisterCommand(kw, usage, this, grp);
890kw = "call";
891usage = "Dynamically linked user function call \n Usage: call userf [arg1 arg2 ...]";
892usage += "\n User function : f(vector<string>& args)";
893usage += "\n Related commands: link";
894mpiac->RegisterCommand(kw, usage, this, grp);
895
896kw = "openppf";
897usage = "Reads all or some objects from a PPF file \n Usage: openppf filename [objname1 objname2 ...]";
898usage += "\n Related commands: saveall ";
899mpiac->RegisterCommand(kw, usage, this, "FileIO");
900kw = "saveppf";
901usage = "Saves objects with names matching a pattern into a\n";
902usage += " PPF file (pattern: x?y*) - Alias saveppf\n";
903usage += "Usage: saveppf nameobjpattern filename";
904usage += "\n Related commands: saveobjs savelist saveall openppf";
905mpiac->RegisterCommand(kw, usage, this, "FileIO");
906kw = "saveobjs";
907usage = "Saves objects with names matching a pattern into a\n";
908usage += " PPF file (pattern: x?y*) - Alias saveppf\n";
909usage += "Usage: saveobjs nameobjpattern filename";
910usage += "\n Related commands: saveppf savelist saveall openppf ";
911mpiac->RegisterCommand(kw, usage, this, "FileIO");
912kw = "saveall";
913usage = "Saves all objects into a PPF file \n Usage: saveall filename";
914usage += "\n Related commands: saveobj savelist openppf";
915mpiac->RegisterCommand(kw, usage, this, "FileIO");
916kw = "savelist";
917usage = "Saves a list of objects into a PPF file";
918usage = "\n Usage: savelist objname1 [objname2 ...] filename";
919usage += "\n Related commands: saveobj openppf";
920mpiac->RegisterCommand(kw, usage, this, "FileIO");
921kw = "ntfrascii";
922usage = "Fills an existing NTuple or DataTable from ASCII table file";
923usage += "\n Usage: ntfrascii nt_name file_name [def_init_val]";
924usage += "\n Related commands: ntloop fillnt ";
925mpiac->RegisterCommand(kw, usage, this, "FileIO");
926#ifndef SANS_EVOLPLANCK
927kw = "mtxfrascii";
928usage = "Reads a matrix from an ASCII file (TMatrix<r_8>)";
929usage += "\n Usage: mtxfrascii mtx_name file_name [CommChar Separator]";
930usage += "\n Related commands: arrtoascii vecfrascii ntfrascii ";
931mpiac->RegisterCommand(kw, usage, this, "FileIO");
932kw = "vecfrascii";
933usage = "Reads a vector from an ASCII file (TVector<r_8>)";
934usage += "\n Usage: vecfrascii vec_name file_name";
935usage += "\n Related commands: arrtoascii mtxfrascii ntfrascii [CommChar Separator]";
936mpiac->RegisterCommand(kw, usage, this, "FileIO");
937kw = "arrtoascii";
938usage = "Writes an array (TArray<T>) to an ASCII file ";
939usage += "\n Usage: arrtoascii array_name file_name";
940usage += "\n Related commands: mtxfrascii vecfrascii ntfrascii ";
941mpiac->RegisterCommand(kw, usage, this, "FileIO");
942#endif
943
944kw = "print";
945usage = "Prints an object \n Usage: print nameobj";
946mpiac->RegisterCommand(kw, usage, this, "FileIO");
947
948//------- Commandes gestion de repertoires et d'objets
949kw = "mkdir";
950usage = "Create a directory";
951usage += "\n Usage: mkdir dirname [true]";
952usage += "\n if second argument==true, the directory's KeepOld attribute is set to true";
953mpiac->RegisterCommand(kw, usage, this, "Object Management");
954kw = "rmdir";
955usage = "Removes an empty directory";
956usage += "\n Usage: remove dirname";
957mpiac->RegisterCommand(kw, usage, this, "Object Management");
958kw = "setdiratt";
959usage = "Sets directory attributes";
960usage += "\n Usage: setdiratt dirname KeepOldFlag(=true/false)";
961usage += "\n KeepOldFlag=true Object with the same name is moved to old";
962usage += "\n when adding objects";
963mpiac->RegisterCommand(kw, usage, this, "Object Management");
964kw = "cd";
965usage = "Change current directory";
966usage += "\n Usage: cd [dirname]";
967mpiac->RegisterCommand(kw, usage, this, "Object Management");
968kw = "pwd";
969usage = "Prints current directory";
970usage += "\n Usage: pwd";
971mpiac->RegisterCommand(kw, usage, this, "Object Management");
972kw = "listdirs";
973usage = "Prints the list of directories";
974usage += "\n Usage: listdirs [patt=*] \n patt : * , ? ";
975mpiac->RegisterCommand(kw, usage, this, "Object Management");
976kw = "listobjs";
977usage = "Prints the list of objects (Alias: ls)";
978 usage += "\n Usage: listobjs [patt=*] \n patt : /*/x?y* ... ";
979mpiac->RegisterCommand(kw, usage, this, "Object Management");
980kw = "rename";
981usage = "Rename an object (Alias: mv) \n Usage: rename nameobj namenew";
982usage += "\n Related commands: mv del delobjs";
983mpiac->RegisterCommand(kw, usage, this, "Object Management");
984kw = "mv";
985usage = "Rename an object (Alias: rename) \n Usage: mv nameobj namenew";
986usage += "\n Related commands: rename del delobjs";
987mpiac->RegisterCommand(kw, usage, this, "Object Management");
988kw = "copy";
989usage = "Copy objects (Alias cp) \n";
990usage +=" Usage: copy name_from name_to";
991usage += "\n Related commands: cp new...";
992mpiac->RegisterCommand(kw, usage, this, "Object Management");
993kw = "cp";
994usage = "Copy objects (Alias copy) \n";
995usage +=" Usage: cp name_from name_to";
996usage += "\n Related commands: copy new...";
997mpiac->RegisterCommand(kw, usage, this, "Object Management");
998kw = "del";
999usage = "Deletes an object (Alias: rm) \n Usage: del nameobj [nameobj2 ...]";
1000usage += "\n Related commands: rm delobjs rename";
1001mpiac->RegisterCommand(kw, usage, this, "Object Management");
1002kw = "rm";
1003usage = "Deletes an object (Alias: del) \n Usage: rm nameobj [nameobj2 ...]";
1004usage += "\n Related commands: del delobjs rename";
1005mpiac->RegisterCommand(kw, usage, this, "Object Management");
1006kw = "delobjs";
1007usage = "Delete a set of objects with names matching a pattern (x?y*)";
1008usage += "\n Usage: delobjs nameobjpattern \n";
1009usage += "\n Related commands: del rename";
1010mpiac->RegisterCommand(kw, usage, this, "Object Management");
1011
1012//------- Commandes creation/manipulation d'objets
1013kw = "newh1d";
1014usage = "Creates a 1D histogramm \n Usage: newh1d name xmin xmax nbin";
1015usage += "\n Related commands: newh2d newprof[e] newdt newnt newgfd ";
1016mpiac->RegisterCommand(kw, usage, this, "Objects");
1017kw = "newh2d";
1018usage = "Creates a 2D histogramm \n Usage: newh2d name xmin xmax nbinx ymin ymax nbiny";
1019usage += "\n Related commands: newh1d newprof[e] newdt newnt newgfd ";
1020mpiac->RegisterCommand(kw, usage, this, "Objects");
1021kw = "newprof";
1022usage = "Creates a profile histogramm \n Usage: newprof name xmin xmax nbin [ymin ymax]";
1023usage += "\n Errors represent the data spread in the X bin ";
1024usage += "\n Related commands: newh1d newh2d newprofe newdt newnt newgfd ";
1025mpiac->RegisterCommand(kw, usage, this, "Objects");
1026kw = "newprofe";
1027usage = "Creates a profile histogramm \n Usage: newprofe name xmin xmax nbin [ymin ymax]";
1028usage += "\n Errors represent the error on the data mean in the X bin ";
1029usage += "\n Related commands: newh1d newh2d newprof newdt newnt newgfd ";
1030mpiac->RegisterCommand(kw, usage, this, "Objects");
1031kw = "newnt";
1032usage = "Creates a ntuple \n Usage: newnt name v1 v2 v3 .. vn";
1033usage += "\n newnt name nvar";
1034usage += "\n Related commands: newdt newh1d newh2d newprof[e] newgfd ";
1035mpiac->RegisterCommand(kw, usage, this, "Objects");
1036kw = "newdt";
1037usage = "Creates a datatable \n Usage: newdt name v1:t1 v2:t2 v3:t3 .. vn:tn";
1038usage += "\n newdt name nvar";
1039usage += "\n vi : variable name";
1040usage += "\n ti : variable type";
1041usage += "\n r8,r4 for 8 and 4 bytes float";
1042usage += "\n i8,i4 for 8 and 4 bytes signed integer";
1043usage += "\n s for string";
1044usage += "\n Related commands: newnt newh1d newh2d newprof[e] newgfd";
1045mpiac->RegisterCommand(kw, usage, this, "Objects");
1046kw = "newgfd";
1047usage = "Creates GeneralFit Data object \n Usage: newgfd nvar nalloc [errx(0/1)]";
1048usage += "\n Related commands: newh1d newh2d newprof[e] newdt newnt ";
1049mpiac->RegisterCommand(kw, usage, this, "Objects");
1050kw = "newvec";
1051usage = "Creates (and optionaly fills) a vector \n Usage: newvec name size [f(i) [dopt] ] ";
1052usage += "\n Related commands: newmtx line2vec";
1053mpiac->RegisterCommand(kw, usage, this, "Objects");
1054kw = "newmtx";
1055usage = "Creates (and optionaly fills) a matrix \n";
1056usage +=" Usage: newmtx name sizeX(Col) sizeY(Lines) [f(i,j) [dopt] ] ";
1057usage += "\n Related commands: newvec";
1058mpiac->RegisterCommand(kw, usage, this, "Objects");
1059kw = "line2vec";
1060usage = "Creates a vector from the line \n";
1061usage += " Usage: line2vec vecname v0 v1 v2 ... \n";
1062usage += " Related commands: newvec line2nt";
1063mpiac->RegisterCommand(kw, usage, this, "Objects");
1064kw = "line2nt";
1065usage = "Fills (append) an NTuple from the line content \n";
1066usage += " Usage: line2nt ntname col0 col1 ... \n";
1067usage += " Related commands: newnt line2vec ntline2var ntcol2var";
1068mpiac->RegisterCommand(kw, usage, this, "Objects");
1069kw = "vec2var";
1070usage = "Vector content to an interpreter variable varname = 'v0 v1 v2 ...' \n";
1071usage += " Usage: line2vec vecname varname [LoopParam start:end[:step] ]\n";
1072usage += " Related commands: line2vec ntline2var";
1073mpiac->RegisterCommand(kw, usage, this, "Objects");
1074kw = "ntline2var";
1075usage = "Object NTupleInterface line to an interpreter variable \n";
1076usage += " Usage: ntline2var objname line_number varname \n";
1077usage += " Related commands: vec2var ntcol2var";
1078mpiac->RegisterCommand(kw, usage, this, "Objects");
1079kw = "ntcol2var";
1080usage = "Object NTupleInterface column to an interpreter variable \n";
1081usage += " Usage: ntline2var objname column_number varname [LoopParam start:end[:step] ] \n";
1082usage += " Related commands: vec2var ntline2var";
1083mpiac->RegisterCommand(kw, usage, this, "Objects");
1084
1085//------- Commandes trace de fonctions
1086kw = "func";
1087usage = "Displays a function y=f(x) (Fills a vector with function values)";
1088usage += "\n Usage: func f(x) xmin xmax [npt graphic_attributes]";
1089usage += "\n Related commands: funcff func2d func2dff ";
1090mpiac->RegisterCommand(kw, usage, this, "Func Plot");
1091kw = "funcff";
1092usage = "Displays a function y=f(x) from a C-file (Fills a vector with function values)";
1093usage += "\n Usage: funcff C-FileName FunctionName xmin xmax [npt graphic_attributes]";
1094usage += "\n Related commands: func func2d func2dff ";
1095mpiac->RegisterCommand(kw, usage, this, "Func Plot");
1096kw = "func2d";
1097usage = "Displays a function z=f(x,y) (Fills a matrix with function values)";
1098usage += "\n Usage: func2d f(x,y) xmin xmax nptx ymin ymax npty [graphic_attributes]";
1099usage += "\n Related commands: func";
1100mpiac->RegisterCommand(kw, usage, this, "Func Plot");
1101kw = "func2dff";
1102usage = "Displays a function z=f(x,y) from a C-file (Fills a matrix with function values)";
1103usage += "\n Usage: func2dff C-FileName FunctionName xmin xmax nptx ymin ymax npty [graphic_attributes]";
1104usage += "\n Related commands: func funcff func2d ";
1105mpiac->RegisterCommand(kw, usage, this, "Func Plot");
1106
1107//------ Commandes trace d'expression
1108kw = "ObjectExpressions";
1109usage = "Any mathematical expression (math.h) with object variables can be used";
1110usage += "\n ------ Object Variable names (double) -------- ";
1111usage += "\n (_nl is the table line number or the sequential index)";
1112usage += "\n- NTuple: ntuple variable names,_nl";
1113usage += "\n- Histo1D/HProf: i,x,val,err,_nl";
1114usage += "\n- Histo2D: i,j,x,y,val,err,_nl";
1115usage += "\n- Vector/Matrix: n,r,c,val,real,imag,mod,phas,_nl";
1116usage += "\n- TArray: n,x,y,z,t,u,val,real,imag,mod,phas,_nl";
1117usage += "\n- Image: i,j,x,y,val(=pix),_nl";
1118usage += "\n- GeneralFitData: x0,ex0 x1,ex1 ... xn,exn y,ey ok ,_nl";
1119usage += "\n- LocalMap/SphereThetaPhi/SphereHEALPix: ";
1120usage += "\n- i,k,val,real,imag,mod,phas,teta,phi,_nl";
1121usage += "\n- FITS Binary/ASCII table: fits column names,_nl";
1122#ifdef SANS_EVOLPLANCK
1123usage += "\n ------ Eros Variable names (double) -------- ";
1124usage += "\n- StarList: x,y,flux,fond,pixmax,flags,";
1125usage += "\n- xref,yref,fluxref,fondref,pixmaxref,_nl";
1126#endif
1127usage += "\n ------ Other parameters -------- ";
1128usage += "\nLoop parameters can be specified as I1[:I2[:DI]] for(int i=I1; i<I2; i+=DI)";
1129usage += "\nThe default Cut() expression in true (=1) for all";
1130usage += "\n\n Related commands: plot2d plot2de plot2dw plot3d ";
1131usage += "\n projh1d projh2d projprof fillvec fillmtx ";
1132usage += "\n fillnt fillgd1 fillgd2 ntloop exptovec ... ";
1133grp = "Expr. Plotting";
1134mpiac->RegisterHelp(kw, usage, grp);
1135kw = "plot2d";
1136usage = "Plots (2D) Y=g(Object) vs. X=f(Object) --- Object Variable names (double) :";
1137usage += "\n Usage: plot2d nameobj f_X() g_Y() [f_Cut() graphic_attributes loop_param]";
1138usage += "\n Related commands: plot2de plot2dw plot3d ObjectExpressions ...";
1139mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1140kw = "plot2de";
1141usage = "Plots (2D) Y=g(Object) vs. X=f(Object) with error bars eX/Y=f_ErrX/Y(Object) ";
1142usage += "\n Usage: plot2de nameobj f_X() g_Y() f_ErrX() f_ErrY() [f_Cut() graphic_attributes loop_param]";
1143usage += "\n Related commands: plot2d plot2dw plot3d ObjectExpressions ...";
1144mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1145kw = "plot2dw";
1146usage = "Plots (2D) Y=g(Object) vs. X=f(Object) with Weight W=h(Object) ";
1147usage += "\n Usage: plot2dw nameobj f_X() g_Y() h_Wt() [Cut() graphic_attributes loop_param]";
1148usage += "\n Related commands: plot2d plot2dw plot3d ObjectExpressions ...";
1149mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1150kw = "plot3d";
1151usage = "Plots (3D) Z=h(Object) vs. Y=g(Object) vs. X=f(Object) vs ";
1152usage += "\n Usage: plot3d nameobj f_X() g_Y() h_Z() [Cut() graphic_attributes loop_param]";
1153usage += "\n Related commands: plot2d plot2dw plot2de plot3d ObjectExpressions ...";
1154mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1155
1156kw = "projh1d";
1157usage = "Projects X=f(Object) with weight WT=h(Object) into a 1D histogram ";
1158usage += "\n Usage: projh1d nameh1d nameobj f_X() [h_WT()=1. Cut() graphic_attributes loop_param]";
1159usage += "\n Histo1D nameh1d is created if necessary ";
1160usage += "\n Related commands: projh2d projprof ObjectExpressions ...";
1161mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1162kw = "projh2d";
1163usage = "Projects (X=f(Object),Y=g(Object)) with weight WT=h(Object) into a 2D histogram ";
1164usage += "\n Usage: projh2d nameh2d nameobj f_X() g_Y() [h_WT()=1. Cut() graphic_attributes loop_param]";
1165usage += "\n Histo2D nameh2d is created if necessary ";
1166usage += "\n Related commands: projh1d projprof ObjectExpressions ...";
1167mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1168kw = "projprof";
1169usage = "Projects (X=f(Object),Y=g(Object)) with weight WT=h(Object) into a profile histogram ";
1170usage += "\n Usage: projprof nameprof nameobj f_X() g_Y() [h_WT()=1. Cut() graphic_attributes loop_param]";
1171usage += "\n HProf nameprof is created if necessary ";
1172usage += "\n Related commands: projh1d projh2d ObjectExpressions ...";
1173mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1174kw = "fillvec";
1175usage = "Fills a Vector V((int)(f_X(Object)+0.5)) = h_V(Object) ";
1176usage += "\n Usage: fillvec namevec nameobj f_X() h_V() [Cut() graphic_attributes loop_param]";
1177usage += "\n Related commands: fillmtx fillnt ObjectExpressions ...";
1178mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1179kw = "fillmtx";
1180usage = "Fills a Matrix M(Line=g_Y(Object)+0.5, Col=f_X(Object)+0.5)) = h_V(Object) ";
1181usage += "\n Usage: fillvec namevec nameobj f_X() g_Y() h_V() [Cut() graphic_attributes loop_param]";
1182usage += "\n Related commands: fillvec fillnt ObjectExpressions ...";
1183mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1184
1185kw = "fillnt";
1186usage = "Creates and Fills an NTuple(x,y,z,t) with (X=f(Object),Y=g(...),Z=h(...),T=k(...))";
1187usage += "\n Usage: fillnt nameobj f_X() g_Y() h_Z() k_T() [Cut() nameNt loop_param]";
1188usage += "\n Related commands: ntloop plot2d projh1d projh2d projprof ";
1189usage += "\n Related commands: fillvec fillmtx ntloop exptovec fillgd1 fillgd2 ObjectExpressions ...";
1190mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1191
1192kw = "ntloop";
1193usage = "Loops over an Object NTupleInterface calling a function from a C-file \n";
1194usage += "and optionaly fills an NTuple(x,y,z,t) with (X=f(Object),Y=g(...),Z=h(...),T=k(...))";
1195usage += "\n Usage: ntloop nameobj CFileName FuncName [NtupleName loop_param]";
1196usage += "\n Related commands: fillvec fillmtx fillnt fillgd1 fillgd2 exptovec ObjectExpressions ...";
1197usage += "\n Related commands: ntexpcfile fillnt";
1198mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1199
1200kw = "ntexpcfile";
1201usage = "Creates a C-File with declarations suitable to be used for ntloop";
1202usage += "\n Usage: ntexpcfile nameobj CFileName FuncName ";
1203usage += "\n Related commands: ntloop";
1204mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1205
1206kw = "expmeansig";
1207usage = "Computes Mean/Sigma (+Min/Max) for an expression X=f(Object)";
1208usage += "\n Usage: expmeansig nameobj f_X() [Cut() loop_param]";
1209usage += "\n Related commands: exptovec ntloop fillnt ObjectExpressions ...";
1210mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1211
1212kw = "exptovec";
1213usage = "Creates and Fills a Vector with X=f(Object)";
1214usage += "\n Usage: exptovec namevec nameobj f_X() [Cut() graphic_attributes loop_param]";
1215usage += "\n Related commands: ntloop fillnt ObjectExpressions ...";
1216mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1217
1218kw = "fillgd1";
1219usage = "Creates and Fills a GeneralFitData with (X=f(Object), Y=g(...), ErrY=h(...))";
1220usage += "\n Usage: fillgd1 namegfd nameobj f_X() g_Y() h_ErrY() [Cut() loop_param]";
1221usage += "\n Related commands: ntloop fillnt ObjectExpressions ...";
1222mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1223kw = "fillgd2";
1224usage = "Creates and Fills a GeneralFitData with (X=f(Object), Y=g(...), Z=h(...)) ErrZ=k(...)";
1225usage += "\n Usage: fillgd1 namegfd nameobj f_X() g_Y() h_Z() k_ErrZ() [Cut() loop_param]";
1226usage += "\n Related commands: ntloop fillnt ObjectExpressions ...";
1227mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1228kw = "gdfrvec";
1229usage = "Fills a GeneralFitData with vectors X,Y,Z,EZ";
1230usage += "\n Usage: gdfrvec namegfd X Y";
1231usage += "\n Usage: gdfrvec namegfd X Y ! EY";
1232usage += "\n Usage: gdfrvec namegfd X Y Z";
1233usage += "\n Usage: gdfrvec namegfd X Y Z EZ";
1234usage += "\n Related commands: fillgd1 fillgd2 ...";
1235mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
1236
1237
1238kw = "eval";
1239usage = "Compute arithmetic expression\n";
1240usage += "\n Usage: eval resultvarname arithmetic expression....";
1241usage += "\n resultvarname: store result in variable resultvarname";
1242usage += "\n - If first character is not alphabetic, just print result";
1243usage += "\n arithmetic expression:";
1244usage += "\n ex: x + sqrt(y)+z +3.14 (x,y,z are variables)";
1245usage += "\n ex: $x + sqrt($y)+$z +3.14 (x,y,z are variables)";
1246usage += "\n ex: 360 * M_PI / 180.";
1247mpiac->RegisterCommand(kw, usage, this, "Expr. Arithmetic");
1248
1249}
1250
1251/* --Methode-- */
1252int PIABaseExecutor::LinkUserFuncs(string& fnameso, string& func1, string& func2, string& func3)
1253// string& func4, string& func5)
1254{
1255string cmd;
1256
1257if (dynlink) delete dynlink; dynlink = NULL;
1258usfmap.clear();
1259
1260dynlink = new PDynLinkMgr(fnameso, true);
1261if (dynlink == NULL) {
1262 string sn = fnameso;
1263 cerr << "PIABaseExecutor/LinkUserFuncs_Erreur: Erreur ouverture SO " << sn << endl;
1264 return(2);
1265 }
1266
1267int nok=0;
1268// on utilise donc des DlFunction (Reza 20/08/98) voir commentaire ds .h (pb g++)
1269// DlUserProcFunction f = NULL;
1270DlFunction f = NULL;
1271if ((func1.length() < 1) || (func1 == "-") || (func1 == ".") ) goto fin;
1272// f = (DlUserProcFunction) dlsym(dlhandle, func1.c_str());
1273f = dynlink->GetFunction(func1);
1274if (f) { nok++; usfmap[func1] = f; }
1275else cerr << "PIABaseExecutor/LinkUserFuncs_Erreur: Erreur linking " << func1 << endl;
1276
1277if ((func2.length() < 1) || (func2 == "-") || (func2 == ".") ) goto fin;
1278// f = (DlUserProcFunction) dlsym(dlhandle, func2.c_str());
1279f = dynlink->GetFunction(func2);
1280if (f) { nok++; usfmap[func2] = f; }
1281else cerr << "PIABaseExecutor/LinkUserFuncs_Erreur: Erreur linking " << func2 << endl;
1282
1283if ((func3.length() < 1) || (func3 == "-") || (func3 == ".") ) goto fin;
1284// f = (DlUserProcFunction) dlsym(dlhandle, func3.c_str());
1285f = dynlink->GetFunction(func3);
1286if (f) { nok++; usfmap[func3] = f; }
1287else cerr << "PIABaseExecutor/LinkUserFuncs_Erreur: Erreur linking " << func3 << endl;
1288
1289/* Pb compile g++ 2.7.2
1290if ((func4.length() < 1) || (func4 == "-") || (func4 == ".") ) goto fin;
1291// f = (DlUserProcFunction) dlsym(dlhandle, func4.c_str());
1292f = dynlink->GetFunction(func4);
1293if (f) { nok++; usfmap[func4] = f; }
1294else cerr << "PIABaseExecutor/LinkUserFuncs_Erreur: Erreur linking " << func4 << endl;
1295
1296if ((func5.length() < 1) || (func5 == "-") || (func5 == ".") ) goto fin;
1297// f = (DlUserProcFunction) dlsym(dlhandle, func5.c_str());
1298f = dynlink->GetFunction(func5);
1299if (f) { nok++; usfmap[func5] = f; }
1300else cerr << "PIABaseExecutor/LinkUserFuncs_Erreur: Erreur linking " << func5 << endl;
1301*/
1302fin:
1303if (nok < 1) { if (dynlink) delete dynlink; dynlink = NULL; return(3); }
1304else return(0);
1305}
1306
1307/* --Methode-- */
1308int PIABaseExecutor::LinkUserFuncs2(string& fnameso, string& func1, string& func2, string& func3)
1309{
1310string cmd;
1311
1312if (dynlink2) delete dynlink2; dynlink2 = NULL;
1313usfmap2.clear();
1314
1315dynlink2 = new PDynLinkMgr(fnameso, true);
1316if (dynlink2 == NULL) {
1317 string sn = fnameso;
1318 cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur ouverture SO " << sn << endl;
1319 return(2);
1320 }
1321
1322int nok=0;
1323// on utilise donc des DlFunction (Reza 20/08/98) voir commentaire ds .h (pb g++)
1324// DlUserProcFunction f = NULL;
1325DlFunction f = NULL;
1326if ((func1.length() < 1) || (func1 == "-") || (func1 == ".") ) goto fin;
1327f = dynlink2->GetFunction(func1);
1328if (f) { nok++; usfmap2[func1] = f; }
1329else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func1 << endl;
1330
1331if ((func2.length() < 1) || (func2 == "-") || (func2 == ".") ) goto fin;
1332f = dynlink2->GetFunction(func2);
1333if (f) { nok++; usfmap2[func2] = f; }
1334else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func2 << endl;
1335
1336if ((func3.length() < 1) || (func3 == "-") || (func3 == ".") ) goto fin;
1337f = dynlink2->GetFunction(func3);
1338if (f) { nok++; usfmap2[func3] = f; }
1339else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func3 << endl;
1340
1341fin:
1342if (nok < 1) { if (dynlink2) delete dynlink2; dynlink2 = NULL; return(3); }
1343else return(0);
1344}
1345
Note: See TracBrowser for help on using the repository browser.