source: Sophya/trunk/SophyaPI/PIext/nomhistadapter.cc@ 344

Last change on this file since 344 was 344, checked in by ercodmgr, 26 years ago

1/ Extension de fonctionalites de gestion de repertoires (Lock, ...)
2/ Plus de NTupIntf_Adapter quand les objets heritent de NTupleInterface
3/ Support pour affichage info texte, ds PINtuple et PIStarList

File size: 6.1 KB
Line 
1#include "machdefs.h"
2#include <stdlib.h>
3#include <typeinfo>
4#include <iostream.h>
5#include <string>
6
7#include "nomhistadapter.h"
8#include "pihisto.h"
9#include "pihisto2d.h"
10#include "pipodrw.h"
11
12//-------------------------------------------------------------------------
13// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Histo / HProf
14//-------------------------------------------------------------------------
15
16/* --Methode-- */
17NOMAdapter_Histo::NOMAdapter_Histo(Histo* o)
18 : NObjMgrAdapter(o)
19{
20mHis = o;
21}
22
23/* --Methode-- */
24NOMAdapter_Histo::~NOMAdapter_Histo()
25{
26}
27
28/* --Methode-- */
29NObjMgrAdapter* NOMAdapter_Histo::Clone(AnyDataObj* o)
30{
31Histo* h = dynamic_cast<Histo *>(o);
32if (h) return ( new NOMAdapter_Histo(h) );
33return ( new NObjMgrAdapter(o) );
34}
35
36
37/* --Methode-- */
38void NOMAdapter_Histo::SavePPF(POutPersist& pos, string const & nom)
39{
40#ifdef SANS_EVOLPLANCK
41// PEIDA-EROS L'histo est lui-meme PPersist
42string tag = nom; // A cause de const
43mHis->Write(pos,0,tag);
44#else
45string s = typeid(*mObj).name();
46cout << "NOMAdapter_Histo::SavePPF() - Error : Not supported for " << s << endl;
47#endif
48}
49
50/* --Methode-- */
51void NOMAdapter_Histo::Print(ostream& os)
52{
53mHis->Print(60);
54}
55
56/* --Methode-- */
57PIDrawer* NOMAdapter_Histo::GetDrawer(string & dopt)
58{
59if (typeid(*mHis) == typeid(HProf)) dopt = "fcirclemarker5," + dopt;
60else dopt = "thinline," + dopt;
61return( new PIHisto(mHis, false) );
62}
63
64/* --Methode-- */
65NTupleInterface* NOMAdapter_Histo::GetNTupleInterface(bool& adel)
66{
67adel = true;
68return( new NTupInt_Histo(mHis) );
69}
70
71
72// -------------------------------------------------------------
73
74/* --Methode-- */
75NTupInt_Histo::NTupInt_Histo(Histo* h)
76{
77mHis = h;
78}
79
80/* --Methode-- */
81NTupInt_Histo::~NTupInt_Histo()
82{
83}
84
85/* --Methode-- */
86uint_4 NTupInt_Histo::NbLines() const
87{
88return(mHis->NBins());
89}
90
91/* --Methode-- */
92uint_4 NTupInt_Histo::NbColumns() const
93{
94return(4);
95}
96
97/* --Methode-- */
98r_8* NTupInt_Histo::GetLineD(int k) const
99{
100int i;
101if ((k < 0) || (k >= mHis->NBins()))
102 for(i=0; i<4; i++) mRet[i] = 0.;
103else {
104 mRet[0] = k; mRet[1] = mHis->BinCenter(k);
105 mRet[2] = (*mHis)(k); mRet[3] = mHis->Error(k);
106 }
107return(mRet);
108}
109
110/* --Methode-- */
111string NTupInt_Histo::VarList_C(const char* nx) const
112{
113string nomx;
114if (nx) nomx = nx;
115else nomx = "_xh_";
116string vardec = "double i,x,val,err; \n";
117vardec += "i = " + nomx + "[0]; x = " + nomx + "[1]; \n";
118vardec += "val = " + nomx + "[2]; err = " + nomx + "[3]; \n";
119return(vardec);
120}
121
122//-------------------------------------------------------------------------
123// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Histo2D
124//-------------------------------------------------------------------------
125
126
127/* --Methode-- */
128NOMAdapter_Histo2D::NOMAdapter_Histo2D(Histo2D* o)
129 : NObjMgrAdapter(o)
130{
131mHis = o;
132}
133
134/* --Methode-- */
135NOMAdapter_Histo2D::~NOMAdapter_Histo2D()
136{
137}
138
139/* --Methode-- */
140NObjMgrAdapter* NOMAdapter_Histo2D::Clone(AnyDataObj* o)
141{
142Histo2D* h = dynamic_cast<Histo2D *>(o);
143if (h) return ( new NOMAdapter_Histo2D(h) );
144return ( new NObjMgrAdapter(o) );
145}
146
147
148/* --Methode-- */
149void NOMAdapter_Histo2D::SavePPF(POutPersist& pos, string const & nom)
150{
151#ifdef SANS_EVOLPLANCK
152// PEIDA-EROS L'histo est lui-meme PPersist
153string tag = nom; // A cause de const
154mHis->Write(pos,0,tag);
155#else
156string s = typeid(*mObj).name();
157cout << "NOMAdapter_Histo2D::SavePPF() - Error : Not supported for " << s << endl;
158#endif
159}
160
161/* --Methode-- */
162void NOMAdapter_Histo2D::Print(ostream& os)
163{
164mHis->Print();
165}
166
167/* --Methode-- */
168PIDrawer* NOMAdapter_Histo2D::GetDrawer(string & dopt)
169{
170dopt = "thinline," + dopt;
171return( new PIHisto2D(mHis, false) );
172}
173
174/* --Methode-- */
175P2DArrayAdapter* NOMAdapter_Histo2D::Get2DArray(string & dopt)
176{
177return (new POH2DAdapter(mHis, false) );
178}
179
180/* --Methode-- */
181NTupleInterface* NOMAdapter_Histo2D::GetNTupleInterface(bool& adel)
182{
183adel = true;
184return( new NTupInt_Histo2D(mHis) );
185}
186
187
188
189// -------------------------------------------------------------
190
191/* --Methode-- */
192NTupInt_Histo2D::NTupInt_Histo2D(Histo2D* h)
193{
194mHis = h;
195}
196
197/* --Methode-- */
198NTupInt_Histo2D::~NTupInt_Histo2D()
199{
200}
201
202/* --Methode-- */
203uint_4 NTupInt_Histo2D::NbLines() const
204{
205return(mHis->NBinX()*mHis->NBinY());
206}
207
208/* --Methode-- */
209uint_4 NTupInt_Histo2D::NbColumns() const
210{
211return(6);
212}
213
214/* --Methode-- */
215r_8* NTupInt_Histo2D::GetLineD(int n) const
216{
217int i,j;
218float f2,f3;
219if ((n < 0) || (n >= mHis->NBinX()*mHis->NBinY()))
220 for(i=0; i<6; i++) mRet[i] = 0.;
221else {
222 i = n%mHis->NBinX(); j = n/mHis->NBinX();
223 mRet[0] = i; mRet[1] = j;
224 mHis->BinCenter(i,j,f2,f3);
225 mRet[2] = f2; mRet[3] = f3;
226 mRet[4] = (*mHis)(i,j); mRet[5] = mHis->Error(i, j);
227 }
228return(mRet);
229}
230
231/* --Methode-- */
232string NTupInt_Histo2D::VarList_C(const char* nx) const
233{
234string nomx;
235if (nx) nomx = nx;
236else nomx = "_xh_";
237string vardec = "double i,j,x,y,val,err; \n";
238vardec += "i = " + nomx + "[0]; j = " + nomx + "[1]; \n";
239vardec += "x = " + nomx + "[2]; y = " + nomx + "[3]; \n";
240vardec += "val = " + nomx + "[4]; err = " + nomx + "[5]; \n";
241return(vardec);
242}
243
244
245
246//-------------------------------------------------------------------------
247// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet NTuple
248//-------------------------------------------------------------------------
249
250/* --Methode-- */
251NOMAdapter_NTuple::NOMAdapter_NTuple(NTuple* o)
252 : NObjMgrAdapter(o)
253{
254mNt = o;
255}
256
257/* --Methode-- */
258NOMAdapter_NTuple::~NOMAdapter_NTuple()
259{
260}
261
262/* --Methode-- */
263NObjMgrAdapter* NOMAdapter_NTuple::Clone(AnyDataObj* o)
264{
265NTuple* nt = dynamic_cast<NTuple *>(o);
266if (nt) return ( new NOMAdapter_NTuple(nt) );
267return ( new NObjMgrAdapter(o) );
268}
269
270
271/* --Methode-- */
272void NOMAdapter_NTuple::SavePPF(POutPersist& pos, string const & nom)
273{
274#ifdef SANS_EVOLPLANCK
275// PEIDA-EROS L'histo est lui-meme PPersist
276string tag = nom; // A cause de const
277mNt->Write(pos,0,tag);
278#else
279string s = typeid(*mObj).name();
280cout << "NOMAdapter_NTuple::SavePPF() - Error : Not supported for " << s << endl;
281#endif
282}
283
284/* --Methode-- */
285void NOMAdapter_NTuple::Print(ostream& os)
286{
287os << mNt->Info();
288os << *(mNt);
289}
290
291
292/* --Methode-- */
293NTupleInterface* NOMAdapter_NTuple::GetNTupleInterface(bool& adel)
294{
295adel = false;
296return(mNt);
297// return( new NTupInt_NTuple(mNt) );
298}
299
300
Note: See TracBrowser for help on using the repository browser.