GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ParameterMember.cxx
Go to the documentation of this file.
1 // $Id: TGo4ParameterMember.cxx 3431 2022-01-10 12:00:52Z linev $
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 fuer 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 <cstdlib>
17 #include <iostream>
18 
19 #include "TROOT.h"
20 #include "TDataType.h"
21 
23  TNamed(),
24  fTypeName(),
25  fTypeId(0),
26  fMemberId(0),
27  fValue(),
28  fIndex1(-1),
29  fIndex2(-1),
30  fObject(0),
31  fObjectOwner(kTRUE),
32  fVisible(kTRUE)
33 {
34 }
35 
36 TGo4ParameterMember::TGo4ParameterMember(const char* name, const char* title) :
37  TNamed(name, title),
38  fTypeName(),
39  fTypeId(0),
40  fMemberId(0),
41  fValue(),
42  fIndex1(-1),
43  fIndex2(-1),
44  fObject(0),
45  fObjectOwner(kTRUE),
46  fVisible(kTRUE)
47 {
48 }
49 
51 {
52  if (fObject && fObjectOwner) {
53  delete fObject;
54  fObject = 0;
55  }
56 }
57 
58 void TGo4ParameterMember::SetArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
59 {
60  switch(ndim) {
61  case 1:
62  fIndex1 = indx1;
63  fIndex2 = -1;
64  break;
65  case 2:
66  fIndex1 = indx1;
67  fIndex2 = indx2;
68  break;
69  default:
70  fIndex1 = -1;
71  fIndex2 = -1;
72  break;
73  }
74 }
75 
76 Bool_t TGo4ParameterMember::CheckArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
77 {
78  switch(ndim) {
79  case 1: return (fIndex1==indx1) && (fIndex2<0);
80  case 2: return (fIndex1==indx1) && (fIndex2==indx2);
81  }
82 
83  return (fIndex1<0) && (fIndex2<0);
84 }
85 
86 
87 const char* TGo4ParameterMember::GetFullName(TString& buf)
88 {
89  buf = "";
90  if ((fIndex1<0) && (fIndex2<0))
91  buf = GetName();
92  else
93  if ((fIndex1>=0) && (fIndex2<0))
94  buf.Form("%s[%d]",GetName(),fIndex1);
95  else
96  if ((fIndex1>=0) && (fIndex2>=0))
97  buf.Form("%s[%d][%d]",GetName(),fIndex1,fIndex2);
98  return buf.Data();
99 }
100 
101 void TGo4ParameterMember::SetObject(TObject* obj, Bool_t owner)
102 {
103  if ((fObject!=0) && fObjectOwner) delete fObject;
104 
105  fObject = obj;
106  fObjectOwner = owner;
107 }
108 
110 {
111  if ((fObject!=0) && fObjectOwner) {
112  delete fObject;
113  fObject = 0;
114  }
115 
116  fValue = "";
117  fObject = 0;
118  fObjectOwner = kFALSE;
119 
120  switch (fTypeId) {
121  case kUInt_t:
122  case kInt_t:
123  case kULong_t:
124  case kLong_t:
125  case kULong64_t:
126  case kLong64_t:
127  case kUShort_t:
128  case kShort_t:
129  case kUChar_t:
130  case kChar_t:
131  case kBool_t:
132  case kFloat_t:
133  case kDouble_t:
134  case kDouble32_t: fValue = "0"; break;
135  case kTString_t: break;
136  case kTGo4Fitter_t: break;
137  }
138 }
139 
141 {
142  fValue = "";
143  switch (fTypeId) {
144  case kUInt_t: fValue.Form("%u", *((UInt_t*)addr)); break;
145  case kInt_t: fValue.Form("%d", *((Int_t*)addr)); break;
146  case kULong_t: fValue.Form("%lu", *((ULong_t*)addr)); break;
147  case kLong_t: fValue.Form("%ld", *((Long_t*)addr)); break;
148  case kULong64_t: fValue.Form("%llu", *((ULong64_t*)addr)); break;
149  case kLong64_t: fValue.Form("%lld", *((Long64_t*)addr)); break;
150  case kUShort_t: fValue.Form("%hu", *((UShort_t*)addr)); break;
151  case kShort_t: fValue.Form("%hd", *((Short_t*)addr)); break;
152  case kUChar_t: fValue.Form("%u", *((UChar_t*)addr)); break;
153  case kChar_t: fValue.Form("%d", *((Char_t*)addr)); break;
154  case kBool_t: fValue.Form("%d", *((Bool_t*)addr)); break;
155  case kFloat_t: fValue.Form("%.7g", *((Float_t*)addr)); break;
156  case kDouble_t: fValue.Form("%.16g", *((Double_t*)addr)); break;
157  case kDouble32_t: fValue.Form("%.16g", *((Double32_t*)addr)); break;
158  case kTString_t: fValue = *((TString*)addr); break;
159  case kTGo4Fitter_t: {
160  TObject** f = (TObject**) addr;
161  fObject = *f;
162  fObjectOwner = kFALSE;
163  break;
164  }
165  }
166 }
167 
169 {
170  const char* value = fValue.Data();
171  switch (fTypeId) {
172  case kUInt_t: *((UInt_t*)addr) = atoi(value); break;
173  case kInt_t: *((Int_t*)addr) = atoi(value); break;
174  case kULong_t: *((ULong_t*)addr) = atoi(value); break;
175  case kLong_t: *((Long_t*)addr) = atoi(value); break;
176  case kULong64_t: *((ULong64_t*)addr) = atoi(value); break;
177  case kLong64_t: *((Long64_t*)addr) = atoi(value); break;
178  case kUShort_t: *((UShort_t*)addr) = atoi(value); break;
179  case kShort_t: *((Short_t*)addr) = atoi(value); break;
180  case kUChar_t: *((UChar_t*)addr) = atoi(value); break;
181  case kChar_t: *((Char_t*)addr) = atoi(value); break;
182  case kBool_t:
183  if (!strcmp(value,"true"))
184  *((Bool_t*)addr) = kTRUE;
185  else if (!strcmp(value,"false"))
186  *((Bool_t*)addr) = kFALSE;
187  else
188  *((Bool_t*)addr) = atoi(value);
189  break;
190  case kFloat_t: *((Float_t*)addr) = atof(value); break;
191  case kDouble_t: *((Double_t*)addr) = atof(value); break;
192  case kDouble32_t: *((Double32_t*)addr) = atof(value); break;
193  case kTString_t: *((TString*)addr) = value; break;
194  case kTGo4Fitter_t: {
195  TObject** f = (TObject**)addr;
196  *f = fObject;
197  fObjectOwner = kFALSE;
198  break;
199  }
200  }
201 }
202 
203 Int_t TGo4ParameterMember::PrintMember(Text_t* buffer, Int_t buflen) const
204 {
205  if ((buffer!=0) && (buflen<=0)) return 0;
206 
207  Int_t size = 0;
208 
209  TString name;
210  if ((fIndex1<0) && (fIndex2<0)) name += GetName(); else
211  if (fIndex2<0) name += TString::Format("%s[%d]", GetName(), fIndex1); else
212  name += TString::Format("%s[%d][%d]", GetName(), fIndex1, fIndex2);
213 
214  name += " = ";
215 
216  if (fObject)
217  name += TString::Format("Obj:%p Class:%s", fObject, fObject->ClassName());
218  else if (fTypeId == kBool_t)
219  name += ((fValue == "0") ? "kFALSE" : "kTRUE");
220  else
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 void TGo4ParameterMember::Clear(Option_t* opt)
240 {
241  SetToZero();
242 }
243 
244 void TGo4ParameterMember::Print(Option_t* dummy) const
245 {
246  PrintMember();
247 }
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)