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

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

Introoduction adaptateur XNTuple pour SOPHYA, Reza 7 Fev 2000

File size: 7.5 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#include "servnobjm.h"
12
13//-------------------------------------------------------------------------
14// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Histo / HProf
15//-------------------------------------------------------------------------
16
17/* --Methode-- */
18NOMAdapter_Histo::NOMAdapter_Histo(Histo* o)
19 : NObjMgrAdapter(o)
20{
21mHis = o;
22}
23
24/* --Methode-- */
25NOMAdapter_Histo::~NOMAdapter_Histo()
26{
27}
28
29/* --Methode-- */
30NObjMgrAdapter* NOMAdapter_Histo::Clone(AnyDataObj* o)
31{
32Histo* h = dynamic_cast<Histo *>(o);
33if (h) return ( new NOMAdapter_Histo(h) );
34return ( new NObjMgrAdapter(o) );
35}
36
37/* --Methode-- */
38AnyDataObj* NOMAdapter_Histo::GetCopyObj()
39{
40HProf * hp = dynamic_cast<HProf *>(mHis);
41if (hp == NULL) return( new Histo(*mHis) );
42else return( new HProf(*hp) );
43}
44
45/* --Methode-- */
46void NOMAdapter_Histo::SavePPF(POutPersist& pos, string const & nom)
47{
48#ifdef SANS_EVOLPLANCK
49// PEIDA-EROS L'histo est lui-meme PPersist
50string tag = nom; // A cause de const
51mHis->Write(pos,0,tag);
52#else
53ObjFileIO<Histo> fio(mHis);
54fio.Write(pos, nom);
55#endif
56}
57
58/* --Methode-- */
59void NOMAdapter_Histo::Print(ostream& os)
60{
61mHis->Print(60);
62}
63
64/* --Methode-- */
65PIDrawer* NOMAdapter_Histo::GetDrawer(string & dopt)
66{
67if (typeid(*mHis) == typeid(HProf)) dopt = "fcirclemarker5," + dopt;
68else dopt = "thinline," + dopt;
69PIHisto * pih = new PIHisto(mHis, false);
70pih->SetStats(Services2NObjMgr::GetStatsOption(dopt));
71return( pih );
72}
73
74/* --Methode-- */
75NTupleInterface* NOMAdapter_Histo::GetNTupleInterface(bool& adel)
76{
77adel = true;
78return( new NTupInt_Histo(mHis) );
79}
80
81
82// -------------------------------------------------------------
83
84/* --Methode-- */
85NTupInt_Histo::NTupInt_Histo(Histo* h)
86{
87mHis = h;
88}
89
90/* --Methode-- */
91NTupInt_Histo::~NTupInt_Histo()
92{
93}
94
95/* --Methode-- */
96uint_4 NTupInt_Histo::NbLines() const
97{
98return(mHis->NBins());
99}
100
101/* --Methode-- */
102uint_4 NTupInt_Histo::NbColumns() const
103{
104return(4);
105}
106
107/* --Methode-- */
108r_8* NTupInt_Histo::GetLineD(int k) const
109{
110int i;
111if ((k < 0) || (k >= mHis->NBins()))
112 for(i=0; i<4; i++) mRet[i] = 0.;
113else {
114 mRet[0] = k; mRet[1] = mHis->BinCenter(k);
115 mRet[2] = (*mHis)(k); mRet[3] = mHis->Error(k);
116 }
117return(mRet);
118}
119
120/* --Methode-- */
121string NTupInt_Histo::VarList_C(const char* nx) const
122{
123string nomx;
124if (nx) nomx = nx;
125else nomx = "_xh_";
126string vardec = "double i,x,val,err; \n";
127vardec += "i = " + nomx + "[0]; x = " + nomx + "[1]; \n";
128vardec += "val = " + nomx + "[2]; err = " + nomx + "[3]; \n";
129return(vardec);
130}
131
132//-------------------------------------------------------------------------
133// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Histo2D
134//-------------------------------------------------------------------------
135
136
137/* --Methode-- */
138NOMAdapter_Histo2D::NOMAdapter_Histo2D(Histo2D* o)
139 : NObjMgrAdapter(o)
140{
141mHis = o;
142}
143
144/* --Methode-- */
145NOMAdapter_Histo2D::~NOMAdapter_Histo2D()
146{
147}
148
149/* --Methode-- */
150NObjMgrAdapter* NOMAdapter_Histo2D::Clone(AnyDataObj* o)
151{
152Histo2D* h = dynamic_cast<Histo2D *>(o);
153if (h) return ( new NOMAdapter_Histo2D(h) );
154return ( new NObjMgrAdapter(o) );
155}
156
157/* --Methode-- */
158AnyDataObj* NOMAdapter_Histo2D::GetCopyObj()
159{
160return ( new Histo2D(*mHis) );
161}
162
163/* --Methode-- */
164void NOMAdapter_Histo2D::SavePPF(POutPersist& pos, string const & nom)
165{
166#ifdef SANS_EVOLPLANCK
167// PEIDA-EROS L'histo est lui-meme PPersist
168string tag = nom; // A cause de const
169mHis->Write(pos,0,tag);
170#else
171ObjFileIO<Histo2D> fio(mHis);
172fio.Write(pos, nom);
173#endif
174}
175
176/* --Methode-- */
177void NOMAdapter_Histo2D::Print(ostream& os)
178{
179mHis->Print();
180}
181
182/* --Methode-- */
183PIDrawer* NOMAdapter_Histo2D::GetDrawer(string & dopt)
184{
185dopt = "thinline," + dopt;
186return( new PIHisto2D(mHis, false) );
187}
188
189/* --Methode-- */
190P2DArrayAdapter* NOMAdapter_Histo2D::Get2DArray(string & dopt)
191{
192return (new POH2DAdapter(mHis, false) );
193}
194
195/* --Methode-- */
196NTupleInterface* NOMAdapter_Histo2D::GetNTupleInterface(bool& adel)
197{
198adel = true;
199return( new NTupInt_Histo2D(mHis) );
200}
201
202
203
204// -------------------------------------------------------------
205
206/* --Methode-- */
207NTupInt_Histo2D::NTupInt_Histo2D(Histo2D* h)
208{
209mHis = h;
210}
211
212/* --Methode-- */
213NTupInt_Histo2D::~NTupInt_Histo2D()
214{
215}
216
217/* --Methode-- */
218uint_4 NTupInt_Histo2D::NbLines() const
219{
220return(mHis->NBinX()*mHis->NBinY());
221}
222
223/* --Methode-- */
224uint_4 NTupInt_Histo2D::NbColumns() const
225{
226return(6);
227}
228
229/* --Methode-- */
230r_8* NTupInt_Histo2D::GetLineD(int n) const
231{
232int i,j;
233float f2,f3;
234if ((n < 0) || (n >= mHis->NBinX()*mHis->NBinY()))
235 for(i=0; i<6; i++) mRet[i] = 0.;
236else {
237 i = n%mHis->NBinX(); j = n/mHis->NBinX();
238 mRet[0] = i; mRet[1] = j;
239 mHis->BinCenter(i,j,f2,f3);
240 mRet[2] = f2; mRet[3] = f3;
241 mRet[4] = (*mHis)(i,j); mRet[5] = mHis->Error(i, j);
242 }
243return(mRet);
244}
245
246/* --Methode-- */
247string NTupInt_Histo2D::VarList_C(const char* nx) const
248{
249string nomx;
250if (nx) nomx = nx;
251else nomx = "_xh_";
252string vardec = "double i,j,x,y,val,err; \n";
253vardec += "i = " + nomx + "[0]; j = " + nomx + "[1]; \n";
254vardec += "x = " + nomx + "[2]; y = " + nomx + "[3]; \n";
255vardec += "val = " + nomx + "[4]; err = " + nomx + "[5]; \n";
256return(vardec);
257}
258
259
260
261//-------------------------------------------------------------------------
262// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet NTuple
263//-------------------------------------------------------------------------
264
265/* --Methode-- */
266NOMAdapter_NTuple::NOMAdapter_NTuple(NTuple* o)
267 : NObjMgrAdapter(o)
268{
269mNt = o;
270}
271
272/* --Methode-- */
273NOMAdapter_NTuple::~NOMAdapter_NTuple()
274{
275}
276
277/* --Methode-- */
278NObjMgrAdapter* NOMAdapter_NTuple::Clone(AnyDataObj* o)
279{
280NTuple* nt = dynamic_cast<NTuple *>(o);
281if (nt) return ( new NOMAdapter_NTuple(nt) );
282return ( new NObjMgrAdapter(o) );
283}
284
285/* --Methode-- */
286AnyDataObj* NOMAdapter_NTuple::GetCopyObj()
287{
288return ( new NTuple(*mNt) );
289}
290
291/* --Methode-- */
292void NOMAdapter_NTuple::SavePPF(POutPersist& pos, string const & nom)
293{
294#ifdef SANS_EVOLPLANCK
295// PEIDA-EROS L'histo est lui-meme PPersist
296string tag = nom; // A cause de const
297mNt->Write(pos,0,tag);
298#else
299ObjFileIO<NTuple> fio(mNt);
300fio.Write(pos, nom);
301#endif
302}
303
304/* --Methode-- */
305void NOMAdapter_NTuple::Print(ostream& os)
306{
307os << mNt->Info();
308os << *(mNt);
309}
310
311
312/* --Methode-- */
313NTupleInterface* NOMAdapter_NTuple::GetNTupleInterface(bool& adel)
314{
315adel = false;
316return(mNt);
317// return( new NTupInt_NTuple(mNt) );
318}
319
320//-------------------------------------------------------------------------
321// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet XNTuple
322//-------------------------------------------------------------------------
323
324/* --Methode-- */
325NOMAdapter_XNTuple::NOMAdapter_XNTuple(XNTuple* o)
326 : NObjMgrAdapter(o)
327{
328mNt = o;
329}
330
331/* --Methode-- */
332NOMAdapter_XNTuple::~NOMAdapter_XNTuple()
333{
334}
335
336/* --Methode-- */
337NObjMgrAdapter* NOMAdapter_XNTuple::Clone(AnyDataObj* o)
338{
339XNTuple* nt = dynamic_cast<XNTuple *>(o);
340if (nt) return ( new NOMAdapter_XNTuple(nt) );
341return ( new NObjMgrAdapter(o) );
342}
343
344
345/* --Methode-- */
346void NOMAdapter_XNTuple::SavePPF(POutPersist& pos, string const & nom)
347{
348#ifdef SANS_EVOLPLANCK
349// PEIDA-EROS L'histo est lui-meme PPersist
350string tag = nom; // A cause de const
351mNt->Write(pos,0,tag);
352#else
353ObjFileIO<XNTuple> fio(mNt);
354fio.Write(pos, nom);
355#endif
356}
357
358/* --Methode-- */
359void NOMAdapter_XNTuple::Print(ostream& os)
360{
361// os << mNt->Info();
362mNt->Show(os);
363}
364
365
366/* --Methode-- */
367NTupleInterface* NOMAdapter_XNTuple::GetNTupleInterface(bool& adel)
368{
369adel = false;
370return(mNt);
371}
372
373
Note: See TracBrowser for help on using the repository browser.