Changeset 1065 in Sophya
- Timestamp:
- Jul 11, 2000, 8:58:59 PM (25 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pawexecut.cc
r1059 r1065 105 105 usage += "\n n < 0 means Show Info"; 106 106 piac->RegisterCommand(kw,usage,this,hgrp); 107 108 kw = "h/put_vec"; 109 usage = "Put content of vector (matrix) into content of histogram 1D or 2D"; 110 usage += "\n h/put_vec nameh1d namevector [cont,err2]"; 111 usage += "\n h/put_vec nameh2d namematrix [cont,err2]"; 112 usage += "\n cont : put into histogramme content"; 113 usage += "\n err2 : put into histogramme error^2"; 114 usage += "\n Related commands: h/get_vec"; 115 piac->RegisterCommand(kw,usage,this,hgrp); 116 117 kw = "h/get_vec"; 118 usage = "Get content of histogram 1D profile or 2D into vector (matrix)"; 119 usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]"; 120 usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]"; 121 usage += "\n cont : get histogramme content"; 122 usage += "\n err2 : get histogramme error^2"; 123 usage += "\n absc : get histogramme low bin abscissa (1D only)"; 124 usage += "\n proj :"; 125 usage += "\n show : show available projections for Histo2D"; 126 usage += "\n px : get X projection"; 127 usage += "\n py : get Y projection"; 128 usage += "\n bx n : get X band number n"; 129 usage += "\n by n : get Y band number n"; 130 usage += "\n sx n : get X slice number n"; 131 usage += "\n sy n : get Y slice number n"; 132 usage += "\n Related commands: h/put_vec"; 133 piac->RegisterCommand(kw,usage,this,hgrp); 134 107 135 } 108 136 … … 135 163 } else if(kw == "h/plot/2d") { 136 164 h_plot_2d(tokens); return(0); 165 } else if(kw == "h/put_vec") { 166 h_put_vec(tokens); return(0); 167 } else if(kw == "h/get_vec") { 168 h_get_vec(tokens); return(0); 137 169 } else return(1); 138 170 } … … 509 541 // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y 510 542 { 511 if(tokens.size()< 2)543 if(tokens.size()<1) 512 544 {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;} 545 string proj = "h"; if(tokens.size()>1) proj = tokens[1]; 513 546 NamedObjMgr omg; 514 547 AnyDataObj* mobj = omg.GetObj(tokens[0]); … … 522 555 523 556 Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1"; 524 AnyDataObj* mobjh1 = omg.GetObj(nametoplot); 525 // if(mobjh1!=NULL) omg.DelObj(nametoplot); $CHECK$ Reza 12/12/99 - Ne pas faire - autoclean 557 //AnyDataObj* mobjh1 = omg.GetObj(nametoplot); 526 558 527 559 string dopt = ""; if(tokens.size()>=3) dopt = tokens[2]; 528 if( tokens[1]== "show") {560 if(proj == "show") { 529 561 h2->ShowProj(); 530 562 h2->ShowBand(2); 531 563 h2->ShowSli(2); 532 564 return; 533 } else if( tokens[1]== "h") {565 } else if(proj == "h") { 534 566 nametoplot = tokens[0]; 535 } else if( tokens[1]== "px") {567 } else if(proj == "px") { 536 568 if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} 537 569 else {h2->ShowProj(); return;} 538 } else if( tokens[1]== "py") {570 } else if(proj == "py") { 539 571 if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} 540 572 else {h2->ShowProj(); return;} … … 544 576 int n = atoi(tokens[2].c_str()); 545 577 dopt = ""; if(tokens.size()>=4) dopt = tokens[3]; 546 if( tokens[1]== "bx") {578 if(proj == "bx") { 547 579 if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} 548 580 else {h2->ShowBand(); return;} 549 } else if( tokens[1]== "by") {581 } else if(proj == "by") { 550 582 if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} 551 583 else {h2->ShowBand(); return;} 552 } else if( tokens[1]== "sx") {584 } else if(proj == "sx") { 553 585 if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} 554 586 else {h2->ShowSli(); return;} 555 } else if( tokens[1]== "sy") {587 } else if(proj == "sy") { 556 588 if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} 557 589 else {h2->ShowSli(); return;} … … 612 644 return np; 613 645 } 646 647 /* methode */ 648 void PAWExecutor::h_put_vec(vector<string>& tokens) 649 // Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice 650 // L'histogramme doit deja exister. Le nombre de bins remplit 651 // depend des tailles respectives des 2 objets. 652 // tokens[2] = "cont" : on remplit les valeurs de l'histogramme 653 // = "err2" : on remplit les erreurs de l'histogramme 654 { 655 if(tokens.size()<2) 656 {cout<<"Usage: h/put_vec namehisto namevector"<<endl; 657 return;} 658 string toput = "cont"; if(tokens.size()>2) toput = tokens[2]; 659 if(toput!="cont" && toput!="err2") 660 {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl; 661 return;} 662 string hname = tokens[0]; 663 string vname = tokens[1]; 664 665 // Get objects 666 NamedObjMgr omg; 667 AnyDataObj* mobjh = omg.GetObj(hname); 668 AnyDataObj* mobjv = omg.GetObj(vname); 669 if( mobjh==NULL || mobjv==NULL ) 670 {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl; 671 return;} 672 673 // Fill histo from vector 674 if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) { 675 Histo* h = dynamic_cast<Histo*>(mobjh); 676 Vector* v = dynamic_cast<Vector*>(mobjv); 677 if(toput=="cont") h->PutValue(*v); 678 else if(toput=="err2") h->PutError2(*v); 679 680 } else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) { 681 Histo2D* h = dynamic_cast<Histo2D*>(mobjh); 682 Matrix* v = dynamic_cast<Matrix*>(mobjv); 683 if(toput=="cont") h->PutValue(*v); 684 else if(toput=="err2") h->PutError2(*v); 685 686 } else { 687 cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n" 688 <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl; 689 return; 690 } 691 692 } 693 694 /* methode */ 695 void PAWExecutor::h_get_vec(vector<string>& tokens) 696 // Pour copier un histo dans un vecteur ou une matrice 697 // Si le vecteur (matrice) n'existe pas, il est cree. 698 // Le vecteur ou la matrice est re-dimensionne correctement. 699 // tokens[2] = "cont" : on copie les valeurs de l'histogramme 700 // = "err2" : on copie les erreurs de l'histogramme 701 // = "absc" : on copie les erreurs de l'histogramme (1D only) 702 // tokens[3[,4]] = show : show available projections for Histo2D 703 // px : get X projection 704 // py : get Y projection 705 // bx n : get X band number n 706 // by n : get Y band number n 707 // sx n : get X slice number n 708 // sy n : get Y slice number n 709 { 710 if(tokens.size()<2) 711 {cout<<"Usage: h/get_vec namehisto namevector"<<endl; 712 return;} 713 string toget = "cont"; if(tokens.size()>2) toget = tokens[2]; 714 if(toget!="cont" && toget!="err2" && toget!="absc") 715 {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl; 716 return;} 717 string proj = "h"; if(tokens.size()>3) proj = tokens[3]; 718 int nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str()); 719 string hname = tokens[0]; 720 string vname = tokens[1]; 721 722 // Get objects 723 NamedObjMgr omg; 724 AnyDataObj* mobjh = omg.GetObj(hname); 725 AnyDataObj* mobjv = omg.GetObj(vname); 726 if( mobjh==NULL) 727 {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl; 728 return;} 729 730 // Fill histo from vector 731 Histo* h = dynamic_cast<Histo*>(mobjh); 732 Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh); 733 if( h != NULL ) { // Histo ou HProf 734 HProf* hp = dynamic_cast<HProf*>(mobjh); 735 if(hp!=NULL) if(!(hp->IsOk())) hp->UpdateHisto(); 736 Vector* v = NULL; 737 if(mobjv==NULL) // le vecteur n'existe pas 738 {v = new Vector(1); omg.AddObj(v,vname);} 739 AnyDataObj* mobjv = omg.GetObj(vname); 740 if(typeid(*mobjv) != typeid(Vector)) 741 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n" 742 <<typeid(*mobjv).name()<<endl; return;} 743 v = dynamic_cast<Vector*>(mobjv); 744 if(toget=="cont") h->GetValue(*v); 745 else if(toget=="err2") h->GetError2(*v); 746 else if(toget=="absc") h->GetAbsc(*v); 747 748 } else if( h2 != NULL) { // Histo2D 749 750 if(proj == "h") { // On veut les valeurs de l'histogramme 2D 751 Matrix* v = NULL; 752 if(mobjv==NULL) // la matrice n'existe pas 753 {v = new Matrix(1,1); omg.AddObj(v,vname);} 754 AnyDataObj* mobjv = omg.GetObj(vname); 755 if(typeid(*mobjv) != typeid(Matrix)) 756 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n" 757 <<typeid(*mobjv).name()<<endl; return;} 758 v = dynamic_cast<Matrix*>(mobjv); 759 if(toget=="cont") h2->GetValue(*v); 760 else if(toget=="err2") h2->GetError2(*v); 761 else 762 {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl; 763 return;} 764 765 } else { // On veut les valeurs d'une projection de l'histo 2D 766 h = NULL; 767 if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);} 768 else if(proj == "px") h = h2->HProjX(); 769 else if(proj == "py") h = h2->HProjY(); 770 else if(proj == "bx") h = h2->HBandX(nproj); 771 else if(proj == "by") h = h2->HBandY(nproj); 772 else if(proj == "sx") h = h2->HSliX(nproj); 773 else if(proj == "sy") h = h2->HSliY(nproj); 774 if(h==NULL) 775 {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj 776 <<" number "<<nproj<<endl; return;} 777 Vector* v = NULL; 778 if(mobjv==NULL) // le vecteur n'existe pas 779 {v = new Vector(1); omg.AddObj(v,vname);} 780 AnyDataObj* mobjv = omg.GetObj(vname); 781 if(typeid(*mobjv) != typeid(Vector)) 782 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj 783 <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;} 784 v = dynamic_cast<Vector*>(mobjv); 785 if(toget=="cont") h->GetValue(*v); 786 else if(toget=="err2") h->GetError2(*v); 787 else if(toget=="absc") h->GetAbsc(*v); 788 } 789 790 } else { 791 cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n" 792 <<typeid(*mobjh).name()<<endl; 793 return; 794 } 795 796 } -
trunk/SophyaPI/PIext/pawexecut.h
r1054 r1065 30 30 void h_oper(vector<string>& tokens); 31 31 void h_plot_2d(vector<string>& tokens); 32 void h_put_vec(vector<string>& tokens); 33 void h_get_vec(vector<string>& tokens); 32 34 int decodepawstring(string tokens,string& nameobj 33 35 ,string& xexp,string& yexp,string& zexp);
Note:
See TracChangeset
for help on using the changeset viewer.