Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4Parameter.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4Parameter.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TList.h"
00021 #include "TObjArray.h"
00022 #include "TClass.h"
00023 #include "TDataMember.h"
00024 #include "TDataType.h"
00025 #include "TBaseClass.h"
00026 #include "snprintf.h"
00027 
00028 #include "TGo4Log.h"
00029 #include "TGo4ParameterMember.h"
00030 
00031 TGo4Parameter::TGo4Parameter() :
00032    TNamed()
00033 {
00034 }
00035 
00036 TGo4Parameter::TGo4Parameter(const char* name, const char* title) :
00037    TNamed(name, title)
00038 {
00039    TRACE((12,"TGo4Parameter ::TGo4Parameter (Text_t*, Text_t*)",__LINE__, __FILE__));
00040 
00041 }
00042 
00043 void TGo4Parameter::Print(Option_t* dummy) const
00044 {
00045    // this trick is needed since root defines Print as const function...
00046    TGo4Parameter* const localthis= const_cast<TGo4Parameter* const>(this);
00047    localthis->PrintParameter();
00048 }
00049 
00050 Int_t TGo4Parameter::PrintParameter(Text_t* buffer, Int_t buflen)
00051 {
00052    TRACE((12,"TGo4Parameter ::PrintParameter()",__LINE__, __FILE__));
00053    //
00054    if(buflen<=0 && buffer!=0)
00055       return 0;
00056    Int_t locallen=2048;
00057    Text_t localbuf[2048];
00058    Int_t size=0;
00059    size=snprintf(localbuf, locallen-1,
00060                      " Parameter Class %s, name: %s \n",
00061                         ClassName(), GetName());
00062    if(buffer==0)
00063       {
00064           cout << localbuf << endl;
00065       }
00066    else
00067       {
00068          if(size>buflen-1)
00069             size=buflen-1;
00070          strncpy(buffer,localbuf,size);
00071       }
00072    return size;
00073 }
00074 
00075 TGo4Parameter::~TGo4Parameter()
00076 {
00077    TRACE((12,"TGo4Parameter ::~TGo4Parameter ()",__LINE__, __FILE__));
00078 }
00079 
00080 Bool_t TGo4Parameter::UpdateFrom(TGo4Parameter* rhs)
00081 {
00082    if(rhs) return kFALSE;
00083    // this method should better be pure virtual.
00084    // however, we have to implement dummy for root
00085    // to let it clone and stream this with baseclass type
00086    cout << "GO4> !!! ERROR: TGo4Parameter::UpdateFrom() not implemented!!!" << endl;
00087    cout << "GO4> Please overwrite virtual method in your class: " << this->ClassName() << endl;
00088    return kFALSE;
00089 }
00090 
00091 void TGo4Parameter::Clear(Option_t* opt)
00092 {
00093  // dummy clear, may be implemented by user
00094   cout << "GO4> !!! ERROR: TGo4Parameter::Clear() not implemented!!!" << endl;
00095   cout << "GO4> Please overwrite virtual method in your class: ";
00096   cout << this->ClassName() << endl;
00097 }
00098 
00099 void TGo4Parameter::GetMemberValues(TObjArray* fItems)
00100 {
00101    GetMemberValues(fItems, IsA(), (char*) this, 0);
00102 }
00103 
00104 Bool_t TGo4Parameter::SetMemberValues(TObjArray* fItems)
00105 {
00106    if (fItems==0) return kFALSE;
00107 
00108    TIterator* iter = fItems->MakeIterator();
00109 
00110    Bool_t res = SetMemberValues(iter, IsA(), (char*) this, 0);
00111 
00112    delete iter;
00113 
00114    return res;
00115 }
00116 
00117 
00118 void TGo4Parameter::GetMemberValues(TObjArray* fItems, TClass* cl, char* ptr, unsigned long int cloffset)
00119 {
00120    if ((fItems==0) || (cl==0) || (ptr==0)) return;
00121 
00122    TIter iter(cl->GetListOfDataMembers());
00123    Int_t lastmemberid = -1;
00124    if (fItems->GetLast()>=0)
00125       lastmemberid = ((TGo4ParameterMember*) fItems->Last())->GetMemberId();
00126 
00127    TObject* obj = 0;
00128    while ((obj=iter()) != 0) {
00129       TDataMember* member = dynamic_cast<TDataMember*>(obj);
00130       if (member==0) continue;
00131       const char* memtypename = member->GetFullTypeName();
00132       Int_t memtypeid = 0;
00133 
00134       // do not edit IsA info
00135       if(strcmp(memtypename,"TClass*")==0) continue;
00136       // skip for a moment all types which are not basic types
00137 
00138       if (strcmp(memtypename,"TString")==0)
00139         memtypeid = TGo4ParameterMember::kTString_t;
00140       else
00141       if (strcmp(memtypename,"TGo4Fitter*")==0)
00142         memtypeid = TGo4ParameterMember::kTGo4Fitter_t;
00143       else {
00144         if (!member->IsBasic()) continue;
00145         memtypeid = member->GetDataType()->GetType();
00146       }
00147 
00148       Int_t unitsize = member->GetUnitSize();
00149       Int_t arraydim = member->GetArrayDim();
00150 
00151       Int_t maxindex1 = 1;
00152       Int_t maxindex2 = 1;
00153 
00154       switch(arraydim) {
00155         case 1:
00156           maxindex1 = member->GetMaxIndex(0);
00157           break;
00158         case 2:
00159           maxindex1 = member->GetMaxIndex(0);
00160           maxindex2 = member->GetMaxIndex(1);
00161           break;
00162       } // switch()
00163 
00164       lastmemberid++;
00165 
00166       for(Int_t ix1=0;ix1<maxindex1;ix1++)
00167         for(Int_t ix2=0;ix2<maxindex2;ix2++) {
00168           TGo4ParameterMember* info = new TGo4ParameterMember(member->GetName(), member->GetTitle());
00169           fItems->Add(info);
00170 
00171           info->SetMemberId(lastmemberid);
00172 
00173           info->SetType(memtypename, memtypeid);
00174 
00175           info->SetVisible((ix1==0) && (ix2==0));
00176 
00177           info->SetArrayIndexes(arraydim, ix1, ix2);
00178 
00179           char* addr = ptr + cloffset + member->GetOffset() + (ix1*maxindex2 + ix2) * unitsize;
00180           info->SetValue(addr);
00181         }
00182    }
00183 
00184    // expand base classes
00185    TIter cliter(cl->GetListOfBases());
00186    while((obj=cliter()) !=0) {
00187       TBaseClass* baseclass = dynamic_cast<TBaseClass*>(obj);
00188       if (baseclass==0) continue;
00189       TClass* bclass = baseclass->GetClassPointer();
00190       if(bclass==0) continue;
00191       if(strcmp(bclass->GetName(), "TGo4Parameter")==0) continue;
00192       if(strcmp(bclass->GetName(), "TNamed")==0) continue;
00193 
00194       GetMemberValues(fItems, bclass, ptr, cloffset + baseclass->GetDelta());
00195    }
00196 }
00197 
00198 Bool_t TGo4Parameter::SetMemberValues(TIterator* fItems, TClass* cl, char* ptr, unsigned long int cloffset)
00199 {
00200    if ((fItems==0) || (cl==0) || (ptr==0)) return kFALSE;
00201 
00202    TIter iter(cl->GetListOfDataMembers());
00203 
00204    TObject* obj = 0;
00205    while ((obj=iter()) != 0) {
00206       TDataMember* member = dynamic_cast<TDataMember*>(obj);
00207       if (member==0) continue;
00208       const char* memtypename = member->GetFullTypeName();
00209       Int_t memtypeid = 0;
00210 
00211       // do not edit IsA info
00212       if(strcmp(memtypename,"TClass*")==0) continue;
00213       // skip for a moment all types which are not basic types
00214 
00215       if (strcmp(memtypename,"TString")==0)
00216         memtypeid = TGo4ParameterMember::kTString_t;
00217       else
00218       if (strcmp(memtypename,"TGo4Fitter*")==0)
00219         memtypeid = TGo4ParameterMember::kTGo4Fitter_t;
00220       else {
00221         if (!member->IsBasic()) continue;
00222         memtypeid = member->GetDataType()->GetType();
00223       }
00224 
00225       Int_t unitsize = member->GetUnitSize();
00226       Int_t arraydim = member->GetArrayDim();
00227 
00228       Int_t maxindex1 = 1;
00229       Int_t maxindex2 = 1;
00230 
00231       switch(arraydim) {
00232         case 1:
00233           maxindex1 = member->GetMaxIndex(0);
00234           break;
00235         case 2:
00236           maxindex1 = member->GetMaxIndex(0);
00237           maxindex2 = member->GetMaxIndex(1);
00238           break;
00239       } // switch()
00240 
00241       for(Int_t ix1=0;ix1<maxindex1;ix1++)
00242         for(Int_t ix2=0;ix2<maxindex2;ix2++) {
00243           TGo4ParameterMember* info =
00244             dynamic_cast<TGo4ParameterMember*> (fItems->Next());
00245           if (info==0) return kFALSE;
00246 
00247           if (strcmp(info->GetName(), member->GetName())!=0) return kFALSE;
00248           if (strcmp(info->GetTitle(), member->GetTitle())!=0) return kFALSE;
00249 
00250           if (strcmp(info->GetTypeName(), memtypename)!=0) return kFALSE;
00251           if (info->GetTypeId() != memtypeid) return kFALSE;
00252 
00253           if (!info->CheckArrayIndexes(arraydim, ix1, ix2)) return kFALSE;
00254 
00255           char* addr = ptr + cloffset + member->GetOffset() + (ix1*maxindex2 + ix2) * unitsize;
00256           info->GetValue(addr);
00257         }
00258    }
00259 
00260    // expand base classes
00261    TIter cliter(cl->GetListOfBases());
00262    while((obj=cliter()) !=0) {
00263       TBaseClass* baseclass = dynamic_cast<TBaseClass*>(obj);
00264       if (baseclass==0) continue;
00265       TClass* bclass = baseclass->GetClassPointer();
00266       if(bclass==0) continue;
00267       if(strcmp(bclass->GetName(), "TGo4Parameter")==0) continue;
00268       if(strcmp(bclass->GetName(), "TNamed")==0) continue;
00269 
00270       if (!SetMemberValues(fItems, bclass, ptr, cloffset + baseclass->GetDelta())) return kFALSE;
00271    }
00272 
00273    return kTRUE;
00274 }
00275 
00276 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:29 2008 for Go4-v3.04-1 by  doxygen 1.4.2