[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); }
|
---|
| 39 | inline sa_size_t AddFloatColumn(const char * cnom)
|
---|
| 40 | { return AddColumn(FloatField, cnom); }
|
---|
| 41 | inline sa_size_t AddFloatColumn(string const & cnom)
|
---|
| 42 | { return AddColumn(FloatField, cnom); }
|
---|
| 43 | inline sa_size_t AddDoubleColumn(const char * cnom)
|
---|
| 44 | { return AddColumn(DoubleField, cnom); }
|
---|
| 45 | inline sa_size_t AddDoubleColumn(string const & cnom)
|
---|
| 46 | { return AddColumn(DoubleField, cnom); }
|
---|
| 47 |
|
---|
| 48 | inline sa_size_t AddColumn(FieldType ft, const char * cnom)
|
---|
| 49 | { string nom = cnom; return AddColumn(ft, nom); }
|
---|
| 50 |
|
---|
| 51 | //! Pure virtual method for adding a new column to the Data Table
|
---|
| 52 | virtual sa_size_t AddColumn(FieldType ft, string const & cnom) = 0;
|
---|
| 53 | //! Duplicate the data table structure from the source Table
|
---|
| 54 | virtual sa_size_t CopyStructure(BaseDataTable const & a);
|
---|
| 55 | //! Checks if the two table have the same column structure
|
---|
| 56 | virtual bool CompareStructure(BaseDataTable const & a);
|
---|
| 57 |
|
---|
| 58 | // Verifie la validite du nom de colonne:envoie une exception
|
---|
| 59 | // si nom en double ou non valide
|
---|
| 60 | virtual bool CheckColName(string const & cnom);
|
---|
| 61 |
|
---|
| 62 | // Acces to various counts and parameters
|
---|
| 63 | inline sa_size_t NEntry() const { return mNEnt ; }
|
---|
| 64 | inline sa_size_t NVar() const { return mNames.size() ; }
|
---|
| 65 | inline sa_size_t NVars() const { return mNames.size() ; }
|
---|
| 66 | inline sa_size_t SegmentSize() const { return mSegSz ; }
|
---|
| 67 | inline sa_size_t NbSegments() const { return mNSeg ; }
|
---|
| 68 |
|
---|
| 69 | // Filling data structures (adding lines)
|
---|
| 70 | virtual sa_size_t AddLine(const r_8* data);
|
---|
| 71 | virtual sa_size_t AddLine(const MuTyV * data);
|
---|
| 72 |
|
---|
| 73 | inline sa_size_t Fill(const r_8* data)
|
---|
| 74 | { return AddLine(data); }
|
---|
| 75 | inline sa_size_t Fill(const MuTyV * data);
|
---|
| 76 |
|
---|
| 77 | virtual sa_size_t Extend();
|
---|
| 78 |
|
---|
| 79 | // Getting a given line (record) information
|
---|
| 80 | virtual MuTyV * GetLine(sa_size_t n) const ;
|
---|
| 81 |
|
---|
| 82 | sa_size_t IndexNom(char const* nom) const ;
|
---|
| 83 | inline sa_size_t IndexNom(string const & nom) const
|
---|
| 84 | { return IndexNom(nom.c_str()); }
|
---|
| 85 | string NomIndex(sa_size_t k) const ;
|
---|
| 86 |
|
---|
| 87 | //! Copy or merges the data from \b a into the data table (cp=true -> copy)
|
---|
| 88 | virtual void CopyMerge(BaseDataTable const& a, bool cp=false) ;
|
---|
| 89 | //! Equal (copy) operator
|
---|
| 90 | inline BaseDataTable& operator = (BaseDataTable const& a)
|
---|
| 91 | { CopyMerge(a, true) ; return *this ; }
|
---|
| 92 |
|
---|
| 93 | void Print(int num, int nmax=1) const ;
|
---|
| 94 |
|
---|
| 95 | void Show(ostream& os) const ;
|
---|
| 96 | inline void Show() const { Show(cout) ; }
|
---|
| 97 |
|
---|
| 98 | DVList& Info() const ;
|
---|
| 99 |
|
---|
| 100 | // Remplissage depuis fichier ASCII
|
---|
| 101 | int FillFromASCIIFile(string const& fn);
|
---|
| 102 |
|
---|
| 103 | // Declaration de l interface NTuple
|
---|
| 104 | virtual sa_size_t NbLines() const ;
|
---|
| 105 | virtual sa_size_t NbColumns() const ;
|
---|
| 106 | virtual r_8 * GetLineD(sa_size_t n) const ;
|
---|
| 107 | virtual r_8 GetCell(sa_size_t n, sa_size_t k) const ;
|
---|
| 108 | virtual r_8 GetCell(sa_size_t n, string const & nom) const ;
|
---|
| 109 | virtual string GetCelltoString(sa_size_t n, sa_size_t k) const ;
|
---|
| 110 | virtual void GetMinMax(sa_size_t k, double& min, double& max) const ;
|
---|
| 111 | virtual void GetMinMax(string const & nom, double& min, double& max) const ;
|
---|
| 112 | virtual sa_size_t ColumnIndex(string const & nom) const ;
|
---|
| 113 | virtual string ColumnName(sa_size_t k) const;
|
---|
| 114 | virtual string VarList_C(const char* nomx=NULL) const ;
|
---|
| 115 | virtual string LineHeaderToString() const;
|
---|
| 116 | virtual string LineToString(sa_size_t n) const;
|
---|
| 117 |
|
---|
| 118 | protected:
|
---|
| 119 | uint_8 mNEnt ; // nb total d'entrees
|
---|
| 120 | uint_8 mSegSz ; // taille bloc/segment
|
---|
| 121 | uint_8 mNSeg; // Nb total de segments
|
---|
| 122 | mutable r_8 * mVarD; // Pour retourner une ligne de la table
|
---|
| 123 | mutable MuTyV * mVarMTV; // Pour retourner une ligne de la table en MuTyV
|
---|
| 124 |
|
---|
| 125 | typedef struct {
|
---|
| 126 | string nom;
|
---|
| 127 | FieldType type;
|
---|
| 128 | sa_size_t ser;
|
---|
| 129 | } colst;
|
---|
| 130 | std::vector<colst> mNames;
|
---|
| 131 |
|
---|
| 132 | mutable DVList* mInfo; // Infos (variables) attachees au NTuple
|
---|
| 133 |
|
---|
| 134 | // Pour calculer et garder le min/max
|
---|
| 135 | mutable std::vector<r_8> mMin;
|
---|
| 136 | mutable std::vector<r_8> mMax;
|
---|
| 137 | mutable std::vector<uint_8> mMinMaxNEnt;
|
---|
| 138 |
|
---|
| 139 | // Les pointeurs des SegDataBlock ...
|
---|
| 140 | std::vector< SegDBInterface<int_4> * > mIColsP;
|
---|
| 141 | std::vector< sa_size_t > mIColIdx;
|
---|
| 142 | std::vector< SegDBInterface<int_8> * > mLColsP;
|
---|
| 143 | std::vector< sa_size_t > mLColIdx;
|
---|
| 144 | std::vector< SegDBInterface<r_4> * > mFColsP;
|
---|
| 145 | std::vector< sa_size_t > mFColIdx;
|
---|
| 146 | std::vector< SegDBInterface<r_8> * > mDColsP;
|
---|
| 147 | std::vector< sa_size_t > mDColIdx;
|
---|
| 148 | std::vector< SegDBInterface<string> * > mSColsP;
|
---|
| 149 | std::vector< sa_size_t > mSColIdx;
|
---|
| 150 |
|
---|
| 151 | };
|
---|
| 152 | /*! Prints table information (Column name and type, min/max) on stream \b s (bd.Show(s)) */
|
---|
| 153 | inline ostream& operator << (ostream& s, BaseDataTable const & bd)
|
---|
| 154 | { bd.Show(s); return(s); }
|
---|
| 155 |
|
---|
| 156 | } // namespace SOPHYA
|
---|
| 157 |
|
---|
| 158 | #endif
|
---|