source: Sophya/trunk/SophyaLib/HiStats/xntuple.h@ 835

Last change on this file since 835 was 835, checked in by ansari, 25 years ago

Recorrection mktemp() pour Mac ds XNTuple - Reza 7/4/2000

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