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

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

Extension de l'interface NObjMgrAdapter et ajout de DVList pour les variables globales ds NamedObjMgr - Reza 30/8/2000

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