GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4TreeHistogramEntry.cxx
Go to the documentation of this file.
1 // $Id: TGo4TreeHistogramEntry.cxx 2769 2020-04-16 14:54:23Z 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 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(Form("%s%s",histogramname,fgcENTRYSUF)); // 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  Form("Tree Histogram Entry: %s Reached end of tree %s. Draw() is stopped. ", 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