00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4ParaEditStatus.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TDataMember.h"
00021 #include "TBaseClass.h"
00022 #include "TFile.h"
00023 #include "TObjString.h"
00024 #include "TClass.h"
00025
00026 #include "Go4LockGuard/TGo4LockGuard.h"
00027 #include "Go4StatusBase/TGo4Parameter.h"
00028 #include "Go4Fit/TGo4Fitter.h"
00029
00030
00031 TGo4ParaEditStatus::TGo4ParaEditStatus(const char* name, const char* title) :
00032 TGo4Status(name, title), fxPara(0), fxParaClass(0) ,fiMemNum(0),
00033 fxDataFloat(0),fxDataDouble(0), fxDataInt(0),fxDataUInt(0), fxDataShort(0),
00034 fxDataChar(0), fxDataLong(0), fxDataBool(0), fxDataUShort(0),
00035 fxDataUChar(0), fxDataULong(0), fxDataString(0),fxFitPointer(0), fiDatatypeSize(0),fxNextParaClass(0)
00036 {
00037 TGo4LockGuard Global;
00038 BuildParameterList();
00039 fxPara=new TGo4Parameter("defaultname");
00040 UpdateMemberLists();
00041 }
00042
00043 TGo4ParaEditStatus::~TGo4ParaEditStatus()
00044 {
00045 TGo4LockGuard Global;
00046 delete fxPara;
00047 delete fxNextParaClass;
00048 }
00049
00050 void TGo4ParaEditStatus::UpdateParameter(TGo4Parameter* source)
00051 {
00052 if(source==0) return;
00053 {
00054 TGo4LockGuard Global;
00055 delete fxPara;
00056 fxPara=dynamic_cast<TGo4Parameter*> (source->Clone());
00057 }
00058 UpdateMemberLists();
00059 }
00060
00061 void TGo4ParaEditStatus::UpdateLastFitter(TGo4Fitter* source)
00062 {
00063 if(source==0) return;
00064 TGo4LockGuard Global;
00065 if(fxFitPointer)
00066 {
00067 if(*fxFitPointer) delete *fxFitPointer;
00068 *fxFitPointer=dynamic_cast<TGo4Fitter*> (source->Clone());
00069 }
00070 }
00071
00072
00073 void TGo4ParaEditStatus::SetParaName(const Text_t* name)
00074 {
00075 if(name==0) return;
00076 if(fxPara)
00077 {
00078 fxPara->SetName(name);
00079 }
00080
00081 }
00082
00083 void TGo4ParaEditStatus::SetParaClass(const Text_t* name)
00084 {
00085 if(name==0) return;
00086 TGo4LockGuard Global;
00087 TClass* nclass=gROOT->GetClass(name);
00088 if(nclass)
00089 {
00090 snprintf(fcTextBuffer,256,"%s",fxPara->GetName());
00091 delete fxPara;
00092 fxPara= (TGo4Parameter*) nclass->New();
00093 fxPara->SetName(fcTextBuffer);
00094 UpdateMemberLists();
00095 }
00096 else
00097 {
00098 cout <<"Could not set parameter to class "<< name << endl;
00099 }
00100
00101 }
00102
00103
00104 const Text_t* TGo4ParaEditStatus::GetParaName()
00105 {
00106 if(fxPara==0) return 0;
00107 return fxPara->GetName();
00108 }
00109
00110 const Text_t* TGo4ParaEditStatus::GetParaClass()
00111 {
00112 if(fxParaClass==0) return 0;
00113 return fxParaClass->GetName();
00114 }
00115
00116 const Text_t* TGo4ParaEditStatus::GetParaMember(Int_t i)
00117 {
00118 if ((i>fiMemNum) || (i<0)) return 0;
00119 TGo4LockGuard Global;
00120 const Text_t* rev;
00121 TObjString* memname=dynamic_cast<TObjString*>(fxNames[i]);
00122 if(memname)
00123 {
00124 rev=memname->GetName();
00125 }
00126 else
00127 {
00128 rev=0;
00129 }
00130 return rev;
00131 }
00132
00133 const Text_t* TGo4ParaEditStatus::GetParaMemType(Int_t i)
00134 {
00135 if ((i>fiMemNum) || (i<0)) return 0;
00136 TGo4LockGuard Global;
00137 const Text_t* rev;
00138 TObjString* memtype=dynamic_cast<TObjString*>(fxTypes[i]);
00139 if(memtype)
00140 {
00141 rev=memtype->GetName();
00142 }
00143 else
00144 {
00145 rev=0;
00146 }
00147 return rev;
00148 }
00149
00150 const Text_t* TGo4ParaEditStatus::GetParaMemVal(Int_t i)
00151 {
00152 if ((i>fiMemNum) || (i<0)) return 0;
00153 TGo4LockGuard Global;
00154 Long_t address=fxAddress[i];
00155 const Text_t* memtype=GetParaMemType(i);
00156 const Text_t* value=ValueString(memtype,address);
00157
00158 return value;
00159 }
00160
00161 const Text_t* TGo4ParaEditStatus::GetParaMemComment(Int_t i) {
00162 if ((i>fiMemNum) || (i<0)) return 0;
00163 TGo4LockGuard Global;
00164 const Text_t* rev;
00165 TObjString* memtitle=dynamic_cast<TObjString*>(fxComments[i]);
00166 if(memtitle)
00167 {
00168 rev = memtitle->GetName();
00169 }
00170 else
00171 {
00172 rev=0;
00173 }
00174 return rev;
00175 }
00176
00177 void TGo4ParaEditStatus::SetParaMemVal(Int_t i, const Text_t* val)
00178 {
00179 if ((i>fiMemNum) || (i<0)) return;
00180 TGo4LockGuard Global;
00181 Long_t address=fxAddress[i];
00182 const Text_t* memtype=GetParaMemType(i);
00183 SetValue(memtype,val,address);
00184 }
00185
00186 const Int_t TGo4ParaEditStatus::GetParaMemArrIndex(Int_t i)
00187 {
00188 if ((i>fiMemNum) || (i<0)) return 0;
00189 TGo4LockGuard Global;
00190 Int_t index=fxArrayIndex[i];
00191 return index;
00192 }
00193
00194 const Int_t TGo4ParaEditStatus::GetParaMemArrIndey(Int_t i)
00195 {
00196 if ((i>fiMemNum) || (i<0)) return 0;
00197 TGo4LockGuard Global;
00198 Int_t index=fxArrayIndey[i];
00199 return index;
00200 }
00201
00202
00203 Bool_t TGo4ParaEditStatus::IsParaMemVisible(Int_t i)
00204 {
00205 if ((i>fiMemNum) || (i<0)) return kFALSE;
00206 TGo4LockGuard Global;
00207 Bool_t visible=fbMemberVisible[i];
00208 return visible;
00209 }
00210
00211 void TGo4ParaEditStatus::SetParaMemVisible(Int_t i, Bool_t on)
00212 {
00213 if ((i>fiMemNum) || (i<0)) return;
00214 TGo4LockGuard Global;
00215 fbMemberVisible[i]=on;
00216 }
00217
00218 Long_t TGo4ParaEditStatus::GetMemberAddress(Int_t i)
00219 {
00220 if ((i>fiMemNum) || (i<0)) return 0;
00221 TGo4LockGuard Global;
00222 return fxAddress[i];
00223 }
00224
00225 void TGo4ParaEditStatus::UpdateMemberLists()
00226 {
00227 if(fxPara==0) return;
00228 TGo4LockGuard Global;
00229 fxParaClass=fxPara->IsA();
00230 fiMemNum=0;
00231
00232 fxAddress.clear();
00233 fxArrayIndex.clear();
00234 fxArrayIndey.clear();
00235 fbMemberVisible.clear();
00236 fxNames.Delete();
00237 fxTypes.Delete();
00238 fxVals.Delete();
00239 fxComments.Delete();
00240
00241 fxNames.Compress();
00242 fxNames.Expand(fxNames.GetLast()+1);
00243 fxTypes.Compress();
00244 fxTypes.Expand(fxTypes.GetLast()+1);
00245 fxVals.Compress();
00246 fxVals.Expand(fxVals.GetLast()+1);
00247 fxComments.Compress();
00248 fxComments.Expand(fxComments.GetLast()+1);
00249
00250 EvalMembers(fxParaClass,0);
00251 }
00252
00253
00254 void TGo4ParaEditStatus::EvalMembers(TClass* cl, Long_t baseoffset)
00255 {
00256 if(cl)
00257 {
00258 TGo4LockGuard glob;
00259
00260 TList* members =cl->GetListOfDataMembers();
00261 TIterator* memiter=members->MakeIterator();
00262 TObject* nob=0;
00263 Bool_t isvisible=kTRUE;
00264 while((nob=memiter->Next()) !=0)
00265 {
00266 TDataMember* mem=dynamic_cast<TDataMember*>(nob);
00267 const Text_t* memtypename=mem->GetFullTypeName();
00268 if(!strcmp(memtypename,"TClass*")) continue;
00269
00270 Long_t arrayoffset=0;
00271 Int_t arrayindex=0;
00272 Int_t arrayindey=0;
00273 Int_t arraydim=mem->GetArrayDim();
00274 Int_t maxindex;
00275 Int_t maxindey;
00276 switch(arraydim)
00277 {
00278 case 1:
00279 SetCast(memtypename,0);
00280 maxindex=mem->GetMaxIndex(0);
00281 maxindey=1;
00282 break;
00283
00284 case 2:
00285 SetCast(memtypename,0);
00286 maxindex=mem->GetMaxIndex(0);
00287 maxindey=mem->GetMaxIndex(1);
00288
00289
00290
00291
00292
00293 break;
00294
00295 default:
00296 maxindex=1;
00297 maxindey=1;
00298 break;
00299 }
00300
00301 for(Int_t ix=0;ix<maxindex;++ix)
00302 {
00303 for(Int_t iy=0;iy<maxindey;++iy)
00304 {
00305 arrayoffset=(ix*maxindey + iy) * fiDatatypeSize;
00306 Long_t offset=baseoffset + mem->GetOffset()+arrayoffset;
00307 Long_t address=(Long_t) fxPara + offset;
00308 TObjString* memtype=new TObjString(memtypename);
00309 TObjString* memval=new TObjString(ValueString(memtypename, address));
00310 TObjString* memname= new TObjString(mem->GetName());
00311 TObjString* memtitle = new TObjString(mem->GetTitle());
00312 switch(arraydim)
00313 {
00314 case 1:
00315 snprintf(fcTextBuffer,256,"%s[%d]",memname->GetName(),ix);
00316 memname->SetString(fcTextBuffer);
00317 arrayindex=ix;
00318 arrayindey=-1;
00319 break;
00320 case 2:
00321 snprintf(fcTextBuffer,256,"%s[%d][%d]",memname->GetName(),ix,iy);
00322 memname->SetString(fcTextBuffer);
00323 arrayindex=ix;
00324 arrayindey=iy;
00325 break;
00326 default:
00327
00328 arrayindex=-1;
00329 arrayindey=-1;
00330 break;
00331 }
00332 if(ix==0 && iy==0)
00333 isvisible=kTRUE;
00334 else
00335 isvisible=kFALSE;
00336 fxNames.AddAtAndExpand(memname,fiMemNum);
00337 fxTypes.AddAtAndExpand(memtype,fiMemNum);
00338 fxVals.AddAtAndExpand(memval,fiMemNum);
00339 fxComments.AddAtAndExpand(memtitle,fiMemNum);
00340 fxAddress.push_back(address);
00341 fxArrayIndex.push_back(arrayindex);
00342 fxArrayIndey.push_back(arrayindey);
00343 fbMemberVisible.push_back(isvisible);
00344
00345 fiMemNum++;
00346 }
00347 }
00348 }
00349 delete memiter;
00350
00351
00352 TList* baselist=cl->GetListOfBases();
00353 TIterator* baseiter=baselist->MakeIterator();
00354 TObject* bob=0;
00355 while((bob=baseiter->Next()) !=0)
00356 {
00357 TBaseClass* baseclass=dynamic_cast<TBaseClass*>(bob);
00358 if(baseclass)
00359 {
00360
00361 TClass* bclass=baseclass->GetClassPointer();
00362 if(bclass==0) continue;
00363 if(!strcmp(bclass->GetName(),"TGo4Parameter")) continue;
00364 if(!strcmp(bclass->GetName(),"TNamed")) continue;
00365 Int_t bdelta=baseclass->GetDelta();
00366 EvalMembers(bclass, baseoffset+bdelta);
00367
00368 }
00369 }
00370 delete baseiter;
00371 }
00372 else
00373 {
00374
00375
00376 cout <<"Parameter class not known to ROOT!!!" << endl;
00377 cout <<"Please load library first !!!" << endl;
00378 }
00379 }
00380
00381 const Text_t* TGo4ParaEditStatus::ValueString(const Text_t* memtype,
00382 Long_t address)
00383 {
00384 TGo4LockGuard glob;
00385 SetCast(memtype,address);
00386 if(fxDataFloat) snprintf(fcTextBuffer,256,"%f",*fxDataFloat);
00387 else if(fxDataDouble) snprintf(fcTextBuffer,256,"%f",*fxDataDouble);
00388 else if(fxDataInt) snprintf(fcTextBuffer,256,"%d", *fxDataInt);
00389 else if(fxDataUInt) snprintf(fcTextBuffer,256,"%u", *fxDataUInt);
00390 else if(fxDataShort) snprintf(fcTextBuffer,256,"%hd", *fxDataShort);
00391 else if(fxDataChar) snprintf(fcTextBuffer,256,"%hhd", *fxDataChar);
00392 else if(fxDataLong) snprintf(fcTextBuffer,256,"%ld", *fxDataLong);
00393 else if(fxDataBool) snprintf(fcTextBuffer,256,"%d", *fxDataBool);
00394 else if(fxDataUShort)snprintf(fcTextBuffer,256,"%hu", *fxDataUShort);
00395 else if(fxDataUChar) snprintf(fcTextBuffer,256,"%hhu", *fxDataUChar);
00396 else if(fxDataULong) snprintf(fcTextBuffer,256,"%lu", *fxDataULong);
00397 else if(fxDataString) snprintf(fcTextBuffer,256,"%s", (*fxDataString).Data());
00398 else if(memtype && !strcmp(memtype,"TGo4Fitter*")) snprintf(fcTextBuffer,256,"RMB Edit");
00399 else snprintf(fcTextBuffer,256,"Unknown type %s",memtype);
00400 return fcTextBuffer;
00401 }
00402
00403 void TGo4ParaEditStatus::SetCast(const Text_t* memtype,
00404 Long_t address)
00405 {
00406 if(memtype==0) return;
00407 fxDataFloat=0;
00408 fxDataDouble=0;
00409 fxDataInt=0;
00410 fxDataShort=0;
00411 fxDataChar=0;
00412 fxDataLong=0;
00413 fxDataBool=0;
00414 fxDataUInt=0;
00415 fxDataUShort=0;
00416 fxDataUChar=0;
00417 fxDataULong=0;
00418 fxDataString=0;
00419 fiDatatypeSize=0;
00420
00421 if(!strcmp(memtype,"Float_t"))
00422 {
00423
00424 fxDataFloat=(Float_t*) (address);
00425 fiDatatypeSize=sizeof(Float_t);
00426
00428
00429 else if (!strcmp(memtype,"Double_t"))
00430 {
00431
00432 fxDataDouble=(Double_t*) (address);
00433 fiDatatypeSize=sizeof(Double_t);
00434 }
00435 else if (!strcmp(memtype,"Int_t"))
00436 {
00437
00438 fxDataInt=(Int_t*) (address);
00439 fiDatatypeSize=sizeof(Int_t);
00440 }
00441 else if (!strcmp(memtype,"Short_t"))
00442 {
00443
00444 fxDataShort=(Short_t*) (address);
00445 fiDatatypeSize=sizeof(Short_t);
00446 }
00447 else if (!strcmp(memtype,"Char_t"))
00448 {
00449
00450 fxDataChar=(Char_t*) (address);
00451 fiDatatypeSize=sizeof(Char_t);
00452 }
00453 else if (!strcmp(memtype,"Long_t"))
00454 {
00455
00456 fxDataLong=(Long_t*) (address);
00457 fiDatatypeSize=sizeof(Long_t);
00458 }
00459 else if (!strcmp(memtype,"Bool_t"))
00460 {
00461
00462 fxDataBool=(Bool_t*) (address);
00463 fiDatatypeSize=sizeof(Bool_t);
00464 }
00465 else if (!strcmp(memtype,"UInt_t"))
00466 {
00467
00468 fxDataUInt=(UInt_t*) (address);
00469 fiDatatypeSize=sizeof(UInt_t);
00470 }
00471 else if (!strcmp(memtype,"UShort_t"))
00472 {
00473
00474 fxDataUShort=(UShort_t*) (address);
00475 fiDatatypeSize=sizeof(UShort_t);
00476 }
00477 else if (!strcmp(memtype,"UChar_t"))
00478 {
00479
00480 fxDataUChar=(UChar_t*) (address);
00481 fiDatatypeSize=sizeof(UChar_t);
00482 }
00483 else if (!strcmp(memtype,"ULong_t"))
00484 {
00485
00486 fxDataULong=(ULong_t*) (address);
00487 fiDatatypeSize=sizeof(ULong_t);
00488 }
00489 else if (!strcmp(memtype,"TString"))
00490 {
00491
00492 fxDataString=(TString*) (address);
00493 fiDatatypeSize=sizeof(TString);
00494 }
00495 else if (!strcmp(memtype,"TGo4Fitter*"))
00496 {
00497
00498 fiDatatypeSize=sizeof(TGo4Fitter*);
00499 }
00500 else
00501 {
00502
00503
00504
00505 }
00506
00507
00508 }
00509
00510 void TGo4ParaEditStatus::SetValue(const Text_t* memtype,
00511 const Text_t* expression,
00512 Long_t address)
00513 {
00514 TGo4LockGuard glob;
00515 SetCast(memtype,address);
00516 if(fxDataFloat) *fxDataFloat=atof(expression);
00517 else if(fxDataDouble) *fxDataDouble=atof(expression);
00518 else if(fxDataInt) *fxDataInt=atoi(expression);
00519 else if(fxDataUInt) *fxDataUInt=atoi(expression);
00520 else if(fxDataShort) *fxDataShort=(Short_t) atoi(expression);
00521 else if(fxDataChar) *fxDataChar=(Char_t) atoi(expression);
00522 else if(fxDataLong) *fxDataLong=atoi(expression);
00523 else if(fxDataBool) *fxDataBool= (Bool_t) atoi(expression);
00524 else if(fxDataUShort)*fxDataUShort=(UShort_t) atoi(expression);
00525 else if(fxDataUChar) *fxDataUChar=(UChar_t) atoi(expression);
00526 else if(fxDataULong) *fxDataULong=atoi(expression);
00527 else if(fxDataString) *fxDataString=expression;
00528 else ;
00529 }
00530
00531 Bool_t TGo4ParaEditStatus::LoadParameter(
00532 const Text_t* filename, const Text_t* parname)
00533 {
00534
00535 TGo4LockGuard Global;
00536
00537 TFile parafile(filename,"READ");
00538 if(!parafile.IsOpen()) return kFALSE;
00539
00540 const Text_t* obname;
00541 if(parname)
00542 {
00543 obname=parname;
00544 }
00545 else
00546 {
00547 if(fxPara==0) return kFALSE;
00548 obname=fxPara->GetName();
00549 }
00550 TObject* ob=parafile.Get(obname);
00551
00552 if(ob && ob->InheritsFrom("TGo4Parameter"))
00553 {
00554
00555 UpdateParameter(dynamic_cast<TGo4Parameter*>(ob));
00556 return kTRUE;
00557 }
00558 else
00559 {
00560
00561 return kFALSE;
00562 }
00563
00564
00565 }
00566
00567
00568 void TGo4ParaEditStatus::BuildParameterList()
00569 {
00570 TGo4LockGuard Global;
00571 fxParaClassList.Clear("nodelete");
00572 TSeqCollection* allclasses=gROOT->GetListOfClasses();
00573 TClass* cl=0;
00574 TIterator* cliter=allclasses->MakeIterator();
00575 while((cl=dynamic_cast<TClass*>(cliter->Next())) !=0)
00576 {
00577
00578 if(cl->InheritsFrom("TGo4Parameter"))
00579 {
00580 fxParaClassList.AddLast(cl);
00581 }
00582 }
00583 delete cliter;
00584 delete fxNextParaClass;
00585 fxNextParaClass=fxParaClassList.MakeIterator();
00586 }
00587
00588
00589 void TGo4ParaEditStatus::ResetParameterList()
00590 {
00591 TGo4LockGuard Global;
00592 if(fxNextParaClass)
00593 {
00594 fxNextParaClass->Reset();
00595
00596 }
00597 }
00598
00599 const Text_t* TGo4ParaEditStatus::NextParameterClass()
00600 {
00601 TGo4LockGuard Global;
00602 TClass* nextclass=dynamic_cast<TClass*>(fxNextParaClass->Next());
00603 if(nextclass)
00604 {
00605
00606 return nextclass->GetName();
00607 }
00608 else
00609 return 0;
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621