Changeset 2708 in Sophya for trunk/SophyaPI/PIext


Ignore:
Timestamp:
Apr 28, 2005, 7:33:16 PM (20 years ago)
Author:
cmv
Message:
  • intro de v/sort
  • acceleration lecture fichiers ASCII n/read

cmv 28/04/05

File:
1 edited

Legend:

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

    r2689 r2708  
    3030
    3131/* Reza + cmv  13/10/99 */
     32
     33inline bool __vector_sort_up_r8(r_8 x1,r_8 x2) {return x1<x2;}
     34inline bool __vector_sort_down_r8(r_8 x1,r_8 x2) {return x1>x2;}
     35inline bool __vector_sort_up_r4(r_4 x1,r_4 x2) {return x1<x2;}
     36inline bool __vector_sort_down_r4(r_4 x1,r_4 x2) {return x1>x2;}
     37inline bool __vector_sort_up_i4(int_4 x1,int_4 x2) {return x1<x2;}
     38inline bool __vector_sort_down_i4(int_4 x1,int_4 x2) {return x1>x2;}
     39inline bool __vector_sort_up_u8(uint_8 x1,uint_8 x2) {return x1<x2;}
     40inline bool __vector_sort_down_u8(uint_8 x1,uint_8 x2) {return x1>x2;}
    3241
    3342uint_4 PAWExecutor::autoc_counter_ = 0;
     
    117126piac->RegisterCommand(kw,usage,this,hgrp);
    118127
    119 //#ifndef SANS_EVOLPLANCK
    120128kw = "v/integ";
    121129usage = "Integrate a TVector / vector";
     
    124132usage += "\n  Related commands: h/integ h/deriv v/deriv";
    125133piac->RegisterCommand(kw,usage,this,hgrp);
    126 //#endif
     134
     135kw = "v/sort";
     136usage = "Sort a vector into itself";
     137usage += "\n v/sort namevec [+1/-1]";
     138usage += "\n \"+1\" means increasing order, \"-1\" decreasing order";
     139piac->RegisterCommand(kw,usage,this,hgrp);
    127140
    128141kw = "h/deriv";
     
    132145piac->RegisterCommand(kw,usage,this,hgrp);
    133146
    134 //#ifndef SANS_EVOLPLANCK
    135147kw = "v/deriv";
    136148usage = "Derivate a TVector / vector";
     
    141153usage += "\n  Related commands: h/integ h/deriv v/integ";
    142154piac->RegisterCommand(kw,usage,this,hgrp);
    143 //#endif
    144155
    145156kw = "h/rebin";
     
    274285} else if(kw == "h/integ") {
    275286  h_integ(tokens); return(0);
    276   //#ifndef SANS_EVOLPLANCK
    277287} else if(kw == "v/integ") {
    278288  v_integ(tokens); return(0);
    279   //#endif
     289} else if(kw == "v/sort") {
     290  v_sort(tokens); return(0);
    280291} else if(kw == "h/deriv") {
    281292  h_deriv(tokens); return(0);
    282   //#ifndef SANS_EVOLPLANCK
    283293} else if(kw == "v/deriv") {
    284294  v_deriv(tokens); return(0);
    285   //#endif
    286295} else if(kw == "h/rebin") {
    287296  h_rebin(tokens); return(0);
     
    737746     {line[lc-1]='\0'; lc = strlen(line); if(lc<1) continue;}
    738747
    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);
    746749   //cout<<"\'"<<sline<<"\'  lc="<<lc<<endl;
    747750
     
    790793   // Decodage de la ligne
    791794   vector<string> vs;
    792    FillVStringFrString(sline,vs,separator);
     795   //FillVStringFrString(sline,vs,separator);
     796   SplitStringToVString(sline,vs,separator);
    793797   int lvs = vs.size();
     798   //for(int i=0;i<lvs;i++) cout<<"|"<<vs[i]<<"| "; cout<<endl;
    794799   if(lvs<numcolmaxi) continue; // Pas assez de champs decodes, mauvaise ligne
    795800
     
    954959norm /= (*v)(n-1);
    955960for(uint_4 i=0;i<n;i++) (*v)(i) *= norm;
     961}
     962
     963/* methode */
     964void 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
    9561026}
    9571027
Note: See TracChangeset for help on using the changeset viewer.