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

Last change on this file since 3449 was 3428, checked in by ansari, 18 years ago

Correction ds NamedObjMgr::ReadAll() + ajout commande ls comme alias de listobjs , Reza 08/12/2007

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