| 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>
 | 
|---|
| 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 | //  Forward class declaration for Fits handler
 | 
|---|
| 22 | class FITS_NTuple;
 | 
|---|
| 23 | //  Forward class declaration for Thread-safe operations
 | 
|---|
| 24 | class ThSafeOp;
 | 
|---|
| 25 | 
 | 
|---|
| 26 | //! Class for creation and management of double or float data sets in a table
 | 
|---|
| 27 | class NTuple : public AnyDataObj , public NTupleInterface {
 | 
|---|
| 28 | 
 | 
|---|
| 29 | public:
 | 
|---|
| 30 |   NTuple();
 | 
|---|
| 31 |   NTuple(int nvar, char** noms, int blk=512, bool fgdouble=true);
 | 
|---|
| 32 |   NTuple(vector<string>& noms, int blk=512, bool fgdouble=true);
 | 
|---|
| 33 |   NTuple(const NTuple& NT);
 | 
|---|
| 34 |   virtual ~NTuple();
 | 
|---|
| 35 | 
 | 
|---|
| 36 |   // Activate/deactivate thread-safe Fill operation
 | 
|---|
| 37 |   void SetThreadSafe(bool fg=true);
 | 
|---|
| 38 |   //! Return true if Fill  operations are thread-safe
 | 
|---|
| 39 |   inline bool IsThreadSafe() const { return ((mThS)?true:false); }
 | 
|---|
| 40 | 
 | 
|---|
| 41 |   NTuple& operator = (const NTuple& NT);
 | 
|---|
| 42 |  
 | 
|---|
| 43 |   void              Fill(r_4* x);
 | 
|---|
| 44 |   void              Fill(r_8* x);
 | 
|---|
| 45 |   //! Return the number of lines (rows) in the table)
 | 
|---|
| 46 |   inline int_4      NEntry() const  { return(mNEnt); }
 | 
|---|
| 47 |   //! Return the number of columns in the tables (number of cells in a row)  
 | 
|---|
| 48 |   inline int_4      NVar() const { return(mNVar); }  
 | 
|---|
| 49 |   //! Return the bloc size 
 | 
|---|
| 50 |   inline int_4      BLock() const { return(mBlk); }  
 | 
|---|
| 51 | // $CHECK$ Reza 21/10/99 Pourquoi faire BLock() ?
 | 
|---|
| 52 | 
 | 
|---|
| 53 |   //! Return the content of the cell for line (row) \b n , column \b k
 | 
|---|
| 54 |   float             GetVal(int n, int k)   const;
 | 
|---|
| 55 |   //! Return the content of the cell for line (row) \b and column name \b nom
 | 
|---|
| 56 |   inline float      GetVal(int n, const char* nom) const 
 | 
|---|
| 57 |                             { return(GetVal(n, IndexNom(nom)) ); }
 | 
|---|
| 58 |   int               IndexNom(const char* nom)  const ;
 | 
|---|
| 59 |   char*             NomIndex(int k) const;
 | 
|---|
| 60 |   //! Return the content of line \b n as a vector of r_4 (float)
 | 
|---|
| 61 |   r_4*              GetVec(int n, r_4* ret=NULL)  const ;
 | 
|---|
| 62 |   //! Return the content of line \b n as a vector of r_8 (double)
 | 
|---|
| 63 |   r_8*              GetVecD(int n, r_8* ret=NULL)  const ;
 | 
|---|
| 64 | 
 | 
|---|
| 65 | // Impression, I/O
 | 
|---|
| 66 |   void              Print(int num, int nmax=1)  const ;
 | 
|---|
| 67 |   void              Show(ostream& os) const;
 | 
|---|
| 68 |   inline void       Show() const { Show(cout); }
 | 
|---|
| 69 | 
 | 
|---|
| 70 |   //! Return the associated DVList object 
 | 
|---|
| 71 |   DVList&           Info();
 | 
|---|
| 72 | 
 | 
|---|
| 73 | // Remplissage depuis fichier ASCII 
 | 
|---|
| 74 |   int               FillFromASCIIFile(string const& fn, float defval=0.);
 | 
|---|
| 75 | 
 | 
|---|
| 76 | 
 | 
|---|
| 77 | // Declaration de l interface NTuple
 | 
|---|
| 78 |   virtual sa_size_t     NbLines() const ;
 | 
|---|
| 79 |   virtual sa_size_t     NbColumns() const ;
 | 
|---|
| 80 |   virtual r_8 *         GetLineD(sa_size_t n) const ;
 | 
|---|
| 81 |   virtual r_8           GetCell(sa_size_t n, sa_size_t k) const ;
 | 
|---|
| 82 |   virtual r_8           GetCell(sa_size_t n, string const & nom) const ;
 | 
|---|
| 83 |   virtual void          GetMinMax(sa_size_t k, double& min, double& max)   const ; 
 | 
|---|
| 84 |   virtual void          GetMinMax(string const & nom, double& min, double& max)   const ; 
 | 
|---|
| 85 |   virtual sa_size_t     ColumnIndex(string const & nom)  const ;
 | 
|---|
| 86 |   virtual string        ColumnName(sa_size_t k) const;
 | 
|---|
| 87 |   virtual string        VarList_C(const char* nomx=NULL) const ;
 | 
|---|
| 88 |   virtual string        LineHeaderToString() const;
 | 
|---|
| 89 |   virtual string        LineToString(sa_size_t n) const;  
 | 
|---|
| 90 | 
 | 
|---|
| 91 | //  Pour la gestion de persistance
 | 
|---|
| 92 |   friend class ObjFileIO<NTuple> ;
 | 
|---|
| 93 | 
 | 
|---|
| 94 |   // pour fichiers FITS
 | 
|---|
| 95 |   friend class FITS_NTuple;
 | 
|---|
| 96 | 
 | 
|---|
| 97 | private:
 | 
|---|
| 98 |   void  Clean();
 | 
|---|
| 99 | 
 | 
|---|
| 100 |   int_4 mNVar, mNEnt, mBlk, mNBlk;
 | 
|---|
| 101 |   r_4* mVar;
 | 
|---|
| 102 |   r_8* mVarD;
 | 
|---|
| 103 |   vector<string> mNames;
 | 
|---|
| 104 | 
 | 
|---|
| 105 |   bool mFgDouble;      // true -> les donnees sont gardees en double
 | 
|---|
| 106 |   vector<r_4*> mPtr;    // Pointeur de tableau float
 | 
|---|
| 107 |   vector<r_8*> mPtrD;   // Pointeur de tableau double
 | 
|---|
| 108 | 
 | 
|---|
| 109 |   DVList* mInfo;        // Infos (variables) attachees au NTuple
 | 
|---|
| 110 |   
 | 
|---|
| 111 |   ThSafeOp* mThS;       // != NULL -> Thread safe operations
 | 
|---|
| 112 | };
 | 
