[763] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // Class NTuple
|
---|
| 3 | // CMV+Reza Juillet 97
|
---|
| 4 | // CEA-DAPNIA LAL-IN2P3/CNRS
|
---|
| 5 |
|
---|
| 6 | #ifndef NTUPLE_H_SEEN
|
---|
| 7 | #define NTUPLE_H_SEEN
|
---|
| 8 |
|
---|
| 9 | #include "objfio.h"
|
---|
| 10 |
|
---|
| 11 | #include <iostream.h>
|
---|
| 12 | #include <string>
|
---|
| 13 | #include <vector>
|
---|
| 14 |
|
---|
| 15 | #include "ntupintf.h"
|
---|
| 16 | #include "ppersist.h"
|
---|
| 17 | #include "dvlist.h"
|
---|
| 18 |
|
---|
| 19 | namespace SOPHYA {
|
---|
| 20 |
|
---|
| 21 | class NTuple : public AnyDataObj , public NTupleInterface {
|
---|
| 22 | public:
|
---|
| 23 | // enum {classId = ClassId_NTuple };
|
---|
| 24 |
|
---|
| 25 | NTuple(int nvar, char** noms, int blk=512);
|
---|
| 26 | NTuple();
|
---|
| 27 | NTuple(const NTuple& NT);
|
---|
| 28 | NTuple(char* flnm);
|
---|
| 29 | virtual ~NTuple();
|
---|
| 30 |
|
---|
| 31 | NTuple& operator = (const NTuple& NT);
|
---|
| 32 |
|
---|
| 33 | void Fill(r_4* x);
|
---|
| 34 |
|
---|
| 35 | inline int_4 NEntry() const { return(mNEnt); }
|
---|
| 36 | inline int_4 NVar() const { return(mNVar); }
|
---|
| 37 | inline int_4 BLock() const { return(mBlk); }
|
---|
| 38 | // $CHECK$ Reza 21/10/99 Pourquoi faire BLock() ?
|
---|
| 39 |
|
---|
| 40 | float GetVal(int n, int k) const;
|
---|
| 41 | inline float GetVal(int n, const char* nom) const
|
---|
| 42 | { return(GetVal(n, IndexNom(nom)) ); }
|
---|
| 43 | int IndexNom(const char* nom) const ;
|
---|
| 44 | char* NomIndex(int k) const;
|
---|
| 45 |
|
---|
| 46 | r_4* GetVec(int n, r_4* ret=NULL) const ;
|
---|
| 47 | r_8* GetVecD(int n, r_8* ret=NULL) const ;
|
---|
| 48 |
|
---|
| 49 | // Impression, I/O
|
---|
| 50 | void Print(int num, int nmax=1) const ;
|
---|
| 51 | void Show(ostream& os) const;
|
---|
| 52 | inline void Show() const { Show(cout); }
|
---|
| 53 |
|
---|
| 54 | DVList& Info();
|
---|
| 55 |
|
---|
| 56 | // Remplissage depuis fichier ASCII
|
---|
| 57 | int FillFromASCIIFile(string const& fn, float defval=0.);
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | // Declaration de l interface NTuple
|
---|
| 61 | virtual uint_4 NbLines() const ;
|
---|
| 62 | virtual uint_4 NbColumns() const ;
|
---|
| 63 | virtual r_8 * GetLineD(int n) const ;
|
---|
| 64 | virtual r_8 GetCell(int n, int k) const ;
|
---|
| 65 | virtual r_8 GetCell(int n, string const & nom) const ;
|
---|
| 66 | virtual void GetMinMax(int k, double& min, double& max) const ;
|
---|
| 67 | virtual void GetMinMax(string const & nom, double& min, double& max) const ;
|
---|
| 68 | virtual int ColumnIndex(string const & nom) const ;
|
---|
| 69 | virtual string ColumnName(int k) const;
|
---|
| 70 | virtual string VarList_C(const char* nomx=NULL) const ;
|
---|
| 71 | virtual string LineHeaderToString() const;
|
---|
| 72 | virtual string LineToString(int n) const;
|
---|
| 73 |
|
---|
| 74 | // Pour la gestion de persistance
|
---|
| 75 | friend class ObjFileIO<NTuple> ;
|
---|
| 76 |
|
---|
| 77 | private:
|
---|
| 78 | void Clean();
|
---|
| 79 |
|
---|
| 80 | int_4 mNVar, mNEnt, mBlk, mNBlk;
|
---|
| 81 | r_4* mVar;
|
---|
| 82 | r_8* mVarD;
|
---|
| 83 | char* mNames;
|
---|
| 84 |
|
---|
| 85 | vector<r_4*> mPtr;
|
---|
| 86 |
|
---|
| 87 | DVList* mInfo; // Infos (variables) attachees au NTuple
|
---|
| 88 |
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | inline ostream& operator << (ostream& s, NTuple const & nt)
|
---|
| 92 | { nt.Show(s); return(s); }
|
---|
| 93 |
|
---|
| 94 | inline POutPersist& operator << (POutPersist& os, NTuple & obj)
|
---|
| 95 | { ObjFileIO<NTuple> fio(&obj); fio.Write(os); return(os); }
|
---|
| 96 | inline PInPersist& operator >> (PInPersist& is, NTuple & obj)
|
---|
| 97 | { ObjFileIO<NTuple> fio(&obj); fio.Read(is); return(is); }
|
---|
| 98 |
|
---|
| 99 | // Classe pour la gestion de persistance
|
---|
| 100 | // ObjFileIO<NTuple>
|
---|
| 101 |
|
---|
| 102 | #ifdef __MWERKS__
|
---|
| 103 | __MSL_FIX_ITERATORS__(r_4*);
|
---|
| 104 | #endif
|
---|
| 105 |
|
---|
| 106 | } // namespace SOPHYA
|
---|
| 107 |
|
---|
| 108 | #endif
|
---|
| 109 |
|
---|