| [1371] | 1 | 
 | 
|---|
| [2615] | 2 | #include "sopnamsp.h"
 | 
|---|
| [1371] | 3 | #include "ntupintf.h"
 | 
|---|
 | 4 | #include <stdlib.h>
 | 
|---|
 | 5 | #include <stdio.h>
 | 
|---|
| [2682] | 6 | #include "pexceptions.h"
 | 
|---|
| [1371] | 7 | 
 | 
|---|
 | 8 | /*!
 | 
|---|
 | 9 |    \class SOPHYA::NTupleInterface
 | 
|---|
 | 10 |    \ingroup HiStats
 | 
|---|
 | 11 |    Interface class (pure virtual) defining generic operations on NTuple,
 | 
|---|
 | 12 |    a 2-dimensional data set with named columns
 | 
|---|
 | 13 | */
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | //++
 | 
|---|
 | 16 | // Class        NTupleInterface
 | 
|---|
| [2142] | 17 | // Lib          HiStats
 | 
|---|
| [1371] | 18 | // include      ntupintf.h
 | 
|---|
 | 19 | //
 | 
|---|
 | 20 | //      Interface permettant de construire des vues NTuples (tableau lignes-colonnes) 
 | 
|---|
 | 21 | //      pour differents objets. Toutes les methodes ont une implementation par defaut. 
 | 
|---|
 | 22 | //--
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | //++
 | 
|---|
 | 25 | // NTupleInterface()
 | 
|---|
 | 26 | //      Constructeur.
 | 
|---|
 | 27 | // virtual ~NTupleInterface()
 | 
|---|
 | 28 | //      Destructeur
 | 
|---|
 | 29 | // uint_4  NbLines() const 
 | 
|---|
 | 30 | //      Nombre de lignes du tableau
 | 
|---|
 | 31 | // uint_4  NbColumns() const 
 | 
|---|
 | 32 | //      Nombre de colonnes du tableau
 | 
|---|
 | 33 | // r_8 *  GetLineD(int n) const
 | 
|---|
 | 34 | //      Renvoie un tableau avec le contenu de la ligne "n"
 | 
|---|
 | 35 | // r_8  GetCell(int n, int k) const
 | 
|---|
 | 36 | //      Renvoie le contenu de la cellule correspondant a la ligne "n"
 | 
|---|
 | 37 | //      et colonne "k"
 | 
|---|
 | 38 | // r_8  GetCell(int n, string const & nom) const
 | 
|---|
 | 39 | //      Renvoie le contenu de la cellule correspondant a la ligne "n"
 | 
|---|
 | 40 | //      pour la colonne identifiee par "nom"
 | 
|---|
 | 41 | // string  GetCelltoString(int n, int k) const
 | 
|---|
 | 42 | //      Renvoie le contenu de la cellule correspondant a la ligne "n"
 | 
|---|
 | 43 | //      et colonne "k", sous forme de chaine de caracteres.
 | 
|---|
 | 44 | // string  GetCell(int n, string const & nom) const
 | 
|---|
 | 45 | //      Renvoie le contenu de la cellule correspondant a la ligne "n"
 | 
|---|
 | 46 | //      pour la colonne identifiee par "nom", sous forme de chaine de caracteres.
 | 
|---|
 | 47 | // void GetMinMax(int k, double& min, double& max)  const
 | 
|---|
 | 48 | //      Renvoie la valeur mini et maxi de la colonne numero "k"
 | 
|---|
 | 49 | // void GetMinMax(string const & nom, double& min, double& max)
 | 
|---|
 | 50 | //      Renvoie la valeur mini et maxi de la colonne identifiee par "nom"
 | 
|---|
 | 51 | // int  ColumnIndex(string const & nom)  const
 | 
|---|
 | 52 | //      Renvoie le numero de colonne identifiee par "nom". Renvoie -1 (negatif)
 | 
|---|
 | 53 | //      si colonne "nom" n'existe pas.
 | 
|---|
 | 54 | // string ColumnName(int k) const
 | 
|---|
 | 55 | //      Renvoie le nom de la colonne numero "k"
 | 
