[763] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // Class NTuple
|
---|
| 3 | // CMV+Reza Juillet 97
|
---|
| 4 | // CEA-DAPNIA LAL-IN2P3/CNRS
|
---|
| 5 |
|
---|
| 6 | #ifndef NTUPLE_H_SEEN
|
---|
| 7 | #define NTUPLE_H_SEEN
|
---|
| 8 |
|
---|
| 9 | #include "objfio.h"
|
---|
| 10 |
|
---|
[2322] | 11 | #include <iostream>
|
---|
[763] | 12 | #include <string>
|
---|
| 13 | #include <vector>
|
---|
| 14 |
|
---|
| 15 | #include "ntupintf.h"
|
---|
| 16 | #include "ppersist.h"
|
---|
| 17 | #include "dvlist.h"
|
---|
| 18 |
|
---|
| 19 | namespace SOPHYA {
|
---|
| 20 |
|
---|
[869] | 21 | // Forward class declaration for Fits handler
|
---|
[2663] | 22 | class FITS_NTuple;
|
---|
[869] | 23 |
|
---|
[2808] | 24 | //! Class for creation and management of double or float data sets in a table
|
---|
[763] | 25 | class NTuple : public AnyDataObj , public NTupleInterface {
|
---|
[846] | 26 |
|
---|
[763] | 27 | public:
|
---|
[2663] | 28 | NTuple();
|
---|
| 29 | NTuple(int nvar, char** noms, int blk=512, bool fgdouble=true);
|
---|
[763] | 30 | NTuple(const NTuple& NT);
|
---|
| 31 | virtual ~NTuple();
|
---|
| 32 |
|
---|
| 33 | NTuple& operator = (const NTuple& NT);
|
---|
| 34 |
|
---|
| 35 | void Fill(r_4* x);
|
---|
[2663] | 36 | void Fill(r_8* x);
|
---|
[2808] | 37 | //! Return the number of lines (rows) in the table)
|
---|
| 38 | inline int_4 NEntry() const { return(mNEnt); }
|
---|
| 39 | //! Return the number of columns in the tables (number of cells in a row)
|
---|
[763] | 40 | inline int_4 NVar() const { return(mNVar); }
|
---|
[2808] | 41 | //! Return the bloc size
|
---|
[763] | 42 | inline int_4 BLock() const { return(mBlk); }
|
---|
| 43 | // $CHECK$ Reza 21/10/99 Pourquoi faire BLock() ?
|
---|
| 44 |
|
---|
[2808] | 45 | //! Return the content of the cell for line (row) \b n , column \b k
|
---|
[763] | 46 | float GetVal(int n, int k) const;
|
---|
[2808] | 47 | //! Return the content of the cell for line (row) \b and column name \b nom
|
---|
[763] | 48 | inline float GetVal(int n, const char* nom) const
|
---|
| 49 | { return(GetVal(n, IndexNom(nom)) ); }
|
---|
| 50 | int IndexNom(const char* nom) const ;
|
---|
| 51 | char* NomIndex(int k) const;
|
---|
[2808] | 52 | //! Return the content of line \b n as a vector of r_4 (float)
|
---|
[763] | 53 | r_4* GetVec(int n, r_4* ret=NULL) const ;
|
---|
[2808] | 54 | //! Return the content of line \b n as a vector of r_8 (double)
|
---|
[763] | 55 | r_8* GetVecD(int n, r_8* ret=NULL) const ;
|
---|
| 56 |
|
---|
| 57 | // Impression, I/O
|
---|
| 58 | void Print(int num, int nmax=1) const ;
|
---|
| 59 | void Show(ostream& os) const;
|
---|
| 60 | inline void Show() const { Show(cout); }
|
---|
| 61 |
|
---|
[2808] | 62 | //! Return the associated DVList object
|
---|
[763] | 63 | DVList& Info();
|
---|
| 64 |
|
---|
| 65 | // Remplissage depuis fichier ASCII
|
---|
| 66 | int FillFromASCIIFile(string const& fn, float defval=0.);
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | // Declaration de l interface NTuple
|
---|
[2682] | 70 | virtual sa_size_t NbLines() const ;
|
---|
| 71 | virtual sa_size_t NbColumns() const ;
|
---|
| 72 | virtual r_8 * GetLineD(sa_size_t n) const ;
|
---|
| 73 | virtual r_8 GetCell(sa_size_t n, sa_size_t k) const ;
|
---|
| 74 | virtual r_8 GetCell(sa_size_t n, string const & nom) const ;
|
---|
| 75 | virtual void GetMinMax(sa_size_t k, double& min, double& max) const ;
|
---|
[763] | 76 | virtual void GetMinMax(string const & nom, double& min, double& max) const ;
|
---|
[2682] | 77 | virtual sa_size_t ColumnIndex(string const & nom) const ;
|
---|
| 78 | virtual string ColumnName(sa_size_t k) const;
|
---|
[763] | 79 | virtual string VarList_C(const char* nomx=NULL) const ;
|
---|
| 80 | virtual string LineHeaderToString() const;
|
---|
[2682] | 81 | virtual string LineToString(sa_size_t n) const;
|
---|
[763] | 82 |
|
---|
| 83 | // Pour la gestion de persistance
|
---|
| 84 | friend class ObjFileIO<NTuple> ;
|
---|
| 85 |
|
---|
[1046] | 86 | // pour fichiers FITS
|
---|
[2663] | 87 | friend class FITS_NTuple;
|
---|
[869] | 88 |
|
---|
[763] | 89 | private:
|
---|
| 90 | void Clean();
|
---|
| 91 |
|
---|
| 92 | int_4 mNVar, mNEnt, mBlk, mNBlk;
|
---|
| 93 | r_4* mVar;
|
---|
| 94 | r_8* mVarD;
|
---|
[2663] | 95 | vector<string> mNames;
|
---|
[763] | 96 |
|
---|
[2663] | 97 | bool mFgDouble; // true -> les donnees sont gardees en double
|
---|
| 98 | vector<r_4*> mPtr; // Pointeur de tableau float
|
---|
| 99 | vector<r_8*> mPtrD; // Pointeur de tableau double
|
---|
[763] | 100 |
|
---|
| 101 | DVList* mInfo; // Infos (variables) attachees au NTuple
|
---|
| 102 |
|
---|
| 103 | };
|
---|
| 104 |
|
---|
[1413] | 105 | /*! Prints table information on stream \b s (nt.Show(s)) */
|
---|
[763] | 106 | inline ostream& operator << (ostream& s, NTuple const & nt)
|
---|
| 107 | { nt.Show(s); return(s); }
|
---|
| 108 |
|
---|
[1405] | 109 | /*! Writes the object in the POutPersist stream \b os */
|
---|
[763] | 110 | inline POutPersist& operator << (POutPersist& os, NTuple & obj)
|
---|
| 111 | { ObjFileIO<NTuple> fio(&obj); fio.Write(os); return(os); }
|
---|
[1405] | 112 | /*! Reads the object from the PInPersist stream \b is */
|
---|
[763] | 113 | inline PInPersist& operator >> (PInPersist& is, NTuple & obj)
|
---|
[2479] | 114 | { ObjFileIO<NTuple> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
[763] | 115 |
|
---|
| 116 | // Classe pour la gestion de persistance
|
---|
| 117 | // ObjFileIO<NTuple>
|
---|
| 118 |
|
---|
[846] | 119 |
|
---|
| 120 |
|
---|
[763] | 121 | #ifdef __MWERKS__
|
---|
| 122 | __MSL_FIX_ITERATORS__(r_4*);
|
---|
| 123 | #endif
|
---|
| 124 |
|
---|
| 125 | } // namespace SOPHYA
|
---|
| 126 |
|
---|
| 127 | #endif
|
---|
| 128 |
|
---|