Index: /trunk/SophyaLib/HiStats/basedtable.cc
===================================================================
--- /trunk/SophyaLib/HiStats/basedtable.cc	(revision 2848)
+++ /trunk/SophyaLib/HiStats/basedtable.cc	(revision 2849)
@@ -3,4 +3,57 @@
 #include "sopnamsp.h"
 #include "pexceptions.h"
+
+/*!
+   \class SOPHYA::DataTableRow
+   \ingroup HiStats
+   This class is intented to be used with datatable classes
+   (inheriting from BaseDataTable) for representing a row (line)
+   of the table. 
+*/
+DataTableRow::DataTableRow( vector<string>& colnames )
+{
+  if (colnames.size() < 1) 
+    throw ParmError("DataTableRow::DataTableRow(vector<string>& cn) cn.size()==0 ");
+  size_ = colnames.size();
+  mtv_ = new MuTyV[ size_ ];
+  for(sa_size_t k=0; k<size_; k++) 
+    nm2idx_[colnames[k]] = k;
+}
+
+DataTableRow::DataTableRow(DataTableRow const & a )
+{
+  size_ = a.size_;
+  mtv_ = new MuTyV[ size_ ];
+  nm2idx_ = a.nm2idx_;
+}
+
+MuTyV DataTableRow::get(string const& colname) const
+{
+  map<string, sa_size_t>::const_iterator it = nm2idx_.find(colname);
+  if (it == nm2idx_.end()) { 
+    string msg = "DataTableRow::get( " ;
+    msg += colname;    msg += " ) Not found column name";
+    throw NotFoundExc(msg);
+  }
+  return mtv_[(*it).second];
+}
+
+MuTyV& DataTableRow::get(string const& colname) 
+{
+  map<string, sa_size_t>::const_iterator it = nm2idx_.find(colname);
+  if (it == nm2idx_.end()) { 
+    string msg = "DataTableRow::get( " ;
+    msg += colname;    msg += " ) const - Not found column name";
+    throw NotFoundExc(msg);
+  }
+  return mtv_[(*it).second];
+}
+
+ostream&   DataTableRow::Print(ostream& os) const
+{
+  for(sa_size_t k=0; k<size_; k++) 
+    os << (string)mtv_[k] << " ";
+  return os;
+}
 
 /*!
@@ -143,4 +196,19 @@
 }
 
+// Retourne une structure
+/*!
+ The returned BaseDataTable object can be used for subsequent call to 
+ AddRow() or GetRow() methods.
+ Generate an exception if called for a table with no columns
+*/
+DataTableRow BaseDataTable::EmptyRow()
+{
+  if (NCols == 0) 
+    throw ParmError("BaseDataTable::EmptyRow() Table has no column !");
+  vector<string> nms;
+  for(sa_size_t k=0; k<NVar(); k++)  nms.push_back(mNames[k].nom);
+  return DataTableRow(nms);
+}
+
 // 
 // A quel index correspond mon nom ? 
@@ -162,5 +230,5 @@
 }
 
-//! Adds a line (or row to the table) with r_8* inout data
+//! Adds a row (or line) to the table with r_8* inout data
 /*! 
   The data to be added is provided as an array (vector) of double (r_8).
@@ -171,8 +239,8 @@
   (data[k] k=0..NbColumns()) 
 */
-sa_size_t BaseDataTable::AddLine(const r_8* data)
+sa_size_t BaseDataTable::AddRow(const r_8* data)
 {
   if (NVar() == 0) 
-    throw ParmError("BaseDataTable::AddLine(const r_8*) Table has no column !");
+    throw ParmError("BaseDataTable::AddRow(const r_8*) Table has no column !");
   if (NEntry() == SegmentSize()*NbSegments())  Extend();
   sa_size_t n = NEntry();
@@ -198,5 +266,5 @@
 }
 
-//! Adds a line (or row to the table) with input data as an array of MuTyV
+//! Adds a row (or line) to the table with input data as an array of MuTyV
 /*! 
   The data to be added is provided as an array (vector) of MuTyV.
@@ -207,8 +275,8 @@
   (data[k] k=0..NbColumns()) 
 */
-sa_size_t BaseDataTable::AddLine(const MuTyV* data)
+sa_size_t BaseDataTable::AddRow(const MuTyV* data)
 {
   if (NVar() == 0) 
-    throw ParmError("BaseDataTable::AddLine(const MuTyV*) Table has no column !");
+    throw ParmError("BaseDataTable::AddRow(const MuTyV*) Table has no column !");
   if (NEntry() == SegmentSize()*NbSegments())  Extend();
   sa_size_t n = NEntry();
@@ -235,5 +303,24 @@
   return mNEnt;
 }
