#include "datatable.h" #include "strutil.h" #include "pexceptions.h" #include "fiosegdb.h" #include "thsafeop.h" namespace SOPHYA { /*! \class DataTable \ingroup HiStats This class can be used to organize data in table (row-column) form. Each column holds homogeneous data (same data type), while different columns can be used for different data types (integer, float, string ...). The whole data set is kept in memory. \sa SOPHYA::MuTyV \sa SOPHYA::DataTableRow \sa SOPHYA::BaseDataTable \sa SOPHYA::SegDataBlock \code #include "datatable.h" // ... DataTable dt(64); dt.AddFloatColumn("X0_f"); dt.AddFloatColumn("X1_f"); dt.AddDoubleColumn("X0X0pX1X1_d"); double x[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.AddRow(x); } // Printing table info cout << dt ; // Saving object into a PPF file POutPersist po("dtable.ppf"); 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 */ //! Default constructor - optional specification of block (or segment) size DataTable::DataTable(sa_size_t segsz) : BaseDataTable(segsz) { } //! copy constructor /*! The copy constructur shares the data if \b share=true. Otherwise, the Clone() method is called to make a complete copy. This constructor copies also the thread safety state from \b a . */ DataTable::DataTable(DataTable const & a, bool share) : BaseDataTable(a.SegmentSize()) { if (share) Share(a); else Clone(a); mNEnt = a.mNEnt; mNSeg = a.mNSeg; if (a.mInfo) mInfo = new DVList(*(a.mInfo)); } /*! Copy the table structure from \b a and shares the data (columns content). The tread-safety state is copied from \b a . */ void DataTable::Share(DataTable const & a) { // On copie la structure de table CopyStructure(a); if (a.IsThreadSafe()) SetThreadSafe(true); else SetThreadSafe(false); // Et on partage les donnees des colonnes for (size_t kk=0; kk 0) throw ParmError("DataTable::AddColumn() Table contains already data "); CheckColName(cnom); sa_size_t ser; sa_size_t idx = NVar(); switch (ft) { case IntegerField : ser = mICols.size(); mICols.push_back(SegDataBlock(mSegSz)); mIColIdx.push_back(idx); mIColsP.push_back(NULL); for(sa_size_t kk=0; kk(mSegSz)); mLColIdx.push_back(idx); mLColsP.push_back(NULL); for(sa_size_t kk=0; kk(mSegSz)); mFColIdx.push_back(idx); mFColsP.push_back(NULL); for(sa_size_t kk=0; kk(mSegSz)); mDColIdx.push_back(idx); mDColsP.push_back(NULL); for(sa_size_t kk=0; kk >(mSegSz)); mYColIdx.push_back(idx); mYColsP.push_back(NULL); for(sa_size_t kk=0; kk >(mSegSz)); mZColIdx.push_back(idx); mZColsP.push_back(NULL); for(sa_size_t kk=0; kk(mSegSz)); mSColIdx.push_back(idx); mSColsP.push_back(NULL); for(sa_size_t kk=0; kk