00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4ParameterMember.h"
00015
00016 #include <stdlib.h>
00017
00018 #include "RVersion.h"
00019 #include "Riostream.h"
00020 #include "TROOT.h"
00021 #include "TDataType.h"
00022
00023 TGo4ParameterMember::TGo4ParameterMember() :
00024 TNamed(),
00025 fTypeName(),
00026 fTypeId(0),
00027 fMemberId(0),
00028 fValue(),
00029 fIndex1(-1),
00030 fIndex2(-1),
00031 fObject(0),
00032 fObjectOwner(kTRUE),
00033 fVisible(kTRUE)
00034 {
00035 }
00036
00037 TGo4ParameterMember::TGo4ParameterMember(const char* name, const char* title) :
00038 TNamed(name, title),
00039 fTypeName(),
00040 fTypeId(0),
00041 fMemberId(0),
00042 fValue(),
00043 fIndex1(-1),
00044 fIndex2(-1),
00045 fObject(0),
00046 fObjectOwner(kTRUE),
00047 fVisible(kTRUE)
00048 {
00049 }
00050
00051 TGo4ParameterMember::~TGo4ParameterMember()
00052 {
00053 if ((fObject!=0) && fObjectOwner) {
00054 delete fObject;
00055 fObject = 0;
00056 }
00057 }
00058
00059 void TGo4ParameterMember::SetArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
00060 {
00061 switch(ndim) {
00062 case 1:
00063 fIndex1 = indx1;
00064 fIndex2 = -1;
00065 break;
00066 case 2:
00067 fIndex1 = indx1;
00068 fIndex2 = indx2;
00069 break;
00070 default:
00071 fIndex1 = -1;
00072 fIndex2 = -1;
00073 break;
00074 }
00075 }
00076
00077 Bool_t TGo4ParameterMember::CheckArrayIndexes(Int_t ndim, Int_t indx1, Int_t indx2)
00078 {
00079 switch(ndim) {
00080 case 1: return (fIndex1==indx1) && (fIndex2<0);
00081 case 2: return (fIndex1==indx1) && (fIndex2==indx2);
00082 default: return (fIndex1<0) && (fIndex2<0);
00083 }
00084
00085 return (fIndex1<0) && (fIndex2<0);
00086 }
00087
00088
00089 const char* TGo4ParameterMember::GetFullName(TString& buf)
00090 {
00091 buf = "";
00092 if ((fIndex1<0) && (fIndex2<0))
00093 buf = GetName();
00094 else
00095 if ((fIndex1>=0) && (fIndex2<0))
00096 buf.Form("%s[%d]",GetName(),fIndex1);
00097 else
00098 if ((fIndex1>=0) && (fIndex2>=0))
00099 buf.Form("%s[%d][%d]",GetName(),fIndex1,fIndex2);
00100 return buf.Data();
00101 }
00102
00103 void TGo4ParameterMember::SetObject(TObject* obj, Bool_t owner)
00104 {
00105 if ((fObject!=0) && fObjectOwner) delete fObject;
00106
00107 fObject = obj;
00108 fObjectOwner = owner;
00109 }
00110
00111 void TGo4ParameterMember::SetToZero()
00112 {
00113 if ((fObject!=0) && fObjectOwner) {
00114 delete fObject;
00115 fObject = 0;
00116 }
00117
00118 fValue = "";
00119 fObject = 0;
00120 fObjectOwner = kFALSE;
00121
00122 switch (fTypeId) {
00123 case kUInt_t:
00124 case kInt_t:
00125 case kULong_t:
00126 case kLong_t:
00127 case kULong64_t:
00128 case kLong64_t:
00129 case kUShort_t:
00130 case kShort_t:
00131 case kUChar_t:
00132 case kChar_t:
00133 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
00134 case kBool_t:
00135 #endif
00136 case kFloat_t:
00137 case kDouble_t:
00138 case kDouble32_t: fValue = "0"; break;
00139 case kTString_t: break;
00140 case kTGo4Fitter_t: break;
00141 }
00142 }
00143
00144 void TGo4ParameterMember::SetValue(char* addr)
00145 {
00146 fValue = "";
00147 switch (fTypeId) {
00148 case kUInt_t: fValue.Form("%u", *((UInt_t*)addr)); break;
00149 case kInt_t: fValue.Form("%d", *((Int_t*)addr)); break;
00150 case kULong_t: fValue.Form("%lu", *((ULong_t*)addr)); break;
00151 case kLong_t: fValue.Form("%ld", *((Long_t*)addr)); break;
00152 case kULong64_t: fValue.Form("%llu", *((ULong64_t*)addr)); break;
00153 case kLong64_t: fValue.Form("%lld", *((Long64_t*)addr)); break;
00154 case kUShort_t: fValue.Form("%hu", *((UShort_t*)addr)); break;
00155 case kShort_t: fValue.Form("%hd", *((Short_t*)addr)); break;
00156 case kUChar_t: fValue.Form("%u", *((UChar_t*)addr)); break;
00157 case kChar_t: fValue.Form("%d", *((Char_t*)addr)); break;
00158 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
00159 case kBool_t: fValue.Form("%d", *((Bool_t*)addr)); break;
00160 #endif
00161 case kFloat_t: fValue.Form("%f", *((Float_t*)addr)); break;
00162 case kDouble_t: fValue.Form("%f", *((Double_t*)addr)); break;
00163 case kDouble32_t: fValue.Form("%f", *((Double32_t*)addr)); break;
00164 case kTString_t: fValue = *((TString*)addr); break;
00165 case kTGo4Fitter_t: {
00166 TObject** f = (TObject**) addr;
00167 fObject = *f;
00168 fObjectOwner = kFALSE;
00169 break;
00170 }
00171 }
00172 }
00173
00174 void TGo4ParameterMember::GetValue(char* addr)
00175 {
00176 const char* value = fValue.Data();
00177 switch (fTypeId) {
00178 case kUInt_t: *((UInt_t*)addr) = atoi(value); break;
00179 case kInt_t: *((Int_t*)addr) = atoi(value); break;
00180 case kULong_t: *((ULong_t*)addr) = atoi(value); break;
00181 case kLong_t: *((Long_t*)addr) = atoi(value); break;
00182 case kULong64_t: *((ULong64_t*)addr) = atoi(value); break;
00183 case kLong64_t: *((Long64_t*)addr) = atoi(value); break;
00184 case kUShort_t: *((UShort_t*)addr) = atoi(value); break;
00185 case kShort_t: *((Short_t*)addr) = atoi(value); break;
00186 case kUChar_t: *((UChar_t*)addr) = atoi(value); break;
00187 case kChar_t: *((Char_t*)addr) = atoi(value); break;
00188 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
00189 case kBool_t: *((Bool_t*)addr) = atoi(value); break;
00190 #endif
00191 case kFloat_t: *((Float_t*)addr) = atof(value); break;
00192 case kDouble_t: *((Double_t*)addr) = atof(value); break;
00193 case kDouble32_t: *((Double32_t*)addr) = atof(value); break;
00194 case kTString_t: *((TString*)addr) = value; break;
00195 case kTGo4Fitter_t: {
00196 TObject** f = (TObject**)addr;
00197 *f = fObject;
00198 fObjectOwner = kFALSE;
00199 break;
00200 }
00201 }
00202 }
00203
00204 Int_t TGo4ParameterMember::PrintMember(Text_t* buffer, Int_t buflen) const
00205 {
00206 if ((buffer!=0) && (buflen<=0)) return 0;
00207
00208 Int_t size = 0;
00209
00210 TString name;
00211 if ((fIndex1<0) && (fIndex2<0)) name += GetName(); else
00212 if (fIndex2<0) name += TString::Format("%s[%d]", GetName(), fIndex1); else
00213 name += TString::Format("%s[%d][%d]", GetName(), fIndex1, fIndex2);
00214
00215 name += " = ";
00216
00217 if (fObject) name += TString::Format("Obj:%p Class:%s", fObject, fObject->ClassName()); else
00218 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
00219 if (fTypeId==kBool_t) name += ((fValue=="0") ? "kFALSE" : "kTRUE"); else
00220 #endif
00221 name += fValue;
00222
00223 if ((GetTitle() != 0) && (strlen(GetTitle())>0)) { name += " // "; name += GetTitle(); }
00224
00225 name += "\n";
00226
00227 if(buffer==0) {
00228 TROOT::IndentLevel();
00229 std::cout << name;
00230 } else {
00231 size = name.Length();
00232 if(size>buflen) size = buflen;
00233 strncpy(buffer, name.Data(), size);
00234 }
00235
00236 return size;
00237
00238 }
00239
00240
00241 void TGo4ParameterMember::Clear(Option_t* opt)
00242 {
00243 SetToZero();
00244 }
00245
00246 void TGo4ParameterMember::Print(Option_t* dummy) const
00247 {
00248 PrintMember();
00249 }