-
+//! Adds a row (or line) to the table with input data as DataTableRow object
+/*! 
+  The internal MuTyV array of the object contains the date and the 
+  MuTyV class conversion operators are used to match against each 
+  cell data type.
+  Only the size of the input data object is checked.
+  Return the new number of table rows (lines / entries)
+  \param data : Data  for each cell of the row to be appended 
+  (data[k] k=0..NbColumns()) 
+*/
+sa_size_t BaseDataTable::AddRow(DataTableRow const& data)
+{
+  if ( data.Size() != NCols() )
+    throw SzMismatchError(" BaseDataTable::AddRow() - data.Size() != NCols() ");
+  return AddRow(data.MTVPtr());
+}
+
+/*! 
+  Extends the table (in the row direction). This method is called automatically when needed.
+*/
 sa_size_t BaseDataTable::Extend()
 {
@@ -256,9 +343,24 @@
 }
 
-
-MuTyV* BaseDataTable::GetLine(sa_size_t n) const 
+/*!
+  Fills the input \b row object with the content of row \b n.
+  Return a reference to the input \b row object. 
+  Generate an exception if the input \b row object has the wrong size.
+  This method is slower(less efficient) than the GetRow(n) method.
+*/
+DataTableRow& BaseDataTable::GetRow(sa_size_t n, DataTableRow& row) const
+{
+  if ( row.Size() != NCols() )
+    throw SzMismatchError(" BaseDataTable::GetRow(n, row) - row.Size() != NCols() ");
+  MuTyV* rmtv = GetRow(n);
+  for(sa_size_t k=0; k<NCols(); k++)
+    row[k] = rmtv[k];
+  return row;
+}
+
+MuTyV* BaseDataTable::GetRow(sa_size_t n) const 
 {
   if ((n < 0) || (n >= NEntry())) 
-    throw RangeCheckError("BaseDataTable::GetLine() out of range line index n");
+    throw RangeCheckError("BaseDataTable::GetRow() out of range line index n");
   if (mVarMTV == NULL) mVarMTV = new MuTyV[NVar()];
 
@@ -345,5 +447,5 @@
   }
   for(sa_size_t kk=0; kk<a.NEntry(); kk++) 
-    AddLine(a.GetLine(kk));
+    AddRow(a.GetLine(kk));
 }
 
@@ -456,5 +558,5 @@
 	}
       }
-      AddLine(mVarMTV);
+      AddRow(mVarMTV);
       nl++;
     }
Index: /trunk/SophyaLib/HiStats/basedtable.h
===================================================================
--- /trunk/SophyaLib/HiStats/basedtable.h	(revision 2848)
+++ /trunk/SophyaLib/HiStats/basedtable.h	(revision 2849)
@@ -12,4 +12,5 @@
 #include <string>
 #include <vector>
+#include <map>
 
 #include <complex>
@@ -24,4 +25,47 @@
 //  Forward class declaration for Fits handler
 template <class T>  class FitsHandler;
+
+//! Class for representing and manipulating DataTable rows.  
+class DataTableRow {
+public:
+//! Constructor - For use by BaseDataTable class
+  DataTableRow( vector<string>& colnames );
+//! Copy constructor
+  DataTableRow( DataTableRow const & a );
+//! Returns the value for column \b k. No bound checking performed 
+  inline MuTyV      operator[]  (sa_size_t k)  const { return mtv_[k]; }
+//! Returns a reference to the value of column \b k. No bound checking performed 
+  inline MuTyV&     operator[]  (sa_size_t k)  { return mtv_[k]; }
+//! Returns the value for column \b colname. 
+  inline MuTyV      operator[]  (string const& colname)  const { return get(colname); }
+//! Returns a reference to the value of column \b k. 
+  inline MuTyV&     operator[]  (string const& colname)   { return get(colname); }
+//! Returns the value for column \b colname. 
+  inline MuTyV      operator[]  (const char* colname)  const 
+  { string sc(colname); return get(sc); }
+//! Returns a reference to the value of column \b k. 
+  inline MuTyV&     operator[]  (const char* colname)   
+  { string sc(colname); return get(sc); }
+//! Returns the value for column \b colname. 
+  MuTyV      get(string const& colname) const;
+//! Returns a reference to the value of column \b k. 
+  MuTyV&     get(string const& colname);
+//! Acces to the MuTyV pointer
+  inline sa_size_t  Size() const { return size_; }
+//! Acces to the MuTyV pointer
+  inline MuTyV const *     MTVPtr() const { return mtv_; }
+//! Acces to the MuTyV pointer
+  inline MuTyV*     MTVPtr() { return mtv_; }
+//! prints the object content on the output stream 
+  ostream&   Print(ostream& os) const;
+protected:
+  MuTyV * mtv_;
+  sa_size_t size_;
+  map<string , sa_size_t> nm2idx_;
+};
+
+/*! Prints the DataTableRow object content on the output stream ( */
+inline ostream& operator << (ostream& s, DataTableRow const & row)
+  {  row.Print(s);  return(s);  }
 
 //! Interface definition for classes handling data in a table.
