Changeset 1070 in Sophya for trunk


Ignore:
Timestamp:
Jul 13, 2000, 11:47:17 AM (25 years ago)
Author:
ercodmgr
Message:

intro de h/copy cmv 13/7/00

Location:
trunk/SophyaPI/PIext
Files:
2 edited

Legend:

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

    r1067 r1070  
    131131usage += "\n            sy n  : get Y slice number n";
    132132usage += "\n  Related commands: h/put_vec"; 
     133piac->RegisterCommand(kw,usage,this,hgrp);
     134
     135kw = "h/copy";
     136usage = "Copy content of object1 into objecft2";
     137usage += "\n objects are Vector,Matrix,Histo,Histo2D";
     138usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]]";
     139usage += "\n   copy obj1Dfrom(i1->i2) into obj1Dto";
     140usage += "\n   copy obj2Dfrom(i1:j1->i2:j2) into obj2Dto";
     141usage += "\n Warnig: elements from i1 to i2 included are copied";
     142usage += "\n  Related commands: copy"; 
    133143piac->RegisterCommand(kw,usage,this,hgrp);
    134144
     
    167177} else if(kw == "h/get_vec") {
    168178  h_get_vec(tokens); return(0);
     179} else if(kw == "h/copy") {
     180  h_copy(tokens); return(0);
    169181} else return(1);
    170182}
     
    797809
    798810}
     811
     812/* methode */
     813void PAWExecutor::h_copy(vector<string>& tokens)
     814// Pour copier un object dans un object
     815// objects are Vector,Matrix,Histo,Histo2D
     816//   h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]]
     817//   copy obj1Dfrom(i1->i2) into obj1Dto
     818//   copy obj2Dfrom(i1:j1->i2:j2) into obj2Dto
     819// Attention: elements depuis i1 jusqu'a i2 COMPRIS
     820{
     821if(tokens.size()<2)
     822  {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]]"<<endl;
     823   return;}
     824
     825NamedObjMgr omg;
     826AnyDataObj* mobjv1 = omg.GetObj(tokens[0]);
     827if( mobjv1==NULL)
     828  {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
     829  return;}
     830
     831// Cas d'un Vector
     832if(typeid(*mobjv1) == typeid(Vector)) {
     833  Vector* v1 = dynamic_cast<Vector*>(mobjv1);
     834  int_4 i1=0,i2=v1->NElts()-1;
     835  if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     836  if(i1<0) i1=0; if(i2>=(int_4)v1->NElts()) i2=v1->NElts()-1;
     837  if(i2<i1)
     838    {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
     839         <<v1->NElts()<<endl; return;}
     840  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<endl;
     841  Vector* v2 = NULL;
     842  AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
     843  if(mobjv2==NULL)
     844    {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]);}
     845  mobjv2 = omg.GetObj(tokens[1]);
     846  if(typeid(*mobjv2) != typeid(Vector))
     847    {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
     848         <<typeid(*mobjv2).name()<<endl; return;}
     849  v2 = dynamic_cast<Vector*>(mobjv2);
     850  if(i2-i1+1>(int_4)v2->NElts())
     851    {cout<<"PAWExecutor::h_copy Error: Vector to copy to small "
     852         <<v2->NElts()<<endl; return;}
     853  for(int i=i1,ii=0;i<=i2;i++,ii++) (*v2)(ii) = (*v1)(i);
     854  return;
     855}
     856
     857// Cas d'un Histo
     858if(typeid(*mobjv1) == typeid(Histo)) {
     859  Histo* v1 = dynamic_cast<Histo*>(mobjv1);
     860  int_4 i1=0,i2=v1->NBins()-1;
     861  if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     862  if(i1<0) i1=0; if(i2>=(int_4)v1->NBins()) i2=v1->NBins()-1;
     863  if(i2<i1)
     864    {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
     865         <<v1->NBins()<<endl; return;}
     866  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<endl;
     867  Histo* v2 = NULL;
     868  AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
     869  if(mobjv2==NULL)
     870    {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1); omg.AddObj(v2,tokens[1]);}
     871  mobjv2 = omg.GetObj(tokens[1]);
     872  if(typeid(*mobjv2) != typeid(Histo))
     873    {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
     874         <<typeid(*mobjv2).name()<<endl; return;}
     875  v2 = dynamic_cast<Histo*>(mobjv2);
     876  if(i2-i1+1>(int_4)v2->NBins())
     877    {cout<<"PAWExecutor::h_copy Error: Histo to copy to small "
     878         <<v2->NBins()<<endl; return;}
     879  for(int i=i1,ii=0;i<=i2;i++,ii++) (*v2)(ii) = (*v1)(i);
     880  return;
     881}
     882
     883// Cas d'une Matrix
     884if(typeid(*mobjv1) == typeid(Matrix)) {
     885  Matrix* v1 = dynamic_cast<Matrix*>(mobjv1);
     886  int_4 i1=0,i2=v1->NRows()-1, j1=0,j2=v1->NCol()-1;
     887  if(tokens.size()>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     888  if(tokens.size()>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
     889  if(i1<0) i1=0; if(i2>=(int_4)v1->NRows()) i2=v1->NRows()-1;
     890  if(j1<0) j1=0; if(j2>=(int_4)v1->NCol())  j2=v1->NCol()-1;
     891  if(i2<i1 || j2<j1)
     892    {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
     893         <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
     894         <<v1->NRows()<<" , "<<v1->NCol()<<endl; return;}
     895  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2<<") to "<<tokens[1]<<endl;
     896  Matrix* v2 = NULL;
     897  AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
     898  if(mobjv2==NULL)
     899    {v2 = new Matrix(i2-i1+1,j2-j1+1); omg.AddObj(v2,tokens[1]);}
     900  mobjv2 = omg.GetObj(tokens[1]);
     901  if(typeid(*mobjv2) != typeid(Matrix))
     902    {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
     903         <<typeid(*mobjv2).name()<<endl; return;}
     904  v2 = dynamic_cast<Matrix*>(mobjv2);
     905  if(i2-i1+1>(int_4)v2->NRows() || j2-j1+1>(int_4)v2->NCol())
     906    {cout<<"PAWExecutor::h_copy Error: Matrix to copy to small "
     907         <<v2->NRows()<<","<<v2->NCol()<<endl; return;}
     908  for(int i=i1,ii=0;i<=i2;i++,ii++)
     909    for(int j=j1,jj=0;j<=j2;j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
     910  return;
     911}
     912
     913// Cas d'un Histo2D
     914if(typeid(*mobjv1) == typeid(Histo2D)) {
     915  Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1);
     916  int_4 i1=0,i2=v1->NBinX()-1, j1=0,j2=v1->NBinY()-1;
     917  if(tokens.size()>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     918  if(tokens.size()>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
     919  if(i1<0) i1=0; if(i2>=(int_4)v1->NBinX()) i2=v1->NBinX()-1;
     920  if(j1<0) j1=0; if(j2>=(int_4)v1->NBinY())  j2=v1->NBinY()-1;
     921  if(i2<i1 || j2<j1)
     922    {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
     923         <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
     924         <<v1->NBinX()<<" , "<<v1->NBinY()<<endl; return;}
     925  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2<<") to "<<tokens[1]<<endl;
     926  Histo2D* v2 = NULL;
     927  AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
     928  if(mobjv2==NULL)
     929    {v2 = new Histo2D(0.,(float)(i2-i1+1),i2-i1+1,0.,(float)(j2-j1+1),j2-j1+1);
     930     omg.AddObj(v2,tokens[1]);}
     931  mobjv2 = omg.GetObj(tokens[1]);
     932  if(typeid(*mobjv2) != typeid(Histo2D))
     933    {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
     934         <<typeid(*mobjv2).name()<<endl; return;}
     935  v2 = dynamic_cast<Histo2D*>(mobjv2);
     936  if(i2-i1+1>(int_4)v2->NBinX() || j2-j1+1>(int_4)v2->NBinY())
     937    {cout<<"PAWExecutor::h_copy Error: Histo2D to copy to small "
     938         <<v2->NBinX()<<","<<v2->NBinY()<<endl; return;}
     939  for(int i=i1,ii=0;i<=i2;i++,ii++)
     940    for(int j=j1,jj=0;j<=j2;j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
     941  return;
     942}
     943
     944// Cas non prevu
     945cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n"
     946    <<typeid(*mobjv1).name()<<endl;
     947return;
     948}
  • trunk/SophyaPI/PIext/pawexecut.h

    r1065 r1070  
    3232  void h_put_vec(vector<string>& tokens);
    3333  void h_get_vec(vector<string>& tokens);
     34  void h_copy(vector<string>& tokens);
    3435  int  decodepawstring(string tokens,string& nameobj
    3536                      ,string& xexp,string& yexp,string& zexp);
Note: See TracChangeset for help on using the changeset viewer.