[763] | 1 | // -*- C++ -*-
|
---|
| 2 | //
|
---|
| 3 | // XNTuple
|
---|
| 4 | //
|
---|
| 5 | // N. Regnault 03/98
|
---|
| 6 | // 07/99 (NTupleInterface)
|
---|
| 7 | //
|
---|
| 8 | //
|
---|
| 9 | #ifndef XNTUPLE_H_SEEN
|
---|
| 10 | #define XNTUPLE_H_SEEN
|
---|
| 11 |
|
---|
[1012] | 12 | #include "machdefs.h"
|
---|
[763] | 13 |
|
---|
| 14 | #include <string.h>
|
---|
| 15 | #include <vector>
|
---|
| 16 | #include <list>
|
---|
| 17 | #include <map>
|
---|
| 18 |
|
---|
| 19 | #include "ntupintf.h"
|
---|
| 20 | #include "ppersist.h"
|
---|
| 21 | #include "dvlist.h"
|
---|
[1012] | 22 | #include "objfio.h"
|
---|
[763] | 23 |
|
---|
[829] | 24 |
|
---|
[763] | 25 | namespace SOPHYA {
|
---|
| 26 | //
|
---|
| 27 | // Bloc de donnees
|
---|
| 28 | //
|
---|
[2808] | 29 | //! \cond Pour ne pas inclure dans la documentation
|
---|
[763] | 30 | struct NTBlk
|
---|
| 31 | {
|
---|
| 32 | NTBlk(int ndvar, int nfvar, int nivar, int nsvar, int strsz, int sz) ;
|
---|
| 33 | ~NTBlk() ;
|
---|
| 34 |
|
---|
| 35 | void free() ; // ne libere que les zones de donnees
|
---|
| 36 |
|
---|
| 37 | int sw ; // swappe ?
|
---|
| 38 | long int swoff ; // offset dans fichier de swap
|
---|
[1012] | 39 | r_4* fdata ;
|
---|
| 40 | r_8* ddata ;
|
---|
[763] | 41 | int_4* idata ;
|
---|
| 42 | char* sdata ;
|
---|
| 43 | } ;
|
---|
[2808] | 44 | //! \endcond
|
---|
[869] | 45 | // Forward class declaration for Fits handler
|
---|
| 46 | class FITS_XNTuple;
|
---|
[763] | 47 |
|
---|
[2808] | 48 | //! Class for creation and management of data sets organised as a table
|
---|
[763] | 49 | class XNTuple : public AnyDataObj , public NTupleInterface {
|
---|
| 50 | public:
|
---|
| 51 | // enum {classId = ClassId_XNTuple };
|
---|
| 52 |
|
---|
| 53 | XNTuple() ;
|
---|
| 54 | XNTuple(int ndvar, int nfvar, int nivar, int nsvar,
|
---|
| 55 | char** vnames,
|
---|
| 56 | int blk=512, int maxblk=100, int strsz=30) ;
|
---|
| 57 | XNTuple(XNTuple const& nt) ;
|
---|
| 58 | XNTuple(string const & flnm);
|
---|
| 59 | virtual ~XNTuple();
|
---|
| 60 |
|
---|
[1012] | 61 | void Fill(r_8* d_data, r_4* f_data, int_4* i_data, char** sdata);
|
---|
[763] | 62 |
|
---|
| 63 | inline int_4 NEntry() const { return mNEnt ; }
|
---|
| 64 | inline int_4 NDVar() const { return mD ; }
|
---|
| 65 | inline int_4 NFVar() const { return mF ; }
|
---|
| 66 | inline int_4 NIVar() const { return mI ; }
|
---|
| 67 | inline int_4 NSVar() const { return mS ; }
|
---|
| 68 | inline int_4 NVar() const { return mNVars ; }
|
---|
| 69 | int IndexNom(char const* nom) const ;
|
---|
| 70 | string NomIndex(int k) const ;
|
---|
| 71 |
|
---|
[1012] | 72 | r_8 GetDVal(int i, int k) const ;
|
---|
| 73 | r_4 GetFVal(int i, int k) const ;
|
---|
| 74 | int_4 GetIVal(int i, int k) const ;
|
---|
[763] | 75 | string GetSVal(int i, int k) const ;
|
---|
| 76 | // MuTyV GetVal(char const* nom) ;
|
---|
| 77 |
|
---|
| 78 | void Copy(XNTuple const& nt) ;
|
---|
| 79 | inline XNTuple& operator=(XNTuple const& nt) { Copy(nt) ; return *this ; }
|
---|
| 80 |
|
---|
| 81 | void Print(int num, int nmax=1) const ;
|
---|
| 82 | void Show(ostream& os) const ;
|
---|
| 83 | inline void Show() const { Show(cout) ; }
|
---|
| 84 |
|
---|
| 85 | DVList& Info() ;
|
---|
| 86 |
|
---|
| 87 | // Remplissage depuis fichier ASCII
|
---|
[1012] | 88 | int FillFromASCIIFile(string const& fn, r_8 ddfval=0., r_4 dfval=0.,
|
---|
[763] | 89 | int dival=0, const char * dsval="");
|
---|
| 90 |
|
---|
[2109] | 91 | static void SetSwapPath(char* p=NULL) ;
|
---|
[763] | 92 | string& SwapPath() { return swp ; }
|
---|
| 93 |
|
---|
| 94 | // Declaration de l interface NTuple
|
---|
[2682] | 95 | virtual sa_size_t NbLines() const ;
|
---|
| 96 | virtual sa_size_t NbColumns() const ;
|
---|
| 97 | virtual r_8 * GetLineD(sa_size_t n) const ;
|
---|
| 98 | virtual r_8 GetCell(sa_size_t n, sa_size_t k) const ;
|
---|
| 99 | virtual r_8 GetCell(sa_size_t n, string const & nom) const ;
|
---|
| 100 | virtual string GetCelltoString(sa_size_t n, sa_size_t k) const ;
|
---|
| 101 | virtual void GetMinMax(sa_size_t k, double& min, double& max) const ;
|
---|
[763] | 102 | virtual void GetMinMax(string const & nom, double& min, double& max) const ;
|
---|
[2682] | 103 | virtual sa_size_t ColumnIndex(string const & nom) const ;
|
---|
| 104 | virtual string ColumnName(sa_size_t k) const;
|
---|
[763] | 105 | virtual string VarList_C(const char* nomx=NULL) const ;
|
---|
| 106 | virtual string LineHeaderToString() const;
|
---|
[2682] | 107 | virtual string LineToString(sa_size_t n) const;
|
---|
[763] | 108 |
|
---|
| 109 | // Pour la gestion de persistance
|
---|
| 110 | friend class ObjFileIO<XNTuple> ;
|
---|
[1046] | 111 |
|
---|
| 112 |
|
---|
| 113 | // pour fichiers FITS
|
---|
[846] | 114 | friend class FITS_XNTuple;
|
---|
| 115 |
|
---|
| 116 |
|
---|
[763] | 117 | private:
|
---|
[846] | 118 |
|
---|
| 119 |
|
---|
| 120 |
|
---|
[763] | 121 | void clean(); // remet tout a zero
|
---|
| 122 | void swap() const ; // swappe le + ancien blk en memoire
|
---|
| 123 | void read_blk(NTBlk*) const ; // relit le bloc
|
---|
| 124 | void write_blk(NTBlk*) const ; // ecrit un bloc
|
---|
| 125 | void get_blk(int i) const ; // == unswap()
|
---|
| 126 | void add_blk() ; // ajout d'un nouveau bloc
|
---|
| 127 |
|
---|
| 128 | int_4 mNEnt ; // nb total d'entrees
|
---|
| 129 | int_4 mNBlk ; // nb total de blocs
|
---|
| 130 | mutable int_4 mNSwBlk ; // nb blocs swappes
|
---|
| 131 | int_4 mBlkSz ; // taille bloc
|
---|
| 132 | int_4 mBlk ; // bloc courant en ecriture
|
---|
| 133 | int_4 mOff ; // offset dans bloc en ecriture ; pointe sur le premiere case vide
|
---|
| 134 | int_4 mMaxBlk ; // nb max de blocs autorises en memoire
|
---|
| 135 | int_4 mStrSz ; // taille des variables char**
|
---|
| 136 | int_4 mNVars ; // mD + mF + mI + mS
|
---|
| 137 | int_4 mD, mF, mI, mS ; // nb variables de chaque type
|
---|
| 138 |
|
---|
| 139 | r_8* mVarD, *mMin, *mMax ;
|
---|
| 140 |
|
---|
| 141 | //
|
---|
| 142 | // Noms + Prefix --> indiquer le type
|
---|
| 143 | //
|
---|
| 144 | // char* mDNames, *mFNames, *mINames, *mSNames ;
|
---|
| 145 | char* mNames ;
|
---|
| 146 | // typedef less<string> SCmp ;
|
---|
| 147 | // map<string,int,SCmp> mNames ;
|
---|
| 148 |
|
---|
| 149 | // Donnees
|
---|
| 150 | mutable vector<NTBlk*> ptr ;
|
---|
| 151 | mutable list<NTBlk*> sw ; // liste --> swap()
|
---|
| 152 |
|
---|
| 153 | mutable FILE* swf ; // fichier --> swap
|
---|
| 154 | mutable char* swf_name ;
|
---|
| 155 | string swp ; // swap_path
|
---|
| 156 |
|
---|
| 157 | DVList* mInfo; // Infos (variables) attachees au NTuple
|
---|
| 158 |
|
---|
| 159 | static char* glob_swp ; // swap_path global
|
---|
| 160 | static long int NbNT ;
|
---|
| 161 | };
|
---|
| 162 |
|
---|
[1405] | 163 | /*! Prints table information on stream \b s (nt.Show(os)) */
|
---|
[763] | 164 | inline ostream& operator << (ostream& s, XNTuple const & nt)
|
---|
| 165 | { nt.Show(s); return(s); }
|
---|
| 166 |
|
---|
[1405] | 167 | /*! Writes the object in the POutPersist stream \b os */
|
---|
[763] | 168 | inline POutPersist& operator << (POutPersist& os, XNTuple & obj)
|
---|
| 169 | { ObjFileIO<XNTuple> fio(&obj); fio.Write(os); return(os); }
|
---|
[1405] | 170 | /*! Reads the object from the PInPersist stream \b is */
|
---|
[763] | 171 | inline PInPersist& operator >> (PInPersist& is, XNTuple & obj)
|
---|
[2479] | 172 | { ObjFileIO<XNTuple> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
[763] | 173 |
|
---|
| 174 | // Classe pour la gestion de persistance
|
---|
| 175 | // ObjFileIO<XNTuple>
|
---|
| 176 | } // namespace SOPHYA
|
---|
| 177 |
|
---|
| 178 | #endif
|
---|
| 179 |
|
---|