Changeset 1065 in Sophya for trunk/SophyaPI/PIext


Ignore:
Timestamp:
Jul 11, 2000, 8:58:59 PM (25 years ago)
Author:
ercodmgr
Message:

introduction de h/get_vec et h/put_vec ...... cmv 11/7/00

Location:
trunk/SophyaPI/PIext
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/pawexecut.cc

    r1059 r1065  
    105105usage += "\n                      n < 0 means Show Info";
    106106piac->RegisterCommand(kw,usage,this,hgrp);
     107
     108kw = "h/put_vec";
     109usage = "Put content of vector (matrix) into content of histogram 1D or 2D";
     110usage += "\n h/put_vec nameh1d namevector [cont,err2]";
     111usage += "\n h/put_vec nameh2d namematrix [cont,err2]";
     112usage += "\n     cont : put into histogramme content";
     113usage += "\n     err2 : put into histogramme error^2";
     114usage += "\n  Related commands: h/get_vec"; 
     115piac->RegisterCommand(kw,usage,this,hgrp);
     116
     117kw = "h/get_vec";
     118usage = "Get content of histogram 1D profile or 2D into vector (matrix)";
     119usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]";
     120usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]";
     121usage += "\n   cont : get histogramme content";
     122usage += "\n   err2 : get histogramme error^2";
     123usage += "\n   absc : get histogramme low bin abscissa (1D only)";
     124usage += "\n     proj :";
     125usage += "\n            show  : show available projections for Histo2D";
     126usage += "\n            px    : get X projection";
     127usage += "\n            py    : get Y projection";
     128usage += "\n            bx n  : get X band number n";
     129usage += "\n            by n  : get Y band number n";
     130usage += "\n            sx n  : get X slice number n";
     131usage += "\n            sy n  : get Y slice number n";
     132usage += "\n  Related commands: h/put_vec"; 
     133piac->RegisterCommand(kw,usage,this,hgrp);
     134
    107135}
    108136
     
    135163} else if(kw == "h/plot/2d") {
    136164  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);
    137169} else return(1);
    138170}
     
    509541// plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
    510542{
    511 if(tokens.size()<2)
     543if(tokens.size()<1)
    512544  {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
     545string proj = "h"; if(tokens.size()>1) proj = tokens[1];
    513546NamedObjMgr omg;
    514547AnyDataObj* mobj = omg.GetObj(tokens[0]);
     
    522555
    523556Histo* 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);
    526558
    527559string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
    528 if(tokens[1] == "show") {
     560if(proj == "show") {
    529561  h2->ShowProj();
    530562  h2->ShowBand(2);
    531563  h2->ShowSli(2);
    532564  return;
    533 } else if(tokens[1] == "h") {
     565} else if(proj == "h") {
    534566  nametoplot = tokens[0];
    535 } else if(tokens[1] == "px") { 
     567} else if(proj == "px") { 
    536568  if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
    537569    else {h2->ShowProj(); return;}
    538 } else if(tokens[1] == "py") {
     570} else if(proj == "py") {
    539571  if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
    540572    else {h2->ShowProj(); return;}
     
    544576  int n = atoi(tokens[2].c_str());
    545577  dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
    546   if(tokens[1] == "bx") {
     578  if(proj == "bx") {
    547579    if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
    548580    else {h2->ShowBand(); return;}
    549   } else if(tokens[1] == "by") {
     581  } else if(proj == "by") {
    550582    if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
    551583    else {h2->ShowBand(); return;}
    552   } else if(tokens[1] == "sx") {
     584  } else if(proj == "sx") {
    553585    if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
    554586    else {h2->ShowSli(); return;}
    555   } else if(tokens[1] == "sy") {
     587  } else if(proj == "sy") {
    556588    if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
    557589    else {h2->ShowSli(); return;}
     
    612644return np;
    613645}
     646
     647/* methode */
     648void 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{
     655if(tokens.size()<2)
     656  {cout<<"Usage: h/put_vec  namehisto namevector"<<endl;
     657   return;}
     658string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
     659if(toput!="cont" && toput!="err2")
     660  {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
     661   return;}
     662string hname = tokens[0];
     663string vname = tokens[1];
     664
     665// Get objects
     666NamedObjMgr omg;
     667AnyDataObj* mobjh = omg.GetObj(hname);
     668AnyDataObj* mobjv = omg.GetObj(vname);
     669if( 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
     674if(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 */
     695void 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{
     710if(tokens.size()<2)
     711  {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
     712   return;}
     713string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
     714if(toget!="cont" && toget!="err2" && toget!="absc")
     715  {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
     716   return;}
     717string proj = "h";  if(tokens.size()>3) proj = tokens[3];
     718int nproj = -1;     if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
     719string hname = tokens[0];
     720string vname = tokens[1];
     721
     722// Get objects
     723NamedObjMgr omg;
     724AnyDataObj* mobjh = omg.GetObj(hname);
     725AnyDataObj* mobjv = omg.GetObj(vname);
     726if( mobjh==NULL)
     727  {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
     728  return;}
     729
     730// Fill histo from vector
     731Histo*   h  = dynamic_cast<Histo*>(mobjh);
     732Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
     733if( 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  
    3030  void h_oper(vector<string>& tokens);
    3131  void h_plot_2d(vector<string>& tokens);
     32  void h_put_vec(vector<string>& tokens);
     33  void h_get_vec(vector<string>& tokens);
    3234  int  decodepawstring(string tokens,string& nameobj
    3335                      ,string& xexp,string& yexp,string& zexp);
Note: See TracChangeset for help on using the changeset viewer.