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