|---|
| 113 | 
 | 
|---|
| 114 | /*! Prints table information on stream \b s (nt.Show(s)) */
 | 
|---|
| 115 | inline ostream& operator << (ostream& s, NTuple const & nt)
 | 
|---|
| 116 |   {  nt.Show(s);  return(s);  }
 | 
|---|
| 117 | 
 | 
|---|
| 118 | /*! Writes the object in the POutPersist stream \b os */
 | 
|---|
| 119 | inline POutPersist& operator << (POutPersist& os, NTuple & obj)
 | 
|---|
| 120 | { ObjFileIO<NTuple> fio(&obj);  fio.Write(os);  return(os); }
 | 
|---|
| 121 | /*! Reads the object from the PInPersist stream \b is */
 | 
|---|
| 122 | inline PInPersist& operator >> (PInPersist& is, NTuple & obj)
 | 
|---|
| 123 | { ObjFileIO<NTuple> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
 | 
|---|
| 124 | 
 | 
|---|
| 125 | // Classe pour la gestion de persistance
 | 
|---|
| 126 | // ObjFileIO<NTuple>
 | 
|---|
| 127 | 
 | 
|---|
| 128 | 
 | 
|---|
| 129 | } // namespace SOPHYA
 | 
|---|
| 130 | 
 | 
|---|
| 131 | #endif
 | 
|---|
| 132 |   
 | 
|---|