source: Sophya/trunk/SophyaPI/PIext/sohiswrap.h@ 3125

Last change on this file since 3125 was 3125, checked in by ansari, 19 years ago

1/ Introduction d'une classe P1DHistoWrapper (fichier phistwrapper.h) pour rendre PIHisto independant de SOPHYA et des objets Histo, HistErr, HProf ...
2/ Ecriture du wrapper/adaptateur pour SOPHYA::Histo,HProf,HistErr
3/ mise en conformite des ObjAdapter piapp pour Histo,HistErr, chgt numero de version

Reza 11/01/2007

File size: 3.0 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// Classes d'emballage (wrapper) d'histos SOPHYA/HiStats
3// pour trace par PIHisto
4// C. Magneville / R. Ansari 2007
5// (C) CEA-DAPNIA LAL-IN2P3/CNRS
6
7#ifndef SOHISWRAP_H
8#define SOHISWRAP_H
9
10#include "histos.h"
11#include "hisprof.h"
12#include "histerr.h"
13
14#include "pexceptions.h"
15
16#include "phistwrapper.h"
17
18namespace SOPHYA {
19
20//! Wrapper class for SOPHYA::Histo , SOPHYA::HProf
21class HistoWrapper : public P1DHistoWrapper
22{
23public:
24 HistoWrapper(Histo* h, bool ad=true)
25 {
26 if (h == NULL) throw NullPtrError("HistoWrapper(Histo* h = NULL)");
27 mHis = h; mAD = ad;
28 }
29 ~HistoWrapper() { if (mAD) delete mHis; }
30
31 virtual int_4 NBins() { return mHis->NBins(); }
32 virtual r_8 XMin() { return mHis->XMin() ; }
33 virtual r_8 XMax() { return mHis->XMax() ; }
34 virtual r_8 BinWidth() { return mHis->BinWidth() ; }
35
36 virtual r_8 BinLowEdge(int_4 i) { return mHis->BinLowEdge(i) ; }
37 virtual r_8 BinCenter(int_4 i) { return mHis->BinCenter(i) ; }
38 virtual r_8 BinHighEdge(int_4 i) { return mHis->BinHighEdge(i) ; }
39
40 virtual r_8 operator()(int_4 i) { return (*mHis)(i) ; }
41 virtual r_8 Error(int_4 i) { return mHis->Error(i) ; }
42
43 virtual void Update() { mHis->UpdateHisto(); }
44
45 // ajoute des lignes de texte avec les infos statistiques
46 virtual int GetStatInfoAsText(vector<string> & text)
47 {
48 char label[64];
49 string s;
50 sprintf(label, "N= %-g",mHis->NData());
51 s = label; text.push_back(s);
52 sprintf(label, "m= %-g",mHis->Mean());
53 s = label; text.push_back(s);
54 sprintf(label, "s= %-g",mHis->Sigma());
55 s = label; text.push_back(s);
56 return 3;
57 }
58
59 // pointeur sur l'objet histo
60 inline Histo* getHisto() { return mHis; }
61protected:
62 Histo* mHis;
63 bool mAD;
64};
65
66
67//! Wrapper class for SOPHYA::HistoErr
68class HistoErrWrapper : public P1DHistoWrapper
69{
70public:
71 HistoErrWrapper(HistoErr* h, bool ad=false)
72 {
73 if (h == NULL) throw NullPtrError("HistoWrapper(HistoErr* h = NULL)");
74 mHis = h; mAD = ad;
75 }
76 ~HistoErrWrapper() { if (mAD) delete mHis; }
77
78 virtual int_4 NBins() { return mHis->NBins(); }
79 virtual r_8 XMin() { return mHis->XMin() ; }
80 virtual r_8 XMax() { return mHis->XMax() ; }
81 virtual r_8 BinWidth() { return mHis->BinWidth() ; }
82
83 virtual r_8 BinLowEdge(int_4 i) { return mHis->BinLowEdge(i) ; }
84 virtual r_8 BinCenter(int_4 i) { return mHis->BinCenter(i) ; }
85 virtual r_8 BinHighEdge(int_4 i) { return mHis->BinHighEdge(i) ; }
86
87 virtual r_8 operator()(int_4 i) { return (*mHis)(i) ; }
88 virtual r_8 Error(int_4 i) { return mHis->Error(i) ; }
89
90 // CMV $CHECK$ pas besoin ? virtual void Update() { }
91
92 // ajoute des lignes de texte avec les infos statistiques
93 virtual int GetStatInfoAsText(vector<string> & text)
94 {
95 // CMV $CHECK$ Y-a-t il qque chose a ecrire ?
96 string s = "HistoErr";
97 text.push_back(s);
98 return 1;
99 }
100
101 // pointeur sur l'objet histo
102 inline HistoErr* getHistoErr() { return mHis; }
103protected:
104 HistoErr* mHis;
105 bool mAD;
106};
107
108} // Fin du namespace
109
110#endif
Note: See TracBrowser for help on using the repository browser.