|---|
 | 56 | // string VarList_C(const char* nomx=NULL) const
 | 
|---|
 | 57 | //      Renvoie une chaine avec les declarations "C" pour les
 | 
|---|
 | 58 | //      variables avec les noms de colonnes
 | 
|---|
 | 59 | // string  LineHeaderToString()
 | 
|---|
 | 60 | //      Renvoie une chaine avec les noms de colonnes, utilisables pour l'impression
 | 
|---|
 | 61 | // string  LineToString(int n)
 | 
|---|
 | 62 | //      Renvoie une chaine avec le contenu de la ligne "n", utilisable pour l'impression
 | 
|---|
 | 63 | //--
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 | /* --Methode-- */
 | 
|---|
 | 66 | NTupleInterface::NTupleInterface()
 | 
|---|
 | 67 | {
 | 
|---|
 | 68 | }
 | 
|---|
 | 69 | /* --Methode-- */
 | 
|---|
 | 70 | NTupleInterface::~NTupleInterface()
 | 
|---|
 | 71 | {
 | 
|---|
 | 72 | }
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 | //! Retuns the number of lines (rows) of the data set
 | 
|---|
 | 75 | /* --Methode-- */
 | 
|---|
| [2682] | 76 | sa_size_t NTupleInterface::NbLines() const
 | 
|---|
| [1371] | 77 | {
 | 
|---|
 | 78 | return(0);
 | 
|---|
 | 79 | }
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 | //! Retuns the number of columns of the data set 
 | 
|---|
 | 82 | /* --Methode-- */
 | 
|---|
| [2682] | 83 | sa_size_t NTupleInterface::NbColumns() const
 | 
|---|
| [1371] | 84 | {
 | 
|---|
 | 85 | return(0);
 | 
|---|
 | 86 | }
 | 
|---|
 | 87 | 
 | 
|---|
 | 88 | //! Retuns the content of a given line 
 | 
|---|
 | 89 | /*! 
 | 
|---|
 | 90 |    An array (double *) containg all cells of a given line, converted to 
 | 
|---|
 | 91 |    float values is returned
 | 
|---|
 | 92 | */
 | 
|---|
 | 93 | /* --Methode-- */
 | 
|---|
| [2682] | 94 | r_8 * NTupleInterface::GetLineD(sa_size_t ) const
 | 
|---|
| [1371] | 95 | {
 | 
|---|
| [2682] | 96 |   throw NotAvailableOperation("NTupleInterface::GetLineD(sa_size_t ) must be redefined in derived classes");
 | 
|---|
| [1371] | 97 | }
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 | //! Returns the content of a given cell
 | 
|---|
 | 100 | /*!
 | 
|---|
 | 101 |     The cell is identified by the line and column number. Its content is
 | 
|---|
 | 102 |     converted to a floating value.
 | 
|---|
 | 103 | */
 | 
|---|
 | 104 | /* --Methode-- */
 | 
|---|
| [2682] | 105 | r_8 NTupleInterface::GetCell(sa_size_t , sa_size_t ) const
 | 
|---|
| [1371] | 106 | {
 | 
|---|
 | 107 | return(0.);
 | 
|---|
 | 108 | }
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 | //! Returns the content of a given cell
 | 
|---|
 | 111 | /*!
 | 
|---|
 | 112 |     The cell is identified by the line number and column name. Its content is
 | 
|---|
 | 113 |     converted to a floating value.
 | 
|---|
 | 114 | */
 | 
|---|
 | 115 | /* --Methode-- */
 | 
|---|
| [2682] | 116 | r_8 NTupleInterface::GetCell(sa_size_t n, string const & nom) const
 | 
