[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 |
|
---|
| 15 | #include "ntupintf.h"
|
---|
| 16 | #include "dvlist.h"
|
---|
| 17 | #include "segdatablock.h"
|
---|
| 18 |
|
---|
| 19 | namespace SOPHYA {
|
---|
| 20 | class BaseDataTable : public AnyDataObj , public NTupleInterface {
|
---|
| 21 | public:
|
---|
| 22 | // ===> DO NOT CHANGE EXISTING enum type VALUES !!!
|
---|
| 23 | enum FieldType {IntegerField=1, LongField=2,
|
---|
| 24 | FloatField=3, DoubleField=4,
|
---|
| 25 | ComplexField=5, DoubleComplexField=6,
|
---|
| 26 | StringField=7, DateField=8};
|
---|
| 27 | // <=====================================================>
|
---|
| 28 |
|
---|
| 29 | static string ColTypeToString(FieldType ft, bool fgl=false);
|
---|
| 30 |
|
---|
| 31 | // constructeur , destructeur
|
---|
| 32 | BaseDataTable(sa_size_t segsz=512);
|
---|
| 33 | virtual ~BaseDataTable();
|
---|
| 34 |
|
---|
| 35 | inline sa_size_t AddIntegerColumn(const char * cnom)
|
---|
| 36 | { return AddColumn(IntegerField, cnom); }
|
---|
| 37 | inline sa_size_t AddIntegerColumn(string const & cnom)
|
---|
| 38 | { return AddColumn(IntegerField, cnom); }
|
---|
[2732] | 39 | inline sa_size_t AddLongColumn(const char * cnom)
|
---|
| 40 | { return AddColumn(LongField, cnom); }
|
---|
| 41 | inline sa_size_t AddLongColumn(string const & cnom)
|
---|
| 42 | { return AddColumn(LongField, cnom); }
|
---|
[2688] | 43 | inline sa_size_t AddFloatColumn(const char * cnom)
|
---|
| 44 | { return AddColumn(FloatField, cnom); }
|
---|
| 45 | inline sa_size_t AddFloatColumn(string const & cnom)
|
---|
| 46 | { return AddColumn(FloatField, cnom); }
|
---|
| 47 | inline sa_size_t AddDoubleColumn(const char * cnom)
|
---|
| 48 | { return AddColumn(DoubleField, cnom); }
|
---|
| 49 | inline sa_size_t AddDoubleColumn(string const & cnom)
|
---|
| 50 | { return AddColumn(DoubleField, cnom); }
|
---|
[2732] | 51 | inline sa_size_t AddStringColumn(const char * cnom)
|
---|
| 52 | { return AddColumn(StringField, cnom); }
|
---|
| 53 | inline sa_size_t AddStringColumn(string const & cnom)
|
---|
| 54 | { return AddColumn(StringField, cnom); }
|
---|
[2688] | 55 |
|
---|
| 56 | inline sa_size_t AddColumn(FieldType ft, const char * cnom)
|
---|
| 57 | { string nom = cnom; return AddColumn(ft, nom); }
|
---|
| 58 |
|
---|
| 59 | //! Pure virtual method for adding a new column to the Data Table
|
---|
| 60 | virtual sa_size_t AddColumn(FieldType ft, string const & cnom) = 0;
|
---|
| 61 | //! Duplicate the data table structure from the source Table
|
---|
| 62 | virtual sa_size_t CopyStructure(BaseDataTable const & a);
|
---|
| 63 | //! Checks if the two table have the same column structure
|
---|
| 64 | virtual bool CompareStructure(BaseDataTable const & a);
|
---|
| 65 |
|
---|
| 66 | // Verifie la validite du nom de colonne:envoie une exception
|
---|
| 67 | // si nom en double ou non valide
|
---|
| 68 | virtual bool CheckColName(string const & cnom);
|
---|
| 69 |
|
---|
| 70 | // Acces to various counts and parameters
|
---|
| 71 | inline sa_size_t NEntry() const { return mNEnt ; }
|
---|
| 72 | inline sa_size_t NVar() const { return mNames.size() ; }
|
---|
| 73 | inline sa_size_t NVars() const { return mNames.size() ; }
|
---|
| 74 | inline sa_size_t SegmentSize() const { return mSegSz ; }
|
---|
| 75 | inline sa_size_t NbSegments() const { return mNSeg ; }
|
---|
| 76 |
|
---|
| 77 | // Filling data structures (adding lines)
|
---|
| 78 | virtual sa_size_t AddLine(const r_8* data);
|
---|
| 79 | virtual sa_size_t AddLine(const MuTyV * data);
|
---|
| 80 |
|
---|
| 81 | inline sa_size_t Fill(const r_8* data)
|
---|
| 82 | { return AddLine(data); }
|
---|
| 83 | inline sa_size_t Fill(const MuTyV * data);
|
---|
| 84 |
|
---|
| 85 | virtual sa_size_t Extend();
|
---|
| 86 |
|
---|
| 87 | // Getting a given line (record) information
|
---|
| 88 | virtual MuTyV * GetLine(sa_size_t n) const ;
|
---|
| 89 |
|
---|
| 90 | sa_size_t IndexNom(char const* nom) const ;
|
---|
| 91 | inline sa_size_t IndexNom(string const & nom) const
|
---|
| 92 | { return IndexNom(nom.c_str()); }
|
---|
| 93 | string NomIndex(sa_size_t k) const ;
|
---|
[2732] | 94 |
|
---|
| 95 | //! Return the column type for column \b k (no check on index range)
|
---|
| 96 | inline FieldType GetColumType(sa_size_t k) const
|
---|
| 97 | { return mNames[k].type; }
|
---|
| 98 | //! Return the column name for column \b k (no check on index range)
|
---|
| 99 | inline const string & GetColumName(sa_size_t k) const
|
---|
| 100 | { return mNames[k].nom; }
|
---|
[2688] | 101 |
|
---|
[2732] | 102 |
|
---|
[2688] | 103 | //! Copy or merges the data from \b a into the data table (cp=true -> copy)
|
---|
| 104 | virtual void CopyMerge(BaseDataTable const& a, bool cp=false) ;
|
---|
[2699] | 105 |
|
---|
| 106 | //! Clear/reset the table content and structure.
|
---|
| 107 | virtual void Clear() = 0;
|
---|
| 108 |
|
---|
| 109 | // ---- ASCII I/O
|
---|
[2688] | 110 | void Print(int num, int nmax=1) const ;
|
---|
| 111 |
|
---|
| 112 | void Show(ostream& os) const ;
|
---|
| 113 | inline void Show() const { Show(cout) ; }
|
---|
| 114 |
|
---|
| 115 | DVList& Info() const ;
|
---|
| 116 |
|
---|
| 117 | // Remplissage depuis fichier ASCII
|
---|
| 118 | int FillFromASCIIFile(string const& fn);
|
---|
| 119 |
|
---|
[2699] | 120 | //-------------------------------------------------------------
|
---|
| 121 | //----------- Declaration de l interface NTuple --------------
|
---|
| 122 |
|
---|
[2688] | 123 | virtual sa_size_t NbLines() const ;
|
---|
| 124 | virtual sa_size_t NbColumns() const ;
|
---|
| 125 | virtual r_8 * GetLineD(sa_size_t n) const ;
|
---|
| 126 | virtual r_8 GetCell(sa_size_t n, sa_size_t k) const ;
|
---|
| 127 | virtual r_8 GetCell(sa_size_t n, string const & nom) const ;
|
---|
| 128 | virtual string GetCelltoString(sa_size_t n, sa_size_t k) const ;
|
---|
| 129 | virtual void GetMinMax(sa_size_t k, double& min, double& max) const ;
|
---|
| 130 | virtual void GetMinMax(string const & nom, double& min, double& max) const ;
|
---|
| 131 | virtual sa_size_t ColumnIndex(string const & nom) const ;
|
---|
| 132 | virtual string ColumnName(sa_size_t k) const;
|
---|
| 133 | virtual string VarList_C(const char* nomx=NULL) const ;
|
---|
| 134 | virtual string LineHeaderToString() const;
|
---|
| 135 | virtual string LineToString(sa_size_t n) const;
|
---|
[2699] | 136 |
|
---|
| 137 | // Pour la gestion de persistance PPF
|
---|
| 138 | friend class ObjFileIO<BaseDataTable> ;
|
---|
[2688] | 139 |
|
---|
| 140 | protected:
|
---|
| 141 | uint_8 mNEnt ; // nb total d'entrees
|
---|
| 142 | uint_8 mSegSz ; // taille bloc/segment
|
---|
| 143 | uint_8 mNSeg; // Nb total de segments
|
---|
| 144 | mutable r_8 * mVarD; // Pour retourner une ligne de la table
|
---|
| 145 | mutable MuTyV * mVarMTV; // Pour retourner une ligne de la table en MuTyV
|
---|
| 146 |
|
---|
| 147 | typedef struct {
|
---|
| 148 | string nom;
|
---|
| 149 | FieldType type;
|
---|
| 150 | sa_size_t ser;
|
---|
| 151 | } colst;
|
---|
| 152 | std::vector<colst> mNames;
|
---|
| 153 |
|
---|
| 154 | mutable DVList* mInfo; // Infos (variables) attachees au NTuple
|
---|
| 155 |
|
---|
| 156 | // Pour calculer et garder le min/max
|
---|
| 157 | mutable std::vector<r_8> mMin;
|
---|
| 158 | mutable std::vector<r_8> mMax;
|
---|
| 159 | mutable std::vector<uint_8> mMinMaxNEnt;
|
---|
| 160 |
|
---|
| 161 | // Les pointeurs des SegDataBlock ...
|
---|
| 162 | std::vector< SegDBInterface<int_4> * > mIColsP;
|
---|
| 163 | std::vector< sa_size_t > mIColIdx;
|
---|
| 164 | std::vector< SegDBInterface<int_8> * > mLColsP;
|
---|
| 165 | std::vector< sa_size_t > mLColIdx;
|
---|
| 166 | std::vector< SegDBInterface<r_4> * > mFColsP;
|
---|
| 167 | std::vector< sa_size_t > mFColIdx;
|
---|
| 168 | std::vector< SegDBInterface<r_8> * > mDColsP;
|
---|
| 169 | std::vector< sa_size_t > mDColIdx;
|
---|
| 170 | std::vector< SegDBInterface<string> * > mSColsP;
|
---|
| 171 | std::vector< sa_size_t > mSColIdx;
|
---|
| 172 |
|
---|
| 173 | };
|
---|
| 174 | /*! Prints table information (Column name and type, min/max) on stream \b s (bd.Show(s)) */
|
---|
| 175 | inline ostream& operator << (ostream& s, BaseDataTable const & bd)
|
---|
| 176 | { bd.Show(s); return(s); }
|
---|
| 177 |
|
---|
| 178 | } // namespace SOPHYA
|
---|
| 179 |
|
---|
| 180 | #endif
|
---|