Changeset 2809 in Sophya for trunk/SophyaPI/PIext/pawexecut.cc


Ignore:
Timestamp:
Jun 14, 2005, 2:40:31 PM (20 years ago)
Author:
cmv
Message:

n/merge/col merging ntuples by columns cmv 14/06/2005

File:
1 edited

Legend:

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

    r2792 r2809  
    117117
    118118kw = "n/merge";
    119 usage = "Merge ntuples";
     119usage = "Merge ntuples (by adding lines)";
    120120usage += "\n n/merge nt nt_1 nt_2 ... nt_n";
    121 usage += "\n Merge ntuples nt_i into ntuple nt";
     121usage += "\n Merge ntuples nt_i lines into ntuple nt";
     122piac->RegisterCommand(kw,usage,this,hgrp);
     123
     124kw = "n/merge/col";
     125usage = "Merge ntuples (by adding columns)";
     126usage += "\n n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]";
     127usage += "\n Merge ntuples nt_i columns into ntuple nt";
     128usage += "\n ext : character string to add at the end of the ntuple variable names";
     129usage += "\n   if \"ext\"=\"!\" no extension is added";
     130usage += "\n   if no \"ext\" is given, automatic extension \"_0\" \"_1\" \"_2\" ...";
    122131piac->RegisterCommand(kw,usage,this,hgrp);
    123132
     
    286295} else if(kw == "n/merge") {
    287296  n_merge(tokens); return(0);
     297} else if(kw == "n/merge/col") {
     298  n_merge_col(tokens); return(0);
    288299} else if(kw == "h/integ") {
    289300  h_integ(tokens); return(0);
     
    668679 int numcolmaxi=-1;
    669680
    670  for(int i=2;i<tokens.size();i++) {
     681 for(int i=2;i<(int_4)tokens.size();i++) {
    671682   int lc = tokens[i].size();
    672683   if(lc<2) continue;
     
    714725   if(onlyreadin.size()>0) {
    715726     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]<<"\'";
    717728     cout<<endl;
    718729   }
    719730   if(onlyreadbeg.size()>0) {
    720731     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]<<"\'";
    722733     cout<<endl;
    723734   }
    724735   if(donotreadin.size()>0) {
    725736     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]<<"\'";
    727738     cout<<endl;
    728739   }
    729740   if(donotreadbeg.size()>0) {
    730741     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]<<"\'";
    732743     cout<<endl;
    733744   }
     
    766777 while(fgets(line,__LENLINE_N_READ__,fascii) != NULL ) {
    767778   nline++;
    768    int lc = strlen(line); if(lc<1) continue;
     779   uint_4 lc = strlen(line); if(lc<1) continue;
    769780   // Pour enlever le \n final
    770781   if(line[lc-1]=='\n' || line[lc-1]=='\r')
     
    778789   if(onlyreadin.size()>0 || onlyreadbeg.size()>0) read_line_1 = false;
    779790   if(onlyreadin.size()>0) {
    780      for(int i=0;i<onlyreadin.size();i++) {
     791     for(int i=0;i<(int_4)onlyreadin.size();i++) {
    781792       uint_4 p = sline.find(onlyreadin[i].c_str());
    782793       if(p>=lc) continue;
     
    786797   }
    787798   if(onlyreadbeg.size()>0) {
    788      for(int i=0;i<onlyreadbeg.size();i++) {
     799     for(int i=0;i<(int_4)onlyreadbeg.size();i++) {
    789800       uint_4 p = sline.find(onlyreadbeg[i].c_str());
    790801       if(p!=0) continue;
     
    797808   bool read_line_2 = true;
    798809   if(donotreadin.size()>0) {
    799      for(int i=0;i<donotreadin.size();i++) {
     810     for(int i=0;i<(int_4)donotreadin.size();i++) {
    800811       uint_4 p = sline.find(donotreadin[i].c_str());
    801812       if(p>=lc) continue;
     
    805816   }
    806817   if(donotreadbeg.size()>0) {
    807      for(int i=0;i<donotreadbeg.size();i++) {
     818     for(int i=0;i<(int_4)donotreadbeg.size();i++) {
    808819       uint_4 p = sline.find(donotreadbeg[i].c_str());
    809820       if(p!=0) continue;
     
    862873{
    863874 if(tokens.size()<2) {
    864    cerr<<"Usage: n/read nt nt_1 nt_2 ... nt_n"<<endl;
     875   cerr<<"Usage: n/merge nt nt_1 nt_2 ... nt_n"<<endl;
    865876   return;
    866877 }
     
    876887 r_8 *xnt=NULL;
    877888
    878  for(int i=1;i<tokens.size();i++) {
     889 for(int i=1;i<(int_4)tokens.size();i++) {
    879890
    880891   AnyDataObj* mobj = omg.GetObj(tokens[i]);
    881892   if(mobj==NULL) {
    882893     cout<<"n_merge Error: unknow object"<<tokens[i]<<endl;
    883      continue;;
     894     continue;
    884895   }
    885896   NTuple* nt1 = dynamic_cast<NTuple*>(mobj);
     
    913924   r_8 *xnt1 = new r_8[n];
    914925   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++) {
    916927     nt1->GetVecD(iev,xnt1);
    917928     nt->Fill(xnt1);
     
    928939   if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt;
    929940 }
     941 return;
     942}
     943
     944/* methode */
     945void 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
    9301044 return;
    9311045}
Note: See TracChangeset for help on using the changeset viewer.