GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4TreeHistogramEntry.cxx
Go to the documentation of this file.
1 // $Id: TGo4TreeHistogramEntry.cxx 1494 2015-06-08 15:33:53Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4TreeHistogramEntry.h"
15 
16 #include "Riostream.h"
17 #include "TTree.h"
18 #include "TROOT.h"
19 
20 #include "TGo4Log.h"
21 #include "TGo4Status.h"
23 
24 const char* TGo4TreeHistogramEntry::fgcENTRYSUF="-DL";
25 
28  fxHistogramName(),
29  fxVarExp(),
30  fxCutExp(),
31  fiDynListInterval(1000),
32  fbNewHistogram(kTRUE),
33  fiLastEvent(0)
34 {
35  GO4TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry()",__LINE__, __FILE__));
36  fxTreeName="Go4Tree";
37  EnableProcessing(kTRUE);
38 }
39 
41  const char* treename,
42  const char* varexp,
43  const char* cutexp) :
44  TGo4DynamicEntry(histogramname),
45  fxHistogramName(histogramname),
46  fxTreeName(treename),
47  fxVarExp(varexp),
48  fxCutExp(cutexp),
49  fiDynListInterval(1000),
50  fbNewHistogram(kTRUE),
51  fiLastEvent(0)
52 {
53  GO4TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const char*, const char*, const char*, const char*)",__LINE__, __FILE__));
54  SetName(Form("%s%s",histogramname,fgcENTRYSUF)); // histogram name is different from entryname!
55  EnableProcessing(kTRUE);
56 
57  Reset();
58 }
59 
61 {
62  GO4TRACE((15,"TGo4TreeHistogramEntry::~TGo4TreeHistogramEntry()",__LINE__, __FILE__));
63 }
64 
66 {
67  GO4TRACE((12,"TGo4TreeHistogramEntry::Reset()",__LINE__, __FILE__));
69  fiLastEvent=0;
70  fbNewHistogram=kTRUE;
71 }
72 
73 void TGo4TreeHistogramEntry::ProcessTreeNew(TTree* tree, Int_t times)
74 {
75  if(times<=0) times=1;
76 
77  Int_t lastentrynumber = static_cast<Int_t> (tree->GetEntries());
78  if(tree->TestBit(TGo4Status::kGo4BackStoreReset))
79  fiLastEvent=0; // start again with first entry of backstore tree
80 
81  if(fiLastEvent==lastentrynumber)
82  throw TGo4DynamicListException(this,
83  "Tree Histogram Entry: %s Reached end of tree %s. Draw() is stopped. ",
84  GetName(), tree->GetName());
85  Int_t startindex= lastentrynumber -times;
86  //std::cout << "\t -- init startindex: "<< startindex<< std::endl;
87  if(startindex<fiLastEvent)
88  {
89  // we have to check if some of the events were not filled in the tree,
90  // in this case we take all from the last processed event to the current:
91  if(startindex>0)
92  {
93  // normal case in continuous processed tree
94  startindex=fiLastEvent;
95  }
96  else
97  {
98  // this can happen when tree was Reset() in the meantime
99  // e.g. tree of TGo4BackStore, then fiLastEvent is wrong
100  startindex=0;
101  }
102  times=lastentrynumber-startindex;
103  }
104  else
105  {
106  // this happens when dynamic list entry started after the tree filling has begun
107  // switch this on for cint tree processing:
108  startindex=fiLastEvent;
109  //times=lastentrynumber-startindex;
110  // <- this would cause to process all events in tree since the last time this
111  // dynamic entry was active. might be dangerous though, not useful...
112  }
113 
114  fiLastEvent=startindex+times; // for cint mode
115 
116  if(fiLastEvent>lastentrynumber) {
117  std::cout <<"Passing over end of tree - NEVER COME HERE!!!" << std::endl;
118  fiLastEvent=lastentrynumber;
119  times=fiLastEvent-startindex;
120  std::cout << "\t -- startindex: "<< startindex<< std::endl;
121  std::cout << "\t -- times: "<< times<< std::endl;
122  std::cout << "\t -- treeentries: "<< lastentrynumber<< std::endl;
123  }
124 
125  TString drawexp = GetVarExp();
126  drawexp += ">>+";
127  drawexp += GetHistogramName();
128 
129  TDirectory* savdir = gDirectory;
130  gROOT->cd(); // be sure to be in the top directory when processing
131  tree->Draw(drawexp.Data(), fxCutExp.Data(), "goff", times, startindex);
132  savdir->cd();
133 }
134 
135 
136 void TGo4TreeHistogramEntry::Print(Option_t*) const
137 {
138  // this trick is needed since root defines Print as const function...
139  TROOT::IndentLevel();
140  std::cout <<"-Dynamic TreeDraw Entry " << GetName() << " :" << std::endl;
141  TROOT::IncreaseDirLevel();
142  if(IsEnabledProcessing()) std::cout <<"\t-- Enabled --" << std::endl;
143  else std::cout <<"\t-- Disabled --" << std::endl;
144 
145  TROOT::IndentLevel();
146  std::cout <<"\tHistogram:\t"<< GetHistogramName()<<std::endl;
147  TROOT::IndentLevel();
148  std::cout <<"\tTree:\t"<< GetTreeName()<<std::endl;
149  TROOT::IndentLevel();
150  std::cout <<"\tDraw Expression:\t" << GetVarExp() <<std::endl;
151  TROOT::IndentLevel();
152  std::cout <<"\tCut Expression:\t" << GetCutExp() << std::endl;
153  TROOT::DecreaseDirLevel();
154  TROOT::IndentLevel();
155  std::cout <<"-End "<<GetName()<<"-----------" << std::endl;
156 }
virtual void Reset()
static const char * fgcENTRYSUF
void ProcessTreeNew(TTree *tree, Int_t times)
const char * GetHistogramName() const
const char * GetCutExp() const
Bool_t IsEnabledProcessing() const
const char * GetTreeName() const
virtual void Print(Option_t *="") const
#define GO4TRACE(X)
Definition: TGo4Log.h:26
void EnableProcessing(Bool_t on=kTRUE)
const char * GetVarExp() const