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

/Go4DynamicList/TGo4HistogramEntry.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 "TGo4HistogramEntry.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TH1.h"
00021 #include "TH2.h"
00022 #include "TH3.h"
00023 #include "TDataMember.h"
00024 #include "TBaseClass.h"
00025 
00026 #include "Go4Log/TGo4Log.h"
00027 #include "Go4Event/TGo4EventElement.h"
00028 #include "Go4Analysis/TGo4AnalysisImp.h"
00029 #include "TGo4HistogramEntryStatus.h"
00030 #include "TGo4DynamicListException.h"
00031 
00032 const UInt_t TGo4HistogramEntry::fguMAXHISDIMENSION=__MAXHISDIM__;
00033 
00034 TGo4HistogramEntry::TGo4HistogramEntry(const Text_t* name)
00035 : TGo4DynamicEntry(name),
00036 fxHistogram(0)
00037 {
00038 TRACE((15,"TGo4HistogramEntry::TGo4HistogramEntry(const Text_t*)",__LINE__, __FILE__));
00039 fxHistogramName=fgcNOCONDITION;
00040 for (UInt_t t=0; t<fguMAXHISDIMENSION;++t)
00041    {
00042        // set names to defaults.
00043        SetHisEventName(t,fgcNOEVENT);
00044        SetHisVarName(t,fgcNODATA);
00045    }
00046 Reset();
00047 }
00048 
00049 TGo4HistogramEntry::TGo4HistogramEntry()
00050 : fxHistogram(0)
00051 {
00052 TRACE((15,"TGo4HistogramEntry::TGo4HistogramEntry()",__LINE__, __FILE__));
00053 //fxHistogramName=fgcNOCONDITION;
00054 //for (UInt_t t=0; t<fguMAXHISDIMENSION;++t)
00055 //   {
00056 //       // set names to defaults.
00057 //       SetHisEventName(t,fgcNOEVENT);
00058 //       SetHisVarName(t,fgcNODATA);
00059 //   }
00060 //Reset();
00061 }
00062 
00063 TGo4HistogramEntry::~TGo4HistogramEntry()
00064 {
00065 TRACE((15,"TGo4HistogramEntry::~TGo4HistogramEntry()",__LINE__, __FILE__));
00066 
00067 }
00068 
00069 
00070 
00071 
00072 Int_t TGo4HistogramEntry::Process()
00073 {
00074 TRACE((12,"TGo4HistogramEntry::Process(Int_t)",__LINE__, __FILE__));
00075    if(!fbProcessEntry)  return 0; //{cout <<"ttttttt entry"<<GetName()<<"disabled " << endl; return 0;}
00076    if(!TestCondition()) return 1; //{cout <<"ttttttt entry"<<GetName()<<"condition false " << endl; return 1;}
00077    if(!fbPointerInitDone) InitPointers();  // get pointer to data if not existing
00078       // fill histogram with data
00079    if(fxHistogram)
00080       {
00081           TH2* his2=0;
00082           TH3* his3=0;
00083           Axis_t dat[3]={0};
00084           UInt_t dimension=fxHistogram->GetDimension();
00085           for(UInt_t j=0; j< dimension; ++j)
00086              {
00087                // fill data from pointers:
00088                  if(fxHisDataFloat[j])          dat[j]   = (*fxHisDataFloat[j]);
00089                  else if (fxHisDataDouble[j])    dat[j]   = (*fxHisDataDouble[j]);
00090                  else if (fxHisDataInt[j])       dat[j]   = (*fxHisDataInt[j]);
00091                  else if (fxHisDataShort[j])    dat[j]   = (*fxHisDataShort[j]);
00092                  else if (fxHisDataChar[j])       dat[j]   = (*fxHisDataChar[j]);
00093                  else if (fxHisDataLong[j])        dat[j]   = (*fxHisDataLong[j]);
00094                  else if (fxHisDataBool[j])        dat[j]   = (*fxHisDataBool[j]);
00095                  else if (fxHisDataUInt[j])       dat[j]   = (*fxHisDataUInt[j]);
00096                  else if (fxHisDataUShort[j])    dat[j]   = (*fxHisDataUShort[j]);
00097                  else if (fxHisDataUChar[j])    dat[j]   = (*fxHisDataUChar[j]);
00098                  else if (fxHisDataULong[j])    dat[j]   = (*fxHisDataULong[j]);
00099                  else throw TGo4DynamicListException(this,
00100                      "Dynamic Histogram Entry %s Process error: pointer not initialized for axis %d !!!",
00101                               GetName(), j);
00102              } // for
00103           switch (dimension)
00104              {
00105                 case 1:
00106                     if(fxHisEvent[0]->IsValid())
00107                        {
00108                           fxHistogram->Fill(dat[0]);
00109                        }
00110                    break;
00111                 case 2:
00112                     if(fxHisEvent[0]->IsValid() &&
00113                        fxHisEvent[1]->IsValid()      )
00114                        {
00115                           his2=dynamic_cast<TH2*>(fxHistogram);
00116                           if(his2) his2->Fill(dat[0],dat[1]);
00117                        }
00118                     break;
00119                  case 3:
00120                     if(fxHisEvent[0]->IsValid() &&
00121                        fxHisEvent[1]->IsValid() &&
00122                        fxHisEvent[2]->IsValid()      )
00123                        {
00124                           his3=dynamic_cast<TH3*>(fxHistogram);
00125                           if(his3) his3->Fill(dat[0],dat[1],dat[2]);
00126                        }
00127                     break;
00128                  default:
00129                     throw TGo4DynamicListException(this,
00130                         "Dynamic Histogram Entry %s Process error: Wrong histogram dimension %d !!!",
00131                                  GetName(), dimension);
00132                      break;
00133              } // switch(dimension)
00134       } // if(fxHistogram)
00135 return 0;
00136 }
00137 
00138 void TGo4HistogramEntry::UpdateStatus(TGo4DynamicEntryStatus * state)
00139 {
00140 TRACE((12,"TGo4HistogramEntry::UpdateStatus(TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
00141    if(state==0) return;
00142    TGo4DynamicEntry::UpdateStatus(state); // fill superclass attributes
00143    TGo4HistogramEntryStatus* thstate= dynamic_cast<TGo4HistogramEntryStatus*> (state);
00144    if (thstate)
00145       {
00146          thstate->SetHistogramName(fxHistogramName.Data());
00147          thstate->SetHisEventNames(fxHisEventName);
00148          thstate->SetHisVarNames(fxHisVarName);
00149       }
00150    else
00151       {
00152          // dynamic cast failed! we have a different status class (never come here...)
00153       throw TGo4DynamicListException(this,
00154                "Dynamic Histogram Entry %s failed to SetStatus: wrong status class %s !!!",
00155                      GetName(), state->ClassName());
00156       }
00157 }
00158 
00159 TGo4DynamicEntryStatus * TGo4HistogramEntry::CreateStatus()
00160 {
00161 TRACE((12,"TGo4HistogramEntry::CreateStatus()",__LINE__, __FILE__));
00162 TGo4HistogramEntryStatus* state= new TGo4HistogramEntryStatus(GetName());
00163 UpdateStatus(state);
00164 return state;
00165 }
00166 
00167 
00168 
00169 void TGo4HistogramEntry::Reset()
00170 {
00171 TRACE((12,"TGo4HistogramEntry::Reset()",__LINE__, __FILE__));
00172 // clear pointers to all external objects, will be searched by name
00173 TGo4DynamicEntry::Reset();
00174 fxHistogram=0;
00175 for(UInt_t t =0; t<fguMAXHISDIMENSION; ++t)
00176    {
00177       fxHisDataFloat[t]=0;
00178       fxHisDataDouble[t]=0;
00179       fxHisDataInt[t]=0;
00180       fxHisDataShort[t]=0;
00181       fxHisDataChar[t]=0;
00182       fxHisDataLong[t]=0;
00183       fxHisDataBool[t]=0;
00184       fxHisDataUInt[t]=0;
00185       fxHisDataUShort[t]=0;
00186       fxHisDataUChar[t]=0;
00187       fxHisDataULong[t]=0;
00188       fxHisEvent[t]=0;
00189    }
00190 }
00191 
00192 void TGo4HistogramEntry::SetHistogramName(const Text_t * name)
00193 {
00194 TRACE((12,"TGo4HistogramEntry::SetHistogramName(const Text_t*)",__LINE__, __FILE__));
00195    fxHistogramName=name;
00196 }
00197 
00198 void TGo4HistogramEntry::SetHisVarName(UInt_t ix, const Text_t * name)
00199 {
00200 TRACE((12,"TGo4HistogramEntry::SetHisVarName(UInt_t, Text_t*)",__LINE__, __FILE__));
00201 if(ix>=fguMAXHISDIMENSION) return;
00202 fxHisVarName[ix]=name;
00203 }
00204 
00205 void TGo4HistogramEntry::SetHisEventName(UInt_t ix, const Text_t * name)
00206 {
00207 TRACE((12,"TGo4HistogramEntry::SetHisEventName(UInt_t, Text_t*)",__LINE__, __FILE__));
00208 if(ix>=fguMAXHISDIMENSION) return;
00209 fxHisEventName[ix]=name;
00210 }
00211 
00212 void TGo4HistogramEntry::InitPointers()
00213 {
00214 TRACE((12,"TGo4HistogramEntry::InitPointers()",__LINE__, __FILE__));
00215    TGo4DynamicEntry::InitPointers();
00216    TGo4Analysis* ana= TGo4Analysis::Instance();
00217    const Text_t* memname;
00218    //cout <<"iiiiiiiiiInitPointers searches histogram " <<fxHistogramName.Data()  << endl;
00219    if(fxHistogramName.Contains(fgcNOCONDITION))
00220       {
00221          //cout <<"iiiiiiiiiInitPointers sets no histogram " <<fxHistogramName.Data()  << endl;
00222          fxHistogram=0;
00223       }
00224    else
00225       {
00226          fxHistogram= ana->GetHistogram(fxHistogramName.Data());
00227       }
00228    if(fxHistogram)
00229       {
00230          //cout <<"iiiiiiiiiInitPointers finds histogram: " <<fxHistogram->Data()<< endl;
00231          for(UInt_t u=0; u< fguMAXHISDIMENSION; ++u)
00232             {
00233              if(fxHisEventName[u].Contains(fgcNOEVENT))
00234                 {
00235                    //cout <<"iiiiiiiiiInitPointers histogramevent zero for " << u << endl;
00236                    fxHisEvent[u]=0;
00237                 }
00238               else
00239                 {
00240                    fxHisEvent[u]=ana->GetEventStructure(fxHisEventName[u].Data());
00241                 }
00242             // now try to find pointer to data: use offset of TClass?
00243             if(fxHisEvent[u])
00244                {
00245                   // we have pointer to the event in u direction!
00246                   // note: root assigns Long_t according to
00247                   // architecture, i.e. 4 byte on 32bit, 8 byte on 64bit sytems
00248                   // this should be correct type for address:                  
00249                   //cout <<"iiiiiiiiiInitPointers eventname["<<u<<"]= " << fxHisEvent[u]->Data() << endl;
00250                   Long_t base = (Long_t) (fxHisEvent[u]);
00251                   //cout <<"iiiiiiiiiInitPointers base["<<u<<"]= " << base << endl;
00252                   Long_t offset=0;
00253                   
00254                   TClass* eventclass=fxHisEvent[u]->IsA();
00255                   if(eventclass)
00256                      {
00257                         //cout <<"iiiiiiiiiInitPointers class["<<u<<"]= " << eventclass->GetName() << endl;
00258                         TDataMember* eventmember;
00259                         if(fxHisVarName[u].Contains(fgcNODATA))
00260                            {
00261                                //cout <<"iiiiiiiiiInitPointers member["<<u<<"] NULL" << endl;
00262                                eventmember=0;
00263                            }
00264                          else
00265                             {
00266                                memname=fxHisVarName[u].Data();
00267                                //cout <<"iiiiiiiiiInitPointers membername["<<u<<"]: " << memname << endl;
00268                                eventmember=FindDataMember(eventclass,memname,&offset);
00269                                //cout <<"iiiiiiiiiInitPointers member["<<u<<"]: " << eventmember << endl;
00270                             }
00271                          if(eventmember)
00272                             {
00273                              //cout <<"iiiiiiiiiInitPointers offset["<<u<<"]: " << offset << endl;
00274                              const Text_t* tname=eventmember->GetFullTypeName();
00275                              //cout <<"iiiiiiiiiInitPointers type["<<u<<"]: " << tname << endl;
00276                              if(!strcmp(tname,"Float_t"))
00277                                 {
00278                                    //cout <<"iiiiiiiiiInitPointers inits Float_t for "<< u  << endl;
00279                                    fxHisDataFloat[u]=(Float_t*) (base+offset);
00280                                 }
00281                              else if (!strcmp(tname,"Double_t"))
00282                                {
00283                                     //cout <<"iiiiiiiiiInitPointers inits Double_t for "<< u  << endl;
00284                                     fxHisDataDouble[u]=(Double_t*) (base+offset);
00285                                }
00286                              else if (!strcmp(tname,"Int_t"))
00287                                {
00288                                     //cout <<"iiiiiiiiiInitPointers inits Int_t for "<< u  << endl;
00289                                     fxHisDataInt[u]=(Int_t*) (base+offset);
00290                                }
00291                              else if (!strcmp(tname,"Short_t"))
00292                                {
00293                                     //cout <<"iiiiiiiiiInitPointers inits Short_t for "<< u  << endl;
00294                                     fxHisDataShort[u]=(Short_t*) (base+offset);
00295                                }
00296                              else if (!strcmp(tname,"Char_t"))
00297                                {
00298                                     //cout <<"iiiiiiiiiInitPointers inits Char_t for "<< u  << endl;
00299                                     fxHisDataChar[u]=(Char_t*) (base+offset);
00300                                }
00301                              else if (!strcmp(tname,"Long_t"))
00302                                {
00303                                     //cout <<"iiiiiiiiiInitPointers inits Long_t for "<< u  << endl;
00304                                     fxHisDataLong[u]=(Long_t*) (base+offset);
00305                                }
00306                              else if (!strcmp(tname,"Bool_t"))
00307                                {
00308                                     //cout <<"iiiiiiiiiInitPointers inits Bool_t for "<< u  << endl;
00309                                     fxHisDataBool[u]=(Bool_t*) (base+offset);
00310                                }
00311                              else if (!strcmp(tname,"UInt_t"))
00312                                {
00313                                     //cout <<"iiiiiiiiiInitPointers inits UInt_t for "<< u  << endl;
00314                                     fxHisDataUInt[u]=(UInt_t*) (base+offset);
00315                                }
00316                              else if (!strcmp(tname,"UShort_t"))
00317                                {
00318                                     //cout <<"iiiiiiiiiInitPointers inits UShort_t for "<< u  << endl;
00319                                     fxHisDataUShort[u]=(UShort_t*) (base+offset);
00320                                }
00321                              else if (!strcmp(tname,"UChar_t"))
00322                                {
00323                                     //cout <<"iiiiiiiiiInitPointers inits UChar_t for "<< u  << endl;
00324                                     fxHisDataUChar[u]=(UChar_t*) (base+offset);
00325                                }
00326                              else if (!strcmp(tname,"ULong_t"))
00327                                {
00328                                     //cout <<"iiiiiiiiiInitPointers inits ULong_t for "<< u  << endl;
00329                                     fxHisDataULong[u]=(ULong_t*) (base+offset);
00330                                }
00331                              else
00332                                 {
00333                                  throw TGo4DynamicListException(this,
00334                                  "Dynamic Histogram Entry %s failed to Init Data Pointers: Type %s of member %s is currently not supported !!!",
00335                                     GetName(), tname, eventmember->GetName());
00336                                 } // if(!strcmp(tname,"Float_t"))
00337                             } else {} // if(eventmember)
00338                      } // if(eventclass)
00339                } else {} // if fxConEvent[u]
00340             }// for
00341       } else {} // if(fxCondition)
00342    fbPointerInitDone=kTRUE;
00343 }
00344 void TGo4HistogramEntry::SetStatus(TGo4DynamicEntryStatus * state)
00345 {
00346 TRACE((12,"TGo4HistogramEntry::SetStatus(TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
00347    //
00348    if(state==0) return;
00349    if(state->InheritsFrom("TGo4HistogramEntryStatus"))
00350       {
00351          TGo4DynamicEntry::SetStatus(state);
00352          TGo4HistogramEntryStatus* hstate= dynamic_cast<TGo4HistogramEntryStatus*>(state);
00353          SetHistogramName(hstate->GetHistogramName());
00354          for(UInt_t i=0; i< fguMAXHISDIMENSION; ++i)
00355             {
00356                SetHisEventName(i,hstate->GetHisEventName(i));
00357                SetHisVarName(i,hstate->GetHisVarName(i));
00358             }
00359          TGo4DynamicEntry::SetStatus(hstate);
00360          //Reset(); // baseclass SetStatus will call Reset()
00361       }
00362    else
00363       {
00364          throw TGo4DynamicListException(this,
00365                "Dynamic Histogram Entry %s failed to SetStatus: wrong status class %s !!!",
00366                      GetName(), state->ClassName());
00367       }
00368 }
00369 
00370 void TGo4HistogramEntry::CleanupHistogram(TH1 * his)
00371 {
00372 TRACE((12,"TGo4HistogramEntry::CleanupHistogram(TH1*)",__LINE__, __FILE__));
00373 TGo4DynamicEntry::CleanupHistogram(his);
00374 if(fxHistogram==his)
00375     Reset();
00376 }
00377 
00378 
00379 void TGo4HistogramEntry::CleanupEvent(TGo4EventElement * ev)
00380 {
00381 TRACE((12,"TGo4HistogramEntry::CleanupEvent(TGo4EventElement*)",__LINE__, __FILE__));
00382    TGo4DynamicEntry::CleanupEvent(ev);
00383    for(UInt_t t =0; t<fguMAXHISDIMENSION; ++t)
00384       {
00385          if(fxHisEvent[t]==ev)
00386             {
00387                Reset();
00388                break;
00389             }
00390       }
00391 }
00392 
00393 ClassImp(TGo4HistogramEntry)
00394 
00395 
00396 
00397 
00398 //----------------------------END OF GO4 SOURCE FILE ---------------------

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