GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4TreeHistogramEntry.cxx
Go to the documentation of this file.
1 // $Id$
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 fuer 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 <iostream>
17 
18 #include "TTree.h"
19 #include "TROOT.h"
20 
21 #include "TGo4Log.h"
22 #include "TGo4Status.h"
24 
25 const char *TGo4TreeHistogramEntry::fgcENTRYSUF = "-DL";
26 
29  fxHistogramName(),
30  fxVarExp(),
31  fxCutExp(),
32  fiDynListInterval(1000),
33  fbNewHistogram(kTRUE),
34  fiLastEvent(0)
35 {
36  GO4TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry()",__LINE__, __FILE__));
37  fxTreeName = "Go4Tree";
38  EnableProcessing(kTRUE);
39 }
40 
42  const char *treename,
43  const char *varexp,
44  const char *cutexp) :
45  TGo4DynamicEntry(histogramname),
46  fxHistogramName(histogramname),
47  fxTreeName(treename),
48  fxVarExp(varexp),
49  fxCutExp(cutexp),
50  fiDynListInterval(1000),
51  fbNewHistogram(kTRUE),
52  fiLastEvent(0)
53 {
54  GO4TRACE((15,"TGo4TreeHistogramEntry::TGo4TreeHistogramEntry(const char*, const char*, const char*, const char*)",__LINE__, __FILE__));
55  SetName(TString::Format("%s%s",histogramname,fgcENTRYSUF).Data()); // histogram name is different from entryname!
56  EnableProcessing(kTRUE);
57 
58  Reset();
59 }
60 
62 {
63  GO4TRACE((15,"TGo4TreeHistogramEntry::~TGo4TreeHistogramEntry()",__LINE__, __FILE__));
64 }
65 
67 {
68  GO4TRACE((12,"TGo4TreeHistogramEntry::Reset()",__LINE__, __FILE__));
70  fiLastEvent = 0;
71  fbNewHistogram = kTRUE;
72 }
73 
74 void TGo4TreeHistogramEntry::ProcessTreeNew(TTree *tree, Int_t times)
75 {
76  if(times <= 0) times = 1;
77 
78  Int_t lastentrynumber = static_cast<Int_t> (tree->GetEntries());
79  if(tree->TestBit(TGo4Status::kGo4BackStoreReset))
80  fiLastEvent = 0; // start again with first entry of backstore tree
81 
82  if(fiLastEvent==lastentrynumber)
83  throw TGo4DynamicListException(this,
84  TString::Format("Tree Histogram Entry: %s Reached end of tree %s. Draw() is stopped. ", GetName(), tree->GetName()).Data());
85  Int_t startindex = lastentrynumber - times;
86  if(startindex < fiLastEvent)
87  {
88  // we have to check if some of the events were not filled in the tree,
89  // in this case we take all from the last processed event to the current:
90  if(startindex>0)
91  {
92  // normal case in continuous processed tree
93  startindex = fiLastEvent;
94  }
95  else
96  {
97  // this can happen when tree was Reset() in the meantime
98  // e.g. tree of TGo4BackStore, then fiLastEvent is wrong
99  startindex = 0;
100  }
101  times=lastentrynumber-startindex;
102  }
103  else
104  {
105  // this happens when dynamic list entry started after the tree filling has begun
106  // switch this on for cint tree processing:
107  startindex=fiLastEvent;
108  //times=lastentrynumber-startindex;
109  // <- this would cause to process all events in tree since the last time this
110  // dynamic entry was active. might be dangerous though, not useful...
111  }
112 
113  fiLastEvent=startindex+times; // for cint mode
114 
115  if(fiLastEvent>lastentrynumber) {
116  std::cout <<"Passing over end of tree - NEVER COME HERE!!!" << std::endl;
117  fiLastEvent=lastentrynumber;
118  times=fiLastEvent-startindex;
119  std::cout << "\t -- startindex: "<< startindex<< std::endl;
120  std::cout << "\t -- times: "<< times<< std::endl;
121  std::cout << "\t -- treeentries: "<< lastentrynumber<< std::endl;
122  }
123 
124  TString drawexp = GetVarExp();
125  drawexp += ">>+";
126  drawexp += GetHistogramName();
127 
128  TDirectory *savdir = gDirectory;
129  gROOT->cd(); // be sure to be in the top directory when processing
130  tree->Draw(drawexp.Data(), fxCutExp.Data(), "goff", times, startindex);
131  savdir->cd();
132 }
133 
134 
135 void TGo4TreeHistogramEntry::Print(Option_t *) const
136 {
137  // this trick is needed since root defines Print as const function...
138  TROOT::IndentLevel();
139  std::cout <<"-Dynamic TreeDraw Entry " << GetName() << " :" << std::endl;
140  TROOT::IncreaseDirLevel();
141  if(IsEnabledProcessing()) std::cout <<"\t-- Enabled --" << std::endl;
142  else std::cout <<"\t-- Disabled --" << std::endl;
143 
144  TROOT::IndentLevel();
145  std::cout <<"\tHistogram:\t"<< GetHistogramName()<<std::endl;
146  TROOT::IndentLevel();
147  std::cout <<"\tTree:\t"<< GetTreeName()<<std::endl;
148  TROOT::IndentLevel();
149  std::cout <<"\tDraw Expression:\t" << GetVarExp() <<std::endl;
150  TROOT::IndentLevel();
151  std::cout <<"\tCut Expression:\t" << GetCutExp() << std::endl;
152  TROOT::DecreaseDirLevel();
153  TROOT::IndentLevel();
154  std::cout <<"-End "<<GetName()<<"-----------" << std::endl;
155 }
virtual void Reset()
const char * GetTreeName() const
static const char * fgcENTRYSUF
void ProcessTreeNew(TTree *tree, Int_t times)
Bool_t IsEnabledProcessing() const
#define GO4TRACE(X)
Definition: TGo4Log.h:25
void EnableProcessing(Bool_t on=kTRUE)
void Print(Option_t *opt="") const override
const char * GetCutExp() const
const char * GetVarExp() const
const char * GetHistogramName() const