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