Changeset 2809 in Sophya for trunk/SophyaPI/PIext
- Timestamp:
- Jun 14, 2005, 2:40:31 PM (20 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pawexecut.cc
r2792 r2809 117 117 118 118 kw = "n/merge"; 119 usage = "Merge ntuples ";119 usage = "Merge ntuples (by adding lines)"; 120 120 usage += "\n n/merge nt nt_1 nt_2 ... nt_n"; 121 usage += "\n Merge ntuples nt_i into ntuple nt"; 121 usage += "\n Merge ntuples nt_i lines into ntuple nt"; 122 piac->RegisterCommand(kw,usage,this,hgrp); 123 124 kw = "n/merge/col"; 125 usage = "Merge ntuples (by adding columns)"; 126 usage += "\n n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]"; 127 usage += "\n Merge ntuples nt_i columns into ntuple nt"; 128 usage += "\n ext : character string to add at the end of the ntuple variable names"; 129 usage += "\n if \"ext\"=\"!\" no extension is added"; 130 usage += "\n if no \"ext\" is given, automatic extension \"_0\" \"_1\" \"_2\" ..."; 122 131 piac->RegisterCommand(kw,usage,this,hgrp); 123 132 … … 286 295 } else if(kw == "n/merge") { 287 296 n_merge(tokens); return(0); 297 } else if(kw == "n/merge/col") { 298 n_merge_col(tokens); return(0); 288 299 } else if(kw == "h/integ") { 289 300 h_integ(tokens); return(0); … … 668 679 int numcolmaxi=-1; 669 680 670 for(int i=2;i< tokens.size();i++) {681 for(int i=2;i<(int_4)tokens.size();i++) { 671 682 int lc = tokens[i].size(); 672 683 if(lc<2) continue; … … 714 725 if(onlyreadin.size()>0) { 715 726 cout<<"n_read Only read line containing ["<<onlyreadin.size()<<"]:"; 716 for(int i=0;i< onlyreadin.size();i++) cout<<" \'"<<onlyreadin[i]<<"\'";727 for(int i=0;i<(int_4)onlyreadin.size();i++) cout<<" \'"<<onlyreadin[i]<<"\'"; 717 728 cout<<endl; 718 729 } 719 730 if(onlyreadbeg.size()>0) { 720 731 cout<<"n_read Only read line begining with ["<<onlyreadbeg.size()<<"]:"; 721 for(int i=0;i< onlyreadbeg.size();i++) cout<<" \'"<<onlyreadbeg[i]<<"\'";732 for(int i=0;i<(int_4)onlyreadbeg.size();i++) cout<<" \'"<<onlyreadbeg[i]<<"\'"; 722 733 cout<<endl; 723 734 } 724 735 if(donotreadin.size()>0) { 725 736 cout<<"n_read Do not read line containing ["<<donotreadin.size()<<"]:"; 726 for(int i=0;i< donotreadin.size();i++) cout<<" \'"<<donotreadin[i]<<"\'";737 for(int i=0;i<(int_4)donotreadin.size();i++) cout<<" \'"<<donotreadin[i]<<"\'"; 727 738 cout<<endl; 728 739 } 729 740 if(donotreadbeg.size()>0) { 730 741 cout<<"n_read Do not read line begining with ["<<donotreadbeg.size()<<"]:"; 731 for(int i=0;i< donotreadbeg.size();i++) cout<<" \'"<<donotreadbeg[i]<<"\'";742 for(int i=0;i<(int_4)donotreadbeg.size();i++) cout<<" \'"<<donotreadbeg[i]<<"\'"; 732 743 cout<<endl; 733 744 } … … 766 777 while(fgets(line,__LENLINE_N_READ__,fascii) != NULL ) { 767 778 nline++; 768 intlc = strlen(line); if(lc<1) continue;779 uint_4 lc = strlen(line); if(lc<1) continue; 769 780 // Pour enlever le \n final 770 781 if(line[lc-1]=='\n' || line[lc-1]=='\r') … … 778 789 if(onlyreadin.size()>0 || onlyreadbeg.size()>0) read_line_1 = false; 779 790 if(onlyreadin.size()>0) { 780 for(int i=0;i< onlyreadin.size();i++) {791 for(int i=0;i<(int_4)onlyreadin.size();i++) { 781 792 uint_4 p = sline.find(onlyreadin[i].c_str()); 782 793 if(p>=lc) continue; … … 786 797 } 787 798 if(onlyreadbeg.size()>0) { 788 for(int i=0;i< onlyreadbeg.size();i++) {799 for(int i=0;i<(int_4)onlyreadbeg.size();i++) { 789 800 uint_4 p = sline.find(onlyreadbeg[i].c_str()); 790 801 if(p!=0) continue; … … 797 808 bool read_line_2 = true; 798 809 if(donotreadin.size()>0) { 799 for(int i=0;i< donotreadin.size();i++) {810 for(int i=0;i<(int_4)donotreadin.size();i++) { 800 811 uint_4 p = sline.find(donotreadin[i].c_str()); 801 812 if(p>=lc) continue; … … 805 816 } 806 817 if(donotreadbeg.size()>0) { 807 for(int i=0;i< donotreadbeg.size();i++) {818 for(int i=0;i<(int_4)donotreadbeg.size();i++) { 808 819 uint_4 p = sline.find(donotreadbeg[i].c_str()); 809 820 if(p!=0) continue; … … 862 873 { 863 874 if(tokens.size()<2) { 864 cerr<<"Usage: n/ readnt nt_1 nt_2 ... nt_n"<<endl;875 cerr<<"Usage: n/merge nt nt_1 nt_2 ... nt_n"<<endl; 865 876 return; 866 877 } … … 876 887 r_8 *xnt=NULL; 877 888 878 for(int i=1;i< tokens.size();i++) {889 for(int i=1;i<(int_4)tokens.size();i++) { 879 890 880 891 AnyDataObj* mobj = omg.GetObj(tokens[i]); 881 892 if(mobj==NULL) { 882 893 cout<<"n_merge Error: unknow object"<<tokens[i]<<endl; 883 continue; ;894 continue; 884 895 } 885 896 NTuple* nt1 = dynamic_cast<NTuple*>(mobj); … … 913 924 r_8 *xnt1 = new r_8[n]; 914 925 for(int i=0;i<n;i++) xnt1[i]=0.; 915 for(uint_4 iev=0;iev< nt1->NEntry();iev++) {926 for(uint_4 iev=0;iev<(uint_4)nt1->NEntry();iev++) { 916 927 nt1->GetVecD(iev,xnt1); 917 928 nt->Fill(xnt1); … … 928 939 if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt; 929 940 } 941 return; 942 } 943 944 /* methode */ 945 void PAWExecutor::n_merge_col(vector<string>& tokens) 946 { 947 if(tokens.size()<2) { 948 cerr<<"Usage: n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]"<<endl; 949 return; 950 } 951 952 NamedObjMgr omg; 953 954 // decodage des arguments 955 string nament = tokens[0]; 956 957 // boucle sur les ntuples 958 uint_4 numnt=0, nentmax=0, ipos=0; 959 vector<string> varname; 960 vector<string> ntname; 961 vector<int> posfirst; 962 for(int i=1;i<(int_4)tokens.size();i++) { 963 964 // Decode NTuple name and extension 965 int_4 lc = tokens[i].size(); 966 string ntn = tokens[i]; 967 string ext = ""; 968 int p = ntn.find(','); 969 if(p>=0 && p<lc) { 970 if(p<lc-1) ext = ntn.substr(p+1,lc-p-1); 971 if(p>0) ntn = ntn.substr(0,p); else ntn = ""; 972 } 973 // choose the extentsion: given,automatic,none 974 if(ext.size()<1) { 975 char str[8]; sprintf(str,"_%d",numnt); 976 ext = str; 977 } else if(ext[0] == '!') { 978 ext = ""; 979 } 980 981 AnyDataObj* mobj = omg.GetObj(ntn); 982 if(mobj==NULL) { 983 cout<<"n_merge_col Error: unknow object "<<ntn<<" ("<<tokens[i]<<")"<<endl; 984 continue; 985 } 986 NTuple* nt1 = dynamic_cast<NTuple*>(mobj); 987 if(nt1==NULL) { 988 cout<<"n_merge_col Error: "<<ntn<<" not a NTuple"<<endl; 989 continue; 990 } 991 if(nt1->NEntry()==0) { 992 cout<<"n_merge_col Error: "<<ntn<<" is empty"<<endl; 993 continue; 994 } 995 if(nt1->NVar()==0) { 996 cout<<"n_merge_col Error: "<<ntn<<" has no variable"<<endl; 997 continue; 998 } 999 1000 ntname.push_back(ntn); 1001 posfirst.push_back(ipos); 1002 if(nt1->NEntry()>(int_4)nentmax) nentmax = nt1->NEntry(); 1003 for(int i=0;i<nt1->NVar();i++) { 1004 string str = nt1->ColumnName(i) + ext; 1005 varname.push_back(str); 1006 } 1007 numnt++; 1008 ipos += nt1->NVar(); 1009 } 1010 1011 if(ntname.size()==0) { 1012 cout<<"n_merge_col Error: no ntuple found in argument list"<<endl; 1013 return; 1014 } else cout<<"Number of NTuple found "<<ntname.size() 1015 <<", Number of variables "<<varname.size() 1016 <<", Max_entries "<<nentmax<<endl; 1017 1018 // create receiving ntuple 1019 int nvar = varname.size(); 1020 char **ntvn = new char*[nvar]; 1021 for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(varname[i].c_str()); 1022 NTuple * nt = new NTuple(nvar,ntvn); 1023 //for(int i=0;i<(int_4)ntname.size();i++) cout<<ntname[i]<<" , p="<<posfirst[i]<<endl; 1024 delete [] ntvn; 1025 1026 // filling with current ntuple 1027 r_8 *xnt = new r_8[nvar]; 1028 for(int iev=0;iev<(int_4)nentmax;iev++) { 1029 for(int i=0;i<nvar;i++) xnt[i]=0.; 1030 for(int i=0;i<(int_4)ntname.size();i++) { 1031 AnyDataObj* mobj = omg.GetObj(ntname[i]); 1032 NTuple* nt1 = dynamic_cast<NTuple*>(mobj); 1033 if(iev < nt1->NEntry()) nt1->GetVecD(iev,&xnt[posfirst[i]]); 1034 } 1035 nt->Fill(xnt); 1036 } 1037 1038 // Ending and saving merging ntuple columns 1039 delete [] xnt; 1040 cout<<"n_merge_col: ntuple filled with "<<ntname.size() 1041 <<" ntuples, "<<nt->NEntry()<<" entries"<<endl; 1042 if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt; 1043 930 1044 return; 931 1045 } -
trunk/SophyaPI/PIext/pawexecut.h
r2755 r2809 28 28 void n_read(vector<string>& tokens); 29 29 void n_merge(vector<string>& tokens); 30 void n_merge_col(vector<string>& tokens); 30 31 void h_integ(vector<string>& tokens); 31 32 void v_integ(vector<string>& tokens);
Note:
See TracChangeset
for help on using the changeset viewer.