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