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

Last change on this file since 2827 was 2808, checked in by ansari, 20 years ago

MAJ documentation - Reza 14/6/2005

File size: 5.7 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//
29//! \cond Pour ne pas inclure dans la documentation
30struct NTBlk
31{
32 NTBlk(int ndvar, int nfvar, int nivar, int nsvar, int strsz, int sz) ;
33 ~NTBlk() ;
34
35 void free() ; // ne libere que les zones de donnees
36
37 int sw ; // swappe ?
38 long int swoff ; // offset dans fichier de swap
39 r_4* fdata ;
40 r_8* ddata ;
41 int_4* idata ;
42 char* sdata ;
43} ;
44//! \endcond
45// Forward class declaration for Fits handler
46class FITS_XNTuple;
47
48//! Class for creation and management of data sets organised as a table
49class XNTuple : public AnyDataObj , public NTupleInterface {
50public:
51 // enum {classId = ClassId_XNTuple };
52
53 XNTuple() ;
54 XNTuple(int ndvar, int nfvar, int nivar, int nsvar,
55 char** vnames,
56 int blk=512, int maxblk=100, int strsz=30) ;
57 XNTuple(XNTuple const& nt) ;
58 XNTuple(string const & flnm);
59 virtual ~XNTuple();
60
61 void Fill(r_8* d_data, r_4* f_data, int_4* i_data, char** sdata);
62
63 inline int_4 NEntry() const { return mNEnt ; }
64 inline int_4 NDVar() const { return mD ; }
65 inline int_4 NFVar() const { return mF ; }
66 inline int_4 NIVar() const { return mI ; }
67 inline int_4 NSVar() const { return mS ; }
68 inline int_4 NVar() const { return mNVars ; }
69 int IndexNom(char const* nom) const ;
70 string NomIndex(int k) const ;
71
72 r_8 GetDVal(int i, int k) const ;
73 r_4 GetFVal(int i, int k) const ;
74 int_4 GetIVal(int i, int k) const ;
75 string GetSVal(int i, int k) const ;
76 // MuTyV GetVal(char const* nom) ;
77
78 void Copy(XNTuple const& nt) ;
79 inline XNTuple& operator=(XNTuple const& nt) { Copy(nt) ; return *this ; }
80
81 void Print(int num, int nmax=1) const ;
82 void Show(ostream& os) const ;
83 inline void Show() const { Show(cout) ; }
84
85 DVList& Info() ;
86
87// Remplissage depuis fichier ASCII
88 int FillFromASCIIFile(string const& fn, r_8 ddfval=0., r_4 dfval=0.,
89 int dival=0, const char * dsval="");
90
91 static void SetSwapPath(char* p=NULL) ;
92 string& SwapPath() { return swp ; }
93
94// Declaration de l interface NTuple
95 virtual sa_size_t NbLines() const ;
96 virtual sa_size_t NbColumns() const ;
97 virtual r_8 * GetLineD(sa_size_t n) const ;
98 virtual r_8 GetCell(sa_size_t n, sa_size_t k) const ;
99 virtual r_8 GetCell(sa_size_t n, string const & nom) const ;
100 virtual string GetCelltoString(sa_size_t n, sa_size_t k) const ;
101 virtual void GetMinMax(sa_size_t k, double& min, double& max) const ;
102 virtual void GetMinMax(string const & nom, double& min, double& max) const ;
103 virtual sa_size_t ColumnIndex(string const & nom) const ;
104 virtual string ColumnName(sa_size_t k) const;
105 virtual string VarList_C(const char* nomx=NULL) const ;
106 virtual string LineHeaderToString() const;
107 virtual string LineToString(sa_size_t n) const;
108
109// Pour la gestion de persistance
110 friend class ObjFileIO<XNTuple> ;
111
112
113 // pour fichiers FITS
114 friend class FITS_XNTuple;
115
116
117private:
118
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/*! Prints table information on stream \b s (nt.Show(os)) */
164inline ostream& operator << (ostream& s, XNTuple const & nt)
165 { nt.Show(s); return(s); }
166
167/*! Writes the object in the POutPersist stream \b os */
168inline POutPersist& operator << (POutPersist& os, XNTuple & obj)
169{ ObjFileIO<XNTuple> fio(&obj); fio.Write(os); return(os); }
170/*! Reads the object from the PInPersist stream \b is */
171inline PInPersist& operator >> (PInPersist& is, XNTuple & obj)
172{ ObjFileIO<XNTuple> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
173
174// Classe pour la gestion de persistance
175// ObjFileIO<XNTuple>
176} // namespace SOPHYA
177
178#endif
179
Note: See TracBrowser for help on using the repository browser.