source: Sophya/trunk/SophyaLib/HiStats/basedtable.h@ 2827

Last change on this file since 2827 was 2827, checked in by ansari, 20 years ago

Modifs code BaseDataTable , DataTable et SwPPFDataTable pour la prise en compte
de colonnes de type complex (complex<r_4> ComplexField et complex<r_8> DoubleComplexField ) Reza , 2 Nov 2005

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