GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ParameterMember.cxx
Go to the documentation of this file.
1 // $Id: TGo4ParameterMember.cxx 1940 2016-08-25 06:04:04Z adamczew $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4ParameterMember.h"
15 
16 #include <stdlib.h>
17 
18 #include "RVersion.h"
19 #include "Riostream.h"
20 #include "TROOT.h"
21 #include "TDataType.h"
22 
24  TNamed(),
25  fTypeName(),
26  fTypeId(0),
27  fMemberId(0),
28  fValue(),
29  fIndex1(-1),
30  fIndex2(-1),
31  fObject(0),
32  fObjectOwner(kTRUE),
33  fVisible(kTRUE)
34 {
35 }
36 
37 TGo4ParameterMember::TGo4ParameterMember(const char* name, const char* title) :
38  TNamed(name, title),
39  fTypeName(),
40  fTypeId(0),
41  fMemberId(0),
42  fValue(),
43  fIndex1(-1),
44  fIndex2(-1),
45  fObject(0),
46  fObjectOwner(kTRUE),
47  fVisible(kTRUE)
48 {
49 }
50 
52 {
53  if ((fObject!=0) && fObjectOwner) {
54  delete fObject;
55  fObject = 0;
56  }
57 }
58 
59 void TGo4ParameterMember::SetArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
60 {
61  switch(ndim) {
62  case 1:
63  fIndex1 = indx1;
64  fIndex2 = -1;
65  break;
66  case 2:
67  fIndex1 = indx1;
68  fIndex2 = indx2;
69  break;
70  default:
71  fIndex1 = -1;
72  fIndex2 = -1;
73  break;
74  }
75 }
76 
77 Bool_t TGo4ParameterMember::CheckArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
78 {
79  switch(ndim) {
80  case 1: return (fIndex1==indx1) && (fIndex2<0);
81  case 2: return (fIndex1==indx1) && (fIndex2==indx2);
82  default: return (fIndex1<0) && (fIndex2<0);
83  }
84 
85  return (fIndex1<0) && (fIndex2<0);
86 }
87 
88 
89 const char* TGo4ParameterMember::GetFullName(TString& buf)
90 {
91  buf = "";
92  if ((fIndex1<0) && (fIndex2<0))
93  buf = GetName();
94  else
95  if ((fIndex1>=0) && (fIndex2<0))
96  buf.Form("%s[%d]",GetName(),fIndex1);
97  else
98  if ((fIndex1>=0) && (fIndex2>=0))
99  buf.Form("%s[%d][%d]",GetName(),fIndex1,fIndex2);
100  return buf.Data();
101 }
102 
103 void TGo4ParameterMember::SetObject(TObject* obj, Bool_t owner)
104 {
105  if ((fObject!=0) && fObjectOwner) delete fObject;
106 
107  fObject = obj;
108  fObjectOwner = owner;
109 }
110 
112 {
113  if ((fObject!=0) && fObjectOwner) {
114  delete fObject;
115  fObject = 0;
116  }
117 
118  fValue = "";
119  fObject = 0;
120  fObjectOwner = kFALSE;
121 
122  switch (fTypeId) {
123  case kUInt_t:
124  case kInt_t:
125  case kULong_t:
126  case kLong_t:
127  case kULong64_t:
128  case kLong64_t:
129  case kUShort_t:
130  case kShort_t:
131  case kUChar_t:
132  case kChar_t:
133 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
134  case kBool_t:
135 #endif
136  case kFloat_t:
137  case kDouble_t:
138  case kDouble32_t: fValue = "0"; break;
139  case kTString_t: break;
140  case kTGo4Fitter_t: break;
141  }
142 }
143 
145 {
146  fValue = "";
147  switch (fTypeId) {
148  case kUInt_t: fValue.Form("%u", *((UInt_t*)addr)); break;
149  case kInt_t: fValue.Form("%d", *((Int_t*)addr)); break;
150  case kULong_t: fValue.Form("%lu", *((ULong_t*)addr)); break;
151  case kLong_t: fValue.Form("%ld", *((Long_t*)addr)); break;
152  case kULong64_t: fValue.Form("%llu", *((ULong64_t*)addr)); break;
153  case kLong64_t: fValue.Form("%lld", *((Long64_t*)addr)); break;
154  case kUShort_t: fValue.Form("%hu", *((UShort_t*)addr)); break;
155  case kShort_t: fValue.Form("%hd", *((Short_t*)addr)); break;
156  case kUChar_t: fValue.Form("%u", *((UChar_t*)addr)); break;
157  case kChar_t: fValue.Form("%d", *((Char_t*)addr)); break;
158 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
159  case kBool_t: fValue.Form("%d", *((Bool_t*)addr)); break;
160 #endif
161  case kFloat_t: fValue.Form("%.7g", *((Float_t*)addr)); break;
162  case kDouble_t: fValue.Form("%.16g", *((Double_t*)addr)); break;
163  case kDouble32_t: fValue.Form("%.16g", *((Double32_t*)addr)); break;
164  case kTString_t: fValue = *((TString*)addr); break;
165  case kTGo4Fitter_t: {
166  TObject** f = (TObject**) addr;
167  fObject = *f;
168  fObjectOwner = kFALSE;
169  break;
170  }
171  }
172 }
173 
175 {
176  const char* value = fValue.Data();
177  switch (fTypeId) {
178  case kUInt_t: *((UInt_t*)addr) = atoi(value); break;
179  case kInt_t: *((Int_t*)addr) = atoi(value); break;
180  case kULong_t: *((ULong_t*)addr) = atoi(value); break;
181  case kLong_t: *((Long_t*)addr) = atoi(value); break;
182  case kULong64_t: *((ULong64_t*)addr) = atoi(value); break;
183  case kLong64_t: *((Long64_t*)addr) = atoi(value); break;
184  case kUShort_t: *((UShort_t*)addr) = atoi(value); break;
185  case kShort_t: *((Short_t*)addr) = atoi(value); break;
186  case kUChar_t: *((UChar_t*)addr) = atoi(value); break;
187  case kChar_t: *((Char_t*)addr) = atoi(value); break;
188 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
189  case kBool_t: *((Bool_t*)addr) = atoi(value); break;
190 #endif
191  case kFloat_t: *((Float_t*)addr) = atof(value); break;
192  case kDouble_t: *((Double_t*)addr) = atof(value); break;
193  case kDouble32_t: *((Double32_t*)addr) = atof(value); break;
194  case kTString_t: *((TString*)addr) = value; break;
195  case kTGo4Fitter_t: {
196  TObject** f = (TObject**)addr;
197  *f = fObject;
198  fObjectOwner = kFALSE;
199  break;
200  }
201  }
202 }
203 
204 Int_t TGo4ParameterMember::PrintMember(Text_t* buffer, Int_t buflen) const
205 {
206  if ((buffer!=0) && (buflen<=0)) return 0;
207 
208  Int_t size = 0;
209 
210  TString name;
211  if ((fIndex1<0) && (fIndex2<0)) name += GetName(); else
212  if (fIndex2<0) name += TString::Format("%s[%d]", GetName(), fIndex1); else
213  name += TString::Format("%s[%d][%d]", GetName(), fIndex1, fIndex2);
214 
215  name += " = ";
216 
217  if (fObject) name += TString::Format("Obj:%p Class:%s", fObject, fObject->ClassName()); else
218 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
219  if (fTypeId==kBool_t) name += ((fValue=="0") ? "kFALSE" : "kTRUE"); else
220 #endif
221  name += fValue;
222 
223  if ((GetTitle() != 0) && (strlen(GetTitle())>0)) { name += " // "; name += GetTitle(); }
224 
225  name += "\n";
226 
227  if(buffer==0) {
228  TROOT::IndentLevel();
229  std::cout << name;
230  } else {
231  size = name.Length();
232  if(size>buflen) size = buflen;
233  strncpy(buffer, name.Data(), size);
234  }
235 
236  return size;
237 
238 }
239 
240 
241 void TGo4ParameterMember::Clear(Option_t* opt)
242 {
243  SetToZero();
244 }
245 
246 void TGo4ParameterMember::Print(Option_t* dummy) const
247 {
248  PrintMember();
249 }
virtual void Clear(Option_t *opt="")
const char * GetFullName(TString &buf)
void SetObject(TObject *obj, Bool_t owner)
Int_t PrintMember(Text_t *buffer=0, Int_t buflen=0) const
Bool_t CheckArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
virtual void Print(Option_t *dummy="") const
void SetArrayIndexes(Int_t ndim=0, Int_t indx1=-1, Int_t indx2=-1)