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

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

Defition de mktemp dans xntuple.cc avec compilation conditionnelle pour le mac.
Faudrais inclure cela proprement dans unixmax. Je laisse ce soin a Eric A.

Dominique Yvon

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