|---|
| [1371] | 117 | {
 | 
|---|
 | 118 | return(GetCell(n, ColumnIndex(nom)));
 | 
|---|
 | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 | //! Returns the string representation of a given cell
 | 
|---|
 | 122 | /*!
 | 
|---|
 | 123 |     The cell is identified by the line and column number. Its content is
 | 
|---|
 | 124 |     converted to a string.
 | 
|---|
 | 125 | */
 | 
|---|
| [2682] | 126 | string NTupleInterface::GetCelltoString(sa_size_t n, sa_size_t k) const
 | 
|---|
| [1371] | 127 | {
 | 
|---|
 | 128 | char strg[64];
 | 
|---|
 | 129 | //sprintf(strg,"C%d= %g\n", k, GetCell(n, k));
 | 
|---|
 | 130 | sprintf(strg,"%g\n", GetCell(n, k));
 | 
|---|
 | 131 | return(strg);
 | 
|---|
 | 132 | }
 | 
|---|
 | 133 | 
 | 
|---|
 | 134 | //! Returns the string representation of a given cell
 | 
|---|
 | 135 | /*!
 | 
|---|
 | 136 |     The cell is identified by the line number and column name. Its content is
 | 
|---|
 | 137 |     converted to a string.
 | 
|---|
 | 138 | */
 | 
|---|
| [2682] | 139 | string NTupleInterface::GetCelltoString(sa_size_t n, string const & nom) const
 | 
|---|
| [1371] | 140 | {
 | 
|---|
 | 141 | return(GetCelltoString(n, ColumnIndex(nom)));
 | 
|---|
 | 142 | }
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 | //! Returns the minimum and maximum values for a given column
 | 
|---|
 | 145 | /* --Methode-- */
 | 
|---|
| [2682] | 146 | void NTupleInterface::GetMinMax(sa_size_t , double& min, double& max)   const
 | 
|---|
| [1371] | 147 | {
 | 
|---|
 | 148 | min = max = 0.;
 | 
|---|
 | 149 | }
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 | /* --Methode-- */
 | 
|---|
 | 152 | //! Returns the minimum and maximum values for a given named column
 | 
|---|
| [2682] | 153 | void NTupleInterface::GetMinMax(string const & nom, double& min, double& max)   const
 | 
|---|
| [1371] | 154 | {
 | 
|---|
| [2682] | 155 |   GetMinMax(ColumnIndex(nom), min, max);
 | 
|---|
| [1371] | 156 | }
 | 
|---|
 | 157 | 
 | 
|---|
 | 158 | /* --Methode-- */
 | 
|---|
 | 159 | //! Returns the column index given the column name
 | 
|---|
| [2682] | 160 | sa_size_t NTupleInterface::ColumnIndex(string const & nom)  const
 | 
|---|
| [1371] | 161 | {
 | 
|---|
 | 162 | return(-1);
 | 
|---|
 | 163 | }
 | 
|---|
 | 164 | 
 | 
|---|
 | 165 | /* --Methode-- */
 | 
|---|
 | 166 | //! Returns the column name corresponding to a column index.
 | 
|---|
| [2682] | 167 | string NTupleInterface::ColumnName(sa_size_t k) const
 | 
|---|
| [1371] | 168 | {
 | 
|---|
 | 169 | return("");
 | 
|---|
 | 170 | }
 | 
|---|
 | 171 | 
 | 
|---|
 | 172 | /* --Methode-- */
 | 
|---|
 | 173 | string NTupleInterface::VarList_C(const char*) const
 | 
|---|
 | 174 | {
 | 
|---|
 | 175 | return("");
 | 
|---|
 | 176 | }
 | 
|---|
 | 177 | 
 | 
|---|
 | 178 | /* --Methode-- */
 | 
|---|
 | 179 | string NTupleInterface::LineHeaderToString() const
 | 
|---|
 | 180 | {
 | 
|---|
 | 181 | return("");
 | 
|---|
 | 182 | }
 | 
|---|
 | 183 | 
 | 
|---|
 | 184 | /* --Methode-- */
 | 
|---|
| [2682] | 185 | string NTupleInterface::LineToString(sa_size_t ) const
 | 
|---|
| [1371] | 186 | {
 | 
|---|
 | 187 | return("");
 | 
|---|
 | 188 | }
 | 
|---|
 | 189 | 
 | 
|---|
 | 190 | 
 | 
|---|
 | 191 | 
 | 
|---|