GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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
15
16#include <iostream>
17
18#include "TTree.h"
19#include "TROOT.h"
20
21#include "TGo4Log.h"
22#include "TGo4Status.h"
24
25const char *TGo4TreeHistogramEntry::fgcENTRYSUF = "-DL";
26
30 fxVarExp(),
31 fxCutExp(),
33 fbNewHistogram(kTRUE),
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),
51 fbNewHistogram(kTRUE),
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
74void 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
135void 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}
#define GO4TRACE(X)
Definition TGo4Log.h:25
virtual void Reset()
Resets this entry to an initial status.
void EnableProcessing(Bool_t on=kTRUE)
Switch the autoprocessing state of this entry.
TGo4DynamicEntry()
default ctor for streamer.
Bool_t IsEnabledProcessing() const
@ kGo4BackStoreReset
Definition TGo4Status.h:69
Bool_t fbNewHistogram
True before Process is called the first time.
TString fxTreeName
The Treename to find the tree.
const char * GetTreeName() const
const char * GetHistogramName() const
Get name of the external histogram to be filled.
Int_t fiLastEvent
index of last tree entry of the previous Process() call
const char * GetVarExp() const
TString fxVarExp
The varexp string needed by TTree:Draw()
TString fxHistogramName
The target histogram name to be filled.
void Print(Option_t *opt="") const override
TGo4TreeHistogramEntry()
default ctor for streamer.
const char * GetCutExp() const
void ProcessTreeNew(TTree *tree, Int_t times)
void Reset() override
Resets this entry to an initial status.
static const char * fgcENTRYSUF
suffix for entryname to differ from histogram name
TString fxCutExp
The selection string needed by TTree:Draw()