Index: trunk/SophyaPI/PIext/pawexecut.cc
===================================================================
--- trunk/SophyaPI/PIext/pawexecut.cc	(revision 2800)
+++ trunk/SophyaPI/PIext/pawexecut.cc	(revision 2809)
@@ -117,7 +117,16 @@
 
 kw = "n/merge";
-usage = "Merge ntuples";
+usage = "Merge ntuples (by adding lines)";
 usage += "\n n/merge nt nt_1 nt_2 ... nt_n";
-usage += "\n Merge ntuples nt_i into ntuple nt";
+usage += "\n Merge ntuples nt_i lines into ntuple nt";
+piac->RegisterCommand(kw,usage,this,hgrp);
+
+kw = "n/merge/col";
+usage = "Merge ntuples (by adding columns)";
+usage += "\n n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]";
+usage += "\n Merge ntuples nt_i columns into ntuple nt";
+usage += "\n ext : character string to add at the end of the ntuple variable names";
+usage += "\n   if \"ext\"=\"!\" no extension is added";
+usage += "\n   if no \"ext\" is given, automatic extension \"_0\" \"_1\" \"_2\" ...";
 piac->RegisterCommand(kw,usage,this,hgrp);
 
@@ -286,4 +295,6 @@
 } else if(kw == "n/merge") {
   n_merge(tokens); return(0);
+} else if(kw == "n/merge/col") {
+  n_merge_col(tokens); return(0);
 } else if(kw == "h/integ") {
   h_integ(tokens); return(0);
@@ -668,5 +679,5 @@
  int numcolmaxi=-1;
 
- for(int i=2;i<tokens.size();i++) {
+ for(int i=2;i<(int_4)tokens.size();i++) {
    int lc = tokens[i].size();
    if(lc<2) continue;
@@ -714,20 +725,20 @@
    if(onlyreadin.size()>0) {
      cout<<"n_read Only read line containing ["<<onlyreadin.size()<<"]:";
-     for(int i=0;i<onlyreadin.size();i++) cout<<" \'"<<onlyreadin[i]<<"\'";
+     for(int i=0;i<(int_4)onlyreadin.size();i++) cout<<" \'"<<onlyreadin[i]<<"\'";
      cout<<endl;
    }
    if(onlyreadbeg.size()>0) {
      cout<<"n_read Only read line begining with ["<<onlyreadbeg.size()<<"]:";
-     for(int i=0;i<onlyreadbeg.size();i++) cout<<" \'"<<onlyreadbeg[i]<<"\'";
+     for(int i=0;i<(int_4)onlyreadbeg.size();i++) cout<<" \'"<<onlyreadbeg[i]<<"\'";
      cout<<endl;
    }
    if(donotreadin.size()>0) {
      cout<<"n_read Do not read line containing ["<<donotreadin.size()<<"]:";
-     for(int i=0;i<donotreadin.size();i++) cout<<" \'"<<donotreadin[i]<<"\'";
+     for(int i=0;i<(int_4)donotreadin.size();i++) cout<<" \'"<<donotreadin[i]<<"\'";
      cout<<endl;
    }
    if(donotreadbeg.size()>0) {
      cout<<"n_read Do not read line begining with ["<<donotreadbeg.size()<<"]:";
-     for(int i=0;i<donotreadbeg.size();i++) cout<<" \'"<<donotreadbeg[i]<<"\'";
+     for(int i=0;i<(int_4)donotreadbeg.size();i++) cout<<" \'"<<donotreadbeg[i]<<"\'";
      cout<<endl;
    }
@@ -766,5 +777,5 @@
  while(fgets(line,__LENLINE_N_READ__,fascii) != NULL ) {
    nline++;
-   int lc = strlen(line); if(lc<1) continue;
+   uint_4 lc = strlen(line); if(lc<1) continue;
    // Pour enlever le \n final
    if(line[lc-1]=='\n' || line[lc-1]=='\r')
@@ -778,5 +789,5 @@
    if(onlyreadin.size()>0 || onlyreadbeg.size()>0) read_line_1 = false;
    if(onlyreadin.size()>0) {
-     for(int i=0;i<onlyreadin.size();i++) {
+     for(int i=0;i<(int_4)onlyreadin.size();i++) {
        uint_4 p = sline.find(onlyreadin[i].c_str());
        if(p>=lc) continue;
@@ -786,5 +797,5 @@
    }
    if(onlyreadbeg.size()>0) {
-     for(int i=0;i<onlyreadbeg.size();i++) {
+     for(int i=0;i<(int_4)onlyreadbeg.size();i++) {
        uint_4 p = sline.find(onlyreadbeg[i].c_str());
        if(p!=0) continue;
@@ -797,5 +808,5 @@
    bool read_line_2 = true;
    if(donotreadin.size()>0) {
-     for(int i=0;i<donotreadin.size();i++) {
+     for(int i=0;i<(int_4)donotreadin.size();i++) {
        uint_4 p = sline.find(donotreadin[i].c_str());
        if(p>=lc) continue;
@@ -805,5 +816,5 @@
    }
    if(donotreadbeg.size()>0) {
-     for(int i=0;i<donotreadbeg.size();i++) {
+     for(int i=0;i<(int_4)donotreadbeg.size();i++) {
        uint_4 p = sline.find(donotreadbeg[i].c_str());
        if(p!=0) continue;
@@ -862,5 +873,5 @@
 {
  if(tokens.size()<2) {
-   cerr<<"Usage: n/read nt nt_1 nt_2 ... nt_n"<<endl;
+   cerr<<"Usage: n/merge nt nt_1 nt_2 ... nt_n"<<endl;
    return;
  }
@@ -876,10 +887,10 @@
  r_8 *xnt=NULL;
 
- for(int i=1;i<tokens.size();i++) {
+ for(int i=1;i<(int_4)tokens.size();i++) {
 
    AnyDataObj* mobj = omg.GetObj(tokens[i]);
    if(mobj==NULL) {
      cout<<"n_merge Error: unknow object"<<tokens[i]<<endl;
-     continue;;
+     continue;
    }
    NTuple* nt1 = dynamic_cast<NTuple*>(mobj);
@@ -913,5 +924,5 @@
    r_8 *xnt1 = new r_8[n];
    for(int i=0;i<n;i++) xnt1[i]=0.;
-   for(uint_4 iev=0;iev<nt1->NEntry();iev++) {
+   for(uint_4 iev=0;iev<(uint_4)nt1->NEntry();iev++) {
      nt1->GetVecD(iev,xnt1);
      nt->Fill(xnt1);
@@ -928,4 +939,107 @@
    if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt;
  }
+ return;
+}
+
+/* methode */
+void PAWExecutor::n_merge_col(vector<string>& tokens)
+{
+ if(tokens.size()<2) {
+   cerr<<"Usage: n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]"<<endl;
+   return;
+ }
+
+ NamedObjMgr omg;
+
+ // decodage des arguments
+ string nament = tokens[0];
+
+ // boucle sur les ntuples
+ uint_4 numnt=0, nentmax=0, ipos=0;
+ vector<string> varname;
+ vector<string> ntname;
+ vector<int> posfirst;
+ for(int i=1;i<(int_4)tokens.size();i++) {
+
+   // Decode NTuple name and extension
+   int_4 lc = tokens[i].size();
+   string ntn = tokens[i];
+   string ext = "";
+   int p = ntn.find(',');
+   if(p>=0 && p<lc) {
+     if(p<lc-1) ext = ntn.substr(p+1,lc-p-1);
+     if(p>0) ntn = ntn.substr(0,p); else ntn = "";
+   }
+   // choose the extentsion: given,automatic,none
+   if(ext.size()<1) {
+     char str[8]; sprintf(str,"_%d",numnt);
+     ext = str;
+   } else if(ext[0] == '!') {
+     ext = "";
+   }
+
+   AnyDataObj* mobj = omg.GetObj(ntn);
+   if(mobj==NULL) {
+     cout<<"n_merge_col Error: unknow object "<<ntn<<" ("<<tokens[i]<<")"<<endl;
+     continue;
+   }
+   NTuple* nt1 = dynamic_cast<NTuple*>(mobj);
+   if(nt1==NULL) {
+     cout<<"n_merge_col Error: "<<ntn<<" not a NTuple"<<endl;
+     continue;
+   }
+   if(nt1->NEntry()==0) {
+     cout<<"n_merge_col Error: "<<ntn<<" is empty"<<endl;
+     continue;
+   }
+   if(nt1->NVar()==0) {
+     cout<<"n_merge_col Error: "<<ntn<<" has no variable"<<endl;
+     continue;
+   }
+
+   ntname.push_back(ntn);
+   posfirst.push_back(ipos);
+   if(nt1->NEntry()>(int_4)nentmax) nentmax = nt1->NEntry();
+   for(int i=0;i<nt1->NVar();i++) {
+     string str = nt1->ColumnName(i) + ext;
+     varname.push_back(str);
+   }
+   numnt++;
+   ipos += nt1->NVar();
+ }
+
+ if(ntname.size()==0) {
+   cout<<"n_merge_col Error: no ntuple found in argument list"<<endl;
+   return;
+ } else cout<<"Number of NTuple found "<<ntname.size()
+            <<", Number of variables "<<varname.size()
+            <<", Max_entries "<<nentmax<<endl;
+
+ // create receiving ntuple
+ int nvar = varname.size();
+ char **ntvn = new char*[nvar];
+ for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(varname[i].c_str());
+ NTuple * nt = new NTuple(nvar,ntvn);
+ //for(int i=0;i<(int_4)ntname.size();i++) cout<<ntname[i]<<" , p="<<posfirst[i]<<endl;
+ delete [] ntvn;
+
+ // filling with current ntuple
+ r_8 *xnt = new r_8[nvar];
+ for(int iev=0;iev<(int_4)nentmax;iev++) {
+   for(int i=0;i<nvar;i++) xnt[i]=0.;
+   for(int i=0;i<(int_4)ntname.size();i++) {
+     AnyDataObj* mobj = omg.GetObj(ntname[i]);
+     NTuple* nt1 = dynamic_cast<NTuple*>(mobj);
+     if(iev < nt1->NEntry())  nt1->GetVecD(iev,&xnt[posfirst[i]]);
+   }
+   nt->Fill(xnt);
+ }
+
+ // Ending and saving merging ntuple columns
+ delete [] xnt;
+ cout<<"n_merge_col: ntuple filled with "<<ntname.size()
+     <<" ntuples, "<<nt->NEntry()<<" entries"<<endl;
+ if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt;
+
  return;
 }
Index: trunk/SophyaPI/PIext/pawexecut.h
===================================================================
--- trunk/SophyaPI/PIext/pawexecut.h	(revision 2800)
+++ trunk/SophyaPI/PIext/pawexecut.h	(revision 2809)
@@ -28,4 +28,5 @@
   void  n_read(vector<string>& tokens);
   void  n_merge(vector<string>& tokens);
+  void  n_merge_col(vector<string>& tokens);
   void  h_integ(vector<string>& tokens);
   void  v_integ(vector<string>& tokens);
