00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4TreeHistogramEntry.h"
00017
00018 #include "Riostream.h"
00019
00020 #include "TTree.h"
00021 #include "snprintf.h"
00022 #include "TROOT.h"
00023
00024 #include "TGo4Log.h"
00025 #include "TGo4Status.h"
00026 #include "TGo4DynamicListException.h"
00027
00028 const char* TGo4TreeHistogramEntry::fgcENTRYSUF="-DL";
00029
00030 TGo4TreeHistogramEntry::TGo4TreeHistogramEntry() :
00031 TGo4DynamicEntry(),
00032 fxHistogramName(),
00033 fxVarExp(),
00034 fxCutExp(),
00035 fiDynListInterval(1000),
00036 fbNewHistogram(kTRUE),
00037 fiLastEvent(0)
00038 {
00039 TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry()",__LINE__, __FILE__));
00040 fxTreeName="Go4Tree";
00041 EnableProcessing(kTRUE);
00042 }
00043
00044 TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const char* histogramname,
00045 const char* treename,
00046 const char* varexp,
00047 const char* cutexp) :
00048 TGo4DynamicEntry(histogramname),
00049 fxHistogramName(histogramname),
00050 fxTreeName(treename),
00051 fxVarExp(varexp),
00052 fxCutExp(cutexp),
00053 fiDynListInterval(1000),
00054 fbNewHistogram(kTRUE),
00055 fiLastEvent(0)
00056 {
00057 TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const Text_t*, const Text_t*, const Text_t*, TCut)",__LINE__, __FILE__));
00058 char buffer[2048];
00059 snprintf(buffer,2047,"%s%s",histogramname,fgcENTRYSUF);
00060 SetName(buffer);
00061 EnableProcessing(kTRUE);
00062
00063 Reset();
00064 }
00065
00066 TGo4TreeHistogramEntry::~TGo4TreeHistogramEntry()
00067 {
00068 TRACE((15,"TGo4TreeHistogramEntry::~TGo4TreeHistogramEntry()",__LINE__, __FILE__));
00069 }
00070
00071 void TGo4TreeHistogramEntry::Reset()
00072 {
00073 TRACE((12,"TGo4TreeHistogramEntry::Reset()",__LINE__, __FILE__));
00074 TGo4DynamicEntry::Reset();
00075 fiLastEvent=0;
00076 fbNewHistogram=kTRUE;
00077 }
00078
00079 void TGo4TreeHistogramEntry::ProcessTreeNew(TTree* tree, Int_t times)
00080 {
00081 if(times<=0) times=1;
00082
00083 Int_t lastentrynumber = static_cast<Int_t> (tree->GetEntries());
00084 if(tree->TestBit(TGo4Status::kGo4BackStoreReset))
00085 fiLastEvent=0;
00086
00087 if(fiLastEvent==lastentrynumber)
00088 throw TGo4DynamicListException(this,
00089 "Tree Histogram Entry: %s Reached end of tree %s. Draw() is stopped. ",
00090 GetName(), tree->GetName());
00091 Int_t startindex= lastentrynumber -times;
00092
00093 if(startindex<fiLastEvent)
00094 {
00095
00096
00097 if(startindex>0)
00098 {
00099
00100 startindex=fiLastEvent;
00101 }
00102 else
00103 {
00104
00105
00106 startindex=0;
00107 }
00108 times=lastentrynumber-startindex;
00109 }
00110 else
00111 {
00112
00113
00114 startindex=fiLastEvent;
00115
00116
00117
00118 }
00119
00120 fiLastEvent=startindex+times;
00121
00122 if(fiLastEvent>lastentrynumber) {
00123 cout <<"Passing over end of tree - NEVER COME HERE!!!" << endl;
00124 fiLastEvent=lastentrynumber;
00125 times=fiLastEvent-startindex;
00126 cout << "\t -- startindex: "<< startindex<< endl;
00127 cout << "\t -- times: "<< times<< endl;
00128 cout << "\t -- treeentries: "<< lastentrynumber<< endl;
00129 }
00130
00131 TString drawexp = GetVarExp();
00132 drawexp += ">>+";
00133 drawexp += GetHistogramName();
00134
00135 TDirectory* savdir = gDirectory;
00136 gROOT->cd();
00137 tree->Draw(drawexp.Data(), fxCutExp.Data(), "goff", times, startindex);
00138 savdir->cd();
00139 }
00140
00141
00142 void TGo4TreeHistogramEntry::Print(Option_t* dummy) const
00143 {
00144
00145 TROOT::IndentLevel();
00146 cout <<"-Dynamic TreeDraw Entry " << GetName() << " :" << endl;
00147 TROOT::IncreaseDirLevel();
00148 if(IsEnabledProcessing()) cout <<"\t-- Enabled --" << endl;
00149 else cout <<"\t-- Disabled --" << endl;
00150
00151 TROOT::IndentLevel();
00152 cout <<"\tHistogram:\t"<< GetHistogramName()<<endl;
00153 TROOT::IndentLevel();
00154 cout <<"\tTree:\t"<< GetTreeName()<<endl;
00155 TROOT::IndentLevel();
00156 cout <<"\tDraw Expression:\t" << GetVarExp() <<endl;
00157 TROOT::IndentLevel();
00158 cout <<"\tCut Expression:\t" << GetCutExp() << endl;
00159 TROOT::DecreaseDirLevel();
00160 TROOT::IndentLevel();
00161 cout <<"-End "<<GetName()<<"-----------" << endl;
00162 }
00163
00164