[2688] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // Class BaseDataTable
|
---|
| 3 | // R. Ansari - Avril 2005
|
---|
| 4 | // (C) LAL-IN2P3/CNRS CEA-DAPNIA
|
---|
| 5 |
|
---|
| 6 | #ifndef BASEDTABLE_H_SEEN
|
---|
| 7 | #define BASEDTABLE_H_SEEN
|
---|
| 8 |
|
---|
| 9 | #include "machdefs.h"
|
---|
| 10 |
|
---|
| 11 | #include <iostream>
|
---|
| 12 | #include <string>
|
---|
| 13 | #include <vector>
|
---|
| 14 |
|
---|
[2827] | 15 | #include <complex>
|
---|
| 16 |
|
---|
[2688] | 17 | #include "ntupintf.h"
|
---|
| 18 | #include "dvlist.h"
|
---|
| 19 | #include "segdatablock.h"
|
---|
[2831] | 20 | #include "tvector.h"
|
---|
[2688] | 21 |
|
---|
| 22 | namespace SOPHYA {
|
---|
[2822] | 23 |
|
---|
| 24 | // Forward class declaration for Fits handler
|
---|
| 25 | template <class T> class FitsHandler;
|
---|
| 26 |
|
---|
[2808] | 27 | //! Interface definition for classes handling data in a table.
|
---|
[2688] | 28 | class BaseDataTable : public AnyDataObj , public NTupleInterface {
|
---|
| 29 | public:
|
---|
| 30 | // ===> DO NOT CHANGE EXISTING enum type VALUES !!!
|
---|
| 31 | enum FieldType {IntegerField=1, LongField=2,
|
---|
| 32 | FloatField=3, DoubleField=4,
|
---|
| 33 | ComplexField=5, DoubleComplexField=6,
|
---|
[2831] | 34 | StringField=7, DateTimeField=8};
|
---|
[2688] | 35 | // <=====================================================>
|
---|
| 36 |
|
---|
[2831] | 37 | //! Return the column type as a string (long or short depending on fgl=true/false)
|
---|
[2688] | 38 | static string ColTypeToString(FieldType ft, bool fgl=false);
|
---|
[2831] | 39 | //! Return the column type corresponding to \b sctyp
|
---|
| 40 | static FieldType StringToColType(string const & sctyp);
|
---|
[2688] | 41 |
|
---|
| 42 | // constructeur , destructeur
|
---|
| 43 | BaseDataTable(sa_size_t segsz=512);
|
---|
| 44 | virtual ~BaseDataTable();
|
---|
| 45 |
|
---|
[2808] | 46 | //! Adds a column holding integer, named \b cnom
|
---|
[2688] | 47 | inline sa_size_t AddIntegerColumn(const char * cnom)
|
---|
| 48 | { return AddColumn(IntegerField, cnom); }
|
---|
[2808] | 49 | //! Adds a column holding integer, named \b cnom
|
---|
[2688] | 50 | inline sa_size_t AddIntegerColumn(string const & cnom)
|
---|
| 51 | { return AddColumn(IntegerField, cnom); }
|
---|
[2808] | 52 | //! Adds a column holding long integer, named \b cnom
|
---|
[2732] | 53 | inline sa_size_t AddLongColumn(const char * cnom)
|
---|
| 54 | { return AddColumn(LongField, cnom); }
|
---|
[2808] | 55 | //! Adds a column holding long integer, named \b cnom
|
---|
[2732] | 56 | inline sa_size_t AddLongColumn(string const & cnom)
|
---|
| 57 | { return AddColumn(LongField, cnom); }
|
---|
[2808] | 58 | //! Adds a column holding floating values (r_4), named \b cnom
|
---|
[2688] | 59 | inline sa_size_t AddFloatColumn(const char * cnom)
|
---|
| 60 | { return AddColumn(FloatField, cnom); }
|
---|
[2808] | 61 | //! Adds a column holding floating values (r_4), named \b cnom
|
---|
[2688] | 62 | inline sa_size_t AddFloatColumn(string const & cnom)
|
---|
| 63 | { return AddColumn(FloatField, cnom); }
|
---|
[2808] | 64 | //! Adds a column holding double values (r_8), named \b cnom
|
---|
[2688] | 65 | inline sa_size_t AddDoubleColumn(const char * cnom)
|
---|
| 66 | { return AddColumn(DoubleField, cnom); }
|
---|
[2808] | 67 | //! Adds a column holding double values (r_8), named \b cnom
|
---|
[2688] | 68 | inline sa_size_t AddDoubleColumn(string const & cnom)
|
---|
| 69 | { return AddColumn(DoubleField, cnom); }
|
---|
[2827] | 70 | //! Adds a column holding single precision complex values (complex<r_4>), named \b cnom
|
---|
| 71 | inline sa_size_t AddComplexColumn(const char * cnom)
|
---|
| 72 | { return AddColumn(ComplexField, cnom); }
|
---|
| 73 | //! Adds a column holding single precision complex values (complex<r_4>), named \b cnom
|
---|
| 74 | inline sa_size_t AddComplexColumn(string const & cnom)
|
---|
| 75 | { return AddColumn(ComplexField, cnom); }
|
---|
| 76 | //! Adds a column holding double precision complex values (complex<r_8>), named \b cnom
|
---|
| 77 | inline sa_size_t AddDoubleComplexColumn(const char * cnom)
|
---|
| 78 | { return AddColumn(DoubleComplexField, cnom); }
|
---|
| 79 | //! Adds a column holding double precision complex values (complex<r_8>), named \b cnom
|
---|
| 80 | inline sa_size_t AddDoubleComplexColumn(string const & cnom)
|
---|
| 81 | { return AddColumn(DoubleComplexField, cnom); }
|
---|
[2808] | 82 | //! Adds a column holding character strings, named \b cnom
|
---|
[2732] | 83 | inline sa_size_t AddStringColumn(const char * cnom)
|
---|
| 84 | { return AddColumn(StringField, cnom); }
|
---|
[2808] | 85 | //! Adds a column holding character strings, named \b cnom
|
---|
[2732] | 86 | inline sa_size_t AddStringColumn(string const & cnom)
|
---|
| 87 | { return AddColumn(StringField, cnom); }
|
---|
[2831] | 88 | //! Adds a column holding Date/Time value, named \b cnom
|
---|
| 89 | inline sa_size_t AddDateTimeColumn(const char * cnom)
|
---|
| 90 | { return AddColumn(DateTimeField, cnom); }
|
---|
| 91 | //! Adds a column holding Date/Time value, named \b cnom
|
---|
| 92 | inline sa_size_t AddDateTimeColumn(string const & cnom)
|
---|
| 93 | { return AddColumn(DateTimeField, cnom); }
|
---|
[2688] | 94 |
|
---|
| 95 | inline sa_size_t AddColumn(FieldType ft, const char * cnom)
|
---|
| 96 | { string nom = cnom; return AddColumn(ft, nom); }
|
---|
| 97 |
|
---|
| 98 | //! Pure virtual method for adding a new column to the Data Table
|
---|
| 99 | virtual sa_size_t AddColumn(FieldType ft, string const & cnom) = 0;
|
---|
| 100 | //! Duplicate the data table structure from the source Table
|
---|
| 101 | virtual sa_size_t CopyStructure(BaseDataTable const & a);
|
---|
| 102 | //! Checks if the two table have the same column structure
|
---|
| 103 | virtual bool CompareStructure(BaseDataTable const & a);
|
---|
| 104 |
|
---|
| 105 | // Verifie la validite du nom de colonne:envoie une exception
|
---|
| 106 | // si nom en double ou non valide
|
---|
| 107 | virtual bool CheckColName(string const & cnom);
|
---|
| 108 |
|
---|
| 109 | // Acces to various counts and parameters
|
---|
[2808] | 110 | //! Return the number of lines (rows) in the table)
|
---|
[2688] | 111 | inline sa_size_t NEntry() const { return mNEnt ; }
|
---|
[2808] | 112 | //! Return the number of columns in the tables (number of cells in a row)
|
---|
[2688] | 113 | inline sa_size_t NVar() const { return mNames.size() ; }
|
---|
[2808] | 114 | //! Return the number of columns in the tables (number of cells in a row)
|
---|
[2688] | 115 | inline sa_size_t NVars() const { return mNames.size() ; }
|
---|
[2808] | 116 | //! Return the segment size (SegDBInterface objects corresponding to columns)
|
---|
[2688] | 117 | inline sa_size_t SegmentSize() const { return mSegSz ; }
|
---|
[2808] | 118 | //! Return the number of segments (SegDBInterface objects corresponding to columns)
|
---|
[2688] | 119 | inline sa_size_t NbSegments() const { return mNSeg ; }
|
---|
| 120 |
|
---|
| 121 | // Filling data structures (adding lines)
|
---|
| 122 | virtual sa_size_t AddLine(const r_8* data);
|
---|
| 123 | virtual sa_size_t AddLine(const MuTyV * data);
|
---|
[2808] | 124 |
|
---|
| 125 | //! Alias for AddLine()
|
---|
[2688] | 126 | inline sa_size_t Fill(const r_8* data)
|
---|
| 127 | { return AddLine(data); }
|
---|
[2808] | 128 | //! Alias for AddLine()
|
---|
[2688] | 129 | inline sa_size_t Fill(const MuTyV * data);
|
---|
| 130 |
|
---|
| 131 | virtual sa_size_t Extend();
|
---|
| 132 |
|
---|
[2808] | 133 | //! Return the information stored in line \b n of the table
|
---|
[2688] | 134 | virtual MuTyV * GetLine(sa_size_t n) const ;
|
---|
[2808] | 135 |
|
---|
[2831] | 136 | //! Return the information stored in column \b k of the table, converted to double
|
---|
| 137 | virtual TVector<r_8> GetColumnD(sa_size_t k) const ;
|
---|
| 138 |
|
---|
| 139 | //! Return the information stored in column named \b nom of the table, converted to double
|
---|
| 140 | inline TVector<r_8> GetColumnD(char const * nom) const
|
---|
| 141 | { return GetColumnD(IndexNom(nom)) ; }
|
---|
| 142 | //! Return the information stored in column named \b nom of the table, converted to double
|
---|
| 143 | inline TVector<r_8> GetColumnD(string const & nom) const
|
---|
| 144 | { return GetColumnD(IndexNom(nom)) ; }
|
---|
| 145 |
|
---|
[2808] | 146 | //! Return the index for column name \b nom
|
---|
[2688] | 147 | sa_size_t IndexNom(char const* nom) const ;
|
---|
[2808] | 148 | //! Return the index for column name \b nom
|
---|
[2688] | 149 | inline sa_size_t IndexNom(string const & nom) const
|
---|
| 150 | { return IndexNom(nom.c_str()); }
|
---|
[2808] | 151 | //! Return the column name for column index \b k
|
---|
[2688] | 152 | string NomIndex(sa_size_t k) const ;
|
---|
[2732] | 153 |
|
---|
| 154 | //! Return the column type for column \b k (no check on index range)
|
---|
| 155 | inline FieldType GetColumType(sa_size_t k) const
|
---|
| 156 | { return mNames[k].type; }
|
---|
| 157 | //! Return the column name for column \b k (no check on index range)
|
---|
| 158 | inline const string & GetColumName(sa_size_t k) const
|
---|
| 159 | { return mNames[k].nom; }
|
---|
[2688] | 160 |
|
---|
[2732] | 161 |
|
---|
[2688] | 162 | //! Copy or merges the data from \b a into the data table (cp=true -> copy)
|
---|
| 163 | virtual void CopyMerge(BaseDataTable const& a, bool cp=false) ;
|
---|
[2699] | 164 |
|
---|
| 165 | //! Clear/reset the table content and structure.
|
---|
| 166 | virtual void Clear() = 0;
|
---|
| 167 |
|
---|
[2831] | 168 | //! Prints the table content (ascii dump)
|
---|
| 169 | virtual ostream& Print(ostream& os, sa_size_t lstart, sa_size_t lend,
|
---|
| 170 | sa_size_t lstep=1) const ;
|
---|
| 171 | //! Prints the table content (ascii dump) on stream \b os
|
---|
| 172 | inline ostream& Print(ostream& os) const
|
---|
| 173 | { return Print(os, 0, NEntry(), 1); }
|
---|
| 174 | //! Prints the table content (ascii dump) on stream \b os
|
---|
| 175 | inline ostream& WriteASCII(ostream& os) const
|
---|
| 176 | { return Print(os, 0, NEntry(), 1); }
|
---|
| 177 |
|
---|
[2688] | 178 |
|
---|
[2831] | 179 | //! Prints table definition and number of entries
|
---|
[2688] | 180 | void Show(ostream& os) const ;
|
---|
[2808] | 181 | //! Prints table definition and number of entries on the standard output stream \b cout
|
---|
[2688] | 182 | inline void Show() const { Show(cout) ; }
|
---|
| 183 |
|
---|
[2831] | 184 | //! Return the associated DVList (info) object.
|
---|
[2688] | 185 | DVList& Info() const ;
|
---|
| 186 |
|
---|
| 187 | // Remplissage depuis fichier ASCII
|
---|
[2831] | 188 | sa_size_t FillFromASCIIFile(istream& is, char clm='#', const char* sep=" \t");
|
---|
[2688] | 189 |
|
---|
[2699] | 190 | //-------------------------------------------------------------
|
---|
| 191 | //----------- Declaration de l interface NTuple --------------
|
---|
| 192 |
|
---|
[2688] | 193 | virtual sa_size_t NbLines() const ;
|
---|
| 194 | virtual sa_size_t NbColumns() const ;
|
---|
| 195 | virtual r_8 * GetLineD(sa_size_t n) const ;
|
---|
| 196 | virtual r_8 GetCell(sa_size_t n, sa_size_t k) const ;
|
---|
| 197 | virtual r_8 GetCell(sa_size_t n, string const & nom) const ;
|
---|
| 198 | virtual string GetCelltoString(sa_size_t n, sa_size_t k) const ;
|
---|
| 199 | virtual void GetMinMax(sa_size_t k, double& min, double& max) const ;
|
---|
| 200 | virtual void GetMinMax(string const & nom, double& min, double& max) const ;
|
---|
| 201 | virtual sa_size_t ColumnIndex(string const & nom) const ;
|
---|
| 202 | virtual string ColumnName(sa_size_t k) const;
|
---|
| 203 | virtual string VarList_C(const char* nomx=NULL) const ;
|
---|
| 204 | virtual string LineHeaderToString() const;
|
---|
| 205 | virtual string LineToString(sa_size_t n) const;
|
---|
[2699] | 206 |
|
---|
[2831] | 207 | //! Return a table row (line), formatted and converted to a string
|
---|
| 208 | virtual string TableRowToString(sa_size_t n, bool qstr, const char* sep=" ",
|
---|
| 209 | int fw=12) const;
|
---|
| 210 |
|
---|
[2699] | 211 | // Pour la gestion de persistance PPF
|
---|
| 212 | friend class ObjFileIO<BaseDataTable> ;
|
---|
[2822] | 213 | // pour fichiers FITS
|
---|
| 214 | friend class FitsHandler<BaseDataTable>;
|
---|
[2688] | 215 |
|
---|
| 216 | protected:
|
---|
| 217 | uint_8 mNEnt ; // nb total d'entrees
|
---|
| 218 | uint_8 mSegSz ; // taille bloc/segment
|
---|
| 219 | uint_8 mNSeg; // Nb total de segments
|
---|
| 220 | mutable r_8 * mVarD; // Pour retourner une ligne de la table
|
---|
| 221 | mutable MuTyV * mVarMTV; // Pour retourner une ligne de la table en MuTyV
|
---|
[2808] | 222 |
|
---|
| 223 | //! \cond Pour pas inclure ds la documentation doxygen
|
---|
[2688] | 224 | typedef struct {
|
---|
| 225 | string nom;
|
---|
| 226 | FieldType type;
|
---|
| 227 | sa_size_t ser;
|
---|
| 228 | } colst;
|
---|
[2808] | 229 | //! \endcond
|
---|
[2688] | 230 | std::vector<colst> mNames;
|
---|
| 231 |
|
---|
| 232 | mutable DVList* mInfo; // Infos (variables) attachees au NTuple
|
---|
| 233 |
|
---|
| 234 | // Pour calculer et garder le min/max
|
---|
| 235 | mutable std::vector<r_8> mMin;
|
---|
| 236 | mutable std::vector<r_8> mMax;
|
---|
| 237 | mutable std::vector<uint_8> mMinMaxNEnt;
|
---|
| 238 |
|
---|
| 239 | // Les pointeurs des SegDataBlock ...
|
---|
| 240 | std::vector< SegDBInterface<int_4> * > mIColsP;
|
---|
| 241 | std::vector< sa_size_t > mIColIdx;
|
---|
| 242 | std::vector< SegDBInterface<int_8> * > mLColsP;
|
---|
| 243 | std::vector< sa_size_t > mLColIdx;
|
---|
| 244 | std::vector< SegDBInterface<r_4> * > mFColsP;
|
---|
| 245 | std::vector< sa_size_t > mFColIdx;
|
---|
| 246 | std::vector< SegDBInterface<r_8> * > mDColsP;
|
---|
| 247 | std::vector< sa_size_t > mDColIdx;
|
---|
[2827] | 248 | std::vector< SegDBInterface< complex<r_4> > * > mYColsP;
|
---|
| 249 | std::vector< sa_size_t > mYColIdx;
|
---|
| 250 | std::vector< SegDBInterface< complex<r_8> > * > mZColsP;
|
---|
| 251 | std::vector< sa_size_t > mZColIdx;
|
---|
[2688] | 252 | std::vector< SegDBInterface<string> * > mSColsP;
|
---|
| 253 | std::vector< sa_size_t > mSColIdx;
|
---|
| 254 |
|
---|
| 255 | };
|
---|
| 256 | /*! Prints table information (Column name and type, min/max) on stream \b s (bd.Show(s)) */
|
---|
| 257 | inline ostream& operator << (ostream& s, BaseDataTable const & bd)
|
---|
| 258 | { bd.Show(s); return(s); }
|
---|
| 259 |
|
---|
| 260 | } // namespace SOPHYA
|
---|
| 261 |
|
---|
| 262 | #endif
|
---|