GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4ParameterMember.cxx
Go to the documentation of this file.
1// $Id$
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
18#include "TROOT.h"
19#include "TDataType.h"
20
21#include "TGo4Status.h"
22
27
28TGo4ParameterMember::TGo4ParameterMember(const char *name, const char *title) :
29 TNamed(name, title)
30{
31}
32
34{
35 if (fObject && fObjectOwner) {
36 delete fObject;
37 fObject = nullptr;
38 }
39}
40
41void TGo4ParameterMember::SetArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
42{
43 switch(ndim) {
44 case 1:
45 fIndex1 = indx1;
46 fIndex2 = -1;
47 break;
48 case 2:
49 fIndex1 = indx1;
50 fIndex2 = indx2;
51 break;
52 default:
53 fIndex1 = -1;
54 fIndex2 = -1;
55 break;
56 }
57}
58
59Bool_t TGo4ParameterMember::CheckArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
60{
61 switch(ndim) {
62 case 1: return (fIndex1==indx1) && (fIndex2<0);
63 case 2: return (fIndex1==indx1) && (fIndex2==indx2);
64 }
65
66 return (fIndex1<0) && (fIndex2<0);
67}
68
69
70const char *TGo4ParameterMember::GetFullName(TString &buf) const
71{
72 buf = "";
73 if ((fIndex1 < 0) && (fIndex2 < 0))
74 buf = GetName();
75 else if ((fIndex1 >= 0) && (fIndex2 < 0))
76 buf.Form("%s[%d]", GetName(), fIndex1);
77 else if ((fIndex1 >= 0) && (fIndex2 >= 0))
78 buf.Form("%s[%d][%d]", GetName(), fIndex1, fIndex2);
79 return buf.Data();
80}
81
82void TGo4ParameterMember::SetObject(TObject *obj, Bool_t owner)
83{
84 if (fObject && fObjectOwner) delete fObject;
85
86 fObject = obj;
87 fObjectOwner = owner;
88}
89
91{
92 if (fObject && fObjectOwner)
93 delete fObject;
94
95 fValue = "";
96 fObject = nullptr;
97 fObjectOwner = kFALSE;
98
99 switch (fTypeId) {
100 case kUInt_t:
101 case kInt_t:
102 case kULong_t:
103 case kLong_t:
104 case kULong64_t:
105 case kLong64_t:
106 case kUShort_t:
107 case kShort_t:
108 case kUChar_t:
109 case kChar_t:
110 case kBool_t:
111 case kFloat_t:
112 case kDouble_t:
113 case kDouble32_t: fValue = "0"; break;
114 case kTString_t: break;
115 case kTGo4Fitter_t: break;
116 }
117}
118
120{
121 fValue = "";
122 switch (fTypeId) {
123 case kUInt_t: fValue.Form("%u", *((UInt_t *)addr)); break;
124 case kInt_t: fValue.Form("%d", *((Int_t *)addr)); break;
125 case kULong_t: fValue.Form("%lu", *((ULong_t *)addr)); break;
126 case kLong_t: fValue.Form("%ld", *((Long_t *)addr)); break;
127 case kULong64_t: fValue.Form("%llu", *((ULong64_t *)addr)); break;
128 case kLong64_t: fValue.Form("%lld", *((Long64_t *)addr)); break;
129 case kUShort_t: fValue.Form("%hu", *((UShort_t *)addr)); break;
130 case kShort_t: fValue.Form("%hd", *((Short_t *)addr)); break;
131 case kUChar_t: fValue.Form("%u", *((UChar_t *)addr)); break;
132 case kChar_t: fValue.Form("%d", *((Char_t *)addr)); break;
133 case kBool_t: fValue.Form("%d", *((Bool_t *)addr)); break;
134 case kFloat_t: fValue.Form("%.7g", *((Float_t *)addr)); break;
135 case kDouble_t: fValue.Form("%.16g", *((Double_t *)addr)); break;
136 case kDouble32_t: fValue.Form("%.16g", *((Double32_t *)addr)); break;
137 case kTString_t: fValue = *((TString *)addr); break;
138 case kTGo4Fitter_t: {
139 TObject **f = (TObject **) addr;
140 fObject = *f;
141 fObjectOwner = kFALSE;
142 break;
143 }
144 }
145}
146
148{
149 const char *value = fValue.Data();
150 switch (fTypeId) {
151 case kUInt_t: *((UInt_t *)addr) = atoi(value); break;
152 case kInt_t: *((Int_t *)addr) = atoi(value); break;
153 case kULong_t: *((ULong_t *)addr) = atoi(value); break;
154 case kLong_t: *((Long_t *)addr) = atoi(value); break;
155 case kULong64_t: *((ULong64_t *)addr) = atoi(value); break;
156 case kLong64_t: *((Long64_t *)addr) = atoi(value); break;
157 case kUShort_t: *((UShort_t *)addr) = atoi(value); break;
158 case kShort_t: *((Short_t *)addr) = atoi(value); break;
159 case kUChar_t: *((UChar_t *)addr) = atoi(value); break;
160 case kChar_t: *((Char_t *)addr) = atoi(value); break;
161 case kBool_t:
162 if (!strcmp(value,"true"))
163 *((Bool_t*)addr) = kTRUE;
164 else if (!strcmp(value,"false"))
165 *((Bool_t*)addr) = kFALSE;
166 else
167 *((Bool_t*)addr) = atoi(value);
168 break;
169 case kFloat_t: *((Float_t *)addr) = atof(value); break;
170 case kDouble_t: *((Double_t *)addr) = atof(value); break;
171 case kDouble32_t: *((Double32_t *)addr) = atof(value); break;
172 case kTString_t: *((TString *)addr) = value; break;
173 case kTGo4Fitter_t: {
174 TObject **f = (TObject **)addr;
175 *f = fObject;
176 fObjectOwner = kFALSE;
177 break;
178 }
179 }
180}
181
183{
184 SetToZero();
185}
186
187void TGo4ParameterMember::Print(Option_t *) const
188{
189 TString value = fValue;
190
191 if (fObject)
192 value = TString::Format("Obj:%p Class:%s", fObject, fObject->ClassName());
193 else if (fTypeId == kBool_t)
194 value = ((value == "0") ? "kFALSE" : "kTRUE");
195
196 if (GetTitle() && (strlen(GetTitle()) > 0)) {
197 value += " // ";
198 value += GetTitle();
199 }
200
201 if ((fIndex1 < 0) && (fIndex2 < 0))
202 TGo4Status::PrintLine("%s = %s", GetName(), value.Data());
203 else if (fIndex2 < 0)
204 TGo4Status::PrintLine("%s[%d] = %s", GetName(), fIndex1, value.Data());
205 else
206 TGo4Status::PrintLine("%s[%d][%d] = %s", GetName(), fIndex1, fIndex2, value.Data());
207}
const char * GetFullName(TString &buf) const
Int_t fIndex2
second array index
Bool_t CheckArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
void SetObject(TObject *obj, Bool_t owner)
Int_t fIndex1
first array index
void Print(Option_t *opt="") const override
Bool_t fObjectOwner
! flag indicating ownership of object
void SetArrayIndexes(Int_t ndim=0, Int_t indx1=-1, Int_t indx2=-1)
TObject * fObject
place for objects like fitter
void Clear(Option_t *opt="") override
Int_t fTypeId
type id of data member
TString fValue
value of data member
static void PrintLine(const char *text,...)
Print single line of debug output with appropriate indent.