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