20 #include "TObjArray.h"
24 #include "TDataMember.h"
25 #include "TDataType.h"
26 #include "TBaseClass.h"
41 TNamed(name ? name :
"Parameter", title)
43 GO4TRACE((12,
"TGo4Parameter ::TGo4Parameter (const char*, const char*)",__LINE__, __FILE__));
55 GO4TRACE((12,
"TGo4Parameter ::PrintParameter()",__LINE__, __FILE__));
57 if(buflen<=0 && buffer!=0)
return 0;
63 TString localbuf = TString::Format(
"Parameter name: %s class %s\n", GetName(), ClassName());
66 std::cout << localbuf;
68 size = localbuf.Length();
69 if(size>buflen) size = buflen;
70 strncpy(buffer, localbuf.Data(), size);
78 TROOT::IncreaseDirLevel();
88 TROOT::DecreaseDirLevel();
95 GO4TRACE((12,
"TGo4Parameter ::~TGo4Parameter ()",__LINE__, __FILE__));
100 if (rhs==0)
return kFALSE;
102 if (rhs->IsA() != IsA()) {
103 std::cout <<
"GO4> !!! ERROR: Wrong parameter class is used in TGo4Parameter::UpdateFrom() method!!!" << std::endl;
104 std::cout <<
"GO4> !!! ERROR: One cannot update " << IsA()->GetName() <<
" class from " << rhs->IsA()->GetName() << std::endl;
105 std::cout <<
"GO4> !!! ERROR: Implement your custom UpdateFrom() method" << std::endl;
124 url.SetOptions(rest_url_opt);
131 const char* optvalue = url.GetValueFromOptions(member->
GetFullName(dummy));
149 std::cout <<
"GO4> !!! Default TGo4Parameter::Clear() method is used." << std::endl;
150 std::cout <<
"GO4> !!! You probably need to overwrite Clear() method for your class" << IsA()->GetName() << std::endl;
171 if (items==0)
return kFALSE;
181 if ((fItems==0) || (cl==0) || (ptr==0))
return;
183 TIter iter(cl->GetListOfDataMembers());
184 Int_t lastmemberid = -1;
185 if (fItems->GetLast()>=0)
189 while ((obj=iter()) != 0) {
190 TDataMember* member =
dynamic_cast<TDataMember*
>(obj);
191 if (member==0)
continue;
192 const char* memtypename = member->GetFullTypeName();
196 if(strcmp(memtypename,
"TClass*")==0)
continue;
199 Int_t arraydim = member->GetArrayDim();
200 if (arraydim>2)
continue;
202 Int_t maxindex1(1), maxindex2(1);
206 maxindex1 = member->GetMaxIndex(0);
209 maxindex1 = member->GetMaxIndex(0);
210 maxindex2 = member->GetMaxIndex(1);
217 if (strcmp(memtypename,
"TString")==0) {
220 if (strcmp(memtypename,
"TGo4Fitter*")==0) {
223 if (strcmp(memtypename,
"TArrayI")==0) {
225 memtypename =
"Int_t";
226 if ((maxindex1>1) || (maxindex2>1))
continue;
227 arri = (TArrayI*) (ptr + cloffset + member->GetOffset());
229 maxindex1 = arri->GetSize();
232 if (strcmp(memtypename,
"TArrayD")==0) {
233 memtypeid = kDouble_t;
234 memtypename =
"Double_t";
235 if ((maxindex1>1) || (maxindex2>1))
continue;
236 arrd = (TArrayD*) (ptr + cloffset + member->GetOffset());
238 maxindex1 = arrd->GetSize();
241 if (!member->IsBasic())
continue;
242 memtypeid = member->GetDataType()->GetType();
261 for(Int_t ix1=0;ix1<maxindex1;ix1++)
262 for(Int_t ix2=0;ix2<maxindex2;ix2++) {
268 info->
SetType(memtypename, memtypeid);
274 char* addr = ptr + cloffset + member->GetOffset() + (ix1*maxindex2 + ix2) * member->GetUnitSize();
275 if (arri) addr = (
char*) (arri->GetArray() + ix1);
276 if (arrd) addr = (
char*) (arrd->GetArray() + ix1);
283 TIter cliter(cl->GetListOfBases());
284 while((obj=cliter()) !=0) {
285 TBaseClass* baseclass =
dynamic_cast<TBaseClass*
>(obj);
286 if (baseclass==0)
continue;
287 TClass* bclass = baseclass->GetClassPointer();
288 if(bclass==0)
continue;
289 if(strcmp(bclass->GetName(),
"TGo4Parameter")==0)
continue;
290 if(strcmp(bclass->GetName(),
"TNamed")==0)
continue;
292 GetMemberValues(fItems, bclass, ptr, cloffset + baseclass->GetDelta());
299 if (info==0)
return -1;
300 if (strcmp(info->GetName(), member->GetName())!=0)
return -1;
301 if (strcmp(info->GetTitle(), member->GetTitle())!=0)
return -1;
309 if ((items==0) || (cl==0) || (ptr==0))
return kFALSE;
311 TIter iter(cl->GetListOfDataMembers());
314 while ((obj=iter()) != 0) {
315 TDataMember* member =
dynamic_cast<TDataMember*
>(obj);
316 if (member==0)
continue;
317 const char* memtypename = member->GetFullTypeName();
321 if(strcmp(memtypename,
"TClass*")==0)
continue;
324 Int_t arraydim = member->GetArrayDim();
325 if (arraydim>2)
continue;
327 Int_t maxindex1(1), maxindex2(1);
331 maxindex1 = member->GetMaxIndex(0);
334 maxindex1 = member->GetMaxIndex(0);
335 maxindex2 = member->GetMaxIndex(1);
342 if (strcmp(memtypename,
"TString")==0) {
345 if (strcmp(memtypename,
"TGo4Fitter*")==0) {
348 if (strcmp(memtypename,
"TArrayI")==0) {
350 memtypename =
"Int_t";
351 if ((maxindex1>1) || (maxindex2>1))
continue;
352 arri = (TArrayI*) (ptr + cloffset + member->GetOffset());
356 if (maxindex1<0)
return kFALSE;
357 if (arri->GetSize()!=maxindex1) arri->Set(maxindex1);
359 if (strcmp(memtypename,
"TArrayD")==0) {
360 memtypeid = kDouble_t;
361 memtypename =
"Double_t";
362 if ((maxindex1>1) || (maxindex2>1))
continue;
363 arrd = (TArrayD*) (ptr + cloffset + member->GetOffset());
367 if (maxindex1<0)
return kFALSE;
368 if (arrd->GetSize()!=maxindex1) arrd->Set(maxindex1);
370 if (!member->IsBasic())
continue;
371 memtypeid = member->GetDataType()->GetType();
374 for(Int_t ix1=0;ix1<maxindex1;ix1++)
375 for(Int_t ix2=0;ix2<maxindex2;ix2++) {
376 if (itemsindx>items->GetLast())
return kFALSE;
379 if (info==0)
return kFALSE;
381 if (strcmp(info->GetName(), member->GetName())!=0)
return kFALSE;
382 if (strcmp(info->GetTitle(), member->GetTitle())!=0)
return kFALSE;
384 if (strcmp(info->
GetTypeName(), memtypename)!=0)
return kFALSE;
385 if (info->
GetTypeId() != memtypeid)
return kFALSE;
389 char* addr = ptr + cloffset + member->GetOffset() + (ix1*maxindex2 + ix2) * member->GetUnitSize();
390 if (arri) addr = (
char*) (arri->GetArray() + ix1);
391 if (arrd) addr = (
char*) (arrd->GetArray() + ix1);
398 TIter cliter(cl->GetListOfBases());
399 while((obj=cliter()) !=0) {
400 TBaseClass* baseclass =
dynamic_cast<TBaseClass*
>(obj);
401 if (baseclass==0)
continue;
402 TClass* bclass = baseclass->GetClassPointer();
403 if(bclass==0)
continue;
404 if(strcmp(bclass->GetName(),
"TGo4Parameter")==0)
continue;
405 if(strcmp(bclass->GetName(),
"TNamed")==0)
continue;
407 if (!
SetMemberValues(items, itemsindx, bclass, ptr, cloffset + baseclass->GetDelta()))
return kFALSE;
416 TString varname = TString::Format(
"param%d", cnt++);
417 Bool_t savemacro = (opt!=0) && (strstr(opt,
"savemacro")!=0);
420 out << Form(
" %s* %s = (%s*) go4->GetParameter(\"%s\",\"%s\");",
421 ClassName(), varname.Data(), ClassName(), GetName(), ClassName()) << std::endl << std::endl;
422 out << Form(
" if (%s==0) {", varname.Data()) << std::endl;
423 out << Form(
" TGo4Log::Error(\"Could not find parameter %s of class %s\");", GetName(), ClassName()) << std::endl;
424 out << Form(
" return;") << std::endl;
425 out << Form(
" }") << std::endl << std::endl;
426 out << Form(
" TGo4Log::Info(\"Set parameter %s as saved at %s\");", GetName(), TDatime().AsString()) << std::endl << std::endl;
428 out << Form(
" %s* %s = new %s;", ClassName(), varname.Data(), ClassName()) << std::endl;
429 out << Form(
" %s->SetName(\"%s\");", varname.Data(), GetName()) << std::endl;
430 out << Form(
" %s->SetTitle(\"%s\");", varname.Data(), GetTitle()) << std::endl;
433 TObjArray *fitems =
new TObjArray();
434 fitems->SetOwner(kTRUE);
448 out << Form(
" %s->%s = \"%s\";", varname.Data(), membername.Data(), info->
GetStrValue()) << std::endl;
451 out << Form(
" // fitter %s->%s ignored", varname.Data(), membername.Data()) << std::endl;
454 out << Form(
" %s->%s.Set(%d);", varname.Data(), membername.Data(), info->
GetIntValue()) << std::endl;
457 out << Form(
" %s->%s = %s;", varname.Data(), membername.Data(), (info->
GetIntValue() ?
"kTRUE" :
"kFALSE")) << std::endl;
460 out << Form(
" %s->%s = %s;", varname.Data(), membername.Data(), info->
GetStrValue()) << std::endl;
Int_t GetIntValue() const
TGo4ParameterStatus * CreateStatus()
void SetType(const char *name, Int_t id)
Int_t FindArrayLength(TObjArray *items, Int_t &itemsindx, TDataMember *member)
const char * GetFullName(TString &buf)
virtual void SavePrimitive(std::ostream &fs, Option_t *opt="")
void SetStrValue(const char *value)
virtual Int_t PrintParameter(Text_t *buffer=0, Int_t buflen=0)
Bool_t UpdateParameterValues(TGo4Parameter *par)
virtual void Clear(Option_t *opt="")
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 SetValue(char *addr)
Bool_t UpdateFromUrl(const char *rest_url_opt)
void SetIntValue(Int_t value)
Bool_t SetMemberValues(TObjArray *fItems)
const char * GetStrValue() const
virtual Bool_t UpdateFrom(TGo4Parameter *rhs)
const char * GetTypeName() const
void SetVisible(Bool_t on=kTRUE)
void GetValue(char *addr)
void SetMemberId(Int_t id)
void SetArrayIndexes(Int_t ndim=0, Int_t indx1=-1, Int_t indx2=-1)
Bool_t SetStatus(TGo4ParameterStatus *status)
void GetMemberValues(TObjArray *fItems)
static void Info(const char *text,...)