Changeset 1071 in Sophya
- Timestamp:
- Jul 13, 2000, 10:56:09 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pawexecut.cc
r1070 r1071 136 136 usage = "Copy content of object1 into objecft2"; 137 137 usage += "\n objects are Vector,Matrix,Histo,Histo2D"; 138 usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]]"; 139 usage += "\n copy obj1Dfrom(i1->i2) into obj1Dto"; 140 usage += "\n copy obj2Dfrom(i1:j1->i2:j2) into obj2Dto"; 141 usage += "\n Warnig: elements from i1 to i2 included are copied"; 138 usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"; 139 usage += "\n copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)"; 140 usage += "\n copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)"; 141 usage += "\n Warning: elements from i1 to i2 included are copied"; 142 usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1"; 143 usage += "\n or obj2Dto with size i2-i1+1,j2-j1+1"; 144 usage += "\n The adressed content of obj?Dfrom is overwritten"; 145 usage += "\n The non-adressed content of obj?Dfrom is left unchanged"; 142 146 usage += "\n Related commands: copy"; 143 147 piac->RegisterCommand(kw,usage,this,hgrp); … … 814 818 // Pour copier un object dans un object 815 819 // 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 obj2Dto820 // h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]] 821 // copy obj1Dfrom(i1->i2) into obj1Dto(ic1->) 822 // copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->) 819 823 // Attention: elements depuis i1 jusqu'a i2 COMPRIS 820 { 821 if(tokens.size()<2) 822 {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]]"<<endl; 824 // Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1 825 // ou obj2Dto avec une taille i2-i1+1,j2-j1+1 826 // Le contenu de obj?Dfrom adresse est surecrit 827 // Le contenu de obj?Dfrom non adresse reste le meme 828 { 829 int tks = tokens.size(); 830 if(tks<2) 831 {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl; 823 832 return;} 824 833 … … 828 837 {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl; 829 838 return;} 839 AnyDataObj* mobjv2 = omg.GetObj(tokens[1]); 840 841 int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2; 830 842 831 843 // Cas d'un Vector 832 844 if(typeid(*mobjv1) == typeid(Vector)) { 833 Vector* v1 = dynamic_cast<Vector*>(mobjv1); 834 i nt_4 i1=0,i2=v1->NElts()-1;835 if(t okens.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;845 Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts(); 846 i2=nx1-1; 847 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); 848 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; 837 849 if(i2<i1) 838 850 {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; 851 <<nx1<<endl; return;} 841 852 Vector* v2 = NULL; 842 AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);843 853 if(mobjv2==NULL) 844 854 {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]);} … … 847 857 {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector " 848 858 <<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); 859 v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts(); 860 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1); 861 if(ic1<0) ic1=0; 862 if(ic1>=nx2) 863 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts=" 864 <<nx2<<endl; return;} 865 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl; 866 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i); 854 867 return; 855 868 } … … 857 870 // Cas d'un Histo 858 871 if(typeid(*mobjv1) == typeid(Histo)) { 859 Histo* v1 = dynamic_cast<Histo*>(mobjv1); 860 i nt_4 i1=0,i2=v1->NBins()-1;861 if(t okens.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;872 Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins(); 873 i2=nx1-1; 874 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); 875 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; 863 876 if(i2<i1) 864 877 {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; 878 <<nx1<<endl; return;} 867 879 Histo* v2 = NULL; 868 AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);869 880 if(mobjv2==NULL) 870 881 {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1); omg.AddObj(v2,tokens[1]);} … … 873 884 {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo " 874 885 <<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); 886 v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins(); 887 if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors(); 888 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1); 889 if(ic1<0) ic1=0; 890 if(ic1>=nx2) 891 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins=" 892 <<nx2<<endl; return;} 893 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl; 894 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) 895 {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);} 880 896 return; 881 897 } … … 883 899 // Cas d'une Matrix 884 900 if(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; 901 Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol(); 902 i2=nx1-1; j2=ny1-1; 903 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); 904 if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); 905 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1; 891 906 if(i2<i1 || j2<j1) 892 907 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2 893 908 <<"] , ["<<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; 909 <<nx1<<" , "<<ny1<<endl; return;} 896 910 Matrix* v2 = NULL; 897 AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);898 911 if(mobjv2==NULL) 899 912 {v2 = new Matrix(i2-i1+1,j2-j1+1); omg.AddObj(v2,tokens[1]);} … … 902 915 {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix " 903 916 <<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); 917 v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol(); 918 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1); 919 if(ic1<0) ic1=0; if(jc1<0) jc1=0; 920 if(ic1>=nx2 || jc1>=ny2) 921 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1 922 <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;} 923 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2 924 <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl; 925 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) 926 for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j); 910 927 return; 911 928 } … … 913 930 // Cas d'un Histo2D 914 931 if(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; 932 Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY(); 933 i2=nx1-1; j2=ny1-1; 934 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); 935 if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); 936 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1; 921 937 if(i2<i1 || j2<j1) 922 938 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2 923 939 <<"] , ["<<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; 940 <<nx1<<" , "<<ny1<<endl; return;} 926 941 Histo2D* v2 = NULL; 927 AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);928 942 if(mobjv2==NULL) 929 943 {v2 = new Histo2D(0.,(float)(i2-i1+1),i2-i1+1,0.,(float)(j2-j1+1),j2-j1+1); … … 933 947 {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D" 934 948 <<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); 949 v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY(); 950 if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors(); 951 if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1); 952 if(ic1<0) ic1=0; if(jc1<0) jc1=0; 953 if(ic1>=nx2 || jc1>=ny2) 954 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1 955 <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;} 956 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2 957 <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl; 958 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) 959 for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) 960 {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);} 941 961 return; 942 962 }
Note:
See TracChangeset
for help on using the changeset viewer.