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

Last change on this file since 1090 was 1090, checked in by ercodmgr, 25 years ago

updatehisto formalisation cmv 25/7/00

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