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

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

int_4 r_4 r_8 ds XNTuple , Reza 19/5/2000

File size: 5.5 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 "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
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 r_4* fdata ;
39 r_8* ddata ;
40 int_4* idata ;
41 char* sdata ;
42} ;
43
44// Forward class declaration for Fits handler
45class FITS_XNTuple;
46
47class XNTuple : public AnyDataObj , public NTupleInterface {
48public:
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 friend class FITS_XNTuple;
110
111
112private:
113
114 // pour la persistance sur fichiers fits
115 void SetDVal(int i, int k, r_8 v);
116 void SetFVal(int i, int k, r_4 v);
117 void SetIVal(int i, int k, int v);
118 void SetSVal(int i, int k, char* v);
119
120
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
163
164inline ostream& operator << (ostream& s, XNTuple const & nt)
165 { nt.Show(s); return(s); }
166
167inline POutPersist& operator << (POutPersist& os, XNTuple & obj)
168{ ObjFileIO<XNTuple> fio(&obj); fio.Write(os); return(os); }
169inline PInPersist& operator >> (PInPersist& is, XNTuple & obj)
170{ ObjFileIO<XNTuple> fio(&obj); fio.Read(is); return(is); }
171
172// Classe pour la gestion de persistance
173// ObjFileIO<XNTuple>
174} // namespace SOPHYA
175
176#endif
177
Note: See TracBrowser for help on using the repository browser.