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

TGo4HistogramEntry.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 "TGo4HistogramEntry.h"
00017 
00018 #include "RVersion.h"
00019 #include "Riostream.h"
00020 #include "TH1.h"
00021 #include "TH2.h"
00022 #include "TH3.h"
00023 #include "TDataMember.h"
00024 #include "TDataType.h"
00025 #include "TROOT.h"
00026 
00027 #include "TGo4Log.h"
00028 #include "TGo4Status.h"
00029 #include "TGo4Condition.h"
00030 #include "TGo4DynamicListException.h"
00031 
00032 const char* TGo4HistogramEntry::fgcNOCONDITION = "No Condition";
00033 const char* TGo4HistogramEntry::fgcNODATA = "No Data";
00034 const char* TGo4HistogramEntry::fgcNOEVENT = "No Event";
00035 
00036 TGo4HistogramEntry::TGo4HistogramEntry() :
00037    TGo4DynamicEntry(),
00038    fxHistogram(0),
00039    fxCondition(0),
00040    fbNeedInitialisation(kTRUE)
00041 {
00042 }
00043 
00044 TGo4HistogramEntry::TGo4HistogramEntry(const char* name) :
00045    TGo4DynamicEntry(name),
00046    fxHistogram(0),
00047    fxCondition(0),
00048    fbNeedInitialisation(kTRUE)
00049 {
00050    fxHistogramName=fgcNOCONDITION;
00051    for (UInt_t t=0; t<__MAXHISDIM__;++t) {
00052       SetHisEventName(t,fgcNOEVENT);
00053       SetHisVarName(t,fgcNODATA);
00054    }
00055 
00056    fxConditionName = fgcNOCONDITION;
00057    for (Int_t t=0; t<__MAXCONDIM__;++t) {
00058       SetConEventName(t,fgcNOEVENT);
00059       SetConVarName(t,fgcNODATA);
00060    }
00061 
00062    Reset();
00063 }
00064 
00065 TGo4HistogramEntry::~TGo4HistogramEntry()
00066 {
00067 }
00068 
00069 void TGo4HistogramEntry::SetHisVarName(Int_t ix, const char* name)
00070 {
00071   if((ix>=0) && (ix<__MAXHISDIM__))
00072      fxHisVarName[ix]=name;
00073 }
00074 
00075 const char* TGo4HistogramEntry::GetHistVarName(Int_t ix) const
00076 {
00077    return ((ix>=0) && (ix<__MAXHISDIM__)) ? fxHisVarName[ix].Data() : 0;
00078 }
00079 
00080 void TGo4HistogramEntry::SetHisEventName(Int_t ix, const char* name)
00081 {
00082    if((ix>=0) && (ix<__MAXHISDIM__))
00083       fxHisEventName[ix]=name;
00084 }
00085 
00086 const char* TGo4HistogramEntry::GetHistEventName(Int_t ix) const
00087 {
00088    return ((ix>=0) && (ix<__MAXHISDIM__)) ? fxHisEventName[ix].Data() : 0;
00089 }
00090 
00091 void TGo4HistogramEntry::SetConVarName(Int_t ix, const char* name)
00092 {
00093   TRACE((12,"TGo4DynamicEntry::SetConVarName(UInt_t, char*)",__LINE__, __FILE__));
00094   if((ix>=0) && (ix<__MAXCONDIM__))
00095      fxConVarName[ix]=name;
00096 }
00097 
00098 const char* TGo4HistogramEntry::GetConVarName(Int_t ix) const
00099 {
00100    return ((ix>=0) && (ix<__MAXCONDIM__)) ? fxConVarName[ix].Data() : 0;
00101 }
00102 
00103 void TGo4HistogramEntry::SetConEventName(Int_t ix, const char* name)
00104 {
00105    TRACE((12,"TGo4DynamicEntry::SetConEventName(UInt_t, char*)",__LINE__, __FILE__));
00106    if((ix>=0) && (ix<__MAXCONDIM__))
00107       fxConEventName[ix]=name;
00108 }
00109 
00110 const char* TGo4HistogramEntry::GetConEventName(Int_t ix) const
00111 {
00112    return ((ix>=0) && (ix<__MAXCONDIM__)) ? fxConEventName[ix].Data() : 0;
00113 }
00114 
00115 
00116 void TGo4HistogramEntry::Reset()
00117 {
00118    fxHistogram=0;
00119    for(Int_t t =0; t<__MAXHISDIM__; ++t) {
00120       fxHisEvents[t] = 0;
00121       fxHistType[t] = 0;
00122       fxHistPtr[t] = 0;
00123    }
00124 
00125    fxCondition = 0;
00126    for(Int_t t =0; t<__MAXCONDIM__; ++t) {
00127       fxConEvents[t] = 0;
00128       fxCondType[t] = 0;
00129       fxCondPtr[t] = 0;
00130    }
00131 
00132    fbNeedInitialisation = kTRUE;
00133 }
00134 
00135 void TGo4HistogramEntry::InitHistPointer(Int_t ix, TObject* event, TDataMember* member, Long_t offset)
00136 {
00137    if ((ix<0) || (ix>=__MAXHISDIM__)) return;
00138    fxHistPtr[ix] = 0;
00139    fxHisEvents[ix] = event;
00140    if ((event==0) || (member==0) || !member->IsBasic()) return;
00141    fxHistPtr[ix] = (char*) event+ offset;
00142    fxHistType[ix] = member->GetDataType()->GetType();
00143 }
00144 
00145 void TGo4HistogramEntry::InitCondPointer(Int_t ix, TObject* event, TDataMember* member, Long_t offset)
00146 {
00147    if ((ix<0) || (ix>=__MAXCONDIM__)) return;
00148    fxCondPtr[ix] = 0;
00149    fxConEvents[ix] = event;
00150    if ((event==0) || (member==0) || !member->IsBasic()) return;
00151    fxCondPtr[ix] = (char*) event+ offset;
00152    fxCondType[ix] = member->GetDataType()->GetType();
00153 }
00154 
00155 Double_t TGo4HistogramEntry::GetPtrValue(Int_t type, void* ptr)
00156 {
00157    if (ptr==0) return 0.;
00158    switch (type) {
00159        case kUInt_t:     return *((UInt_t*)ptr);
00160        case kInt_t:      return *((Int_t*)ptr);
00161        case kULong_t:    return *((ULong_t*)ptr);
00162        case kLong_t:     return *((Long_t*)ptr);
00163        case kULong64_t:  return *((ULong64_t*)ptr);
00164        case kLong64_t:   return *((Long64_t*)ptr);
00165        case kUShort_t:   return *((UShort_t*)ptr);
00166        case kShort_t:    return *((Short_t*)ptr);
00167        case kUChar_t:    return *((UChar_t*)ptr);
00168        case kChar_t:     return *((Char_t*)ptr);
00169 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
00170        case kBool_t:     return *((Bool_t*)ptr);
00171 #endif
00172        case kFloat_t:    return *((Float_t*)ptr);
00173        case kDouble_t:   return *((Double_t*)ptr);
00174        case kDouble32_t: return *((Double32_t*)ptr);
00175    }
00176    return 0.;
00177 }
00178 
00179 Bool_t TGo4HistogramEntry::TestConditionNew()
00180 {
00181    if (fxCondition==0) return kTRUE;
00182 
00183    Bool_t rev = kTRUE;
00184 
00185    Double_t dat[__MAXCONDIM__];
00186 
00187    UInt_t j,dimension;
00188    // find out how many dimensions are set for condition:
00189    // maximum condition dimension defined by first index
00190    // with all data pointers set to zero.
00191    for(dimension=0;dimension<__MAXCONDIM__; ++dimension)
00192       if (fxCondPtr[dimension]==0) break;
00193 
00194    // fill pointers to test variables:
00195    for(j=0;j<dimension; ++j)
00196       dat[j] = GetPtrValue(fxCondType[j], fxCondPtr[j]);
00197 
00198    switch(dimension) {
00199 //         case 0:
00200 //            rev = fxCondition->GetLast(); // no own variables: last result
00201 //            //cout << "found zero dimension for condition" << endl;
00202 //            break;
00203          case 1:
00204             rev=fxCondition->Test(dat[0]);
00205             //cout << "found one dimension for condition" << endl;
00206             break;
00207          case 2:
00208             rev=fxCondition->Test(dat[0], dat[1]);
00209             //cout << "found two dimensions for condition" << endl;
00210             break;
00211          default:
00212             rev = kTRUE;
00213             break;
00214       } // switch(maxt)
00215 
00216    return rev;
00217 }
00218 
00219 void TGo4HistogramEntry::ProcessNew(Bool_t* evvalid)
00220 {
00221    if (fxHistogram==0) return;
00222 
00223    if (!TestConditionNew()) return;
00224 
00225    Double_t dat[3];
00226    Int_t dimension = fxHistogram->GetDimension();
00227    for(Int_t j=0; j<dimension; ++j)
00228      dat[j] = GetPtrValue(fxHistType[j], fxHistPtr[j]);
00229    switch (dimension) {
00230      case 1:
00231         if(evvalid[0]) fxHistogram->Fill(dat[0]);
00232         break;
00233      case 2:
00234         if(evvalid[0] && evvalid[1]) {
00235            TH2* his2 = dynamic_cast<TH2*>(fxHistogram);
00236            if(his2!=0) his2->Fill(dat[0],dat[1]);
00237         }
00238         break;
00239      case 3:
00240         if(evvalid[0] && evvalid[1] && evvalid[2]) {
00241            TH3* his3 = dynamic_cast<TH3*>(fxHistogram);
00242            if(his3!=0) his3->Fill(dat[0],dat[1],dat[2]);
00243         }
00244         break;
00245      default:
00246         throw TGo4DynamicListException(this,
00247           "Dynamic Histogram Entry %s Process error: Wrong histogram dimension %d !!!",
00248                      GetName(), dimension);
00249   } // switch(dimension)
00250 }
00251 
00252 void TGo4HistogramEntry::RecursiveRemove(TObject* obj)
00253 {
00254    if (obj==0) return;
00255 
00256    if(fxHistogram==obj) Reset();
00257 
00258    if(fxCondition==obj) Reset();
00259 
00260    for (Int_t n=0;n<__MAXCONDIM__;n++)
00261      if (fxConEvents[n]==obj) Reset();
00262 
00263    for (Int_t n=0;n<__MAXHISDIM__;n++)
00264      if (fxHisEvents[n]==obj) Reset();
00265 }
00266 
00267 void TGo4HistogramEntry::Print(Option_t* dummy) const
00268 {
00269    // this trick is needed since root defines Print as const function...
00270    TROOT::IndentLevel();
00271    cout <<"-Dynamic Histogram Entry " << GetName()<<" :"<<endl;
00272    TROOT::IncreaseDirLevel();
00273    TROOT::IndentLevel();
00274 
00275    if(IsEnabledProcessing()) cout <<"\t-- Enabled --" << endl;
00276                         else cout <<"\t-- Disabled --" << endl;
00277 
00278    TROOT::IndentLevel();
00279    cout <<"\tCondition: "<< GetConditionName() << endl;
00280    for(Int_t i=0;i<__MAXCONDIM__; ++i) {
00281       TROOT::IndentLevel();
00282       cout << "\t ConEvent(" << i << "): " << GetConEventName(i)
00283            << "\t ConVar(" << i << "): " << GetConVarName(i) << endl;
00284    }
00285    TROOT::IndentLevel();
00286    cout <<"\tHistogram: "<< GetHistogramName() << endl;
00287    for(Int_t i=0;i<__MAXHISDIM__; ++i) {
00288       TROOT::IndentLevel();
00289       cout << "\t HisEvent(" << i<<"): " << GetHistEventName(i)
00290            << "\t HisVar(" << i<< "): " << GetHistVarName(i) << endl;
00291    }
00292    TROOT::DecreaseDirLevel();
00293    TROOT::IndentLevel();
00294    cout <<"-End "<<GetName()<<"-----------" << endl;
00295 }
00296 
00297 const char* TGo4HistogramEntry::Get_fgcNOCONDITION()
00298 {
00299    return fgcNOCONDITION;
00300 }
00301 
00302 const char* TGo4HistogramEntry::Get_fgcNODATA()
00303 {
00304    return fgcNODATA;
00305 }
00306 
00307 const char* TGo4HistogramEntry::Get_fgcNOEVENT()
00308 {
00309    return fgcNOEVENT;
00310 }
00311 
00312 
00313 //----------------------------END OF GO4 SOURCE FILE ---------------------

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