Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4DynamicList/TGo4DynamicEntry.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE 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 "TGo4DynamicEntry.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TDataMember.h"
00021 #include "TBaseClass.h"
00022 
00023 #include "Go4Log/TGo4Log.h"
00024 #include "Go4ConditionsBase/TGo4Condition.h"
00025 #include "Go4Event/TGo4EventElement.h"
00026 #include "Go4Analysis/TGo4AnalysisImp.h"
00027 #include "TGo4DynamicEntryStatus.h"
00028 #include "TGo4DynamicListException.h"
00029 
00030 const Text_t TGo4DynamicEntry::fgcNOCONDITION[]="No Condition";
00031 const Text_t TGo4DynamicEntry::fgcNODATA[]="No Data";
00032 const Text_t TGo4DynamicEntry::fgcNOEVENT[]="No Event";
00033 const UInt_t TGo4DynamicEntry::fguMAXCONDIMENSION=__MAXCONDIM__;
00034 
00035 TGo4DynamicEntry::TGo4DynamicEntry()
00036 //: TNamed("Default dynamic Entry","This is a Go4 dynamic entry"),
00037 :  fbProcessEntry(kTRUE),fbPointerInitDone(kFALSE),fxCondition(0)
00038 {
00039 TRACE((15,"TGo4DynamicEntry::TGo4DynamicEntry()",__LINE__, __FILE__));
00040 //fxConditionName=fgcNOCONDITION;
00041 //for (UInt_t t=0; t<fguMAXCONDIMENSION;++t)
00042 //   {
00043 //       // set names to defaults.
00044 //       SetConEventName(t,fgcNOEVENT);
00045 //       SetConVarName(t,fgcNODATA);
00046 //   }
00047 //Reset();
00048 }
00049 
00050 
00051 TGo4DynamicEntry::TGo4DynamicEntry(const Text_t* name)
00052 : TNamed(const_cast <Text_t*> (name) ,"This is a Go4 dynamic entry"),
00053    fbProcessEntry(kTRUE), fbPointerInitDone(kFALSE), fxCondition(0)
00054 {
00055 TRACE((15,"TGo4DynamicEntry::TGo4DynamicEntry(Text_t *)",__LINE__, __FILE__));
00056 fxConditionName=fgcNOCONDITION;
00057 for (UInt_t t=0; t<fguMAXCONDIMENSION;++t)
00058    {
00059        // set names to defaults.
00060        SetConEventName(t,fgcNOEVENT);
00061        SetConVarName(t,fgcNODATA);
00062    }
00063 Reset();
00064 }
00065 
00066 TGo4DynamicEntry::~TGo4DynamicEntry()
00067 {
00068 TRACE((15,"TGo4DynamicEntry::~TGo4DynamicEntry()",__LINE__, __FILE__));
00069 //delete [] fcConEventName;
00070 //delete [] fcConVarName;
00071 }
00072 
00073 void TGo4DynamicEntry::UpdateStatus(TGo4DynamicEntryStatus * state)
00074 {
00075 TRACE((12,"TGo4DynamicEntry::UpdateStatus(TGo4DynamicEntryStatus* )",__LINE__, __FILE__));
00076    if (state)
00077       {
00078          if(fxCondition)
00079             {
00080                state->SetCondition(fxCondition);
00081             }
00082          else
00083             {
00084                state->fxConditionName=fxConditionName;
00085                state->fxConditionClass="no pointer";
00086             }
00087          state->SetFlags(fbProcessEntry, fbPointerInitDone);
00088          state->SetConEventNames(fxConEventName);
00089          state->SetConVarNames(fxConVarName);
00090       }
00091    else
00092       { }
00093 }
00094 
00095 void TGo4DynamicEntry::CleanupCondition(TGo4Condition * con)
00096 {
00097 TRACE((12,"TGo4DynamicEntry::CleanupCondition(TGo4Condition*)",__LINE__, __FILE__));
00098 if(fxCondition==con)
00099    TGo4DynamicEntry::Reset();
00100 }
00101 
00102 void TGo4DynamicEntry::Reset()
00103 {
00104 TRACE((12,"TGo4DynamicEntry::Reset()",__LINE__, __FILE__));
00105    fxCondition=0;
00106    fbPointerInitDone=kFALSE;
00107    for(UInt_t t =0; t<fguMAXCONDIMENSION; ++t)
00108    {
00109       fxConDataFloat[t]=0;
00110       fxConDataDouble[t]=0;
00111       fxConDataInt[t]=0;
00112       fxConDataShort[t]=0;
00113       fxConDataChar[t]=0;
00114       fxConDataLong[t]=0;
00115       fxConDataBool[t]=0;
00116       fxConDataUInt[t]=0;
00117       fxConDataUShort[t]=0;
00118       fxConDataUChar[t]=0;
00119       fxConDataULong[t]=0;
00120       fxConEvent[t]=0;
00121    }
00122 
00123 }
00124 
00125 void TGo4DynamicEntry::InitPointers()
00126 {
00127 TRACE((42,"TGo4DynamicEntry::InitPointers()",__LINE__, __FILE__));
00128    Reset(); // make sure pointers init to 0
00129    TGo4Analysis* ana= TGo4Analysis::Instance();
00130    if(fxConditionName.Contains(fgcNOCONDITION))
00131       {
00132          //cout <<"iiiiiiiiiInitPointers no Condition "<< endl;
00133          fxCondition=0;
00134       }
00135    else
00136       {
00137          fxCondition= ana->GetAnalysisCondition(fxConditionName.Data());
00138       }
00139    if(fxCondition)
00140       {
00141          for(UInt_t u=0; u< fguMAXCONDIMENSION; ++u)
00142             {
00143              if(fxConEventName[u].Contains(fgcNOEVENT))
00144                 {
00145                    //cout <<"iiiiiiiiicInitPointers condevent zero for " << u << endl;
00146                    fxConEvent[u]=0;
00147                 }
00148               else
00149                 {
00150                    fxConEvent[u]=ana->GetEventStructure(fxConEventName[u].Data());
00151                    //cout <<"iiiiiiiiicInitPointers found event "<<fxConEventName[u].Data()<< " for " << u << endl;
00152                 }
00153             // now try to find pointer to data: use offset of TClass?
00154             if(fxConEvent[u])
00155                {
00156                   // we have pointer to the event in u direction!
00157                   //cout <<"iiiiiiiiiInitPointers ceventname["<<u<<"]= " << fxConEvent[u]->Data() << endl;
00158                   // note: root assigns Long_t according to
00159                   // architecture, i.e. 4 byte on 32bit, 8 byte on 64bit sytems
00160                   // this should be correct type for address:
00161                   Long_t base = (Long_t) (fxConEvent[u]);
00162                   Long_t offset=0;
00163                   TClass* eventclass=fxConEvent[u]->IsA();
00164                   if(eventclass)
00165                      {
00166                         TDataMember* eventmember;
00167                         if(fxConVarName[u].Contains(fgcNODATA))
00168                            {
00169                                //cout <<"iiiiiiiiiInitPointers no event data "<<u << endl;
00170                                eventmember=0;
00171                            }
00172                          else
00173                             {
00174                                const Text_t* memname=fxConVarName[u].Data();
00175                                //cout <<"iiiiiiiiiInitPointers got membername: "<< memname<< endl;
00176                                eventmember=FindDataMember(eventclass,memname,&offset);
00177                             }
00178                          if(eventmember)
00179                             {
00180                                 const Text_t* tname=eventmember->GetFullTypeName();
00181                                 if(!strcmp(tname,"Float_t"))
00182                                 {
00183                                    //cout <<"iiiiiiiiiInitPointers Condition inits Float_t for "<< u  << endl;
00184                                    fxConDataFloat[u]=(Float_t*) (base+offset);
00185                                 }
00186                                 else if (!strcmp(tname,"Double_t"))
00187                                   {
00188                                        //cout <<"iiiiiiiiiInitPointers Condition inits Double_t for "<< u  << endl;
00189                                        fxConDataDouble[u]=(Double_t*) (base+offset);
00190                                   }
00191                                 else if (!strcmp(tname,"Int_t"))
00192                                   {
00193                                        //cout <<"iiiiiiiiiInitPointers Condition inits Int_t for "<< u  << endl;
00194                                        fxConDataInt[u]=(Int_t*) (base+offset);
00195                                   }
00196                                 else if (!strcmp(tname,"Short_t"))
00197                                   {
00198                                        //cout <<"iiiiiiiiiInitPointers Condition inits Short_t for "<< u  << endl;
00199                                        fxConDataShort[u]=(Short_t*) (base+offset);
00200                                   }
00201                                 else if (!strcmp(tname,"Char_t"))
00202                                   {
00203                                        //cout <<"iiiiiiiiiInitPointers Condition inits Char_t for "<< u  << endl;
00204                                        fxConDataChar[u]=(Char_t*) (base+offset);
00205                                   }
00206                                 else if (!strcmp(tname,"Long_t"))
00207                                   {
00208                                        //cout <<"iiiiiiiiiInitPointers Condition inits Long_t for "<< u  << endl;
00209                                        fxConDataLong[u]=(Long_t*) (base+offset);
00210                                   }
00211                                 else if (!strcmp(tname,"Bool_t"))
00212                                   {
00213                                        //cout <<"iiiiiiiiiInitPointers Condition inits Bool_t for "<< u  << endl;
00214                                        fxConDataBool[u]=(Bool_t*) (base+offset);
00215                                   }
00216                                 else if (!strcmp(tname,"UInt_t"))
00217                                   {
00218                                        //cout <<"iiiiiiiiiInitPointers Condition inits UInt_t for "<< u  << endl;
00219                                        fxConDataUInt[u]=(UInt_t*) (base+offset);
00220                                   }
00221                                 else if (!strcmp(tname,"UShort_t"))
00222                                   {
00223                                        //cout <<"iiiiiiiiiInitPointers Condition inits UShort_t for "<< u  << endl;
00224                                        fxConDataUShort[u]=(UShort_t*) (base+offset);
00225                                   }
00226                                 else if (!strcmp(tname,"UChar_t"))
00227                                   {
00228                                        //cout <<"iiiiiiiiiInitPointers Condition inits UChar_t for "<< u  << endl;
00229                                        fxConDataUChar[u]=(UChar_t*) (base+offset);
00230                                   }
00231                                 else if (!strcmp(tname,"ULong_t"))
00232                                   {
00233                                        //cout <<"iiiiiiiiiInitPointers Condition inits ULong_t for "<< u  << endl;
00234                                        fxConDataULong[u]=(ULong_t*) (base+offset);
00235                                   }
00236                                 else
00237                                    {
00238                                     throw TGo4DynamicListException(this,
00239                                     "Dynamic Dynamic Entry %s failed to Init Data Pointers: Type %s of member %s is currently not supported !!!",
00240                                        GetName(), tname, eventmember->GetName());
00241                                    } // if(!strcmp(tname,"Float_t"))
00242                             }
00243                             else
00244                                {
00245                                   //cout <<"iiiiiiiii cond InitPointers no member" << u << endl;
00246                                } // if(eventmember)
00247                      } // if(eventclass)
00248                }
00249                else
00250                   {
00251                      //cout <<"iiiiiiiii cond InitPointers no eventpointer "<< u << endl;
00252                   } // if fxConEvent[u]
00253             }// for
00254       }
00255       else
00256       {
00257          //cout <<"iiiiiiiii cond InitPointers no condition" << endl;
00258       } // if(fxCondition)
00259    fbPointerInitDone=kTRUE;
00260 }
00261 
00262 Bool_t TGo4DynamicEntry::TestCondition()
00263 {
00264 TRACE((12,"TGo4DynamicEntry::TestCondition()",__LINE__, __FILE__));
00265 Bool_t rev=kFALSE;
00266 if(!fbPointerInitDone) InitPointers();
00267 if(fxCondition)
00268    {
00269 // first test how many pointers to external data are exisiting.
00270 // depending on that, call test functions of conditions with
00271 // one, two, or n variables. Otherwise get last result of
00272 // given condition.
00273    Axis_t dat[fguMAXCONDIMENSION]={0};
00274    UInt_t j,dimension;
00275    // find out how many dimensions are set for condition:
00276    for(dimension=0;dimension<fguMAXCONDIMENSION; ++dimension)
00277       {
00278           if ( (fxConDataFloat[dimension]==0) &&
00279                (fxConDataDouble[dimension]==0) &&
00280                (fxConDataInt[dimension]==0) &&
00281                (fxConDataShort[dimension]==0) &&
00282                (fxConDataChar[dimension]==0) &&
00283                (fxConDataLong[dimension]==0) &&
00284                (fxConDataBool[dimension]==0) &&
00285                (fxConDataUInt[dimension]==0) &&
00286                (fxConDataUShort[dimension]==0) &&
00287                (fxConDataUChar[dimension]==0) &&
00288                (fxConDataULong[dimension]==0)    )
00289                     {
00290                         break; // maximum condition dimension defined by first index
00291                                // with all data pointers set to zero.
00292                     }
00293       }
00294 
00295 
00296    // fill pointers to test variables:
00297    for(j=0;j<dimension; ++j)
00298       {
00299          if(fxConDataFloat[j])             dat[j]   = (*fxConDataFloat[j]);
00300          else if (fxConDataDouble[j])       dat[j]   = (*fxConDataDouble[j]);
00301          else if (fxConDataInt[j])          dat[j]   = (*fxConDataInt[j]);
00302          else if (fxConDataShort[j])       dat[j]   = (*fxConDataShort[j]);
00303          else if (fxConDataChar[j])       dat[j]   = (*fxConDataChar[j]);
00304          else if (fxConDataLong[j])        dat[j]   = (*fxConDataLong[j]);
00305          else if (fxConDataBool[j])        dat[j]   = (*fxConDataBool[j]);
00306          else if (fxConDataUInt[j])       dat[j]   = (*fxConDataUInt[j]);
00307          else if (fxConDataUShort[j])       dat[j]   = (*fxConDataUShort[j]);
00308          else if (fxConDataUChar[j])       dat[j]   = (*fxConDataUChar[j]);
00309          else if (fxConDataULong[j])        dat[j]   = (*fxConDataULong[j]);
00310 
00311          else throw TGo4DynamicListException(this,
00312             "Dynamic Dynamic Entry %s Process error: condition value pointer not initialized for axis %d !!!",
00313                      GetName(), j);
00314       }
00315 
00316    switch(dimension)
00317       {
00318          case 0:
00319             rev=fxCondition->GetLast(); // no own variables: last result
00320             //cout << "found zero dimension for condition" << endl;
00321             break;
00322          case 1:
00323             rev=fxCondition->Test(dat[0]);
00324             //cout << "found one dimension for condition" << endl;
00325             break;
00326          case 2:
00327             rev=fxCondition->Test(dat[0], dat[1]);
00328             //cout << "found two dimensions for condition" << endl;
00329             break;
00330          default:
00331             rev=fxCondition->GetLast(); // no own variables: last result
00332             break;
00333       } // switch(maxt)
00334   } // if(fxCondition)
00335 else
00336    {
00337        rev=kTRUE;
00338    }
00339 return rev;
00340 }
00341 
00342 void TGo4DynamicEntry::SetConVarName(UInt_t ix, const Text_t * name)
00343 {
00344 TRACE((12,"TGo4DynamicEntry::SetConVarName(UInt_t, Text_t*)",__LINE__, __FILE__));
00345    if(ix>=fguMAXCONDIMENSION) return;
00346    fxConVarName[ix]=name;
00347 }
00348 void TGo4DynamicEntry::SetConEventName(UInt_t ix, const Text_t * name)
00349 {
00350 TRACE((12,"TGo4DynamicEntry::SetConEventName(UInt_t, Text_t*)",__LINE__, __FILE__));
00351    if(ix>=fguMAXCONDIMENSION) return;
00352    fxConEventName[ix]=name;
00353 }
00354 void TGo4DynamicEntry::SetConditionName(const Text_t * name)
00355        {
00356             fxConditionName=name;
00357        }
00358 
00359 void TGo4DynamicEntry::SetStatus(TGo4DynamicEntryStatus * state)
00360 {
00361 TRACE((12,"TGo4DynamicEntry::SetStatus(TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
00362    if(state==0) return;
00363    SetName(state->GetName());
00364    EnableProcessing(state->AutoProcessIsEnabled());
00365    SetConditionName(state->GetConditionName());
00366    for(UInt_t i=0; i< fguMAXCONDIMENSION; ++i)
00367       {
00368          SetConEventName(i,state->GetConEventName(i));
00369          SetConVarName(i,state->GetConVarName(i));
00370       }
00371    Reset();
00372 }
00373 
00374 void TGo4DynamicEntry::CleanupEvent(TGo4EventElement * ev)
00375 {
00376 TRACE((12,"TGo4DynamicEntry::CleanupEvent(TGo4EventElement*)",__LINE__, __FILE__));
00377    for(UInt_t t =0; t<fguMAXCONDIMENSION; ++t)
00378       {
00379          if(fxConEvent[t]==ev)
00380             {
00381                TGo4DynamicEntry::Reset();
00382                break;
00383             }
00384       }
00385 }
00386 
00387 void TGo4DynamicEntry::CleanupHistogram(TH1 * his)
00388 {
00389  // default implementation, do nothing here since histogram belongs to subclasses
00390 }
00391 
00392 
00393 TDataMember* TGo4DynamicEntry::FindDataMember(TClass* eventclass,
00394                                                 const Text_t* memname,
00395                                                 Long_t* totaloffset)
00396 {
00397 TRACE((12,"TGo4DynamicEntry::FindDataMember(TClass*)",__LINE__, __FILE__));
00398 if(!eventclass) return 0;
00399 // here we might parse the memname for dots to figure out aggregated classes
00400 
00402 // check for array member index:
00403 Long_t indexoffset=0;
00404 Text_t ixtext[256];
00405 Text_t* ixbegin=strstr(memname,"[");
00406 if(ixbegin)
00407 {
00408 //   cout <<"-------------FindDataMember of Entry " << GetName() << endl;
00409 //   cout <<"Found index in member" << memname << endl;
00410    ixbegin++;
00411    Text_t* ixend=strstr(ixbegin,"]");
00412    if(ixend)
00413    {
00414       Int_t ixlen=ixend-ixbegin;
00415       snprintf(ixtext,ixlen+1,"%s",ixbegin);
00416       indexoffset=atoi(ixtext); // to be used downstream
00417       if(indexoffset<0) indexoffset=0;
00418    }
00419    else {}
00420 }
00421 else {}
00423 
00424 TDataMember* eventmember= eventclass->GetDataMember(memname);
00425 if(eventmember)
00426    {
00427      *totaloffset+=eventmember->GetOffset();
00428     }
00429 else
00430    {
00431      // if not found directly, check for baseclass members:
00432      TList* baselist=eventclass->GetListOfBases();
00433      TIterator* baseiter=baselist->MakeIterator();
00434      TObject* ob=0;
00435      while((ob=baseiter->Next()) !=0)
00436         {
00437            TBaseClass* baseclass=dynamic_cast<TBaseClass*>(ob);
00438            if(baseclass)
00439               {
00440                   // we have a baseclass
00441                   TClass* bclass=baseclass->GetClassPointer();
00442                   // search for member in all superclasses recursively:
00443                   eventmember=FindDataMember(bclass,memname,totaloffset);
00444                   if(eventmember)
00445                     {
00446                        // we found member in any of the baseclasses
00447                        *totaloffset+=baseclass->GetDelta();
00448                           // inc total offset to this by baseclass offset
00449                           // member offset is relative to TClass (i.e. baseclass here)
00450                        //cout <<"iiiiiiiiiInitPointers baseclass member: " << eventmember << endl;
00451                        //cout <<"iiiiiiiiiInitPointers baseclass delta: " << baseclass->GetDelta() << endl;
00452                        break;
00453                     } else{ }
00454               } // if(baseclass)
00455         } // while
00456     delete baseiter;
00457     } // if (eventmember)
00458 
00459 // finally, we check for eventmember type to add
00460 //correct offset in case of array:
00461 if(eventmember)
00462    {
00463    const Text_t* tname=eventmember->GetFullTypeName();
00464    //cout <<"Found type "<< tname<<", size:"<< Membersize(tname) << endl;
00465    // check if given index is inside allocated size:
00466    Int_t maxindex=eventmember->GetMaxIndex(0);
00467    if(maxindex<0) maxindex=1; // for non-array members maxindex is -1
00468    if(indexoffset<maxindex)
00469       {
00470          *totaloffset+=indexoffset*Membersize(tname);
00471          //cout <<"totaloffset:"<< *totaloffset<<endl;
00472       }
00473    else
00474       {
00475       throw TGo4DynamicListException(this,
00476          "Index %d for array member:%s out of range %s[%d]",
00477             indexoffset, memname, tname, maxindex);
00478       }
00479    // for now, we only handle 1d arrays
00480    // root allows to check higher dimensions, maybe later...?
00481    //for(Int_t ii=0; ii<4; ++ii)
00482    //{
00483    //   Int_t maxindex=eventmember->GetMaxIndex(ii);
00484    //   cout <<"Found maxindex "<<maxindex<<" for dimension "<<ii << endl;
00485    //}
00486    }
00487 
00488 
00489 
00490 return eventmember;
00491 }
00492 
00493 Int_t TGo4DynamicEntry::Membersize(const Text_t* tname)
00494 {
00495 Int_t rev=0;
00496 if(!strcmp(tname,"Float_t"))          rev=sizeof(Float_t);
00497 else if (!strcmp(tname,"Double_t")) rev=sizeof(Double_t);
00498 else if (!strcmp(tname,"Int_t"))      rev=sizeof(Int_t);
00499 else if (!strcmp(tname,"Short_t"))   rev=sizeof(Short_t);
00500 else if (!strcmp(tname,"Char_t"))   rev=sizeof(Char_t);
00501 else if (!strcmp(tname,"Long_t"))   rev=sizeof(Long_t);
00502 else if (!strcmp(tname,"Bool_t"))   rev=sizeof(Bool_t);
00503 else if (!strcmp(tname,"UInt_t"))   rev=sizeof(UInt_t);
00504 else if (!strcmp(tname,"UShort_t"))   rev=sizeof(UShort_t);
00505 else if (!strcmp(tname,"UChar_t"))   rev=sizeof(UChar_t);
00506 else if (!strcmp(tname,"ULong_t"))   rev=sizeof(ULong_t);
00507 else   rev=0;
00508 return rev;
00509 }
00510 
00511 
00512 
00513 ClassImp(TGo4DynamicEntry)
00514 
00515 
00516 
00517 
00518 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:52 2005 for Go4-v2.10-5 by doxygen1.2.15