00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4TreeHistogramEntry.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TH1.h"
00021 #include "TTree.h"
00022
00023 #include "Go4Log/TGo4Log.h"
00024 #include "Go4Analysis/TGo4AnalysisImp.h"
00025 #include "TGo4TreeHistogramEntryStatus.h"
00026 #include "TGo4DynamicListException.h"
00027
00028 const Text_t TGo4TreeHistogramEntry::fgcENTRYSUF[]="-DL";
00029
00030 TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const Text_t* histogramname,
00031 TTree* tree,
00032 const Text_t* varexp,
00033 const TCut& cut)
00034 : TGo4DynamicEntry(histogramname), fxTree(tree),
00035 fxHistogramName(histogramname), fxVarexp(varexp), fxSelection(cut),
00036 fbNewHistogram(kTRUE), fiLastEvent(0)
00037 {
00038 TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const Text_t*, TTree*, const Text_t*, TCut)",__LINE__, __FILE__));
00039
00040 Text_t buffer[2048];
00041
00042 snprintf(buffer,2048,"%s>>+%s",varexp,histogramname);
00043 fxDrawexp=buffer;
00044 if(fxTree)
00045 fxTreeName=fxTree->GetName();
00046 snprintf(buffer,2048,"%s%s",histogramname,fgcENTRYSUF);
00047 SetName(buffer);
00048 EnableProcessing(kTRUE);
00049 }
00050
00051 TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const Text_t* histogramname,
00052 const Text_t* treename,
00053 const Text_t* varexp,
00054 const TCut& cut)
00055 : TGo4DynamicEntry(histogramname), fxTree(0),
00056 fxHistogramName(histogramname), fxTreeName(treename), fxVarexp(varexp), fxSelection(cut),
00057 fbNewHistogram(kTRUE), fiLastEvent(0)
00058 {
00059 TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const Text_t*, const Text_t*, const Text_t*, TCut)",__LINE__, __FILE__));
00060 Text_t buffer[2048];
00061 snprintf(buffer,2047,"%s>>+%s",varexp,histogramname);
00062 fxDrawexp=buffer;
00063 snprintf(buffer,2047,"%s%s",histogramname,fgcENTRYSUF);
00064 SetName(buffer);
00065 EnableProcessing(kTRUE);
00066 }
00067
00068
00069 TGo4TreeHistogramEntry::TGo4TreeHistogramEntry()
00070 : TGo4DynamicEntry("Go4TreeHistogram1"), fxTree(0),
00071 fxHistogramName(0), fxVarexp(0), fxSelection(0),
00072 fbNewHistogram(kTRUE), fiLastEvent(0)
00073 {
00074 TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry()",__LINE__, __FILE__));
00075 fxDrawexp="x>>+Go4TreeHistogram";
00076 fxTreeName="Go4Tree";
00077 EnableProcessing(kTRUE);
00078 }
00079
00080
00081 TGo4TreeHistogramEntry::~TGo4TreeHistogramEntry()
00082 {
00083 TRACE((15,"TGo4TreeHistogramEntry::~TGo4TreeHistogramEntry()",__LINE__, __FILE__));
00084
00085 }
00086
00087
00088 TGo4DynamicEntryStatus * TGo4TreeHistogramEntry::CreateStatus()
00089 {
00090 TRACE((12,"TGo4TreeHistogramEntry::CreateStatus()",__LINE__, __FILE__));
00091 TGo4TreeHistogramEntryStatus* state = new TGo4TreeHistogramEntryStatus( GetName() );
00092 UpdateStatus(state);
00093 return state;
00094 }
00095
00096
00097 void TGo4TreeHistogramEntry::UpdateStatus(TGo4DynamicEntryStatus * state)
00098 {
00099 TRACE((12,"TGo4TreeHistogramEntry::UpdateStatus(TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
00100 TGo4DynamicEntry::UpdateStatus(state);
00101 TGo4TreeHistogramEntryStatus* thstate= dynamic_cast<TGo4TreeHistogramEntryStatus*> (state);
00102 if (thstate)
00103 {
00104 thstate->SetHistogramName(fxHistogramName.Data());
00105 thstate->SetTreeName(fxTreeName);
00106 thstate->SetVarexp(fxVarexp);
00107 thstate->SetSelection(fxSelection);
00108 if(TGo4Analysis::Exists())
00109 thstate->SetDynListInterval(TGo4Analysis::Instance()->GetDynListInterval());
00110 else
00111 thstate->SetDynListInterval(2000);
00112 }
00113 else
00114 {
00115
00116 throw TGo4DynamicListException(this,
00117 "Dynamic Tree Histogram Entry %s failed to UpdateStatus: wrong status type !!!",
00118 GetName());
00119 }
00120
00121 }
00122
00123 void TGo4TreeHistogramEntry::Reset()
00124 {
00125 TRACE((12,"TGo4TreeHistogramEntry::Reset()",__LINE__, __FILE__));
00126 TGo4DynamicEntry::Reset();
00127 fiLastEvent=0;
00128 fxTree=0;
00129 fbNewHistogram=kTRUE;
00130
00131 }
00132
00133 void TGo4TreeHistogramEntry::SetStatus(TGo4DynamicEntryStatus * state)
00134 {
00135 TRACE((12,"TGo4TreeHistogramEntry::SetStatus(TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
00136
00137 if(state==0) return;
00138 if(state->InheritsFrom("TGo4TreeHistogramEntryStatus"))
00139 {
00140 TGo4DynamicEntry::SetStatus(state);
00141 TGo4TreeHistogramEntryStatus* hstate= dynamic_cast<TGo4TreeHistogramEntryStatus*>(state);
00142 fxHistogramName=hstate->GetHistogramName();
00143 fxTreeName=hstate->GetTreeName();
00144 fxVarexp=hstate->GetVarexp();
00145 fxSelection=hstate->GetSelection();
00146 Text_t buffer[2048];
00147 snprintf(buffer,2048,"%s>>+%s",
00148 fxVarexp.Data(),
00149 fxHistogramName.Data());
00150 fxDrawexp=buffer;
00151
00152 }
00153 else
00154 {
00155 throw TGo4DynamicListException(this,
00156 "Dynamic Tree Histogram Entry %s failed to SetStatus: wrong status type !!!",
00157 GetName());
00158 }
00159 }
00160
00161
00162
00163 Int_t TGo4TreeHistogramEntry::Process()
00164 {
00165 TRACE((12,"TGo4TreeHistogramEntry::Process(Int_t)",__LINE__, __FILE__));
00166 if(!fbProcessEntry)
00167 return 0;
00168 if(TGo4Analysis::Instance()->CheckDynListInterval())
00169 return ( ProcessTree(TGo4Analysis::Instance()->GetDynListInterval()) );
00170 return 0;
00171 }
00172
00173
00174
00175
00176 Int_t TGo4TreeHistogramEntry::ProcessTree(Int_t times)
00177 {
00178 TRACE((12,"TGo4TreeHistogramEntry::ProcessTree(Int_t)",__LINE__, __FILE__));
00179
00180
00181
00182 if(fxTree==0)
00183 {
00184 fxTree=TGo4Analysis::Instance()->GetTree( fxTreeName.Data() );
00185 if (fxTree==0)
00186 throw TGo4DynamicListException(this,
00187 "Tree Histogram Entry: !!! Could not find Tree %s ",
00188 fxTreeName.Data());
00189
00190
00191 }
00192 else { }
00193 Int_t rev=-2;
00194
00195 if(times<=0) times=1;
00196 Int_t lastentrynumber=static_cast<Int_t> (fxTree->GetEntries());
00197 if(fxTree->TestBit(TGo4Status::kGo4BackStoreReset))
00198 {
00199
00200
00201 fiLastEvent=0;
00202
00203
00204 }
00205 if(fiLastEvent==lastentrynumber)
00206 {
00207
00208 throw TGo4DynamicListException(this,
00209 "Tree Histogram Entry: %s Reached end of tree %s. Draw() is stopped. ",
00210 GetName(), fxTreeName.Data());
00211 }
00212 Int_t startindex= lastentrynumber -times;
00213
00214 if(startindex<fiLastEvent)
00215 {
00216
00217
00218 if(startindex>0)
00219 {
00220
00221 startindex=fiLastEvent;
00222 }
00223 else
00224 {
00225
00226
00227 startindex=0;
00228 }
00229 times=lastentrynumber-startindex;
00230 }
00231 else
00232 {
00233
00234
00235 startindex=fiLastEvent;
00236
00237
00238
00239 }
00240
00241
00242
00243
00244
00245 fiLastEvent=startindex+times;
00246 if(fiLastEvent>lastentrynumber)
00247 {
00248 cout <<"Passing over end of tree - NEVER COME HERE!!!" << endl;
00249 fiLastEvent=lastentrynumber;
00250 times=fiLastEvent-startindex;
00251 cout << "\t -- startindex: "<< startindex<< endl;
00252 cout << "\t -- times: "<< times<< endl;
00253 cout << "\t -- treeentries: "<< lastentrynumber<< endl;
00254 }
00255 TDirectory* savdir=gDirectory;
00256 gROOT->cd();
00257 if(fbNewHistogram)
00258 {
00259
00260 TH1* histo;
00261 histo=TGo4Analysis::Instance()->GetHistogram( fxHistogramName.Data());
00262 if(histo==0)
00263 {
00264
00265
00266 rev=fxTree->Draw(fxDrawexp.Data(),fxSelection,"goff",times,startindex);
00267 TObject* ob= gROOT->FindObject( fxHistogramName.Data() );
00268 histo= dynamic_cast<TH1*> (ob);
00269 if(histo!=0)
00270 {
00271
00272 TGo4Analysis::Instance()->AddHistogram(histo);
00273 histo->SetBit(TGo4Status::kGo4CanDelete);
00274 fbNewHistogram=kFALSE;
00275 }
00276 else
00277 {
00278
00279 }
00280 }
00281 else
00282 {
00283
00284
00285
00286
00287
00288
00290
00291 rev=fxTree->Draw(fxDrawexp.Data(),fxSelection,"goff",times,startindex);
00292 fbNewHistogram=kFALSE;
00293 }
00294 }
00295 else
00296 {
00297
00298 rev=fxTree->Draw(fxDrawexp.Data(),fxSelection,"goff",times,startindex);
00299 }
00300 savdir->cd();
00301 return rev;
00302 }
00303 ClassImp(TGo4TreeHistogramEntry)
00304
00305
00306
00307
00308