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

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

Suite a l'intervention de cmv, rend coherent le choix long a la place de int dans xntuple.
Que le magicien verifie, car tout n'est pas transparent. Changement necessaire pour faire compiler fitsxntuple.cc
qui defini iligne en int_4
PB
Dominique

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