@@ -109,5 +153,9 @@
   // Acces to various counts and parameters
   //! Return the number of lines (rows) in the table)
+  inline sa_size_t  NRows() const { return mNEnt ; }
+  //! Return the number of lines (rows) in the table)
   inline sa_size_t  NEntry() const { return mNEnt ; }
+  //! Return the number of columns in the tables (number of cells in a row)  
+  inline sa_size_t  NCols() const   { return mNames.size() ; } 
   //! Return the number of columns in the tables (number of cells in a row)  
   inline sa_size_t  NVar() const   { return mNames.size() ; } 
@@ -119,18 +167,38 @@
   inline sa_size_t  NbSegments() const   { return mNSeg ; } 
 
-  // Filling data structures (adding lines)
-  virtual sa_size_t AddLine(const r_8* data);
-  virtual sa_size_t AddLine(const MuTyV * data);
-
+  //! Return a compatible DataTableRow object (with table column names)
+  virtual DataTableRow  EmptyRow();
+
+  // Filling data structures (adding lines/rows)
+  virtual sa_size_t AddRow(const r_8* data);
+  // Filling data structures (adding lines/rows)
+  virtual sa_size_t AddRow(const MuTyV * data);
+  // Filling data structures (adding lines/rows)
+  virtual sa_size_t AddRow(DataTableRow const & data);
+
+  //! Alias for AddRow()
+  inline sa_size_t  AddLine(const r_8* data)
+  { return AddRow(data); }
+  //! Alias for AddRow()
+  inline sa_size_t  AddLine(const MuTyV * data)
+  { return AddRow(data); }
   //! Alias for AddLine()
+  inline sa_size_t  AddLine(DataTableRow const & data)
+  { return AddRow(data); }
+
+  //! Alias for AddRow() - Kept for backward compatibility with NTuple class interface.
   inline sa_size_t  Fill(const r_8* data)
-  { return AddLine(data); }
-  //! Alias for AddLine()
-  inline sa_size_t  Fill(const MuTyV * data);
-     
+  { return AddRow(data); }
+
+  // Pour etendre la table -      
   virtual sa_size_t Extend();
 
-  //! Return the information stored in line \b n of the table 
-  virtual MuTyV *   GetLine(sa_size_t n) const ;
+  //! Return the information stored in row \b n of the table in \b row object
+  virtual DataTableRow&   GetRow(sa_size_t n, DataTableRow& row) const ;
+  //! Return the information stored in line (row) \b n of the table 
+  virtual MuTyV *   GetRow(sa_size_t n) const ;
+  //! Return the information stored in line \b n of the table. Alias of GetLine 
+  inline  MuTyV *   GetLine(sa_size_t n) const 
+  { return GetRow(n); }
 
   //! Return the information stored in column \b k of the table, converted to double 
Index: /trunk/SophyaLib/HiStats/datatable.cc
===================================================================
--- /trunk/SophyaLib/HiStats/datatable.cc	(revision 2848)
+++ /trunk/SophyaLib/HiStats/datatable.cc	(revision 2849)
@@ -15,4 +15,5 @@
    The whole data set is kept in memory.
    \sa SOPHYA::MuTyV
+   \sa SOPHYA::DataTableRow
    \sa SOPHYA::BaseDataTable
    \sa SOPHYA::SegDataBlock
@@ -28,5 +29,5 @@
    for(int i=0; i<63; i++) {
      x[0] = (i%9)-4.;  x[1] = (i/9)-3.;  x[2] = x[0]*x[0]+x[1]*x[1];
-     dt.AddLine(x);
+     dt.AddRow(x);
    }
    // Printing table info
@@ -36,4 +37,15 @@
    po << dt ;
    \endcode
+
+  DataTableRow objects can also be used to fill the table, or access the data, as
+  shown in the example below:
+  \code
+  // We use the same table as in the example above:
+  DataTableRow row = dt.EmptyRow();
+  row[0] = 83.3; row[1] = 20.;   row[2] = 83.3*83.3+20.*20.;
+  dt.AddRow(row);
+  row["X0_f"] = 7.5; row["X1_f"] = 6.;  row["X0X0pX1X1_d"] = 7.5*7.5+6.*6.;
+  dt.AddRow(row);  
+  \endcode
 */
 
Index: /trunk/SophyaLib/HiStats/swppfdtable.cc
===================================================================
--- /trunk/SophyaLib/HiStats/swppfdtable.cc	(revision 2848)
+++ /trunk/SophyaLib/HiStats/swppfdtable.cc	(revision 2849)
@@ -25,4 +25,5 @@
 
    \sa SOPHYA::MuTyV
+   \sa SOPHYA::DataTableRow
    \sa SOPHYA::DataTable
    \sa SOPHYA::SwSegDataBlock  SOPHYA::PPFDataSwapper
