GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Measure.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
28 #ifndef Gw_Measure
29 #define Gw_Measure
30 #define GW_MEASURE_H Gw_Measure
31 
32 #ifndef ROOT_Rtypes
33 #include <Rtypes.h>
34 #endif
35 
36 #ifndef GW_DATA_H
37 #include "Data.h"
38 #endif
39 
40 
41 namespace Gw {
42 
54 template <typename Data_T> class Measure : public Data <Data_T>
55 {
56 protected:
57  Data_T fError; // the error on this measure
58 
59 public:
60  Measure() : Data<Data_T>() { fError = 0; }
61  explicit Measure(Data_T d, Data_T derr = 0) : Data<Data_T>(d) { fError = derr; }
62  Measure(const Measure & data) : Data<Data_T>(data) { fError = data.fError; }
63  virtual ~Measure() {;}
64 
66  virtual void Set(Data_T data) { Data<Data_T>::fValue = data; fError = 0; }
67  virtual void Set(Data_T d, Data_T derr) { Data<Data_T>::fValue = d; fError = derr; }
68 
70  virtual void Set(const char *s)
71  {
72  std::istringstream input; input.clear(); TString st = s;
73  switch( InfoData::WhatIs(s) ){
74  case InfoData::kKnown:
75  input.str(s); input >> Data<Data_T>::fValue >> fError;
76  if ( input.fail() ) InfoData::SetInfo(InfoData::kUnknown);
78  break;
79  case InfoData::kUnknown:
81  break;
82  case InfoData::kAbout:
83  st.ReplaceAll('~',' ');
84  input.str(st.Data()); input >> Data<Data_T>::fValue >> fError;
85  if ( input.fail() ) InfoData::SetInfo(InfoData::kUnknown);
87  break;
89  st.ReplaceAll('(',' ');
90  st.ReplaceAll(')',' ');
91  input.str(st.Data()); input >> Data<Data_T>::fValue >> fError;
92  if ( input.fail() ) InfoData::SetInfo(InfoData::kUnknown);
94  break;
95  case InfoData::kTheo:
96  st.ReplaceAll('[',' ');
97  st.ReplaceAll(']',' ');
98  input.str(st.Data()); input >> Data<Data_T>::fValue >> fError;
99  if ( input.fail() ) InfoData::SetInfo(InfoData::kUnknown);
101  break;
102  default:
104  break;
105  }
106  }
107 
109  virtual Data_T GetError() const { return fError; }
111  virtual void SetError(Data_T derr) { fError = derr; }
112 
114  virtual Data_T & operator [] (int i) { if ( i == 1 ) return fError; return Data<Data_T>::fValue; }
115 
117  ClassDef(Measure,1); // A measure with an associated error
118 };
119 // inline members
120 
121 /*
122 std::ostream & operator << (std::ostream &out, Measure<float> & m) {
123  out << m.GetValue() << "+/-" << m.GetError(); return out;
124 }
125 ostream & operator << (ostream &out, Measure<double> m) {
126  out << m.GetValue() << "~" << m.GetError(); return out;
127 } */
128 
129 }
130 
131 #endif
virtual Data_T GetError() const
return the error on the measured value
Definition: Measure.h:109
A single value data.
Definition: Data.h:58
static EData WhatIs(const char *)
It deduces from a string the kind of data.
Definition: InfoData.cpp:45
virtual void Set(Data_T data)
set the measure and its error (default err=0)
Definition: Measure.h:66
virtual Data_T & operator[](int i)
to get/set the value or the error
Definition: Measure.h:114
ClassDef(Measure, 1)
rootcint dictionary
template that defines a general Data
virtual ~Measure()
Definition: Measure.h:63
virtual void Set(const char *s)
set the value, can be overloaded
Definition: Measure.h:70
Data_T fError
Definition: Measure.h:57
Measure(const Measure &data)
Definition: Measure.h:62
Measure(Data_T d, Data_T derr=0)
Definition: Measure.h:61
virtual void Set(Data_T d, Data_T derr)
Definition: Measure.h:67
A general measure with an associated error.
Definition: Measure.h:54
virtual void SetInfo(InfoData::EData)
to set some information about this data
Definition: InfoData.h:83
virtual void SetError(Data_T derr)
set the error of this value
Definition: Measure.h:111