Changeset 2708 in Sophya
- Timestamp:
- Apr 28, 2005, 7:33:16 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pawexecut.cc
r2689 r2708 30 30 31 31 /* Reza + cmv 13/10/99 */ 32 33 inline bool __vector_sort_up_r8(r_8 x1,r_8 x2) {return x1<x2;} 34 inline bool __vector_sort_down_r8(r_8 x1,r_8 x2) {return x1>x2;} 35 inline bool __vector_sort_up_r4(r_4 x1,r_4 x2) {return x1<x2;} 36 inline bool __vector_sort_down_r4(r_4 x1,r_4 x2) {return x1>x2;} 37 inline bool __vector_sort_up_i4(int_4 x1,int_4 x2) {return x1<x2;} 38 inline bool __vector_sort_down_i4(int_4 x1,int_4 x2) {return x1>x2;} 39 inline bool __vector_sort_up_u8(uint_8 x1,uint_8 x2) {return x1<x2;} 40 inline bool __vector_sort_down_u8(uint_8 x1,uint_8 x2) {return x1>x2;} 32 41 33 42 uint_4 PAWExecutor::autoc_counter_ = 0; … … 117 126 piac->RegisterCommand(kw,usage,this,hgrp); 118 127 119 //#ifndef SANS_EVOLPLANCK120 128 kw = "v/integ"; 121 129 usage = "Integrate a TVector / vector"; … … 124 132 usage += "\n Related commands: h/integ h/deriv v/deriv"; 125 133 piac->RegisterCommand(kw,usage,this,hgrp); 126 //#endif 134 135 kw = "v/sort"; 136 usage = "Sort a vector into itself"; 137 usage += "\n v/sort namevec [+1/-1]"; 138 usage += "\n \"+1\" means increasing order, \"-1\" decreasing order"; 139 piac->RegisterCommand(kw,usage,this,hgrp); 127 140 128 141 kw = "h/deriv"; … … 132 145 piac->RegisterCommand(kw,usage,this,hgrp); 133 146 134 //#ifndef SANS_EVOLPLANCK135 147 kw = "v/deriv"; 136 148 usage = "Derivate a TVector / vector"; … … 141 153 usage += "\n Related commands: h/integ h/deriv v/integ"; 142 154 piac->RegisterCommand(kw,usage,this,hgrp); 143 //#endif144 155 145 156 kw = "h/rebin"; … … 274 285 } else if(kw == "h/integ") { 275 286 h_integ(tokens); return(0); 276 //#ifndef SANS_EVOLPLANCK277 287 } else if(kw == "v/integ") { 278 288 v_integ(tokens); return(0); 279 //#endif 289 } else if(kw == "v/sort") { 290 v_sort(tokens); return(0); 280 291 } else if(kw == "h/deriv") { 281 292 h_deriv(tokens); return(0); 282 //#ifndef SANS_EVOLPLANCK283 293 } else if(kw == "v/deriv") { 284 294 v_deriv(tokens); return(0); 285 //#endif286 295 } else if(kw == "h/rebin") { 287 296 h_rebin(tokens); return(0); … … 737 746 {line[lc-1]='\0'; lc = strlen(line); if(lc<1) continue;} 738 747 739 // On vire les blancs au debut et a la fin 740 char *newline = line; 741 for(int i=0;i<lc;i++) if(newline[i]!=' ') {newline = &line[i]; break;} 742 lc = strlen(newline); if(lc<1) continue; 743 for(int i=lc-1;i>=0;i--) if(newline[i]==' ') newline[i]='\0'; else break; 744 lc = strlen(newline); if(lc<1) continue; 745 string const sline(newline); 748 string const sline(line); 746 749 //cout<<"\'"<<sline<<"\' lc="<<lc<<endl; 747 750 … … 790 793 // Decodage de la ligne 791 794 vector<string> vs; 792 FillVStringFrString(sline,vs,separator); 795 //FillVStringFrString(sline,vs,separator); 796 SplitStringToVString(sline,vs,separator); 793 797 int lvs = vs.size(); 798 //for(int i=0;i<lvs;i++) cout<<"|"<<vs[i]<<"| "; cout<<endl; 794 799 if(lvs<numcolmaxi) continue; // Pas assez de champs decodes, mauvaise ligne 795 800 … … 954 959 norm /= (*v)(n-1); 955 960 for(uint_4 i=0;i<n;i++) (*v)(i) *= norm; 961 } 962 963 /* methode */ 964 void PAWExecutor::v_sort(vector<string>& tokens) 965 // Pour sort in-place d'un vecteur ascendant ou descendant 966 { 967 if(tokens.size()<1) 968 {cout<<"Usage: v/sort namevec [+1/-1]"<<endl; return;} 969 NamedObjMgr omg; 970 AnyDataObj* mobj = omg.GetObj(tokens[0]); 971 if(mobj==NULL) 972 {cout<<"PAWExecutor::v_sort Error: unknow object"<<tokens[0]<<endl; 973 return;} 974 975 bool up = true; 976 if(tokens.size()>=2) if(atoi(tokens[1].c_str())<0) up=false; 977 978 { 979 TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj); 980 if(v) { 981 if(v->Size()==0) return; 982 if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_r8); 983 else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_r8); 984 cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl; 985 return; 986 } 987 } 988 989 { 990 TVector<r_4>* v = dynamic_cast<TVector<r_4>*>(mobj); 991 if(v) { 992 if(v->Size()==0) return; 993 if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_r4); 994 else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_r4); 995 cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl; 996 return; 997 } 998 } 999 1000 { 1001 TVector<int_4>* v = dynamic_cast<TVector<int_4>*>(mobj); 1002 if(v) { 1003 if(v->Size()==0) return; 1004 if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_i4); 1005 else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_i4); 1006 cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl; 1007 return; 1008 } 1009 } 1010 1011 { 1012 TVector<uint_8>* v = dynamic_cast<TVector<uint_8>*>(mobj); 1013 if(v) { 1014 if(v->Size()==0) return; 1015 if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_u8); 1016 else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_u8); 1017 cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl; 1018 return; 1019 } 1020 } 1021 1022 cout<<"PAWExecutor::v_sort Error: "<<tokens[0] 1023 <<" not a TVector or not a supported TVector<TYPE>"<<endl; 1024 return; 1025 956 1026 } 957 1027
Note:
See TracChangeset
for help on using the changeset viewer.