Changeset 333 in Sophya for trunk/SophyaPI/PIext
- Timestamp:
- Jul 12, 1999, 1:12:29 PM (26 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/basexecut.cc
r331 r333 20 20 #include "ntuple.h" 21 21 #include "generaldata.h" 22 #include "cvector.h" 22 23 23 24 … … 42 43 int PIABaseExecutor::Execute(string& kw, vector<string>& tokens) 43 44 { 44 45 Services2NObjMgr* srvo = mObjMgr->GetServiceObj(); 45 46 // >>>>> Chargement de modules 46 47 if (kw == "loadmodule") { … … 124 125 mObjMgr->ReadAll(tokens[0]); 125 126 } 127 else if (kw == "saveobjs" ) { 128 if (tokens.size() < 2) { cout << "Usage: saveobjs patt filename " << endl; return(0); } 129 mObjMgr->SaveObjects(tokens[0], tokens[1]); 130 } 126 131 else if (kw == "saveall" ) { 127 132 if (tokens.size() < 1) { cout << "Usage: saveall file " << endl; return(0); } … … 132 137 mObjMgr->PrintObj(tokens[0]); 133 138 } 134 else if ( kw == "rename" ){139 else if ( (kw == "rename" ) || (kw == "mv") ) { 135 140 if (tokens.size() < 2) { cout << "Usage: rename nameobj namenew" << endl; return(0); } 136 141 mObjMgr->RenameObj(tokens[0], tokens[1]); 137 142 } 138 else if ( kw == "del") {143 else if ( (kw == "del" ) || (kw == "rm") ) { 139 144 if (tokens.size() < 1) { cout << "Usage: del nameobj " << endl; return(0); } 140 145 mObjMgr->DelObj(tokens[0]); … … 144 149 mObjMgr->DelObjects(tokens[0]); 145 150 } 146 else if ( kw == "listobjs"){151 else if ( (kw == "listobjs") || (kw == "ls") ) { 147 152 if (tokens.size() < 1) tokens.push_back("*"); 148 153 mObjMgr->ListObjs(tokens[0]); 149 154 } 155 // Gestion des repertoires 156 else if (kw == "mkdir" ) { 157 if (tokens.size() < 1) { cout << "Usage: mkdir dirname " << endl; return(0); } 158 mObjMgr->CreateDir(tokens[0]); 159 } 160 else if (kw == "rmdir" ) { 161 if (tokens.size() < 1) { cout << "Usage: rmdir dirname " << endl; return(0); } 162 mObjMgr->DeleteDir(tokens[0]); 163 } 164 else if (kw == "cd") { 165 if (tokens.size() < 1) tokens.push_back("home"); 166 mObjMgr->SetCurrentDir(tokens[0]); 167 } 168 else if (kw == "listdirs") { 169 if (tokens.size() < 1) tokens.push_back("*"); 170 mObjMgr->ListDirs(tokens[0]); 171 } 150 172 151 173 // >>>>>>>>>>> Creation d'histos 1D-2D … … 206 228 } 207 229 230 // Creation/remplissage de vecteur et de matrice 231 else if (kw == "newvec") { 232 if (tokens.size() < 2) { 233 cout << "Usage: newvec name size [f(i) dopt] " << endl; return(0); 234 } 235 int n = atoi(tokens[1].c_str()); 236 double xmin, xmax; 237 xmin = 0.; xmax = n; 238 if (tokens.size() < 3) tokens.push_back("0."); 239 if (tokens.size() < 4) tokens.push_back("n"); 240 mObjMgr->GetServiceObj()->PlotFunc(tokens[2], tokens[0], xmin, xmax, n, tokens[3]); 241 } 242 else if (kw == "newmtx") { 243 if (tokens.size() < 3) { 244 cout << "Usage: newvec name sizeX sizeY [f(i,j) dopt] " << endl; return(0); 245 } 246 int nx = atoi(tokens[1].c_str()); 247 int ny = atoi(tokens[2].c_str()); 248 double xmin, xmax, ymin, ymax; 249 xmin = 0.; xmax = nx; 250 ymin = 0.; ymax = ny; 251 if (tokens.size() < 4) tokens.push_back("0."); 252 if (tokens.size() < 5) tokens.push_back("n"); 253 mObjMgr->GetServiceObj()->PlotFunc2D(tokens[3], tokens[0], xmin, xmax, ymin, ymax, 254 nx, ny, tokens[4]); 255 } 256 208 257 // >>>>>>>>>>> Affichage des objets 209 258 else if ( (kw == "disp") || (kw == "surf") || (kw == "imag") ) { … … 223 272 mObjMgr->DisplayNT(tokens[0],tokens[1],tokens[2], ph, tokens[3], tokens[4], ph, opt); 224 273 } 274 else if (kw == "nt2dw") { 275 if (tokens.size() < 6) { cout << "Usage: nt2dw nameobj varx vary varz errx erry opt" << endl; return(0); } 276 string opt = "n"; 277 if (tokens.size() > 6) opt = tokens[6]; 278 string ph = ""; 279 mObjMgr->DisplayNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], ph, opt, false); 280 } 225 281 else if (kw == "nt3d") { 226 282 if (tokens.size() < 7) { cout << "Usage: nt3d nameobj varx vary varz errx erry errz opt" << endl; return(0); } 227 283 string opt = "n"; 228 284 if (tokens.size() > 7) opt = tokens[7]; 229 mObjMgr->DisplayNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6], opt );285 mObjMgr->DisplayNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6], opt, true); 230 286 } 231 287 … … 258 314 if (tokens.size() > 4) opt = tokens[4]; 259 315 int np; 260 floatxmin, xmax;316 double xmin, xmax; 261 317 np = 100; 262 318 xmin = 0.; xmax = 1.; 263 319 np = atoi(tokens[3].c_str()); 264 320 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str()); 265 mObjMgr->GetServiceObj()->PlotFunc(tokens[0], xmin, xmax, np, opt); 321 string nom = ""; 322 mObjMgr->GetServiceObj()->PlotFunc(tokens[0], nom, xmin, xmax, np, opt); 266 323 } 267 324 else if ( (kw == "funcff") ) { … … 270 327 if (tokens.size() > 5) opt = tokens[5]; 271 328 int np; 272 floatxmin, xmax;329 double xmin, xmax; 273 330 np = 100; 274 331 xmin = 0.; xmax = 1.; 275 332 np = atoi(tokens[4].c_str()); 276 333 xmin = atof(tokens[2].c_str()); xmax = atof(tokens[3].c_str()); 277 mObjMgr->GetServiceObj()->PlotFuncFrCFile(tokens[0], tokens[1], xmin, xmax, np, opt); 334 string nom = ""; 335 mObjMgr->GetServiceObj()->PlotFuncFrCFile(tokens[0], tokens[1], nom, xmin, xmax, np, opt); 278 336 } 279 337 else if ( (kw == "func2d") ) { … … 283 341 } 284 342 int npx, npy; 285 floatxmin, xmax;286 floatymin, ymax;343 double xmin, xmax; 344 double ymin, ymax; 287 345 npx = npy = 50; 288 346 xmin = 0.; xmax = 1.; … … 294 352 string opt = "n"; 295 353 if (tokens.size() > 7) opt = tokens[7]; 296 mObjMgr->GetServiceObj()->PlotFunc2D(tokens[0], xmin, xmax, ymin, ymax, npx, npy, opt); 354 string nom = ""; 355 mObjMgr->GetServiceObj()->PlotFunc2D(tokens[0], nom, xmin, xmax, ymin, ymax, npx, npy, opt); 297 356 } 298 357 else if ( (kw == "func2dff") ) { … … 302 361 } 303 362 int npx, npy; 304 floatxmin, xmax;305 floatymin, ymax;363 double xmin, xmax; 364 double ymin, ymax; 306 365 npx = npy = 50; 307 366 xmin = 0.; xmax = 1.; … … 313 372 string opt = "n"; 314 373 if (tokens.size() > 8) opt = tokens[8]; 315 mObjMgr->GetServiceObj()->PlotFunc2DFrCFile(tokens[0], tokens[1], xmin, xmax, ymin, ymax, npx, npy, opt); 374 string nom = ""; 375 mObjMgr->GetServiceObj()->PlotFunc2DFrCFile(tokens[0], tokens[1], nom, xmin, xmax, ymin, ymax, npx, npy, opt); 316 376 } 317 377 … … 332 392 if (tokens.size() > 6) opt = tokens[6]; 333 393 } 334 mObjMgr->DisplayPoints2D(tokens[0],tokens[1],tokens[2],errx,erry,ecut,opt); 335 } 336 394 srvo->DisplayPoints2D(tokens[0],tokens[1],tokens[2],errx,erry,ecut,opt); 395 } 396 397 else if (kw == "plot2dw" ) { 398 if (tokens.size() < 5) { 399 cout << "Usage: plot2dw nomobj expx expy expwt expcut opt" << endl; 400 return(0); 401 } 402 string opt = "n"; 403 if (tokens.size() > 5) opt = tokens[5]; 404 srvo->DisplayPoints2DW(tokens[0],tokens[1],tokens[2],tokens[3], tokens[4], opt); 405 } 337 406 else if (kw == "plot3d" ) { 338 407 if (tokens.size() < 5) { … … 342 411 string opt = "n"; 343 412 if (tokens.size() > 5) opt = tokens[5]; 344 mObjMgr->DisplayPoints3D(tokens[0],tokens[1],tokens[2],tokens[3], tokens[4], opt);413 srvo->DisplayPoints3D(tokens[0],tokens[1],tokens[2],tokens[3], tokens[4], opt); 345 414 } 346 415 … … 352 421 string opt = "n"; 353 422 if (tokens.size() > 5) opt = tokens[5]; 354 mObjMgr->ProjectH1(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], opt);423 srvo->ProjectH1(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], opt); 355 424 } 356 425 … … 363 432 if (tokens.size() > 6) opt = tokens[6]; 364 433 365 mObjMgr->ProjectH2(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], opt);434 srvo->ProjectH2(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], opt); 366 435 } 367 436 … … 374 443 if (tokens.size() > 6) opt = tokens[6]; 375 444 376 mObjMgr->ProjectHProf(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], opt);445 srvo->ProjectHProf(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], opt); 377 446 } 378 447 379 448 else if (kw == "fillnt" ) { 380 if (tokens.size() < 7) { 381 cout << "Usage: fillnt nameobj expx expy expz expt expcut nament" << endl; 382 return(0); 383 } 384 mObjMgr->FillNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6] ); 449 if (tokens.size() < 6) { 450 cout << "Usage: fillnt nameobj expx expy expz expt expcut [ntname]" << endl; 451 return(0); 452 } 453 if (tokens.size() < 7) tokens.push_back(""); 454 srvo->FillNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6] ); 455 } 456 457 else if (kw == "ntloop" ) { 458 if (tokens.size() < 3) { 459 cout << "Usage: ntloop nameobj fname funcname [ntname]" << endl; 460 return(0); 461 } 462 if (tokens.size() < 4) tokens.push_back(""); 463 srvo->FillNTFrCFile(tokens[0],tokens[1], tokens[2], tokens[3]); 464 } 465 466 else if (kw == "ntexpcfile" ) { 467 if (tokens.size() < 3) { 468 cout << "Usage: ntexpcfile nameobj fname funcname" << endl; 469 return(0); 470 } 471 srvo->PrepareNTExpressionCFile(tokens[0],tokens[1], tokens[2]); 385 472 } 386 473 … … 392 479 string opt = "n"; 393 480 if (tokens.size() > 4) opt = tokens[4]; 394 mObjMgr->FillVect(tokens[0],tokens[1],tokens[2], tokens[3], opt);481 srvo->FillVect(tokens[0],tokens[1],tokens[2], tokens[3], opt); 395 482 } 396 483 … … 403 490 if (tokens.size() > 5) nomgfd = tokens[5]; 404 491 string expy = ""; 405 mObjMgr->FillGFD(tokens[0],tokens[1], expy, tokens[2], tokens[3], tokens[4],nomgfd);492 srvo->FillGFD(tokens[0],tokens[1], expy, tokens[2], tokens[3], tokens[4],nomgfd); 406 493 } 407 494 … … 413 500 string nomgfd = ""; 414 501 if (tokens.size() > 6) nomgfd = tokens[6]; 415 mObjMgr->FillGFD(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5],nomgfd);502 srvo->FillGFD(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5],nomgfd); 416 503 } 417 504 … … 436 523 else if(c[0]=='o') {O += ","; O += c+2;} 437 524 } 438 mObjMgr->Fit12D(tokens[0],tokens[1],p,s,m,M,O);525 srvo->Fit12D(tokens[0],tokens[1],p,s,m,M,O); 439 526 } 440 527 … … 520 607 usage += "\n Related commands: saveall openfits"; 521 608 mpiac->RegisterCommand(kw, usage, this, "FileIO"); 609 kw = "saveobjs"; 610 usage = "Saves objects with names matching a pattern (x?y*) into a PPF file \n"; 611 usage += "Usage: saveall nameobjpattern filename"; 612 usage += "\n Related commands: saveall openppf savefits"; 613 mpiac->RegisterCommand(kw, usage, this, "FileIO"); 522 614 kw = "saveall"; 523 615 usage = "Saves all objects into a PPF file \n Usage: saveall filename"; 524 usage += "\n Related commands: openppf savefits";616 usage += "\n Related commands: saveobj openppf savefits"; 525 617 mpiac->RegisterCommand(kw, usage, this, "FileIO"); 526 618 … … 529 621 mpiac->RegisterCommand(kw, usage, this, "FileIO"); 530 622 623 kw = "mkdir"; 624 usage = "Create a directory"; 625 usage += "\n Usage: mkdir dirname"; 626 mpiac->RegisterCommand(kw, usage, this, "Object Managment"); 627 kw = "rmdir"; 628 usage = "Removes an empty directory"; 629 usage += "\n Usage: remove dirname"; 630 mpiac->RegisterCommand(kw, usage, this, "Object Managment"); 631 kw = "cd"; 632 usage = "Change current directory"; 633 usage += "\n Usage: cd [dirname]"; 634 mpiac->RegisterCommand(kw, usage, this, "Object Managment"); 635 kw = "pwd"; 636 usage = "Prints current directory"; 637 usage += "\n Usage: pwd"; 638 mpiac->RegisterCommand(kw, usage, this, "Object Managment"); 639 kw = "listdirs"; 640 usage = "Prints the list of directories"; 641 usage += "\n Usage: listdirs [patt=*] \n patt : * , ? "; 642 mpiac->RegisterCommand(kw, usage, this, "Object Managment"); 531 643 kw = "listobjs"; 532 usage = "Prints the list of objects ";533 usage += "\n Usage: listobjs";644 usage = "Prints the list of objects (Alias: ls)"; 645 usage += "\n Usage: listobjs [patt=*] \n patt : /*/x?y* ... "; 534 646 mpiac->RegisterCommand(kw, usage, this, "Object Managment"); 535 647 kw = "rename"; 536 usage = "Rename an object \n Usage: rename nameobj namenew";648 usage = "Rename an object (Alias: mv) \n Usage: rename nameobj namenew"; 537 649 usage += "\n Related commands: del delobjs"; 538 650 mpiac->RegisterCommand(kw, usage, this, "Object Managment"); 539 651 kw = "del"; 540 usage = "Deletes an object \n Usage: del nameobj";652 usage = "Deletes an object (Alias: rm) \n Usage: del nameobj"; 541 653 usage += "\n Related commands: delobjs rename"; 542 654 mpiac->RegisterCommand(kw, usage, this, "Object Managment"); … … 550 662 usage = "Creates a 1D histogramm \n Usage: newh1d name xmin xmax nbin"; 551 663 usage += "\n Related commands: newh2d newprof newgfd "; 552 mpiac->RegisterCommand(kw, usage, this, " Histrograms");664 mpiac->RegisterCommand(kw, usage, this, "Objects"); 553 665 kw = "newh2d"; 554 666 usage = "Creates a 2D histogramm \n Usage: newh2d name xmin xmax nbinx ymin ymax nbiny"; 555 667 usage += "\n Related commands: newh1d newprof newgfd "; 556 mpiac->RegisterCommand(kw, usage, this, " Histrograms");668 mpiac->RegisterCommand(kw, usage, this, "Objects"); 557 669 kw = "newprof"; 558 670 usage = "Creates a profile histogramm \n Usage: newprof name xmin xmax nbin [ymin ymax]"; 559 671 usage += "\n Related commands: newh1d newh2d newgfd "; 560 mpiac->RegisterCommand(kw, usage, this, " Histrograms");672 mpiac->RegisterCommand(kw, usage, this, "Objects"); 561 673 kw = "newgfd"; 562 674 usage = "Creates GeneralFit Data object \n Usage: newgfd nvar nalloc [errx(0/1)]"; 563 675 usage += "\n Related commands: newh1d newh2d newprof "; 564 mpiac->RegisterCommand(kw, usage, this, "Histrograms"); 676 mpiac->RegisterCommand(kw, usage, this, "Objects"); 677 kw = "newvec"; 678 usage = "Creates (and fills) a vector \n Usage: newvec name size [f(i) [dopt] ] "; 679 usage += "\n Related commands: newmtx"; 680 mpiac->RegisterCommand(kw, usage, this, "Objets"); 681 kw = "newmtx"; 682 usage = "Creates (and fills) a matrix \n Usage: newvec name sizeX sizeY [f(i,j) [dopt] ] "; 683 usage += "\n Related commands: newvec"; 684 mpiac->RegisterCommand(kw, usage, this, "Objets"); 565 685 566 686 kw = "disp"; … … 579 699 usage = "Displays Points (X-Y) [with error-bars] from an NTuple "; 580 700 usage += "\n Usage : nt2d nameobj varx vary [errx erry] [graphic_attributes]"; 581 usage += "\n Related commands: disp surf nt3d gfd2d "; 701 usage += "\n Related commands: disp surf nt2dw nt3d gfd2d "; 702 mpiac->RegisterCommand(kw, usage, this, "Obj. Display"); 703 kw = "nt2dw"; 704 usage = "Displays Points (X-Y) with weight [with error-bars] from an NTuple "; 705 usage += "\n Usage : nt2d nameobj varx vary varz [errx erry] [graphic_attributes]"; 706 usage += "\n Related commands: disp surf nt2d nt3d gfd2d "; 582 707 mpiac->RegisterCommand(kw, usage, this, "Obj. Display"); 583 708 kw = "nt3d"; 584 709 usage = "Displays 3D-Points (X-Y-Z) [with error-bars] from an NTuple "; 585 710 usage += "\n Usage : nt3d nameobj varx vary varz [errx erry errz] [graphic_attributes]"; 586 usage += "\n Related commands: disp surf nt2d gfd3d ";711 usage += "\n Related commands: disp surf nt2d nt2dw gfd3d "; 587 712 mpiac->RegisterCommand(kw, usage, this, "Obj. Display"); 588 713 kw = "gfd2d"; … … 623 748 usage += "\nVector: i,val - Matrix: i,j,val - Image: x=i,y=j, pix=val"; 624 749 usage += "\n Usage: plot2d nameobj f_X() g_Y() [ f_ErrX() f_ErrY() ] f_Cut() [graphic_attributes]"; 625 usage += "\n Related commands: plot3d projh1d projh2d projprof fillnt fillvec fillgd1 "; 750 usage += "\n Related commands: plot2dw plot3d projh1d projh2d projprof fillnt fillvec fillgd1 "; 751 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting"); 752 kw = "plot2dw"; 753 usage = "Plots (2D) Y=g(Object) vs. X=f(Object) with Weight W=h(Object) "; 754 usage += "\n Usage: plot2dw nameobj f_X() g_Y() h_Wt() Cut() [graphic_attributes]"; 755 usage += "\n Related commands: plot2d projh1d projh2d projprof fillnt fillvec "; 626 756 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting"); 627 757 kw = "plot3d"; 628 758 usage = "Plots (3D) Z=h(Object) vs. Y=g(Object) vs. X=f(Object) vs "; 629 usage += "\n Usage: plot 2d nameobj f_X() g_Y() h_Z() Cut() [graphic_attributes]";630 usage += "\n Related commands: plot2d projh1d projh2d projprof fillnt fillvec ";759 usage += "\n Usage: plot3d nameobj f_X() g_Y() h_Z() Cut() [graphic_attributes]"; 760 usage += "\n Related commands: plot2d plot2dw projh1d projh2d projprof fillnt fillvec "; 631 761 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting"); 632 762 … … 653 783 usage = "Creates and Fills an NTuple(x,y,z,t) with (X=f(Object),Y=g(...),Z=h(...),T=k(...))"; 654 784 usage += "\n Usage: fillnt nameobj f_X() g_Y() h_Z() k_T() Cut() nameNt"; 655 usage += "\n Related commands: plot2d projh1d projh2d projprof "; 656 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting"); 785 usage += "\n Related commands: ntloop plot2d projh1d projh2d projprof "; 786 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting"); 787 kw = "ntloop"; 788 usage = "Loops over an Object NTupleInterface calling a function from a C-file \n"; 789 usage += "and optionaly fills an NTuple(x,y,z,t) with (X=f(Object),Y=g(...),Z=h(...),T=k(...))"; 790 usage += "\n Usage: ntloop nameobj CFileName FuncName [NtupleName]"; 791 usage += "\n Related commands: ntexpcfile fillnt"; 792 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting"); 793 kw = "ntexpcfile"; 794 usage = "Creates a C-File with declarations suitable to be used for ntloop"; 795 usage += "\n Usage: ntexpcfile nameobj CFileName FuncName "; 796 usage += "\n Related commands: ntloop"; 797 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting"); 798 657 799 kw = "fillvec"; 658 800 usage = "Creates and Fills a Vector with X=f(Object)"; … … 685 827 { 686 828 string cmd; 687 int rc;688 829 689 830 if (dynlink) delete dynlink; dynlink = NULL; -
trunk/SophyaPI/PIext/dlftypes.h
r295 r333 16 16 typedef double (* DlFunctionOfX) (double x); 17 17 typedef double (* DlFunctionOfXY) (double x, double y); 18 typedef int (* PlotExprFunc) (double* x, double* rx, double* ry, double* rz, double* wt); 18 typedef int (* PlotExprFunc) (double* x, double* rx, double* ry, double* rz, double* rt); 19 typedef int (* NTLoopExprFunc) (double* x, double* rx, double* ry, double* rz, 20 double* rt, int n, int nmax); 19 21 typedef void (* DlUserProcFunction) (vector<string>& args); 20 22 typedef void (* DlFunction) (); -
trunk/SophyaPI/PIext/nobjmgr.cc
r332 r333 22 22 #include "pistdimgapp.h" 23 23 24 #include "matrix.h"25 #include "cvector.h"26 #include "ntuple.h"27 24 28 25 // EVOL-PLANCK … … 31 28 #endif 32 29 33 #include "fct1dfit.h"34 #include "fct2dfit.h"35 36 30 #include "pisurfdr.h" 37 31 #include "pipodrw.h" 38 #include "pihisto.h" 39 #include "hisprof.h" 40 #include "pihisto2d.h" 32 41 33 #include "pintuple.h" 42 34 #include "pintup3d.h" … … 75 67 AnyDataObj* obj; 76 68 NObjMgrAdapter* obja; 77 int num;69 int oid; 78 70 int dirid; 79 71 list<int> wrsid; … … 95 87 96 88 static string* TmpDir; // Repertoire pour les compilations / link dynamique 89 90 // Pour completer le nom de l'objet avec le nom du repertoire 91 static void RemoveSpacesFromName(string & nom); 92 static bool CheckDirName(string & nom); 93 static int ParseObjectName(string & nom, string & nomrep, string & nomobj); 94 // .................................................................. 97 95 98 96 //++ … … 111 109 { 112 110 if (fgOInit == 0) { 111 myNObj = 0; 112 myDirId = 0; 113 113 myDirs = new NObjDirList; 114 114 myObjs = new NObjList; 115 115 currDir = new string("home"); 116 string dirn = "home"; 117 CreateDir(dirn); 118 dirn = "tmp"; 119 CreateDir(dirn); 120 dirn = "old"; 121 CreateDir(dirn); 122 dirn = "home"; 123 SetCurrentDir(dirn); 124 myDirId = 50; 116 125 char* varenv; 117 126 TmpDir = new string(""); … … 120 129 int l = (*TmpDir).length(); 121 130 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/'; 122 servnobjm = new Services2NObjMgr( NULL, (*TmpDir));131 servnobjm = new Services2NObjMgr(this, (*TmpDir)); 123 132 } 124 133 fgOInit++; … … 148 157 myImgApp = app; 149 158 servnobjm->SetImgApp(app); 159 160 NObjDirList::iterator it; 161 string cn; 162 for(it= myDirs->begin(); it != myDirs->end(); it++) { 163 cn = '/' + (*it).first; 164 (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id); 165 } 150 166 } 151 167 … … 163 179 164 180 /* --Methode-- */ 165 void NamedObjMgr::CreateDir(string const& dirname) 166 { 167 } 168 169 /* --Methode-- */ 170 void NamedObjMgr::DeleteDir(string const& dirname) 171 { 172 } 173 174 /* --Methode-- */ 175 void NamedObjMgr::SetCurrentDir(string const& dirname) 176 { 181 void NamedObjMgr::CreateDir(string & dirname) 182 { 183 if ( !CheckDirName(dirname) ) { 184 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl; 185 return; 186 } 187 NObjDirList::iterator it = myDirs->find(dirname); 188 if (it != myDirs->end()) { 189 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl; 190 return; 191 } 192 myDirId++; 193 nobj_diritem di; 194 di.id = myDirId; 195 di.nobj = 0; 196 (*myDirs)[dirname] = di; 197 if (myImgApp) { 198 string str = '/' + dirname; 199 (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId); 200 } 201 cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl; 202 } 203 204 /* --Methode-- */ 205 void NamedObjMgr::DeleteDir(string & dirname) 206 { 207 if ( !CheckDirName(dirname) ) { 208 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl; 209 return; 210 } 211 NObjDirList::iterator it = myDirs->find(dirname); 212 if (it == myDirs->end()) { 213 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl; 214 return; 215 } 216 if ((*it).second.nobj > 0) { 217 cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl; 218 return; 219 } 220 if ((*it).second.id < 50) { 221 cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl; 222 return; 223 } 224 225 if (myImgApp) 226 (myImgApp->ObjMgrW())->DelDirectory((*it).second.id); 227 myDirs->erase(it); 228 cout << "amedObjMgr::DeleteDir() " << dirname << " deleted " << endl; 229 } 230 231 /* --Methode-- */ 232 void NamedObjMgr::SetCurrentDir(string & dirname) 233 { 234 if ( !CheckDirName(dirname) ) { 235 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl; 236 return; 237 } 238 NObjDirList::iterator it = myDirs->find(dirname); 239 if (it == myDirs->end()) { 240 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl; 241 return; 242 } 243 *currDir = dirname; 244 cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl; 245 } 246 247 /* --Methode-- */ 248 void NamedObjMgr::GetCurrentDir(string & dirname) 249 { 250 dirname = *currDir; 251 } 252 253 /* --Methode-- */ 254 void NamedObjMgr::ListDirs(string & patt) 255 { 256 NObjDirList::iterator it; 257 string cn; 258 cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl; 259 int k = 0; 260 for(it= myDirs->begin(); it != myDirs->end(); it++) { 261 cn = (*it).first; 262 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; 263 k++; 264 cout << k << "- " << (*it).first << " (NbObj= " << (*it).second.nobj << ")" << endl; 265 } 266 } 267 268 /* --Methode-- */ 269 void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd) 270 { 271 NObjDirList::iterator it; 272 string cn; 273 for(it= myDirs->begin(); it != myDirs->end(); it++) { 274 cn = (*it).first; 275 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; 276 lstd.push_back(cn); 277 } 177 278 } 178 279 … … 186 287 { 187 288 } 289 188 290 189 291 //++ … … 209 311 210 312 /* --Methode-- */ 211 void NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool )313 void NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd) 212 314 { 213 315 214 316 if (obj == NULL) return; 215 // on supprime les blancs de debut et de fin 216 size_t p = nom.find_first_not_of(" "); 217 if(p>nom.length()) { 218 nom = ""; 219 } else { 220 nom = nom.substr(p); 221 p = nom.find_first_of(" "); 222 if(p>nom.length()) p=nom.length(); 223 nom = nom.substr(0, p); 224 } 317 // On verifie si l'objet est deja dans la liste 318 NObjList::iterator it; 319 for(it = myObjs->begin(); it != myObjs->end(); it++) { 320 if ((*it).second.obj == obj) { 321 cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl; 322 return; 323 } 324 } 325 string nobj; 326 string nrep; 327 char buff[32]; 328 int did = ParseObjectName(nom, nrep, nobj); 329 if (did == 0) { 330 if (!crd) { 331 cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl; 332 return; 333 } 334 else { CreateDir(nrep); did = myDirId; } 335 } 225 336 226 337 myNObj++; 227 if (nom.length() < 1) nom = typeid(*obj).name(); 228 NObjList::iterator it = myObjs->find(nom); 338 if (nobj.length() < 1) { 339 sprintf(buff,"O%d", myNObj); 340 nobj = buff; 341 } 342 343 nom = '/' + nrep + '/' + nobj; 344 it = myObjs->find(nom); 229 345 if (it != myObjs->end()) { // l'objet existe deja 230 char strg[16]; 231 sprintf(strg, "%d", myNObj); 232 string nomnew = nom + strg; 233 RenameObj(nom, nomnew); 346 if (nrep == "tmp") { // Les objets de /tmp sont jetes 347 cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl; 348 DelObj(nom); 349 } 350 else { // On met l'ancien objet dans /old 351 string on,od; 352 ParseObjectName((*it).first, od, on); 353 sprintf(buff, "%d", (*it).second.oid); 354 string nomnew = "/old/" + on + buff; 355 RenameObj(nom, nomnew); 356 } 234 357 } 235 358 … … 237 360 no.obj = obj; 238 361 no.obja = servnobjm->GetAdapter(obj); // L'adaptateur 239 no.num = myNObj; 362 no.oid = myNObj; 363 no.dirid = did; 240 364 (*myObjs)[nom] = no; 241 if (myImgApp) { 242 string str = nom + " (T= " + typeid(*obj).name() + ")" ; 243 (myImgApp->ObjMgrW())->AddObj(str.c_str(), myNObj+1000); 244 } 245 365 366 NObjDirList::iterator itr = myDirs->find(nrep); 367 (*itr).second.nobj++; 368 246 369 cout << "NamedObjMgr::AddObj() Object " << nom << " ( " 247 370 << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl; … … 252 375 void NamedObjMgr::RenameObj(string & nom, string& nomnew) 253 376 { 254 AnyDataObj* obj = GetObj(nom); 255 if (obj == NULL) return; 256 DelObj(nom, false); 257 AddObj(obj, nomnew); 377 string n1,r1,n2,r2; 378 ParseObjectName(nom, r1, n1); 379 int did = ParseObjectName(nomnew, r2, n2); 380 if (did == 0) { 381 cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl; 382 return; 383 } 384 nom = '/' + r1 + '/' + n1; 385 nomnew = '/' + r2 + '/' + n2; 386 NObjList::iterator it1 = myObjs->find(nom); 387 if (it1 == myObjs->end()) { 388 cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl; 389 return; 390 } 391 NObjList::iterator it2 = myObjs->find(nomnew); 392 if (it2 != myObjs->end()) { 393 cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl; 394 return; 395 } 396 397 nobj_item no = (*it1).second; 398 no.dirid = did; 399 myObjs->erase(it1); 400 NObjDirList::iterator itr = myDirs->find(r1); 401 (*itr).second.nobj--; 402 (*myObjs)[nomnew] = no; 403 itr = myDirs->find(r2); 404 (*itr).second.nobj++; 405 cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl; 258 406 return; 259 407 } … … 262 410 void NamedObjMgr::DelObj(string & nom, bool fgd) 263 411 { 412 string n1,r1; 413 ParseObjectName(nom, r1, n1); 414 nom = '/' + r1 + '/' + n1; 264 415 NObjList::iterator it = myObjs->find(nom); 265 416 if (it == myObjs->end()) return; … … 269 420 for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++) 270 421 myImgApp->DelWRsId((*ii)); 271 (myImgApp->ObjMgrW())->DelObj((*it).second.num+1000);272 422 } 273 423 delete (*it).second.obja; // destruction de l'adaptateur 274 424 if (fgd) delete (*it).second.obj; 425 275 426 myObjs->erase(it); 427 NObjDirList::iterator itr = myDirs->find(r1); 428 (*itr).second.nobj--; 429 276 430 if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl; 277 431 else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl; … … 282 436 void NamedObjMgr::DelObj_Id(int oid) 283 437 { 438 NObjList::iterator it; 439 string nom; 440 bool of = false; 441 for(it = myObjs->begin(); it != myObjs->end(); it++) 442 if ( (*it).second.oid == oid ) { 443 of = true; nom = (*it).first; 444 break; 445 } 446 if (of) DelObj(nom, true); 284 447 } 285 448 … … 287 450 void NamedObjMgr::DelObjects(string & patt, bool fgd) 288 451 { 452 string n1,r1; 453 ParseObjectName(patt, r1, n1); 454 patt = '/' + r1 + '/' + n1; 289 455 NObjList::iterator it; 290 456 list<string> odel; … … 301 467 AnyDataObj* NamedObjMgr::GetObj(string & nom) 302 468 { 469 string n1,r1; 470 ParseObjectName(nom, r1, n1); 471 nom = '/' + r1 + '/' + n1; 303 472 NObjList::iterator it = myObjs->find(nom); 304 473 if (it == myObjs->end()) return(NULL); … … 309 478 NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom) 310 479 { 480 string n1,r1; 481 ParseObjectName(nom, r1, n1); 482 nom = '/' + r1 + '/' + n1; 311 483 NObjList::iterator it = myObjs->find(nom); 312 484 if (it == myObjs->end()) return(NULL); … … 322 494 char strg[256]; 323 495 324 cout << "NamedObjMgr::ListObjs() NObjs= " << myObjs->size() << "\n" ; 496 string n1,r1; 497 ParseObjectName(patt, r1, n1); 498 patt = '/' + r1 + '/' + n1; 499 cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ; 325 500 NObjList::iterator it; k = 0; 501 string cn; 326 502 for(it = myObjs->begin(); it != myObjs->end(); it++) { 503 cn = (*it).first; 504 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; 327 505 obj = (*it).second.obj; 328 329 506 ctyp = typeid(*obj).name(); 330 507 sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str()); … … 338 515 339 516 /* --Methode-- */ 340 void NamedObjMgr::GetObjList(string & patt, vector<string> &) 341 { 517 void NamedObjMgr::GetObjList(string & patt, vector<string> &lst) 518 { 519 string n1,r1; 520 if (patt.length() < 1) return; 521 bool fgr = (patt[0] == '/') ? true : false; 522 ParseObjectName(patt, r1, n1); 523 patt = '/' + r1 + '/' + n1; 524 NObjList::iterator it; 525 string cn; 526 for(it = myObjs->begin(); it != myObjs->end(); it++) { 527 cn = (*it).first; 528 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; 529 if (fgr) lst.push_back(cn); 530 else { 531 ParseObjectName(cn, r1, n1); 532 lst.push_back(n1); 533 } 534 } 342 535 } 343 536 … … 372 565 if (!ok) return; 373 566 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm); 374 AddObj(obj->DataObj(), nobj );567 AddObj(obj->DataObj(), nobj, true); 375 568 return; 376 569 } … … 416 609 ok = false; 417 610 } ENDTRY; 418 if (ok) AddObj(obj->DataObj(), nom );611 if (ok) AddObj(obj->DataObj(), nom, true); 419 612 } 420 613 … … 475 668 static int key_for_write = 5000; 476 669 /* --Methode-- */ 477 void NamedObjMgr::SaveObj(string & nom, POutPersist& s) 478 { 670 void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath) 671 { 672 if (nom.length() < 1) return; 673 string nob,rep; 674 ParseObjectName(nom, rep, nob); 675 nom = '/' + rep + '/' + nob; 479 676 NObjMgrAdapter* obja=NULL; 677 string nomf = (keeppath) ? nom : nob; 480 678 obja = GetObjAdapter(nom); 481 679 if (obja == NULL) return; 482 680 printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n", 483 681 nom.c_str(), typeid(*(obja->GetDataObj())).name()); 484 obja->SavePPF(s, nom );682 obja->SavePPF(s, nomf); 485 683 return; 684 } 685 686 /* --Methode-- */ 687 void NamedObjMgr::SaveObjects(string & patt, string const& flnm) 688 { 689 string n1,r1; 690 if (patt.length() < 1) return; 691 bool keeppath = (patt[0] == '/') ? true : false; 692 ParseObjectName(patt, r1, n1); 693 patt = '/' + r1 + '/' + n1; 694 695 bool ok = true; 696 POutPersist* pout; 697 TRY{ 698 pout = new POutPersist(flnm); 699 } CATCH(merr) 700 { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n", 701 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY; 702 if (!ok) return; 703 NObjList::iterator it; 704 string cn; 705 for(it = myObjs->begin(); it != myObjs->end(); it++) { 706 cn = (*it).first; 707 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue; 708 SaveObj(cn, (*pout), keeppath); 709 } 710 delete pout; 711 return; 486 712 } 487 713 … … 502 728 for(it = myObjs->begin(); it != myObjs->end(); it++) { 503 729 no = (*it).first; 504 SaveObj(no, (*pout) );730 SaveObj(no, (*pout), true); 505 731 } 506 732 delete pout; … … 651 877 /* --Methode-- */ 652 878 void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz, 653 string& erx, string& ery, string& erz, string dopt )879 string& erx, string& ery, string& erz, string dopt, bool fg3d) 654 880 { 655 881 AnyDataObj* obj=GetObj(nom); … … 673 899 int opt = servnobjm->DecodeDispOption(dopt, fgsr); 674 900 675 if ( nmz.length()>0) { // Display 3D901 if ( fg3d && (nmz.length()>0) ) { // Display 3D 676 902 PINTuple3D* pin = new PINTuple3D(nt, false); 677 903 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str()); … … 684 910 pin->SelectXY(nmx.c_str(), nmy.c_str()); 685 911 pin->SelectErrBar(erx.c_str(), ery.c_str()); 686 string titre = nmy + "%" + nmz; 912 if ( nmz.length()>0 ) pin->SelectWt(nmz.c_str()); 913 string titre = nmy + "%" + nmx; 687 914 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, nom, opt, titre); 688 915 } … … 776 1003 servnobjm->DecodeDispOption(gratt, fg); 777 1004 } 1005 778 1006 /* --Methode-- */ 779 1007 void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr) … … 785 1013 786 1014 /* --Methode-- */ 787 void NamedObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy, 788 string& experrx, string& experry, 789 string& expcut, string dopt) 790 { 791 NObjMgrAdapter* obja=NULL; 792 obja = GetObjAdapter(nom); 793 if (obja == NULL) { 794 cout << "NamedObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl; 795 return; 796 } 797 if (!myImgApp) return; 798 799 // Creation NTuple 800 char* ntn[4] = {"expx","expy","expex","expey",}; 801 NTuple* nt = NULL; 802 bool haserr = false; 803 804 if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); } 805 else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); } 806 807 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, experrx, experry, expcut, nt, NULL, NULL); 808 809 if (nt->NEntry() < 1) { 810 cout << "NamedObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl; 811 delete nt; 812 return; 813 } 814 815 // nt->Show(); 816 // nt->Print(0,10); 817 PINTuple* pin = new PINTuple(nt, true); 818 pin->SelectXY(ntn[0], ntn[1]); 819 if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]); 820 821 bool fgsr = true; 822 dopt = "defline," + dopt; 823 int opt = servnobjm->DecodeDispOption(dopt, fgsr); 824 string titre = nom + ":" + expy + "%" + expx; 825 myImgApp->DispScDrawer( (PIDrawer*)pin, titre, opt); 826 if (fgsr) myImgApp->RestoreGraphicAtt(); 827 return; 828 } 829 830 /* --Methode-- */ 831 void NamedObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy, string& expz, 832 string& expcut, string dopt) 833 { 834 NObjMgrAdapter* obja=NULL; 835 obja = GetObjAdapter(nom); 836 if (obja == NULL) { 837 cout << "NamedObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl; 838 return; 839 } 840 if (!myImgApp) return; 841 842 char* ntn[3] = {"expx","expy","expz"}; 843 NTuple* nt = new NTuple(3,ntn); // Creation NTuple 844 845 string expwt = "1."; 846 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, expwt, expcut, nt, NULL, NULL); 847 848 if (nt->NEntry() < 1) { 849 cout << "NamedObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl; 850 delete nt; 851 return; 852 } 853 nt->Show(); 854 nt->Print(0,10); 855 PINTuple3D* pin = new PINTuple3D(nt, true); 856 pin->SelectXYZ(ntn[0], ntn[1], ntn[2]); 857 bool fgsr = true; 858 dopt = "defline," + dopt; 859 int opt = servnobjm->DecodeDispOption(dopt, fgsr); 860 861 // Pour plot a partir de DispScDrawer 862 // string nomdisp = "_NT3D_"; 863 // myImgApp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt); 864 // Pour plot a partir de Disp3DDrawer 865 string titre = nom + ":" + expy + "%" + expx; 866 myImgApp->Disp3DDrawer(pin, titre, opt); 867 868 if (fgsr) myImgApp->RestoreGraphicAtt(); 869 return; 870 } 871 872 /* --Methode-- */ 873 void NamedObjMgr::ProjectH1(string& nom, string& expx, string& expwt, string& expcut, string& nomh1, string dopt) 874 { 875 NObjMgrAdapter* obja=NULL; 876 obja = GetObjAdapter(nom); 877 if (obja == NULL) { 878 cout << "NamedObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl; 879 return; 880 } 881 if (!myImgApp) return; 882 883 Histo* h1 = NULL; 884 NTuple* nt = NULL; 885 AnyDataObj* oh = NULL; 886 if (nomh1.length() > 0) oh=GetObj(nomh1); 887 else nomh1 = "H1Proj"; 888 if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero(); 1015 void NamedObjMgr::AddWRsId(string & nom, int wrsid) 1016 { 1017 if(wrsid != 0) { 1018 NObjList::iterator it = myObjs->find(nom); 1019 if (it == myObjs->end()) return; 1020 (*it).second.wrsid.push_back(wrsid); 1021 } 1022 return; 1023 } 1024 1025 /* --Methode-- */ 1026 void NamedObjMgr::UpdateObjMgrWindow(int did) 1027 { 1028 if (!myImgApp) return; 1029 (myImgApp->ObjMgrW())->ClearHelpList(); 1030 1031 NObjList::iterator it; 1032 string cn; 1033 for(it = myObjs->begin(); it != myObjs->end(); it++) { 1034 if ((*it).second.dirid != did) continue; 1035 cn = (*it).first.substr(1); 1036 cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ; 1037 (myImgApp->ObjMgrW())->AddObj(cn.c_str()); 1038 } 1039 } 1040 1041 1042 /* Nouvelle-Fonction */ 1043 void RemoveSpacesFromName(string & nom) 1044 { 1045 // on supprime les blancs de debut et de fin 1046 size_t p = nom.find_first_not_of(" "); 1047 if(p>nom.length()) { nom = ""; return; } 1048 nom = nom.substr(p); 1049 p = nom.find(' '); 1050 if(p>nom.length()) p=nom.length(); 1051 nom = nom.substr(0, p); 1052 } 1053 1054 /* Nouvelle-Fonction */ 1055 bool CheckDirName(string & nom) 1056 { 1057 RemoveSpacesFromName(nom); 1058 if (nom.length() < 1) return(false); 1059 if (nom[0] == '/') nom = nom.substr(1) ; 1060 size_t p = nom.find('/'); 1061 if (p < nom.length()) nom = nom.substr(0,p); 1062 if (nom.length() < 1) return(false); 1063 return(true); 1064 } 1065 1066 /* Nouvelle-Fonction */ 1067 int ParseObjectName(string & nom, string & nomrep, string & nomobj) 1068 { 1069 RemoveSpacesFromName(nom); 1070 // Si le nom ne commence pas par un slash, c'est le repertoire courant 1071 if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; } 889 1072 else { 890 char* ntn[2]= {"hxval", "hwt"}; 891 nt = new NTuple(2,ntn); // Creation NTuple 892 } 893 string expz = "0."; 894 servnobjm->Nobj_ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, nt, h1, NULL); 895 896 if ((!h1) && (!nt)) return; 897 if (!h1) { 898 if (nt->NEntry() < 1) { 899 cout << "NamedObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl; 900 delete nt; 901 return; 1073 string xx = nom.substr(1); 1074 size_t p = xx.find('/'); 1075 if (p < xx.length()) { 1076 nomrep = xx.substr(0,p); 1077 nomobj = xx.substr(p+1); 902 1078 } 903 double xmin, xmax; 904 nt->GetMinMax(0, xmin, xmax); 905 h1 = new Histo(xmin, xmax, 100); 906 int k; 907 float* xn; 908 for(k=0; k<nt->NEntry(); k++) { 909 xn = nt->GetVec(k); 910 h1->Add(xn[0], xn[1]); 1079 else { 1080 nomrep = xx; 1081 nomobj = ""; 911 1082 } 912 delete nt; 913 AddObj(h1, nomh1); 914 } 915 916 DisplayObj(nomh1, dopt); 917 return; 918 } 919 920 /* --Methode-- */ 921 void NamedObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt, string& expcut, 922 string& nomh2, string dopt) 923 { 924 NObjMgrAdapter* obja=NULL; 925 obja = GetObjAdapter(nom); 926 if (obja == NULL) { 927 cout << "NamedObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl; 928 return; 929 } 930 if (!myImgApp) return; 931 932 Histo2D* h2 = NULL; 933 NTuple* nt = NULL; 934 AnyDataObj* oh = NULL; 935 if (nomh2.length() > 0) oh=GetObj(nomh2); 936 else nomh2 = "H2Proj"; 937 if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero(); 938 else { 939 char* ntn[3]= {"hxval", "hyval", "hwt"}; 940 nt = new NTuple(3,ntn); // Creation NTuple 941 } 942 string expz = "0."; 943 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, h2); 944 945 if ((!h2) && (!nt)) return; 946 if (!h2) { 947 if (nt->NEntry() < 1) { 948 cout << "NamedObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl; 949 delete nt; 950 return; 951 } 952 double xmin, xmax, ymin, ymax; 953 nt->GetMinMax(0, xmin, xmax); 954 nt->GetMinMax(0, ymin, ymax); 955 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50); 956 int k; 957 float* xn; 958 for(k=0; k<nt->NEntry(); k++) { 959 xn = nt->GetVec(k); 960 h2->Add(xn[0], xn[1], xn[2]); 961 } 962 delete nt; 963 AddObj(h2, nomh2); 964 } 965 966 DisplayObj(nomh2, dopt); 967 return; 968 969 } 970 971 /* --Methode-- cmv 13/10/98 */ 972 void NamedObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt, string& expcut, 973 string& nomprof, string dopt) 974 // Pour remplir un ``GeneralFitData'' a partir de divers objets: 975 //| nom = nom de l'objet a projeter dans un HProf. 976 //| expx = expression X de definition du bin. 977 //| expy = expression Y a additionner dans le bin. 978 //| expwt = expression W du poids a additionner. 979 //| expcut = expression du test de selection. 980 //| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas 981 //| les limites Xmin,Xmax sont calculees automatiquement. 982 //| sinon ce sont celles de l'objet preexistant. 983 //| opt = options generales pour le display. 984 { 985 NObjMgrAdapter* obja=NULL; 986 obja = GetObjAdapter(nom); 987 if (obja == NULL) { 988 cout << "NamedObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl; 989 return; 990 } 991 if (!myImgApp) return; 992 993 HProf* hprof = NULL; 994 NTuple* nt = NULL; 995 AnyDataObj* oh = NULL; 996 if (nomprof.length() > 0) oh=GetObj(nomprof); 997 else nomprof = "ProfProj"; 998 if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh; 999 else { 1000 char* ntn[3]= {"hxval", "hyval", "hwt"}; 1001 nt = new NTuple(3,ntn); // Creation NTuple 1002 } 1003 string expz = "0."; 1004 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, NULL, hprof); 1005 1006 if((!hprof) && (!nt)) return; 1007 if(!hprof) { 1008 if (nt->NEntry() < 1) { 1009 cout << "NamedObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl; 1010 delete nt; 1011 return; 1012 } 1013 double xmin, xmax; 1014 nt->GetMinMax(0, xmin, xmax); 1015 hprof = new HProf(xmin, xmax, 100); 1016 int k; 1017 float* xn; 1018 for(k=0; k<nt->NEntry(); k++) { 1019 xn = nt->GetVec(k); 1020 hprof->Add(xn[0], xn[1], xn[2]); 1021 } 1022 delete nt; 1023 AddObj(hprof, nomprof); 1024 } 1025 hprof->UpdateHisto(); 1026 1027 DisplayObj(nomprof, dopt); 1028 return; 1029 } 1030 1031 /* --Methode-- */ 1032 void NamedObjMgr::FillVect(string& nom, string& expx, string& expcut, string& nomvec, string dopt) 1033 { 1034 NObjMgrAdapter* obja=NULL; 1035 obja = GetObjAdapter(nom); 1036 if (obja == NULL) { 1037 cout << "NamedObjMgr::FillVect() Error , Pas d'objet de nom " << nom << endl; 1038 return; 1039 } 1040 if (!myImgApp) return; 1041 1042 NTuple* nt = NULL; 1043 if (nomvec.length() < 1) nomvec = "VecFill"; 1044 1045 char* ntn[2]= {"vecval", "vecwt"}; 1046 nt = new NTuple(1,ntn); // Creation NTuple 1047 1048 string expwt = "1."; 1049 string expz = "0."; 1050 servnobjm->Nobj_ComputeExpressions(obja, expx, expz, expz, expwt, expcut, nt, NULL, NULL); 1051 1052 if (!nt) return; 1053 if (nt->NEntry() < 1) { 1054 cout << "NamedObjMgr::FillVect() Warning Zero points satisfy cut !" << endl; 1055 delete nt; 1056 return; 1057 } 1058 1059 Vector* vec = new Vector(nt->NEntry()); 1060 int k; 1061 float* xn; 1062 for(k=0; k<nt->NEntry(); k++) { 1063 xn = nt->GetVec(k); 1064 (*vec)(k) = xn[0]; 1065 } 1066 delete nt; 1067 AddObj(vec, nomvec); 1068 DisplayObj(nomvec, dopt); 1069 return; 1070 } 1071 1072 /* --Methode-- */ 1073 void NamedObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz, string& expt, 1074 string& expcut, string& nomnt) 1075 { 1076 NObjMgrAdapter* obja=NULL; 1077 obja = GetObjAdapter(nom); 1078 if (obja == NULL) { 1079 cout << "NamedObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl; 1080 return; 1081 } 1082 if (!myImgApp) return; 1083 1084 bool fgnnt = false; 1085 NTuple* nt = NULL; 1086 AnyDataObj* oh = NULL; 1087 if (nomnt.length() > 0) oh=GetObj(nomnt); 1088 else nomnt = "NTFill"; 1089 if ( (oh != NULL) && (typeid(*oh) == typeid(HProf)) ) { 1090 nt = (NTuple*)oh; 1091 if (nt->NVar() > 10) { 1092 cout << "NamedObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl; 1093 nt = NULL; 1094 } 1095 } 1096 if (nt == NULL) { 1097 char* ntn[4]= {"x", "y","z","t"}; 1098 nt = new NTuple(4,ntn); // Creation NTuple 1099 fgnnt = true; 1100 } 1101 1102 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, expt, expcut, nt, NULL, NULL); 1103 1104 if (fgnnt) AddObj(nt, nomnt); 1105 return; 1106 1107 } 1108 1109 /* --Methode-- cmv 13/10/98 */ 1110 void NamedObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz, 1111 string& experr, string& expcut, string& nomgfd) 1112 // Pour remplir un ``GeneralFitData'' a partir de divers objets: 1113 //| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) . 1114 //| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData 1115 //| expx = expression X du GeneralFitData (1er abscisse) 1116 //| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y)) 1117 //| expz = expression Z du GeneralFitData (valeur de l'ordonnee) 1118 //| experr = expression de l'erreur sur l'ordonnee Z 1119 //| expcut = expression du test de selection 1120 //| nomgfd = nom du GeneralFitData engendre (optionnel) 1121 { 1122 NObjMgrAdapter* obja=NULL; 1123 obja = GetObjAdapter(nom); 1124 if (obja == NULL) { 1125 cout << "NamedObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl; 1126 return; 1127 } 1128 if(!myImgApp) return; 1129 1130 // 2D ou 3D? 1131 int nvar = 2; 1132 if(expy.length()<=0) {nvar = 1; expy = "0.";} 1133 1134 // $CHECK$ - cmv calculait le nombre d'entree ndata 1135 // en fonction de chaque objet - Je l'ai vire Reza 11/05/99 1136 1137 // Creation NTuple Buffer 1138 char* ntn[4]= {"x","y","f","e"}; 1139 NTuple*nt = new NTuple(4,ntn); 1140 1141 // Remplissage NTuple buffer 1142 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, experr, expcut, nt, NULL, NULL); 1143 if(nt->NEntry() < 1) 1144 {cout<<"NamedObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl; 1145 delete nt; return;} 1146 1147 //Remplissage de la structure GeneraFitData 1148 if (nt->NEntry() <= 0) { 1149 cout<<"NamedObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl; 1150 delete nt; 1151 return; 1152 } 1153 1154 GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0); 1155 int k; 1156 float* xn; 1157 for(k=0; k<nt->NEntry(); k++) { 1158 xn = nt->GetVec(k); 1159 gfd->AddData(xn,xn[2],xn[3]); 1160 } 1161 1162 // Menage et table d'objets 1163 delete nt; 1164 AddObj(gfd, nomgfd); 1165 return; 1166 } 1167 1168 1169 ///////////////////// Fit 1D et 2D ////////////////////////// 1170 /* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */ 1171 struct DFOptions { 1172 int okres, okfun; 1173 int polcx,polcy; double xc,yc; 1174 double err_e, err_E; 1175 double stc2; 1176 int lp,lpg; 1177 int i1,i2,j1,j2; 1178 }; 1179 typedef struct DFOptions DFOPTIONS; 1180 static void DecodeFitsOptions(string par,string step,string min,string max,string opt 1181 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O); 1182 void DecodeFitsOptions(string par,string step,string min,string max,string opt 1183 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O) 1184 //| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D) 1185 { 1186 // set des vecteurs et decodage des string correspondantes 1187 int NParMax = 100; 1188 Par.Realloc(NParMax); Step.Realloc(NParMax); 1189 Min.Realloc(NParMax); Max.Realloc(NParMax); 1190 { 1191 Vector* v; string* s; 1192 {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}} 1193 for(int j=0;j<4;j++) { 1194 if(j==0) {v=&Par; s=∥} 1195 else if(j==1) {v=&Step; s=&step;} 1196 else if(j==2) {v=&Min; s=&min;} 1197 else if(j==3) {v=&Max; s=&max;} 1198 if(s->length()>0) *s += ","; 1199 for(int i=0;i<NParMax;i++) { 1200 if(s->length()<=0) break; 1201 sscanf(s->c_str(),"%lf",&(*v)(i)); 1202 size_t p = s->find_first_of(',') + 1; 1203 if(p>=s->length()) *s = ""; else *s = s->substr(p); 1204 } 1205 } 1206 } 1207 1208 // Decodage de options de opt 1209 O.okres = O.okfun = 0; 1210 O.polcx = O.polcy = 0; 1211 O.xc = O.yc = 0.; 1212 O.stc2 = 1.e-3; 1213 O.err_e = O.err_E = -1.; 1214 O.lp = 1; O.lpg = 0; 1215 O.i1 = O.j1 = O.i2 = O.j2 = -1; 1216 1217 if(opt.length()<=0) return; 1218 opt = "," + opt + ","; 1219 1220 if(strstr(opt.c_str(),",r,")) O.okres = 1; // residus 1221 if(strstr(opt.c_str(),",f,")) O.okfun = 1; // fonction fittee 1222 if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc) 1223 O.polcx = 2; // Le centrage est calcule automatiquement 1224 size_t p = opt.find(",x"); 1225 size_t q = opt.find_first_of(',',p+1); 1226 string dum = opt.substr(p,q-p); 1227 if(dum.length()>2) { 1228 sscanf(dum.c_str(),",x%lf",&O.xc); 1229 O.polcx = 1; // Le centrage est fixe par la valeur lue 1230 } 1231 } 1232 if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc) 1233 O.polcy = 2; // Le centrage est calcule automatiquement 1234 size_t p = opt.find(",y"); 1235 size_t q = opt.find_first_of(',',p+1); 1236 string dum = opt.substr(p,q-p); 1237 if(dum.length()>2) { 1238 sscanf(dum.c_str(),",y%lf",&O.yc); 1239 O.polcy = 1; // Le centrage est fixe par la valeur lue 1240 } 1241 } 1242 if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)" 1243 size_t p = opt.find(",E"); 1244 size_t q = opt.find_first_of(',',p+1); 1245 string dum = opt.substr(p,q-p); 1246 if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E); 1247 if(O.err_E<=0.) O.err_E = 1.; 1248 O.err_e=-1.; 1249 } 1250 if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b" 1251 size_t p = opt.find(",e"); 1252 size_t q = opt.find_first_of(',',p+1); 1253 string dum = opt.substr(p,q-p); 1254 if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e); 1255 if(O.err_e<=0.) O.err_e = 1.; 1256 O.err_E=-1.; 1257 } 1258 if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2 1259 size_t p = opt.find(",X"); 1260 size_t q = opt.find_first_of(',',p+1); 1261 string dum = opt.substr(p,q-p); 1262 if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2); 1263 if(O.stc2<=0.) O.stc2 = 1.e-3; 1264 } 1265 if(strstr(opt.c_str(),",l")) { // niveau de print 1266 size_t p = opt.find(",l"); 1267 size_t q = opt.find_first_of(',',p+1); 1268 string dum = opt.substr(p,q-p); 1269 float ab; 1270 if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab); 1271 if(ab<0) ab = 0.; 1272 O.lp = (int) ab; O.lpg = (int) 10.*(ab-O.lp); 1273 } 1274 if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X 1275 size_t p = opt.find(",I"); 1276 size_t q = opt.find_first_of(',',p+1); 1277 string dum = opt.substr(p,q-p); 1278 if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2); 1279 } 1280 if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y 1281 size_t p = opt.find(",J"); 1282 size_t q = opt.find_first_of(',',p+1); 1283 string dum = opt.substr(p,q-p); 1284 if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2); 1285 } 1286 return; 1287 } 1288 1289 /* --Methode-- cmv 13/10/98 */ 1290 void NamedObjMgr:: Fit12D(string& nom, string& func, 1291 string par,string step,string min,string max, 1292 string opt) 1293 //| --------------- Fit d'objets a 1 et 2 dimensions --------------- 1294 //| nom : nom de l'objet qui peut etre: 1295 //| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D) 1296 //| fit-2D: Matrix,Histo2D,Imagexx ou GeneraFitData(2D) 1297 //| func : pnn = fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D 1298 //| : Pnn = fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D 1299 //| : gnn = fit gaussienne (hauteur) + polynome de degre nn 1D 1300 //| : g = fit gaussienne (hauteur) 1D 1301 //| : enn = fit exponentielle + polynome de degre nn 1D 1302 //| : e = fit exponentielle 1D 1303 //| : Gnn = fit gaussienne (volume) + polynome de degre nn 1D 1304 //| : G = fit gaussienne (volume) 1D 1305 //| : = fit gaussienne+fond (volume) 2D 1306 //| : Gi = fit gaussienne+fond integree (volume) 2D 1307 //| : d = fit DL de gaussienne+fond (volume) 2D 1308 //| : di = fit DL de gaussienne+fond integree (volume) 2D 1309 //| : D = fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D 1310 //| : Di = fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D 1311 //| : M = fit Moffat+fond (expos=p6) (volume) 2D 1312 //| : Mi = fit Moffat+fond integree (expos=p6) (volume) 2D 1313 //| par : p1,...,pn valeur d'initialisation des parametres (def=0) 1314 //| step : s1,...,sn valeur des steps de depart (def=1) 1315 //| min : m1,...,mn valeur des minima (def=1) 1316 //| max : M1,...,Mn valeur des maxima (def=-1) (max<=min : pas de limite) 1317 //| opt : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b" 1318 //| f = generation d'un Objet identique contenant la fonction fittee 1319 //| r = generation d'un Objet identique contenant les residus 1320 //| Xaa.b = aa.b valeur du DXi2 d'arret (def=1.e-3) 1321 //| la.b = niveau "a.b" de print: a=niveau de print Fit1/2D 1322 //| b=niveau de debug GeneralFit 1323 //| Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2] 1324 //|2D Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2] 1325 //| - L'erreur est celle associee a l'objet si existe, 1 sinon sauf si 1326 //| E = erreur prise comme la racine de la valeur a fitter 1327 //| Eaa.b = erreur prise aa.b*sqrt(val) 1328 //| e = erreur prise egale a 1 pour toutes les valeurs 1329 //| eaa.b = erreur prise egale a aa.b 1330 //| xaa.b = demande de centrage: on fit x-aa.b au lieu de x) 1331 //| x = demande de centrage: on fit x-xc au lieu de x 1332 //| avec xc=abscisse du milieu de l'histogramme 1333 //| Actif pour: exp+poly 1D, poly 1D 1334 //| gauss+poly 1D (mais xc est le centre de la gaussienne) 1335 //|2D yaa.b et y = idem "xaa.b et x" mais pour y 1336 { 1337 AnyDataObj* obj=GetObj(nom); 1338 if (obj == NULL) { 1339 cout<<"NamedObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl; 1340 return; 1341 } 1342 if (!myImgApp) return; 1343 if(func.length()<=0) 1344 {cout<<"NamedObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl; 1345 return;} 1346 string ctyp = typeid(*obj).name(); 1347 1348 int ndim = 0, nbinx=0, nbiny=0, ndata = 0; 1349 Vector* v = NULL; Histo* h = NULL; 1350 Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL; 1351 GeneralFitData* g = NULL; 1352 1353 // 1D 1354 if (typeid(*obj) == typeid(Vector)) { 1355 ndim = 1; 1356 v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1; 1357 } 1358 else if ( (typeid(*obj) == typeid(HProf)) || (typeid(*obj) == typeid(Histo)) ) { 1359 ndim = 1; 1360 h = (Histo*) obj; nbinx = h->NBins(); nbiny = 1; 1361 } 1362 else if (typeid(*obj) == typeid(Matrix)) { 1363 ndim = 2; 1364 m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows(); 1365 } 1366 else if (typeid(*obj) == typeid(Histo2D)) { 1367 ndim = 2; 1368 h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY(); 1369 } 1370 else if (typeid(*obj) == typeid(GeneralFitData)) { 1371 g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1; 1372 if( g->NVar()==1) ndim = 1; 1373 else if(g->NVar()==2) ndim = 2; 1374 else { 1375 cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: " 1376 <<((GeneralFitData*) obj)->NVar()<<endl; return; } 1377 } 1378 else if (dynamic_cast<RzImage*>(obj)) { 1379 ndim = 2; 1380 im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize(); 1381 } 1382 else { 1383 cout<<"NamedObjMgr::Fit12D() Error , Objet n'est pas un " 1384 <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl; 1385 return; 1386 } 1387 1388 ndata = nbinx*nbiny; 1389 if(ndata<=0) 1390 {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;} 1391 1392 // Decodage des options et des parametres, mise en forme 1393 Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O; 1394 DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O); 1395 O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1; 1396 O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2; 1397 if(ndim>=2) { 1398 O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1; 1399 O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2; 1400 } else O.j2 = O.j1 = 0; 1401 if(O.polcx==2) { 1402 if(v||m) O.xc = (O.i2-O.i1+1)/2.; 1403 else if(h) O.xc = (h->XMin()+h->XMax())/2.; 1404 else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.; 1405 else if(g) {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;} 1406 else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;} 1407 } 1408 if(O.polcy==2 && ndim>=2) { 1409 if(m) O.yc = (O.j2-O.j1+1)/2.; 1410 if(h2) O.yc = (h2->YMin()+h2->YMax())/2.; 1411 if(g) {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;} 1412 if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;} 1413 } 1414 if(O.lp>0) 1415 cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":" 1416 <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl 1417 <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y" 1418 <<" TypE="<<O.err_e<<","<<O.err_E 1419 <<" StpX2="<<O.stc2 1420 <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl; 1421 1422 /////////////////////////////////// 1423 // Remplissage de GeneralFitData // 1424 /////////////////////////////////// 1425 GeneralFitData mydata(ndim,ndata,0); 1426 {for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) { 1427 double x,y,f,e; 1428 1429 if(v) 1430 {x= (double) i; f=(*v)(i); e=1.;} 1431 else if(h) 1432 {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;} 1433 else if(m) 1434 {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;} 1435 else if(h2) 1436 {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf; 1437 f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;} 1438 else if(im) 1439 {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize(); 1440 f=im->DValue(i,j); e=1.;} 1441 else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);} 1442 else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);} 1443 else x=y=f=e=0.; 1444 1445 // Gestion des erreurs a utiliser 1446 if(O.err_e>0.) e=O.err_e; 1447 else if(O.err_E>0.) {e=(y<-1.||y>1.)?O.err_E*sqrt(fabs(y)):O.err_E;} 1448 1449 // Remplissage de generalfit 1450 if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;} 1451 if(ndim==1) mydata.AddData1(x,f,e); 1452 else if(ndim==2) mydata.AddData2(x,y,f,e); 1453 }} 1454 if(mydata.NData()<=0) 1455 {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl; 1456 return;} 1457 if(O.lpg>1) { 1458 mydata.PrintStatus(); 1459 mydata.PrintData(0); 1460 mydata.PrintData(mydata.NData()-1); 1461 } 1462 1463 //////////////////////////////////////////// 1464 // Identification de la fonction a fitter // 1465 //////////////////////////////////////////// 1466 GeneralFunction* myfunc = NULL; 1467 if(func[0]=='p' && ndim==1) { 1468 // Fit de polynome sans passer par les GeneralFit 1469 int degre = 0; 1470 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1471 cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl; 1472 Poly p1(0); 1473 double c2rl = mydata.PolFit(0,p1,degre); 1474 cout<<"C2r_lineaire = "<<c2rl<<endl; 1475 if(O.lp>0) cout<<p1<<endl; 1476 return; 1477 1478 } else if(func[0]=='P' && ndim==1) { 1479 // Fit de polynome 1480 int degre = 0; 1481 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1482 cout<<"Fit polynome 1D de degre "<<degre<<endl; 1483 Polyn1D* myf = new Polyn1D(degre,O.xc); 1484 myfunc = myf; 1485 1486 } else if(func[0]=='e' && ndim==1) { 1487 // Fit d'exponentielle 1488 int degre =-1; 1489 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1490 cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl; 1491 Exp1DPol* myf; 1492 if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc); 1493 else myf = new Exp1DPol(O.xc); 1494 myfunc = myf; 1495 1496 } else if(func[0]=='g' && ndim==1) { 1497 // Fit de gaussienne en hauteur 1498 int degre =-1; 1499 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1500 cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl; 1501 Gauss1DPol* myf; 1502 if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false)); 1503 else { bool bfg = (O.polcx)?true:false; myf = new Gauss1DPol(bfg); } 1504 myfunc = myf; 1505 1506 } else if(func[0]=='G' && ndim==1) { 1507 // Fit de gaussienne en volume 1508 int degre =-1; 1509 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1510 cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl; 1511 GaussN1DPol* myf; 1512 if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false)); 1513 else { bool bfg = (O.polcx)?true:false; myf = new GaussN1DPol(bfg); } 1514 myfunc = myf; 1515 1516 } else if(func[0]=='p' && ndim==2) { 1517 // Fit de polynome 2D sans passer par les GeneralFit 1518 int degre = 0; 1519 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1520 cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl; 1521 Poly2 p2(0); 1522 double c2rl = mydata.PolFit(0,1,p2,degre); 1523 cout<<"C2r_lineaire = "<<c2rl<<endl; 1524 if(O.lp>0) cout<<p2<<endl; 1525 return; 1526 1527 } else if(func[0]=='P' && ndim==2) { 1528 // Fit de polynome 2D 1529 int degre = 0; 1530 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1531 cout<<"Fit polynome 2D de degre "<<degre<<endl; 1532 Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc); 1533 myfunc = myf; 1534 1535 } else if(func[0]=='G' && ndim==2) { 1536 // Fit de gaussienne+fond en volume 1537 int integ = 0; 1538 if(func.length()>1) if(func[1]=='i') integ=1; 1539 cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl; 1540 if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;} 1541 else {GauRho2D* myf = new GauRho2D; myfunc = myf;} 1542 1543 } else if(func[0]=='d' && ndim==2) { 1544 // Fit de DL gaussienne+fond en volume 1545 int integ = 0; 1546 if(func.length()>1) if(func[1]=='i') integ=1; 1547 cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl; 1548 if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;} 1549 else {GdlRho2D* myf = new GdlRho2D; myfunc = myf;} 1550 1551 } else if(func[0]=='D' && ndim==2) { 1552 // Fit de DL gaussienne+fond avec coeff variable p6 en volume 1553 int integ = 0; 1554 if(func.length()>1) if(func[1]=='i') integ=1; 1555 cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl; 1556 if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;} 1557 else {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;} 1558 1559 } else if(func[0]=='M' && ndim==2) { 1560 // Fit de Moffat+fond (volume) 1561 int integ = 0; 1562 if(func.length()>1) if(func[1]=='i') integ=1; 1563 cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl; 1564 if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;} 1565 else {MofRho2D* myf = new MofRho2D; myfunc = myf;} 1566 1567 } else { 1568 cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl; 1569 return; 1570 } 1571 1572 ///////////////////////// 1573 // Fit avec generalfit // 1574 ///////////////////////// 1575 if(myfunc->NPar()>Par.NElts()) 1576 {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl; 1577 if(myfunc) delete myfunc; return;} 1578 GeneralFit myfit(myfunc); 1579 myfit.SetDebug(O.lpg); 1580 myfit.SetData(&mydata); 1581 myfit.SetStopChi2(O.stc2); 1582 {for(int i=0;i<myfunc->NPar();i++) { 1583 char str[10]; 1584 sprintf(str,"P%d",i); 1585 myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i)); 1586 }} 1587 if(O.lp>1) myfit.PrintFit(); 1588 double c2r = (double) myfit.Fit(); 1589 if(O.lp>0) myfit.PrintFit(); 1590 if(c2r>0.) { 1591 c2r = myfit.GetChi2Red(); 1592 cout<<"C2r_Reduit = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl; 1593 Vector ParFit(myfunc->NPar()); 1594 for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i); 1595 } else { 1596 cout<<"echec Fit, rc = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl; 1597 } 1598 1599 // Mise a disposition des resultats 1600 if(c2r>=0. && myfunc && (O.okres>0||O.okfun>0)) { 1601 string nomres = nom + "res"; 1602 string nomfun = nom + "fun"; 1603 if(v) { 1604 if(O.okres) {Vector* ob = v->FitResidus(myfit); if(ob) AddObj(ob,nomres);} 1605 if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) AddObj(ob,nomfun);} 1606 } else if(h) { 1607 if(O.okres) {Histo* ob = h->FitResidus(myfit); if(ob) AddObj(ob,nomres);} 1608 if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) AddObj(ob,nomfun);} 1609 } else if(m) { 1610 if(O.okres) {Matrix* ob = m->FitResidus(myfit); if(ob) AddObj(ob,nomres);} 1611 if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) AddObj(ob,nomfun);} 1612 } else if(h2) { 1613 if(O.okres) {Histo2D* ob = h2->FitResidus(myfit); if(ob) AddObj(ob,nomres);} 1614 if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) AddObj(ob,nomfun);} 1615 } else if(im) { 1616 if(O.okres) {RzImage* ob = im->FitResidus(myfit); if(ob) AddObj(ob,nomres);} 1617 if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) AddObj(ob,nomfun);} 1618 } else if(g) { 1619 if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit); if(ob) AddObj(ob,nomres);} 1620 if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) AddObj(ob,nomfun);} 1621 } 1622 } 1623 1624 // Nettoyage 1625 if(myfunc) delete myfunc; 1626 return; 1627 } 1628 1083 } 1084 int rc = 0; 1085 NObjDirList::iterator it = myDirs->find(nomrep); 1086 if (it != myDirs->end()) rc = (*it).second.id; 1087 return(rc); 1088 } 1089 -
trunk/SophyaPI/PIext/nobjmgr.h
r331 r333 32 32 33 33 // Gestion des repertoires 34 virtual void CreateDir(string const& dirname); 35 virtual void DeleteDir(string const& dirname); 36 virtual void SetCurrentDir(string const& dirname); 34 virtual void CreateDir(string & dirname); 35 virtual void DeleteDir(string & dirname); 36 virtual void SetCurrentDir(string & dirname); 37 virtual void GetCurrentDir(string & dirname); 38 virtual void ListDirs(string & patt); 39 virtual void GetDirList(string & patt, vector<string>& ); 37 40 virtual void CleanTmpDir(); 38 41 virtual void CleanOldDir(); … … 53 56 virtual void ReadAll(string const & nomppf); 54 57 virtual void ReadFits(string const & flnm, string & nobj); 55 virtual void SaveObj(string & nom, POutPersist& s); 58 virtual void SaveObj(string & nom, POutPersist& s, bool keeppath=false); 59 virtual void SaveObjects(string & patt, string const& nomppf); 56 60 virtual void SaveAll(string const& nomppf); 57 61 virtual void SaveFits(string & nom, string const & flnm); … … 65 69 virtual void DisplaySurf3D(string & nom, string dopt=""); 66 70 virtual void DisplayNT(string & nom, string& nmx, string& nmy, string& nmz, 67 string& erx, string& ery, string& erz, string dopt=""); 68 virtual void DisplayGFD(string & nom, string& numvarx, string& numvary, string& err, string dopt=""); 71 string& erx, string& ery, string& erz, 72 string dopt="", bool fg3d=false); 73 virtual void DisplayGFD(string & nom, string& numvarx, string& numvary, 74 string& err, string dopt=""); 69 75 70 76 virtual void SetGraphicAttributes(string gratt=""); 71 77 virtual void SetGraphicWinZone(int nzx, int nzy, bool fcr=false); 72 78 73 74 // Trace d'expression de NTuple, et d'autres objets 75 virtual void DisplayPoints2D(string & nom, string& expx, string& expy, 76 string& experrx, string& experry, 77 string& expcut, string dopt=""); 78 virtual void DisplayPoints3D(string & nom, string& expx, string& expy, string& expz, 79 string& expcut, string dopt=""); 80 // Projection d'expressions dans histogramme (et trace) 81 virtual void ProjectH1(string & nom, string& expx, string& expwt, string& expcut, 82 string& nomh1, string dopt=""); 83 virtual void ProjectH2(string & nom, string& expx, string& expy, string& expwt, 84 string& expcut, string& nomh2, string dopt=""); 85 virtual void ProjectHProf(string & nom, string& expx, string& expy, string& expwt, 86 string& expcut, string& nomprof, string dopt=""); 87 // Projection d'expression dans vecteurs et dans n-tuple 88 virtual void FillVect(string & nom, string& expx, string& expcut, 89 string& nomvec, string dopt=""); 90 virtual void FillNT(string & nom, string& expx, string& expy, string& expz, 91 string& expt, string& expcut, string& nomnt); 92 virtual void FillGFD(string & nom, string& expx, string& expy, string& expz, 93 string& experr, string& expcut, string& nomgfd); 94 95 // Methodes de fit, a rajouter (pour CMV , deux methodes H1 H2 ou 1 seule ??) ... 96 virtual void Fit12D(string & nom, string& func, 97 string par,string step,string min,string max,string opt); 79 // Acces a l'adaptateur 80 virtual NObjMgrAdapter* GetObjAdapter(string & nom); 98 81 99 82 // Acces au PIApplication et a la classe de service … … 101 84 virtual Services2NObjMgr* GetServiceObj(); 102 85 103 protected : 104 virtual NObjMgrAdapter* GetObjAdapter(string & nom); 86 virtual void AddWRsId(string & nom, int wrsid); 87 // Pour utilisation par ObjMgrWind 88 virtual void UpdateObjMgrWindow(int did); 105 89 }; 106 90 -
trunk/SophyaPI/PIext/piacmd.cc
r330 r333 141 141 usage += " set unset listvar listcommands exec shell \n"; 142 142 usage += " > set varname 'string' # To set a variable, $varname \n"; 143 usage += " > setol varname patt # Fills varname with object list \n"; 143 144 usage += " > unset varname # clear variable definition \n"; 145 usage += " > echo string # output string \n"; 144 146 usage += " > listvars # List of variable names and values \n"; 145 147 usage += " > listcommands # List of all known commands \n"; … … 282 284 int PIACmd::Interpret(string& s) 283 285 { 284 286 int rc = 0; 285 287 cmdtok tokens; 286 288 if (s.length() < 1) return(0); … … 334 336 else if (kw == "set") { 335 337 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); } 336 mVars[tokens[0]] = tokens[1]; 338 string xx = ""; 339 for (int kk=0; kk<tokens.size(); kk++) xx += (tokens[kk] + ' '); 340 mVars[tokens[0]] = xx; 341 } 342 else if (kw == "setol") { 343 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: setol varname objnamepattern" << endl; return(0); } 344 vector<string> ol; 345 mObjMgr->GetObjList(tokens[1], ol); 346 string vol = ""; 347 for (int kk=0; kk<ol.size(); kk++) vol += (ol[kk] + ' '); 348 mVars[tokens[0]] = vol; 337 349 } 338 350 else if (kw == "unset") { … … 341 353 if (it != mVars.end()) mVars.erase(it); 342 354 else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl; 355 } 356 else if (kw == "echo") { 357 for (int kk=0; kk<tokens.size(); kk++) cout << tokens[kk] << " " ; 358 cout << endl; 343 359 } 344 360 else if (kw == "listvars") { … … 379 395 } 380 396 // Execution d'une commande enregistree 381 else { 382 CmdExmap::iterator it = cmdexmap.find(kw); 383 if (it == cmdexmap.end()) cout << "No such command : " << kw << " ! " << endl; 397 else rc = ExecuteCommand(kw, tokens); 398 399 if (timing) gltimer->Split(); 400 return(rc); 401 } 402 403 /* --Methode-- */ 404 int PIACmd::ExecuteCommandLine(string& line) 405 { 406 cmdtok tokens; 407 if (line.length() < 1) return(0); 408 409 string toks,kw; 410 size_t p = line.find_first_not_of(" "); 411 line = line.substr(p); 412 p = 0; 413 size_t q = line.find_first_of(" "); 414 size_t l = line.length(); 415 416 if (q < l) 417 { kw = line.substr(p,q-p); toks = line.substr(q, l-q); } 418 else { kw = line.substr(p,l-p); toks = ""; } 419 420 q = 0; 421 while (q < l) { 422 p = toks.find_first_not_of(" ",q+1); // au debut d'un token 423 if (p>=l) break; 424 q = toks.find_first_of(" ",p); // la fin du token; 425 string token = toks.substr(p,q-p); 426 tokens.push_back(token); 427 } 428 429 return(ExecuteCommand(kw, tokens)); 430 } 431 432 /* --Methode-- */ 433 int PIACmd::ExecuteCommand(string& keyw, vector<string>& args) 434 { 435 int rc = -1; 436 CmdExmap::iterator it = cmdexmap.find(keyw); 437 if (it == cmdexmap.end()) cout << "No such command : " << keyw << " ! " << endl; 384 438 else { 385 if ((*it).second.cex) (*it).second.cex->Execute(kw, tokens);386 else cout << "Dont know how to execute " << k w << " ? " << endl;439 if ((*it).second.cex) rc = (*it).second.cex->Execute(keyw, args); 440 else cout << "Dont know how to execute " << keyw << " ? " << endl; 387 441 } 388 } 389 390 if (timing) gltimer->Split(); 391 return(0); 392 } 393 442 return(rc); 443 } 394 444 395 445 /* --Methode-- */ -
trunk/SophyaPI/PIext/piacmd.h
r330 r333 72 72 73 73 virtual int Interpret(string& line); 74 virtual int ExecuteCommandLine(string& line); 75 virtual int ExecuteCommand(string& keyw, vector<string>& args); 74 76 virtual int ExecFile(string& file); 75 77 -
trunk/SophyaPI/PIext/pintup3d.cc
r326 r333 23 23 string name; 24 24 if (mNT == NULL) xK = yK = zK = -1; 25 if (mNT == NULL) xK = yK = -1;26 25 if (px == NULL) xK = -1; 27 26 else { name = px; xK = mNT->ColumnIndex(name); } -
trunk/SophyaPI/PIext/pintuple.cc
r326 r333 27 27 if (py == NULL) yK = -1; 28 28 else { name = py; yK = mNT->ColumnIndex(name); } 29 } 30 31 /* --Methode-- */ 32 void PINTuple::SelectWt(const char* pw, int nbins) 33 { 34 nWbins = (nbins > 0) ? nbins : 10; 35 if (pw == NULL) wK = -1; 36 else { string name = pw; wK = mNT->ColumnIndex(name); } 37 38 if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax); 39 else { wMin = 0.; wMax = 1.; } 29 40 } 30 41 … … 67 78 void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax) 68 79 { 69 double xp,yp,xer,yer ;80 double xp,yp,xer,yer,wp; 70 81 double xl,yl; 71 82 int nok; … … 74 85 if ( (xK < 0) || (yK < 0) ) return; 75 86 if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine); 87 88 // Pour tracer des markers avec taille fonction de Wt (poids) 89 double dw = (wMax-wMin)/nWbins; 90 if (dw < 1.e-19) dw = 1.e19; 91 int msz,sz; 92 93 PIMarker mrk; 94 if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker; 95 else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker; 96 msz = mMSz; 97 if (msz < 1) msz = 1; 98 g->SelMarker(sz, mrk); 76 99 77 100 nok = 0; … … 93 116 if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer); 94 117 } 118 if (wK >= 0) { // Taille de marker en fonction du poids 119 wp = mNT->GetCell(i, wK); 120 sz = (int)((wp-wMin)/dw); 121 if (sz < 0) sz = 0; 122 if (sz > nWbins) sz = nWbins; 123 sz += msz; 124 if (sz < 2) g->SelMarker(sz, PI_DotMarker); 125 else g->SelMarker(sz, mrk); 126 } 95 127 g->DrawMarker(xp, yp); 96 128 } -
trunk/SophyaPI/PIext/pintuple.h
r326 r333 14 14 15 15 void SelectXY(const char* px, const char* py); 16 void SelectWt(const char* pw=NULL, int nbins=10); 16 17 void SelectErrBar(const char* erbx=NULL, const char* erby=NULL); 17 18 … … 22 23 int xK, yK; // Index du nom de variable en X/Y ds le ntuple 23 24 int xebK, yebK; // Index du nom de variable en ErrBarX/Y ds le ntuple 25 int wK; // Index du nom de variable poids 26 double wMin, wMax; // Valeurs de poids min/max 27 int nWbins; // Nombre de bins pour le poids (Wt) 24 28 25 29 }; -
trunk/SophyaPI/PIext/pisiadw.cc
r332 r333 34 34 // On definit la taille a partir de la taille par defaut des composantes 35 35 PIApplicationPrefCompSize(bsx, bsy); 36 spx = bsx/4; spy = bsy/ 3;37 tsx = 5*bsx+6*spx; tsy = 7*bsy+4*spy;36 spx = bsx/4; spy = bsy/4; 37 tsx = 4.0*bsx+3*spx; tsy = 6*bsy+7*spy; 38 38 SetSize(tsx,tsy); 39 objlist = new PIList(this, "objlist", tsx-spx, tsy-4*spy-bsy, spx/2, spy/2); 39 dirlist = new PIOptMenu(this, "dirlist", 2.5*bsx, bsy, spx+0.25*bsx, spy); 40 dirlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 41 objlist = new PIList(this, "objlist", 3*bsx, tsy-3*spy-bsy, spx, 2*spy+bsy); 40 42 objlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 41 objlist->SetBorderWidth(2); 42 43 int py = tsy-2*spy-bsy; 44 int px = spx; 45 mBut[0] = new PIButton(this, "Display", 100, bsx, bsy, px, py); px += (bsx+spx); 46 mBut[1] = new PIButton(this, "Print", 200, bsx, bsy, px, py); px += (bsx+spx); 47 mBut[2] = new PIButton(this, "SavePPF", 300, bsx, bsy, px, py); px += (bsx+spx); 48 mBut[3] = new PIButton(this, "Delete", 400, bsx, bsy, px, py); px += (bsx+spx); 49 mBut[4] = new PIButton(this, "Dismiss", 900, bsx, bsy, px, py); px += (bsx+spx); 43 // objlist->SetBorderWidth(2); 44 45 int py = spy; 46 int px = 2*spx+3*bsx; 47 mBut[0] = new PIButton(this, "SetCurDir", 20, bsx, bsy, px, py); py += (bsy+spy); 48 mBut[1] = new PIButton(this, "Display", 20, bsx, bsy, px, py); py += (bsy+spy); 49 mBut[2] = new PIButton(this, "Print", 30, bsx, bsy, px, py); py += (bsy+spy); 50 mBut[3] = new PIButton(this, "SavePPF", 40, bsx, bsy, px, py); py += (bsy+spy); 51 mBut[4] = new PIButton(this, "Delete", 50, bsx, bsy, px, py); py += (bsy+spy); 52 mBut[5] = new PIButton(this, "Dismiss", 90, bsx, bsy, px, py); py += (bsy+spy); 50 53 51 54 for(i=0; i<5; i++) … … 59 62 { 60 63 int i; 64 delete dirlist; 61 65 delete objlist; 62 for(i=0; i< 5; i++) delete mBut[i];66 for(i=0; i<6; i++) delete mBut[i]; 63 67 } 64 68 … … 67 71 { 68 72 dap->SetBlocked(); 73 string cdir; 74 dap->ObjMgr()->GetCurrentDir(cdir); 75 cdir = '/' + cdir; 76 dirlist->SetValueStr(cdir); 77 dap->ObjMgr()->UpdateObjMgrWindow(dirlist->GetValue()-30000); 69 78 PIWindow::Show(); 70 79 return; … … 77 86 // PIMessage ssg = ModMsg(msg); 78 87 msg = UserMsg(msg); 79 if (msg == 90 0) {88 if (msg == 90) { 80 89 dap->SetReady(); 81 90 this->Hide(); 82 91 return; 83 } 92 } 93 else if (msg >= 30000) { 94 dap->ObjMgr()->UpdateObjMgrWindow(msg-30000); 95 return; 96 } 97 else if (msg == 10) { 98 string cdir = dirlist->GetValueStr(); 99 dap->ObjMgr()->SetCurrentDir(cdir); 100 return; 101 } 84 102 85 103 string nom = ""; 86 if ( (msg == 100) || (msg == 200) || (msg == 300) || (msg == 400) ) {104 if ( (msg == 20) || (msg == 30) || (msg == 40) || (msg == 50) ) { 87 105 string sel = objlist->GetSelectionStr(); 88 106 // size_t p = sel.find_first_not_of(" \t"); … … 91 109 size_t q = sel.find_first_of(" \t"); 92 110 if (q > l) q = l; 93 nom = sel.substr(0, q);94 }111 nom = dirlist->GetValueStr() + '/' + sel.substr(0, q); 112 } 95 113 96 114 NamedObjMgr* om = dap->ObjMgr(); 97 115 if (om == NULL) return; 98 if (nom == "") return;116 if (nom.length() < 1) return; 99 117 100 118 switch (msg) 101 119 { 102 case 100:120 case 20: 103 121 om->DisplayObj(nom); 104 122 break; 105 case 200:123 case 30: 106 124 om->PrintObj(nom); 107 125 break; 108 case 300:109 if (dap->mPpfout) om->SaveObj(nom, *(dap->mPpfout) );110 break; 111 case 400:126 case 40: 127 if (dap->mPpfout) om->SaveObj(nom, *(dap->mPpfout), false); 128 break; 129 case 50: 112 130 om->DelObj(nom); 113 break; 114 115 case 900: 116 dap->SetReady(); 117 Hide(); 131 objlist->DeleteItemMsg(objlist->GetSelection()); 132 // dap->ObjMgr()->UpdateObjMgrWindow(dirlist->GetValue()-30000); 118 133 break; 119 134 … … 218 233 if (ln <= 0) nom = "?"; 219 234 else { strncpy(noms, mPin->TagName(i).c_str(), 31); noms[31] = '\0'; nom = noms; } 220 //sprintf(strg, "%s (T=%s, Key=%d)", nom, dap->ObjMgr()->GetServiceObj()->PClassIdToClassName(cid), key);221 sprintf(strg, "%s (T=%s, Key=%d)", nom, " DataObject ?", key);235 sprintf(strg, "%s (T=%s, Key=%d)", nom, dap->ObjMgr()->GetServiceObj()->PClassIdToClassName(cid), key); 236 // sprintf(strg, "%s (T=%s, Key=%d)", nom, " DataObject ?", key); Attention SANS_EVOLPLANCK 222 237 objlist->AppendItem(strg, 5000+i); 223 238 } -
trunk/SophyaPI/PIext/pisiadw.h
r293 r333 1 // This may look like C code, but it is really -*- C++ -*- 2 // Classe de fenetre pour gestion d'objet et PPF-In 3 // Reza Aout 97 , Juillet,Aout 98, Ete 99 4 // CEA-DAPNIA LAL-IN2P3/CNRS 5 1 6 #ifndef PISIADW_H_SEEN 2 7 #define PISIADW_H_SEEN … … 25 30 virtual void Show(); 26 31 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL); 27 inline void AddObj(const char * objid, PIMessage msg) 28 { objlist->AppendItem(objid, msg); } 29 inline void DelObj(PIMessage msg) 30 { objlist->DeleteItemMsg(msg); } 32 inline void AddDirectory(const char * dir, int did) 33 { dirlist->AppendItem(dir, 30000+did); } 34 inline void DelDirectory(int did) 35 { dirlist->Menu()->DeleteItemMsg(30000+did); } 36 inline void ClearHelpList() 37 { mNitem=0; objlist->DeleteAllItems(); } 38 inline void AddObj(const char * objn) 39 { mNitem++; objlist->AppendItem(objn, 100+mNitem); } 31 40 private: 32 41 PIStdImgApp* dap; 42 PIOptMenu* dirlist; 43 int mNitem; 33 44 PIList* objlist; 34 PIButton * mBut[ 5];45 PIButton * mBut[6]; 35 46 }; 36 47 -
trunk/SophyaPI/PIext/pistdimgapp.cc
r331 r333 149 149 150 150 mObjMgr = new NamedObjMgr; 151 mObjMgr->SetImgApp(this);152 151 mCmd = new PIACmd(mObjMgr, this); 153 152 … … 161 160 mObjmgrw = new ObjMgrWind(this); 162 161 mPpinmgrw = new PPInMgrWind(this); 162 163 // Attention : A faire apres creation de ObjMgrWind !!! 164 mObjMgr->SetImgApp(this); 163 165 164 166 // Gestion des feneteres widgets et drawers -
trunk/SophyaPI/PIext/servnobjm.cc
r331 r333 21 21 #include "pistdimgapp.h" 22 22 23 #include "fct1dfit.h" 24 #include "fct2dfit.h" 25 26 #include "matrix.h" 27 #include "cvector.h" 28 #include "ntuple.h" 29 #include "cimage.h" 30 23 31 #include "histos.h" 24 32 #include "histos2.h" … … 28 36 #include "piscdrawwdg.h" 29 37 #include "pisurfdr.h" 38 39 #include "pintuple.h" 40 #include "pintup3d.h" 41 30 42 #include "pipodrw.h" 31 43 … … 33 45 34 46 /* --Methode-- */ 35 Services2NObjMgr::Services2NObjMgr( PIStdImgApp* app, string& tmpdir)47 Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir) 36 48 { 37 49 TmpDir = tmpdir; 38 50 PDynLinkMgr::SetTmpDir(tmpdir); 39 mImgapp = app; 51 mImgapp = NULL; 52 mOmg = omg; 40 53 dynlink = NULL; 41 54 InitGrAttNames(); … … 71 84 72 85 /* --Methode-- */ 73 void Services2NObjMgr::Nobj_ComputeExpressions(NObjMgrAdapter* obja, string& expx, string& expy, string& expz, 74 string& expwt, string& expcut, NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp) 86 void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt) 87 { 88 FILE *fip; 89 string fname = TmpDir + "func1_pia_dl.c"; 90 string cmd; 91 int rc; 92 93 if (!mImgapp) return; 94 95 cmd = "rm -f " + fname; 96 rc = system(cmd.c_str()); 97 // printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc); 98 99 if ((fip = fopen(fname.c_str(), "w")) == NULL) { 100 string sn = fname; 101 cout << "Services2NObjMgr/PlotFunc_Erreur: Pb. Ouverture " << sn << endl; 102 return; 103 } 104 105 // constitution du fichier a compiler 106 fputs("#include <math.h> \n", fip); 107 fputs("double func1_pia_dl_func(double x) \n{\n", fip); 108 fprintf(fip,"return(%s); \n}\n", expfunc.c_str()); 109 fclose(fip); 110 111 string func = "func1_pia_dl_func"; 112 DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func); 113 if (!f) return; 114 PlotFunc(f, nom, xmin, xmax, np, dopt); 115 CloseDLL(); 116 return; 117 } 118 119 /* --Methode-- */ 120 void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax, 121 double ymin, double ymax, int npx, int npy, string dopt) 122 { 123 FILE *fip; 124 string fname = TmpDir + "func2_pia_dl.c"; 125 string cmd; 126 int rc; 127 128 if (!mImgapp) return; 129 130 cmd = "rm " + fname; 131 rc = system(cmd.c_str()); 132 // printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc); 133 134 if ((fip = fopen(fname.c_str(), "w")) == NULL) { 135 string sn = fname; 136 cout << "Services2NObjMgr/PlotFunc2D_Erreur: Pb. Ouverture " << sn << endl; 137 return; 138 } 139 140 // constitution du fichier a compiler 141 fputs("#include <math.h> \n", fip); 142 fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip); 143 fprintf(fip,"return(%s); \n}\n", expfunc.c_str()); 144 fclose(fip); 145 146 string func = "func2_pia_dl_func"; 147 DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func); 148 if (!f) return; 149 PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt); 150 CloseDLL(); 151 return; 152 } 153 154 /* --Methode-- */ 155 void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom, 156 double xmin, double xmax, int np, string dopt) 157 { 158 DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func); 159 if (!f) return; 160 PlotFunc(f, nom, xmin, xmax, np, dopt); 161 CloseDLL(); 162 return; 163 } 164 165 /* --Methode-- */ 166 void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom, 167 double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt) 168 { 169 DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func); 170 if (!f) return; 171 PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt); 172 CloseDLL(); 173 return; 174 } 175 176 /* --Methode-- */ 177 void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt) 178 { 179 if (!mImgapp) return; 180 181 int k; 182 if (np < 1) np = 1; 183 if (xmax <= xmin) xmax = xmin+1.; 184 Vector* vpy = new Vector(np); 185 186 double xx; 187 double dx = (xmax-xmin)/np; 188 TRY { 189 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); } 190 } CATCH(merr) { 191 fflush(stdout); 192 cout << endl; 193 cerr << endl; 194 string es = PeidaExc(merr); 195 cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es; 196 delete vpy; 197 vpy = NULL; 198 } ENDTRY; 199 200 201 if (vpy) { 202 string titre = (nom.length() < 1) ? "Function f(x)" : nom; 203 P1DArrayAdapter* vya = new POVectorAdapter(vpy, true); 204 vya->DefineXCoordinate(xmin, (xmax-xmin)/np); 205 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ; 206 bool fgsr = true; 207 dopt = "thinline," + dopt; 208 int opt = DecodeDispOption(dopt, fgsr); 209 int rsid = mImgapp->DispScDrawer(dr, titre, opt); 210 if (fgsr) mImgapp->RestoreGraphicAtt(); 211 if (nom.length() > 0) { 212 mOmg->AddObj(vpy, nom); 213 mOmg->AddWRsId(nom, rsid); 214 } 215 } 216 217 return; 218 } 219 220 /* --Methode-- */ 221 void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax, 222 int npx, int npy, string dopt) 223 { 224 if (!mImgapp) return; 225 226 if (npx < 3) npx = 3; 227 if (npy < 3) npy = 3; 228 if (npx > 250) npx = 250; 229 if (npy > 250) npy = 250; 230 if (xmax <= xmin) xmax = xmin+1.; 231 if (ymax <= ymin) ymax = ymin+1.; 232 233 Matrix* mtx = new Matrix(npy, npx); 234 235 int i,j; 236 double xx, yy; 237 double dx = (xmax-xmin)/npx; 238 double dy = (ymax-ymin)/npy; 239 // printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax); 240 TRY { 241 for(j=0; j<npy; j++) { 242 yy = ymin+dy*j; 243 for(i=0; i<npx; i++) { 244 xx = xmin+dx*i; 245 (*mtx)(j, i) = f(xx, yy); 246 } 247 } 248 } CATCH(merr) { 249 fflush(stdout); 250 cout << endl; 251 cerr << endl; 252 string es = PeidaExc(merr); 253 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es; 254 delete mtx; mtx = NULL; 255 } ENDTRY; 256 257 if (mtx) { 258 string titre = (nom.length() < 1) ? "Function f(x,y)" : nom; 259 bool fgsr = true; 260 int opt = DecodeDispOption(dopt, fgsr); 261 P2DArrayAdapter* arr = new POMatrixAdapter(mtx, true); 262 arr->DefineXYCoordinates(xmin, ymin, dx, dy); 263 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true); 264 int rsid = mImgapp->Disp3DDrawer(sdr, titre, opt); 265 if (fgsr) mImgapp->RestoreGraphicAtt(); 266 if (nom.length() > 0) { 267 mOmg->AddObj(mtx, nom); 268 mOmg->AddWRsId(nom, rsid); 269 } 270 } 271 272 return; 273 } 274 275 /* --Methode-- */ 276 void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy, 277 string& experrx, string& experry, 278 string& expcut, string dopt) 279 { 280 NObjMgrAdapter* obja=NULL; 281 obja = mOmg->GetObjAdapter(nom); 282 if (obja == NULL) { 283 cout << "Services2NObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl; 284 return; 285 } 286 if (!mImgapp) return; 287 288 // Creation NTuple 289 char* ntn[4] = {"expx","expy","expex","expey",}; 290 NTuple* nt = NULL; 291 bool haserr = false; 292 293 if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); } 294 else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); } 295 296 ComputeExpressions(obja, expx, expy, experrx, experry, expcut, nt, NULL, NULL); 297 298 if (nt->NEntry() < 1) { 299 cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl; 300 delete nt; 301 return; 302 } 303 304 // nt->Show(); 305 // nt->Print(0,10); 306 PINTuple* pin = new PINTuple(nt, true); 307 pin->SelectXY(ntn[0], ntn[1]); 308 if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]); 309 310 bool fgsr = true; 311 dopt = "defline," + dopt; 312 int opt = DecodeDispOption(dopt, fgsr); 313 string titre = nom + ":" + expy + "%" + expx; 314 mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt); 315 if (fgsr) mImgapp->RestoreGraphicAtt(); 316 return; 317 } 318 319 /* --Methode-- */ 320 void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy, 321 string& expz, string& expcut, string dopt) 322 { 323 NObjMgrAdapter* obja=NULL; 324 obja = mOmg->GetObjAdapter(nom); 325 if (obja == NULL) { 326 cout << "Services2NObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl; 327 return; 328 } 329 if (!mImgapp) return; 330 331 char* ntn[3] = {"expx","expy","expz"}; 332 NTuple* nt = new NTuple(3,ntn); // Creation NTuple 333 334 string expwt = "1."; 335 ComputeExpressions(obja, expx, expy, expz, expwt, expcut, nt, NULL, NULL); 336 337 if (nt->NEntry() < 1) { 338 cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl; 339 delete nt; 340 return; 341 } 342 nt->Show(); 343 nt->Print(0,10); 344 PINTuple3D* pin = new PINTuple3D(nt, true); 345 pin->SelectXYZ(ntn[0], ntn[1], ntn[2]); 346 bool fgsr = true; 347 dopt = "defline," + dopt; 348 int opt = DecodeDispOption(dopt, fgsr); 349 350 // Pour plot a partir de DispScDrawer 351 // string nomdisp = "_NT3D_"; 352 // mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt); 353 // Pour plot a partir de Disp3DDrawer 354 string titre = nom + ":" + expy + "%" + expx; 355 mImgapp->Disp3DDrawer(pin, titre, opt); 356 357 if (fgsr) mImgapp->RestoreGraphicAtt(); 358 return; 359 } 360 361 /* --Methode-- */ 362 void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy, 363 string& expwt, string& expcut, string dopt) 364 { 365 NObjMgrAdapter* obja=NULL; 366 obja = mOmg->GetObjAdapter(nom); 367 if (obja == NULL) { 368 cout << "Services2NObjMgr::DisplayPoints2DW() Error , Pas d'objet de nom " << nom << endl; 369 return; 370 } 371 if (!mImgapp) return; 372 373 char* ntn[3] = {"expx","expy","expw"}; 374 NTuple* nt = new NTuple(3,ntn); // Creation NTuple 375 376 string exp = "1."; 377 ComputeExpressions(obja, expx, expy, expwt, exp, expcut, nt, NULL, NULL); 378 379 if (nt->NEntry() < 1) { 380 cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl; 381 delete nt; 382 return; 383 } 384 385 PINTuple* pin = new PINTuple(nt, true); 386 pin->SelectXY(ntn[0], ntn[1]); 387 pin->SelectWt(ntn[2]); 388 389 bool fgsr = true; 390 int opt = DecodeDispOption(dopt, fgsr); 391 string titre = nom + ":" + expwt + "_" + expy + "%" + expx ; 392 mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt); 393 if (fgsr) mImgapp->RestoreGraphicAtt(); 394 return; 395 } 396 397 /* --Methode-- */ 398 void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt, 399 string& expcut, string& nomh1, string dopt) 400 { 401 NObjMgrAdapter* obja=NULL; 402 obja = mOmg->GetObjAdapter(nom); 403 if (obja == NULL) { 404 cout << "Services2NObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl; 405 return; 406 } 407 if (!mImgapp) return; 408 409 Histo* h1 = NULL; 410 NTuple* nt = NULL; 411 AnyDataObj* oh = NULL; 412 if (nomh1.length() > 0) oh=mOmg->GetObj(nomh1); 413 else nomh1 = "/tmp/projh1d"; 414 if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero(); 415 else { 416 char* ntn[2]= {"hxval", "hwt"}; 417 nt = new NTuple(2,ntn); // Creation NTuple 418 } 419 string expz = "0."; 420 ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, nt, h1, NULL); 421 422 if ((!h1) && (!nt)) return; 423 if (!h1) { 424 if (nt->NEntry() < 1) { 425 cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl; 426 delete nt; 427 return; 428 } 429 double xmin, xmax; 430 nt->GetMinMax(0, xmin, xmax); 431 h1 = new Histo(xmin, xmax, 100); 432 int k; 433 float* xn; 434 for(k=0; k<nt->NEntry(); k++) { 435 xn = nt->GetVec(k); 436 h1->Add(xn[0], xn[1]); 437 } 438 delete nt; 439 mOmg->AddObj(h1, nomh1); 440 } 441 442 mOmg->DisplayObj(nomh1, dopt); 443 return; 444 } 445 446 /* --Methode-- */ 447 void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt, 448 string& expcut, string& nomh2, string dopt) 449 { 450 NObjMgrAdapter* obja=NULL; 451 obja = mOmg->GetObjAdapter(nom); 452 if (obja == NULL) { 453 cout << "Services2NObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl; 454 return; 455 } 456 if (!mImgapp) return; 457 458 Histo2D* h2 = NULL; 459 NTuple* nt = NULL; 460 AnyDataObj* oh = NULL; 461 if (nomh2.length() > 0) oh=mOmg->GetObj(nomh2); 462 else nomh2 = "/tmp/projh2d"; 463 if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero(); 464 else { 465 char* ntn[3]= {"hxval", "hyval", "hwt"}; 466 nt = new NTuple(3,ntn); // Creation NTuple 467 } 468 string expz = "0."; 469 ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, h2); 470 471 if ((!h2) && (!nt)) return; 472 if (!h2) { 473 if (nt->NEntry() < 1) { 474 cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl; 475 delete nt; 476 return; 477 } 478 double xmin, xmax, ymin, ymax; 479 nt->GetMinMax(0, xmin, xmax); 480 nt->GetMinMax(0, ymin, ymax); 481 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50); 482 int k; 483 float* xn; 484 for(k=0; k<nt->NEntry(); k++) { 485 xn = nt->GetVec(k); 486 h2->Add(xn[0], xn[1], xn[2]); 487 } 488 delete nt; 489 mOmg->AddObj(h2, nomh2); 490 } 491 492 mOmg->DisplayObj(nomh2, dopt); 493 return; 494 495 } 496 497 /* --Methode-- cmv 13/10/98 */ 498 void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt, 499 string& expcut, string& nomprof, string dopt) 500 // Pour remplir un ``GeneralFitData'' a partir de divers objets: 501 //| nom = nom de l'objet a projeter dans un HProf. 502 //| expx = expression X de definition du bin. 503 //| expy = expression Y a additionner dans le bin. 504 //| expwt = expression W du poids a additionner. 505 //| expcut = expression du test de selection. 506 //| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas 507 //| les limites Xmin,Xmax sont calculees automatiquement. 508 //| sinon ce sont celles de l'objet preexistant. 509 //| opt = options generales pour le display. 510 { 511 NObjMgrAdapter* obja=NULL; 512 obja = mOmg->GetObjAdapter(nom); 513 if (obja == NULL) { 514 cout << "Services2NObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl; 515 return; 516 } 517 if (!mImgapp) return; 518 519 HProf* hprof = NULL; 520 NTuple* nt = NULL; 521 AnyDataObj* oh = NULL; 522 if (nomprof.length() > 0) oh=mOmg->GetObj(nomprof); 523 else nomprof = "/tmp/projprof"; 524 if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh; 525 else { 526 char* ntn[3]= {"hxval", "hyval", "hwt"}; 527 nt = new NTuple(3,ntn); // Creation NTuple 528 } 529 string expz = "0."; 530 ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, NULL, hprof); 531 532 if((!hprof) && (!nt)) return; 533 if(!hprof) { 534 if (nt->NEntry() < 1) { 535 cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl; 536 delete nt; 537 return; 538 } 539 double xmin, xmax; 540 nt->GetMinMax(0, xmin, xmax); 541 hprof = new HProf(xmin, xmax, 100); 542 int k; 543 float* xn; 544 for(k=0; k<nt->NEntry(); k++) { 545 xn = nt->GetVec(k); 546 hprof->Add(xn[0], xn[1], xn[2]); 547 } 548 delete nt; 549 mOmg->AddObj(hprof, nomprof); 550 } 551 hprof->UpdateHisto(); 552 553 mOmg->DisplayObj(nomprof, dopt); 554 return; 555 } 556 557 /* --Methode-- */ 558 void Services2NObjMgr::FillVect(string& nom, string& expx, string& expcut, 559 string& nomvec, string dopt) 560 { 561 NObjMgrAdapter* obja=NULL; 562 obja = mOmg->GetObjAdapter(nom); 563 if (obja == NULL) { 564 cout << "Services2NObjMgr::FillVect() Error , Pas d'objet de nom " << nom << endl; 565 return; 566 } 567 if (!mImgapp) return; 568 569 NTuple* nt = NULL; 570 if (nomvec.length() < 1) nomvec = "/tmp/fillvec"; 571 572 char* ntn[2]= {"vecval", "vecwt"}; 573 nt = new NTuple(1,ntn); // Creation NTuple 574 575 string expwt = "1."; 576 string expz = "0."; 577 ComputeExpressions(obja, expx, expz, expz, expwt, expcut, nt, NULL, NULL); 578 579 if (!nt) return; 580 if (nt->NEntry() < 1) { 581 cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl; 582 delete nt; 583 return; 584 } 585 586 Vector* vec = new Vector(nt->NEntry()); 587 int k; 588 float* xn; 589 for(k=0; k<nt->NEntry(); k++) { 590 xn = nt->GetVec(k); 591 (*vec)(k) = xn[0]; 592 } 593 delete nt; 594 mOmg->AddObj(vec, nomvec); 595 mOmg->DisplayObj(nomvec, dopt); 596 return; 597 } 598 599 /* --Methode-- */ 600 void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz, 601 string& expt, string& expcut, string& nomnt) 602 { 603 NObjMgrAdapter* obja=NULL; 604 obja = mOmg->GetObjAdapter(nom); 605 if (obja == NULL) { 606 cout << "Services2NObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl; 607 return; 608 } 609 if (!mImgapp) return; 610 611 bool fgnnt = false; 612 NTuple* nt = NULL; 613 AnyDataObj* oh = NULL; 614 if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt); 615 else nomnt = "/tmp/fillnt"; 616 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) { 617 nt = (NTuple*)oh; 618 if (nt->NVar() > 10) { 619 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl; 620 nt = NULL; 621 } 622 } 623 if (nt == NULL) { 624 char* ntn[4]= {"x", "y","z","t"}; 625 nt = new NTuple(4,ntn); // Creation NTuple 626 fgnnt = true; 627 } 628 629 ComputeExpressions(obja, expx, expy, expz, expt, expcut, nt, NULL, NULL); 630 631 if (fgnnt) mOmg->AddObj(nt, nomnt); 632 return; 633 634 } 635 636 /* --Methode-- */ 637 void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname, 638 string const & funcname, string & nomnt) 639 { 640 if (!mImgapp) return; 641 642 NObjMgrAdapter* obja=NULL; 643 obja = mOmg->GetObjAdapter(nom); 644 if (obja == NULL) { 645 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl; 646 return; 647 } 648 NTupleInterface* objnt = obja->GetNTupleInterface(); 649 if (objnt == NULL) { 650 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No NTupleInterface !" <<endl; 651 return; 652 } 653 654 NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname); 655 if (!f) { 656 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl; 657 return; 658 } 659 660 bool fgnnt = false; 661 NTuple* nt = NULL; 662 if (nomnt.length() > 0) { 663 AnyDataObj* oh = NULL; 664 oh=mOmg->GetObj(nomnt); 665 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) { 666 nt = (NTuple*)oh; 667 if (nt->NVar() > 10) { 668 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var ds NTuple -> new NTuple" << endl; 669 nt = NULL; 670 } 671 } 672 if (nt == NULL) { 673 char* ntn[4]= {"x", "y","z","t"}; 674 nt = new NTuple(4,ntn); // Creation NTuple 675 fgnnt = true; 676 } 677 } 678 679 double xnt[10]; 680 float fxnt[10]; 681 682 int i,k; 683 for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.; 684 685 686 // $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression 687 // redirige - On redirige la sortie sur le terminal 688 bool red = mImgapp->HasRedirectedStdOutErr(); 689 mImgapp->RedirectStdOutErr(false); 690 691 TRY { 692 double* xn; 693 int kmax = objnt->NbLines(); 694 for(k=0; k<kmax; k++) { 695 xn = objnt->GetLineD(k); 696 if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) { 697 if (nt) { 698 for(i=0; i<4; i++) fxnt[i] = xnt[i]; 699 nt->Fill(fxnt); 700 } 701 } 702 } 703 } 704 CATCH(merr) { 705 fflush(stdout); 706 cout << endl; 707 cerr << endl; 708 string es = PeidaExc(merr); 709 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es; 710 } ENDTRY; 711 712 CloseDLL(); 713 714 // $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole 715 mImgapp->RedirectStdOutErr(red); 716 717 if (fgnnt) mOmg->AddObj(nt, nomnt); 718 return; 719 } 720 721 /* --Methode-- */ 722 void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname, 723 string const & funcname) 724 { 725 NObjMgrAdapter* obja=NULL; 726 obja = mOmg->GetObjAdapter(nom); 727 if (obja == NULL) { 728 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl; 729 return; 730 } 731 NTupleInterface* objnt = obja->GetNTupleInterface(); 732 if (objnt == NULL) { 733 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom 734 << "...) No NTupleInterface !" <<endl; 735 return; 736 } 737 string vardec = objnt->VarList_C("_xnti_"); 738 739 FILE *fip; 740 if ((fip = fopen(fname.c_str(), "w")) == NULL) { 741 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl; 742 return; 743 } 744 // constitution du fichier des decalarations des variables de l'interface NTuple 745 fputs("#include <stdlib.h> \n", fip); 746 fputs("#include <stdio.h> \n", fip); 747 fputs("#include <math.h> \n\n", fip); 748 fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip); 749 fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip); 750 fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n", 751 funcname.c_str()); 752 fprintf(fip," double* _rt_, int _n_, int _nmax_) \n"); 753 fprintf(fip, "{ \n %s \n", vardec.c_str()); 754 fputs(" if (!1) { /* Cut Expression failed */ \n", fip); 755 fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip); 756 fputs(" } \n /* Cut expression satisfied */ \n", fip); 757 fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip); 758 fputs(" return(1); \n} \n", fip); 759 760 fclose(fip); 761 return; 762 } 763 764 765 /* --Methode-- cmv 13/10/98 */ 766 void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz, 767 string& experr, string& expcut, string& nomgfd) 768 // Pour remplir un ``GeneralFitData'' a partir de divers objets: 769 //| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) . 770 //| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData 771 //| expx = expression X du GeneralFitData (1er abscisse) 772 //| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y)) 773 //| expz = expression Z du GeneralFitData (valeur de l'ordonnee) 774 //| experr = expression de l'erreur sur l'ordonnee Z 775 //| expcut = expression du test de selection 776 //| nomgfd = nom du GeneralFitData engendre (optionnel) 777 { 778 NObjMgrAdapter* obja=NULL; 779 obja = mOmg->GetObjAdapter(nom); 780 if (obja == NULL) { 781 cout << "Services2NObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl; 782 return; 783 } 784 if(!mImgapp) return; 785 786 // 2D ou 3D? 787 int nvar = 2; 788 if(expy.length()<=0) {nvar = 1; expy = "0.";} 789 790 // $CHECK$ - cmv calculait le nombre d'entree ndata 791 // en fonction de chaque objet - Je l'ai vire Reza 11/05/99 792 793 // Creation NTuple Buffer 794 char* ntn[4]= {"x","y","f","e"}; 795 NTuple*nt = new NTuple(4,ntn); 796 797 // Remplissage NTuple buffer 798 ComputeExpressions(obja, expx, expy, expz, experr, expcut, nt, NULL, NULL); 799 if(nt->NEntry() < 1) 800 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl; 801 delete nt; return;} 802 803 //Remplissage de la structure GeneraFitData 804 if (nt->NEntry() <= 0) { 805 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl; 806 delete nt; 807 return; 808 } 809 810 GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0); 811 int k; 812 float* xn; 813 for(k=0; k<nt->NEntry(); k++) { 814 xn = nt->GetVec(k); 815 gfd->AddData(xn,xn[2],xn[3]); 816 } 817 818 // Menage et table d'objets 819 delete nt; 820 mOmg->AddObj(gfd, nomgfd); 821 return; 822 } 823 824 825 ///////////////////// Fit 1D et 2D ////////////////////////// 826 /* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */ 827 struct DFOptions { 828 int okres, okfun; 829 int polcx,polcy; double xc,yc; 830 double err_e, err_E; 831 double stc2; 832 int lp,lpg; 833 int i1,i2,j1,j2; 834 }; 835 typedef struct DFOptions DFOPTIONS; 836 static void DecodeFitsOptions(string par,string step,string min,string max,string opt 837 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O); 838 void DecodeFitsOptions(string par,string step,string min,string max,string opt 839 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O) 840 //| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D) 841 { 842 // set des vecteurs et decodage des string correspondantes 843 int NParMax = 100; 844 Par.Realloc(NParMax); Step.Realloc(NParMax); 845 Min.Realloc(NParMax); Max.Realloc(NParMax); 846 { 847 Vector* v=NULL; string* s=NULL; 848 {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}} 849 for(int j=0;j<4;j++) { 850 if(j==0) {v=&Par; s=∥} 851 else if(j==1) {v=&Step; s=&step;} 852 else if(j==2) {v=&Min; s=&min;} 853 else if(j==3) {v=&Max; s=&max;} 854 if(s->length()>0) *s += ","; 855 for(int i=0;i<NParMax;i++) { 856 if(s->length()<=0) break; 857 sscanf(s->c_str(),"%lf",&(*v)(i)); 858 size_t p = s->find_first_of(',') + 1; 859 if(p>=s->length()) *s = ""; else *s = s->substr(p); 860 } 861 } 862 } 863 864 // Decodage de options de opt 865 O.okres = O.okfun = 0; 866 O.polcx = O.polcy = 0; 867 O.xc = O.yc = 0.; 868 O.stc2 = 1.e-3; 869 O.err_e = O.err_E = -1.; 870 O.lp = 1; O.lpg = 0; 871 O.i1 = O.j1 = O.i2 = O.j2 = -1; 872 873 if(opt.length()<=0) return; 874 opt = "," + opt + ","; 875 876 if(strstr(opt.c_str(),",r,")) O.okres = 1; // residus 877 if(strstr(opt.c_str(),",f,")) O.okfun = 1; // fonction fittee 878 if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc) 879 O.polcx = 2; // Le centrage est calcule automatiquement 880 size_t p = opt.find(",x"); 881 size_t q = opt.find_first_of(',',p+1); 882 string dum = opt.substr(p,q-p); 883 if(dum.length()>2) { 884 sscanf(dum.c_str(),",x%lf",&O.xc); 885 O.polcx = 1; // Le centrage est fixe par la valeur lue 886 } 887 } 888 if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc) 889 O.polcy = 2; // Le centrage est calcule automatiquement 890 size_t p = opt.find(",y"); 891 size_t q = opt.find_first_of(',',p+1); 892 string dum = opt.substr(p,q-p); 893 if(dum.length()>2) { 894 sscanf(dum.c_str(),",y%lf",&O.yc); 895 O.polcy = 1; // Le centrage est fixe par la valeur lue 896 } 897 } 898 if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)" 899 size_t p = opt.find(",E"); 900 size_t q = opt.find_first_of(',',p+1); 901 string dum = opt.substr(p,q-p); 902 if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E); 903 if(O.err_E<=0.) O.err_E = 1.; 904 O.err_e=-1.; 905 } 906 if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b" 907 size_t p = opt.find(",e"); 908 size_t q = opt.find_first_of(',',p+1); 909 string dum = opt.substr(p,q-p); 910 if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e); 911 if(O.err_e<=0.) O.err_e = 1.; 912 O.err_E=-1.; 913 } 914 if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2 915 size_t p = opt.find(",X"); 916 size_t q = opt.find_first_of(',',p+1); 917 string dum = opt.substr(p,q-p); 918 if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2); 919 if(O.stc2<=0.) O.stc2 = 1.e-3; 920 } 921 if(strstr(opt.c_str(),",l")) { // niveau de print 922 size_t p = opt.find(",l"); 923 size_t q = opt.find_first_of(',',p+1); 924 string dum = opt.substr(p,q-p); 925 float ab; 926 if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab); 927 if(ab<0) ab = 0.; 928 O.lp = (int) ab; O.lpg = (int) 10.*(ab-O.lp); 929 } 930 if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X 931 size_t p = opt.find(",I"); 932 size_t q = opt.find_first_of(',',p+1); 933 string dum = opt.substr(p,q-p); 934 if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2); 935 } 936 if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y 937 size_t p = opt.find(",J"); 938 size_t q = opt.find_first_of(',',p+1); 939 string dum = opt.substr(p,q-p); 940 if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2); 941 } 942 return; 943 } 944 945 /* --Methode-- cmv 13/10/98 */ 946 void Services2NObjMgr::Fit12D(string& nom, string& func, 947 string par,string step,string min,string max, 948 string opt) 949 //| --------------- Fit d'objets a 1 et 2 dimensions --------------- 950 //| nom : nom de l'objet qui peut etre: 951 //| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D) 952 //| fit-2D: Matrix,Histo2D,Imagexx ou GeneraFitData(2D) 953 //| func : pnn = fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D 954 //| : Pnn = fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D 955 //| : gnn = fit gaussienne (hauteur) + polynome de degre nn 1D 956 //| : g = fit gaussienne (hauteur) 1D 957 //| : enn = fit exponentielle + polynome de degre nn 1D 958 //| : e = fit exponentielle 1D 959 //| : Gnn = fit gaussienne (volume) + polynome de degre nn 1D 960 //| : G = fit gaussienne (volume) 1D 961 //| : = fit gaussienne+fond (volume) 2D 962 //| : Gi = fit gaussienne+fond integree (volume) 2D 963 //| : d = fit DL de gaussienne+fond (volume) 2D 964 //| : di = fit DL de gaussienne+fond integree (volume) 2D 965 //| : D = fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D 966 //| : Di = fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D 967 //| : M = fit Moffat+fond (expos=p6) (volume) 2D 968 //| : Mi = fit Moffat+fond integree (expos=p6) (volume) 2D 969 //| par : p1,...,pn valeur d'initialisation des parametres (def=0) 970 //| step : s1,...,sn valeur des steps de depart (def=1) 971 //| min : m1,...,mn valeur des minima (def=1) 972 //| max : M1,...,Mn valeur des maxima (def=-1) (max<=min : pas de limite) 973 //| opt : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b" 974 //| f = generation d'un Objet identique contenant la fonction fittee 975 //| r = generation d'un Objet identique contenant les residus 976 //| Xaa.b = aa.b valeur du DXi2 d'arret (def=1.e-3) 977 //| la.b = niveau "a.b" de print: a=niveau de print Fit1/2D 978 //| b=niveau de debug GeneralFit 979 //| Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2] 980 //|2D Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2] 981 //| - L'erreur est celle associee a l'objet si existe, 1 sinon sauf si 982 //| E = erreur prise comme la racine de la valeur a fitter 983 //| Eaa.b = erreur prise aa.b*sqrt(val) 984 //| e = erreur prise egale a 1 pour toutes les valeurs 985 //| eaa.b = erreur prise egale a aa.b 986 //| xaa.b = demande de centrage: on fit x-aa.b au lieu de x) 987 //| x = demande de centrage: on fit x-xc au lieu de x 988 //| avec xc=abscisse du milieu de l'histogramme 989 //| Actif pour: exp+poly 1D, poly 1D 990 //| gauss+poly 1D (mais xc est le centre de la gaussienne) 991 //|2D yaa.b et y = idem "xaa.b et x" mais pour y 992 { 993 AnyDataObj* obj=mOmg->GetObj(nom); 994 if (obj == NULL) { 995 cout<<"Services2NObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl; 996 return; 997 } 998 if (!mImgapp) return; 999 if(func.length()<=0) 1000 {cout<<"Services2NObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl; 1001 return;} 1002 string ctyp = typeid(*obj).name(); 1003 1004 int ndim = 0, nbinx=0, nbiny=0, ndata = 0; 1005 Vector* v = NULL; Histo* h = NULL; 1006 Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL; 1007 GeneralFitData* g = NULL; 1008 1009 // 1D 1010 if (typeid(*obj) == typeid(Vector)) { 1011 ndim = 1; 1012 v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1; 1013 } 1014 else if ( (typeid(*obj) == typeid(HProf)) || (typeid(*obj) == typeid(Histo)) ) { 1015 ndim = 1; 1016 h = (Histo*) obj; nbinx = h->NBins(); nbiny = 1; 1017 } 1018 else if (typeid(*obj) == typeid(Matrix)) { 1019 ndim = 2; 1020 m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows(); 1021 } 1022 else if (typeid(*obj) == typeid(Histo2D)) { 1023 ndim = 2; 1024 h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY(); 1025 } 1026 else if (typeid(*obj) == typeid(GeneralFitData)) { 1027 g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1; 1028 if( g->NVar()==1) ndim = 1; 1029 else if(g->NVar()==2) ndim = 2; 1030 else { 1031 cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: " 1032 <<((GeneralFitData*) obj)->NVar()<<endl; return; } 1033 } 1034 else if (dynamic_cast<RzImage*>(obj)) { 1035 ndim = 2; 1036 im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize(); 1037 } 1038 else { 1039 cout<<"Services2NObjMgr::Fit12D() Error , Objet n'est pas un " 1040 <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl; 1041 return; 1042 } 1043 1044 ndata = nbinx*nbiny; 1045 if(ndata<=0) 1046 {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;} 1047 1048 // Decodage des options et des parametres, mise en forme 1049 Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O; 1050 DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O); 1051 O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1; 1052 O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2; 1053 if(ndim>=2) { 1054 O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1; 1055 O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2; 1056 } else O.j2 = O.j1 = 0; 1057 if(O.polcx==2) { 1058 if(v||m) O.xc = (O.i2-O.i1+1)/2.; 1059 else if(h) O.xc = (h->XMin()+h->XMax())/2.; 1060 else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.; 1061 else if(g) {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;} 1062 else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;} 1063 } 1064 if(O.polcy==2 && ndim>=2) { 1065 if(m) O.yc = (O.j2-O.j1+1)/2.; 1066 if(h2) O.yc = (h2->YMin()+h2->YMax())/2.; 1067 if(g) {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;} 1068 if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;} 1069 } 1070 if(O.lp>0) 1071 cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":" 1072 <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl 1073 <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y" 1074 <<" TypE="<<O.err_e<<","<<O.err_E 1075 <<" StpX2="<<O.stc2 1076 <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl; 1077 1078 /////////////////////////////////// 1079 // Remplissage de GeneralFitData // 1080 /////////////////////////////////// 1081 GeneralFitData mydata(ndim,ndata,0); 1082 {for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) { 1083 double x,y,f,e; 1084 1085 if(v) 1086 {x= (double) i; f=(*v)(i); e=1.;} 1087 else if(h) 1088 {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;} 1089 else if(m) 1090 {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;} 1091 else if(h2) 1092 {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf; 1093 f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;} 1094 else if(im) 1095 {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize(); 1096 f=im->DValue(i,j); e=1.;} 1097 else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);} 1098 else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);} 1099 else x=y=f=e=0.; 1100 1101 // Gestion des erreurs a utiliser 1102 if(O.err_e>0.) e=O.err_e; 1103 else if(O.err_E>0.) {e=(y<-1.||y>1.)?O.err_E*sqrt(fabs(y)):O.err_E;} 1104 1105 // Remplissage de generalfit 1106 if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;} 1107 if(ndim==1) mydata.AddData1(x,f,e); 1108 else if(ndim==2) mydata.AddData2(x,y,f,e); 1109 }} 1110 if(mydata.NData()<=0) 1111 {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl; 1112 return;} 1113 if(O.lpg>1) { 1114 mydata.PrintStatus(); 1115 mydata.PrintData(0); 1116 mydata.PrintData(mydata.NData()-1); 1117 } 1118 1119 //////////////////////////////////////////// 1120 // Identification de la fonction a fitter // 1121 //////////////////////////////////////////// 1122 GeneralFunction* myfunc = NULL; 1123 if(func[0]=='p' && ndim==1) { 1124 // Fit de polynome sans passer par les GeneralFit 1125 int degre = 0; 1126 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1127 cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl; 1128 Poly p1(0); 1129 double c2rl = mydata.PolFit(0,p1,degre); 1130 cout<<"C2r_lineaire = "<<c2rl<<endl; 1131 if(O.lp>0) cout<<p1<<endl; 1132 return; 1133 1134 } else if(func[0]=='P' && ndim==1) { 1135 // Fit de polynome 1136 int degre = 0; 1137 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1138 cout<<"Fit polynome 1D de degre "<<degre<<endl; 1139 Polyn1D* myf = new Polyn1D(degre,O.xc); 1140 myfunc = myf; 1141 1142 } else if(func[0]=='e' && ndim==1) { 1143 // Fit d'exponentielle 1144 int degre =-1; 1145 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1146 cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl; 1147 Exp1DPol* myf; 1148 if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc); 1149 else myf = new Exp1DPol(O.xc); 1150 myfunc = myf; 1151 1152 } else if(func[0]=='g' && ndim==1) { 1153 // Fit de gaussienne en hauteur 1154 int degre =-1; 1155 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1156 cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl; 1157 Gauss1DPol* myf; 1158 if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false)); 1159 else { bool bfg = (O.polcx)?true:false; myf = new Gauss1DPol(bfg); } 1160 myfunc = myf; 1161 1162 } else if(func[0]=='G' && ndim==1) { 1163 // Fit de gaussienne en volume 1164 int degre =-1; 1165 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1166 cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl; 1167 GaussN1DPol* myf; 1168 if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false)); 1169 else { bool bfg = (O.polcx)?true:false; myf = new GaussN1DPol(bfg); } 1170 myfunc = myf; 1171 1172 } else if(func[0]=='p' && ndim==2) { 1173 // Fit de polynome 2D sans passer par les GeneralFit 1174 int degre = 0; 1175 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1176 cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl; 1177 Poly2 p2(0); 1178 double c2rl = mydata.PolFit(0,1,p2,degre); 1179 cout<<"C2r_lineaire = "<<c2rl<<endl; 1180 if(O.lp>0) cout<<p2<<endl; 1181 return; 1182 1183 } else if(func[0]=='P' && ndim==2) { 1184 // Fit de polynome 2D 1185 int degre = 0; 1186 if(func.length()>1) sscanf(func.c_str()+1,"%d",°re); 1187 cout<<"Fit polynome 2D de degre "<<degre<<endl; 1188 Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc); 1189 myfunc = myf; 1190 1191 } else if(func[0]=='G' && ndim==2) { 1192 // Fit de gaussienne+fond en volume 1193 int integ = 0; 1194 if(func.length()>1) if(func[1]=='i') integ=1; 1195 cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl; 1196 if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;} 1197 else {GauRho2D* myf = new GauRho2D; myfunc = myf;} 1198 1199 } else if(func[0]=='d' && ndim==2) { 1200 // Fit de DL gaussienne+fond en volume 1201 int integ = 0; 1202 if(func.length()>1) if(func[1]=='i') integ=1; 1203 cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl; 1204 if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;} 1205 else {GdlRho2D* myf = new GdlRho2D; myfunc = myf;} 1206 1207 } else if(func[0]=='D' && ndim==2) { 1208 // Fit de DL gaussienne+fond avec coeff variable p6 en volume 1209 int integ = 0; 1210 if(func.length()>1) if(func[1]=='i') integ=1; 1211 cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl; 1212 if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;} 1213 else {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;} 1214 1215 } else if(func[0]=='M' && ndim==2) { 1216 // Fit de Moffat+fond (volume) 1217 int integ = 0; 1218 if(func.length()>1) if(func[1]=='i') integ=1; 1219 cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl; 1220 if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;} 1221 else {MofRho2D* myf = new MofRho2D; myfunc = myf;} 1222 1223 } else { 1224 cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl; 1225 return; 1226 } 1227 1228 ///////////////////////// 1229 // Fit avec generalfit // 1230 ///////////////////////// 1231 if(myfunc->NPar()>Par.NElts()) 1232 {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl; 1233 if(myfunc) delete myfunc; return;} 1234 GeneralFit myfit(myfunc); 1235 myfit.SetDebug(O.lpg); 1236 myfit.SetData(&mydata); 1237 myfit.SetStopChi2(O.stc2); 1238 {for(int i=0;i<myfunc->NPar();i++) { 1239 char str[10]; 1240 sprintf(str,"P%d",i); 1241 myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i)); 1242 }} 1243 if(O.lp>1) myfit.PrintFit(); 1244 double c2r = (double) myfit.Fit(); 1245 if(O.lp>0) myfit.PrintFit(); 1246 if(c2r>0.) { 1247 c2r = myfit.GetChi2Red(); 1248 cout<<"C2r_Reduit = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl; 1249 Vector ParFit(myfunc->NPar()); 1250 for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i); 1251 } else { 1252 cout<<"echec Fit, rc = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl; 1253 } 1254 1255 // Mise a disposition des resultats 1256 if(c2r>=0. && myfunc && (O.okres>0||O.okfun>0)) { 1257 string nomres = nom + "res"; 1258 string nomfun = nom + "fun"; 1259 if(v) { 1260 if(O.okres) {Vector* ob = v->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);} 1261 if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);} 1262 } else if(h) { 1263 if(O.okres) {Histo* ob = h->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);} 1264 if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);} 1265 } else if(m) { 1266 if(O.okres) {Matrix* ob = m->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);} 1267 if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);} 1268 } else if(h2) { 1269 if(O.okres) {Histo2D* ob = h2->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);} 1270 if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);} 1271 } else if(im) { 1272 if(O.okres) {RzImage* ob = im->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);} 1273 if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);} 1274 } else if(g) { 1275 if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);} 1276 if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);} 1277 } 1278 } 1279 1280 // Nettoyage 1281 if(myfunc) delete myfunc; 1282 return; 1283 } 1284 1285 1286 /* --Methode-- */ 1287 void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx, 1288 string& expy, string& expz, string& expt, string& expcut, 1289 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp) 75 1290 { 76 1291 if (obja == NULL) return; 77 1292 NTupleInterface* objnt = obja->GetNTupleInterface(); 78 1293 if (objnt == NULL) return; 79 string vardec = objnt->VarList_C("_zz6 1qq_");80 81 PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, exp wt, expcut);1294 string vardec = objnt->VarList_C("_zz6qi_"); 1295 1296 PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut); 82 1297 if (!f) { 83 cerr << " NamedObjMgr_ComputeExpressions() Error Creation PlotExprFunc " << endl;1298 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl; 84 1299 return; 85 1300 } … … 88 1303 float fxnt[10]; 89 1304 90 int i, j,k;1305 int i,k; 91 1306 for(i=0; i<10; i++) xnt[i] = 0.; 92 1307 … … 111 1326 cerr << endl; 112 1327 string es = PeidaExc(merr); 113 cerr << " NamedObjMgr_ComputeExpressions() Exception :" << merr << es;1328 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es; 114 1329 } ENDTRY; 115 1330 … … 122 1337 123 1338 /* --Methode-- */ 124 PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy, string& expz,125 string& exp wt, string& cut)1339 PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy, 1340 string& expz, string& expt, string& cut) 126 1341 { 127 1342 FILE *fip; … … 136 1351 if ((fip = fopen(fname.c_str(), "w")) == NULL) { 137 1352 string sn = fname; 138 cout << " NamedObjMgr/LinkExprFunc_Erreur: Pb. Ouverture " << sn << endl;1353 cout << "Services2NObjMgr/LinkExprFunc_Erreur: Pb. Ouverture " << sn << endl; 139 1354 return(NULL); 140 1355 } 141 1356 142 1357 // constitution du fichier a compiler 1358 fputs("#include <stdlib.h> \n", fip); 143 1359 fputs("#include <math.h> \n", fip); 144 fputs("int expf_pia_dl_func(double* _zz6 1qq_, double* _rx_61qq_, double* _ry_61qq_, double* _rz_61qq_, double* _wt_61qq_) \n{\n", fip);1360 fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip); 145 1361 fprintf(fip,"%s \n", vardec.c_str()); 146 fprintf(fip, "if (!(%s)) { *_rx_6 1qq_ = *_ry_61qq_ = *_rz_61qq_ = *_wt_61qq_ = 0.; return(0); } \n", cut.c_str());147 fprintf(fip, "*_rx_6 1qq_ = %s ; \n", expx.c_str());148 fprintf(fip, "*_ry_6 1qq_ = %s ; \n", expy.c_str());149 fprintf(fip, "*_rz_6 1qq_ = %s ; \n", expz.c_str());150 fprintf(fip, "*_ wt_61qq_ = %s ; \n", expwt.c_str());1362 fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str()); 1363 fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str()); 1364 fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str()); 1365 fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str()); 1366 fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str()); 151 1367 fputs("return(1); \n} \n", fip); 152 1368 fclose(fip); … … 163 1379 dynlink = PDynLinkMgr::BuildFromCFile(fname); 164 1380 if (dynlink == NULL) { 165 cerr << " NamedObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;1381 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl; 166 1382 return(NULL); 167 1383 } … … 170 1386 if (retfunc == NULL) { 171 1387 string sn = funcname; 172 cerr << " NamedObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;1388 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl; 173 1389 CloseDLL(); 174 1390 return(NULL); … … 183 1399 } 184 1400 185 /* --Methode-- */186 void Services2NObjMgr::PlotFunc(string const & expfunc, float xmin, float xmax, int np, string dopt)187 {188 FILE *fip;189 string fname = TmpDir + "func1_pia_dl.c";190 string cmd;191 int rc;192 193 if (!mImgapp) return;194 195 cmd = "rm -f " + fname;196 rc = system(cmd.c_str());197 // printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);198 199 if ((fip = fopen(fname.c_str(), "w")) == NULL) {200 string sn = fname;201 cout << "NamedObjMgr/PlotFunc_Erreur: Pb. Ouverture " << sn << endl;202 return;203 }204 205 // constitution du fichier a compiler206 fputs("#include <math.h> \n", fip);207 fputs("double func1_pia_dl_func(double x) \n{\n", fip);208 fprintf(fip,"return(%s); \n}\n", expfunc.c_str());209 fclose(fip);210 211 string func = "func1_pia_dl_func";212 DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);213 if (!f) return;214 PlotFunc(f, xmin, xmax, np, dopt);215 CloseDLL();216 return;217 }218 219 /* --Methode-- */220 void Services2NObjMgr::PlotFunc2D(string const & expfunc, float xmin, float xmax, float ymin, float ymax,221 int npx, int npy, string dopt)222 {223 FILE *fip;224 string fname = TmpDir + "func2_pia_dl.c";225 string cmd;226 int rc;227 228 if (!mImgapp) return;229 230 cmd = "rm " + fname;231 rc = system(cmd.c_str());232 // printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);233 234 if ((fip = fopen(fname.c_str(), "w")) == NULL) {235 string sn = fname;236 cout << "NamedObjMgr/PlotFunc2D_Erreur: Pb. Ouverture " << sn << endl;237 return;238 }239 240 // constitution du fichier a compiler241 fputs("#include <math.h> \n", fip);242 fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);243 fprintf(fip,"return(%s); \n}\n", expfunc.c_str());244 fclose(fip);245 246 string func = "func2_pia_dl_func";247 DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);248 if (!f) return;249 PlotFunc2D(f, xmin, xmax, ymin, ymax, npx, npy, dopt);250 CloseDLL();251 return;252 }253 254 /* --Methode-- */255 void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, float xmin, float xmax,256 int np, string dopt)257 {258 DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);259 if (!f) return;260 PlotFunc(f, xmin, xmax, np, dopt);261 CloseDLL();262 return;263 }264 265 /* --Methode-- */266 void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, float xmin, float xmax,267 float ymin, float ymax, int npx, int npy, string dopt)268 {269 DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);270 if (!f) return;271 PlotFunc2D(f, xmin, xmax, ymin, ymax, npx, npy, dopt);272 CloseDLL();273 return;274 }275 276 /* --Methode-- */277 void Services2NObjMgr::PlotFunc(DlFunctionOfX f, float xmin, float xmax, int np, string dopt)278 {279 if (!mImgapp) return;280 281 int k;282 if (np < 1) np = 1;283 if (xmax <= xmin) xmax = xmin+1.;284 Vector* vpy = new Vector(np);285 286 double xx;287 double dx = (xmax-xmin)/np;288 TRY {289 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }290 } CATCH(merr) {291 fflush(stdout);292 cout << endl;293 cerr << endl;294 string es = PeidaExc(merr);295 cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es;296 delete vpy;297 vpy = NULL;298 } ENDTRY;299 300 301 if (vpy) {302 string nom = "Func";303 P1DArrayAdapter* vya = new POVectorAdapter(vpy, true);304 vya->DefineXCoordinate(xmin, (xmax-xmin)/np);305 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;306 bool fgsr = true;307 dopt = "thinline," + dopt;308 int opt = DecodeDispOption(dopt, fgsr);309 int wrsid = mImgapp->DispScDrawer(dr, nom, opt);310 if (fgsr) mImgapp->RestoreGraphicAtt();311 }312 313 return;314 }315 316 /* --Methode-- */317 void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, float xmin, float xmax, float ymin, float ymax,318 int npx, int npy, string dopt)319 {320 if (!mImgapp) return;321 322 if (npx < 3) npx = 3;323 if (npy < 3) npy = 3;324 if (npx > 250) npx = 250;325 if (npy > 250) npy = 250;326 if (xmax <= xmin) xmax = xmin+1.;327 if (ymax <= ymin) ymax = ymin+1.;328 329 Matrix* mtx = new Matrix(npy, npx);330 331 int i,j;332 double xx, yy;333 double dx = (xmax-xmin)/npx;334 double dy = (ymax-ymin)/npy;335 // printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);336 TRY {337 for(j=0; j<npy; j++) {338 yy = ymin+dy*j;339 for(i=0; i<npx; i++) {340 xx = xmin+dx*i;341 (*mtx)(j, i) = f(xx, yy);342 }343 }344 } CATCH(merr) {345 fflush(stdout);346 cout << endl;347 cerr << endl;348 string es = PeidaExc(merr);349 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es;350 delete mtx; mtx = NULL;351 } ENDTRY;352 353 if (mtx) {354 string nom = "Func2";355 int wrsid = 0;356 bool fgsr = true;357 int opt = DecodeDispOption(dopt, fgsr);358 P2DArrayAdapter* arr = new POMatrixAdapter(mtx, true);359 arr->DefineXYCoordinates(xmin, ymin, dx, dy);360 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);361 wrsid = mImgapp->Disp3DDrawer(sdr, nom, opt);362 if (fgsr) mImgapp->RestoreGraphicAtt();363 }364 365 return;366 }367 1401 368 1402 /* --Methode-- */ … … 663 1697 664 1698 } 1699 1700 1701 // SANS_EVOLPLANCK Attention ! 1702 #include "pclassids.h" 1703 1704 /* --Methode-- */ 1705 char* Services2NObjMgr::PClassIdToClassName(int cid) 1706 { 1707 switch (cid) { 1708 case ClassId_Poly1 : 1709 return("Poly1"); 1710 case ClassId_Poly2 : 1711 return("Poly2"); 1712 case ClassId_Matrix : 1713 return("Matrix"); 1714 case ClassId_Vector : 1715 return("Vector"); 1716 1717 case ClassId_DVList : 1718 return("DVList"); 1719 1720 case ClassId_Histo1D : 1721 return("Histo1D"); 1722 case ClassId_Histo2D : 1723 return("Histo2D"); 1724 case ClassId_HProf : 1725 return("HProf"); 1726 case ClassId_NTuple : 1727 return("NTuple"); 1728 case ClassId_GeneralFitData : 1729 return("GeneralFitData"); 1730 1731 case ClassId_Image : 1732 return("RzImage"); 1733 case ClassId_Image + kuint_1 : 1734 return("ImageU1"); 1735 case ClassId_Image + kint_1 : 1736 return("ImageI1"); 1737 case ClassId_Image + kuint_2 : 1738 return("ImageU2"); 1739 case ClassId_Image + kint_2 : 1740 return("ImageI2"); 1741 case ClassId_Image + kuint_4 : 1742 return("ImageU4"); 1743 case ClassId_Image + kint_4 : 1744 return("ImageI4"); 1745 case ClassId_Image + kr_4 : 1746 return("ImageR4"); 1747 case ClassId_Image + kr_8 : 1748 return("ImageR8"); 1749 1750 case ClassId_ZFidu : 1751 return("ZFidu"); 1752 1753 case ClassId_StarList : 1754 return("StarList"); 1755 case ClassId_Transfo : 1756 return("Transfo"); 1757 case ClassId_PSF : 1758 return("PSF"); 1759 1760 1761 // - Ajout objet PPF 1762 default: 1763 return("AnyDataObj"); 1764 } 1765 } 1766 -
trunk/SophyaPI/PIext/servnobjm.h
r330 r333 25 25 class Histo2D; 26 26 class HProf; 27 class NamedObjMgr; 27 28 class PIStdImgApp; 28 29 class NObjMgrAdapter; … … 30 31 class Services2NObjMgr { 31 32 public: 32 Services2NObjMgr( PIStdImgApp* app, string& tmpdir);33 Services2NObjMgr(NamedObjMgr* omg, string& tmpdir); 33 34 virtual ~Services2NObjMgr(); 34 35 … … 40 41 inline void SetImgApp(PIStdImgApp* app) {mImgapp = app; } 41 42 42 void Nobj_ComputeExpressions(NObjMgrAdapter* obja, string& expx, string& expy, string& expz, 43 string& expwt, string& expcut, 44 NTuple* nt=NULL, Histo* h1=NULL, 45 Histo2D* h2=NULL, HProf* hp=NULL); 46 PlotExprFunc LinkExprFunc(string& vardec, string& expx, string& expy, string& expz, 47 string& wt, string& cut); 43 // Trace de fonctions 1-D , 2-D 44 virtual void PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, 45 int np=100, string dopt=""); 46 virtual void PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax, 47 double ymin, double ymax, int npx=50, int npy=50, string dopt=""); 48 virtual void PlotFuncFrCFile(string const & fname, string const & func, string & nom, 49 double xmin, double xmax, int np=100, string dopt=""); 50 virtual void PlotFunc2DFrCFile(string const & fname, string const & func, string & nom, 51 double xmin, double xmax, double ymin, double ymax, 52 int npx=50, int npy=50, string dopt=""); 53 virtual void PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, 54 int np=100, string dopt=""); 55 virtual void PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, 56 double ymin, double ymax, int npx=50, int npy=50, string dopt=""); 57 58 // Trace d'expression de NTuple, et d'autres objets 59 virtual void DisplayPoints2D(string & nom, string& expx, string& expy, 60 string& experrx, string& experry, 61 string& expcut, string dopt=""); 62 virtual void DisplayPoints3D(string & nom, string& expx, string& expy, string& expz, 63 string& expcut, string dopt=""); 64 virtual void DisplayPoints2DW(string & nom, string& expx, string& expy, 65 string& expwt, string& expcut, string dopt=""); 66 // Projection d'expressions dans histogramme (et trace) 67 virtual void ProjectH1(string & nom, string& expx, string& expwt, string& expcut, 68 string& nomh1, string dopt=""); 69 virtual void ProjectH2(string & nom, string& expx, string& expy, string& expwt, 70 string& expcut, string& nomh2, string dopt=""); 71 virtual void ProjectHProf(string & nom, string& expx, string& expy, string& expwt, 72 string& expcut, string& nomprof, string dopt=""); 73 // Projection d'expression dans vecteurs et dans n-tuple 74 virtual void FillVect(string & nom, string& expx, string& expcut, 75 string& nomvec, string dopt=""); 76 virtual void FillNT(string & nom, string& expx, string& expy, string& expz, 77 string& expt, string& expcut, string& nomnt); 78 virtual void FillGFD(string & nom, string& expx, string& expy, string& expz, 79 string& experr, string& expcut, string& nomgfd); 80 virtual void FillNTFrCFile(string & nom, string const & fname, 81 string const & funcname, string & nomnt); 82 virtual void PrepareNTExpressionCFile(string & nomobj, string const & fname, 83 string const & funcname); 84 85 // Methodes de fit - CMV , deux methodes H1 H2 ou 1 seule ??) ... 86 virtual void Fit12D(string & nom, string& func, 87 string par,string step,string min,string max,string opt); 88 89 // Calcul d'expressions d'interface NTuple pour les objets 90 void ComputeExpressions(NObjMgrAdapter* obja, string& expx, string& expy, 91 string& expz, string& expt, string& expcut, 92 NTuple* nt=NULL, Histo* h1=NULL, 93 Histo2D* h2=NULL, HProf* hp=NULL); 94 PlotExprFunc LinkExprFunc(string& vardec, string& expx, string& expy, 95 string& expz, string& expt, string& cut); 48 96 DlFunction LinkFunctionFromFile(string const & fname, string const & funcname); 49 97 void CloseDLL(); 50 51 // Trace de fonctions 1-D , 2-D52 virtual void PlotFunc(string const & expfunc, float xmin, float xmax, int np=100, string dopt="");53 virtual void PlotFunc2D(string const & expfunc, float xmin, float xmax, float ymin, float ymax,54 int npx=50, int npy=50, string dopt="");55 virtual void PlotFuncFrCFile(string const & fname, string const & func, float xmin, float xmax,56 int np=100, string dopt="");57 virtual void PlotFunc2DFrCFile(string const & fname, string const & func, float xmin, float xmax,58 float ymin, float ymax, int npx=50, int npy=50, string dopt="");59 virtual void PlotFunc(DlFunctionOfX f, float xmin, float xmax, int np=100, string dopt="");60 virtual void PlotFunc2D(DlFunctionOfXY f, float xmin, float xmax, float ymin, float ymax,61 int npx=50, int npy=50, string dopt="");62 98 63 99 // Utilitaires divers 64 100 string FileName2Name(string const & fn); 65 101 int DecodeDispOption(string& dopt, bool& fgsrgr); 102 char* PClassIdToClassName(int cid); 66 103 67 104 protected: … … 94 131 95 132 PIStdImgApp* mImgapp; 133 NamedObjMgr* mOmg; 96 134 97 135 };
Note:
See TracChangeset
for help on using the changeset viewer.