GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4TreeSource.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 "TGo4TreeSource.h"
15 
16 #include <iostream>
17 
18 #include "TTree.h"
19 #include "TBranch.h"
20 
21 #include "TGo4Log.h"
22 #include "TGo4MainTree.h"
24 
26 : TGo4EventSource(name)
27 {
28  GO4TRACE((15,"TGo4TreeSource::TGo4TreeSource(const char *)",__LINE__, __FILE__));
29  Open();
30 }
31 
33 : TGo4EventSource(par->GetName())
34 {
35  GO4TRACE((15,"TGo4TreeSource::TGo4TreeSource(TGo4TreeSourceParameter*)",__LINE__, __FILE__));
36  Open();
37 }
38 
39 
41 : TGo4EventSource("Go4TreeSource")
42 {
43  GO4TRACE((15,"TGo4TreeSource::TGo4TreeSource()",__LINE__, __FILE__));
44 }
45 
47 {
48  GO4TRACE((15,"TGo4TreeSource::~TGo4TreeSource()",__LINE__, __FILE__));
49  // we have to readout rest of branch into memory before whole tree is written again
50  Int_t current = fxSingletonTree->GetCurrentIndex();
51  Int_t max = fxSingletonTree->GetMaxIndex();
52  Int_t z = 0;
53  for (Int_t ix = current; ix < max; ++ix) {
54  z++;
55  if (fxBranch->GetEntry(ix) == 0) {
56  std::cout << "reached end of branch after " << z << " dummy event retrieves" << std::endl;
57  break;
58  }
59  }
60  std::cout << "treesource " << GetName() << " is destroyed after " << z << "dummy retrieves." << std::endl;
61 }
62 
64 {
65  GO4TRACE((15,"TGo4TreeSource::Open()",__LINE__, __FILE__));
66 
67  // for branches containing the same event structure
68  TString buffer = TString::Format("%s.",GetName());
69 
72  fxBranch = fxTree->GetBranch(buffer.Data());
73  if(fxBranch)
74  TGo4Log::Debug(" TreeSource: Found existing branch %s ", buffer.Data());
75  else
76  ThrowError(77,0, "!!! ERROR: Branch %s not found!!!", buffer.Data());
77 
78  return 0;
79 }
80 
81 
82 
84 {
85  GO4TRACE((12,"TGo4TreeSource::BuildEvent(TGo4EventElement *)",__LINE__, __FILE__));
86  //
87  Bool_t rev=kTRUE;
88  if(!dest) ThrowError(0,22,"!!! ERROR BuildEvent: no destination event!!!");
89  if(!fxBranch) ThrowError(0,23,"!!! ERROR BuildEvent: branch was not initialized !!!");
90  fxBranch->SetAddress(&dest);
91  Int_t current=fxSingletonTree->GetCurrentIndex();
92  if(fxBranch->GetEntry(current) == 0) {
93  ThrowError(0,24,"!!! ERROR BuildEvent: getting branch entry failed !!!");
94  } else {
95  rev=kTRUE;
96  }
97  return rev;
98 }
static TGo4MainTree * Instance()
TBranch * fxBranch
Int_t GetMaxIndex()
Bool_t BuildEvent(TGo4EventElement *dest) override
void ThrowError(Int_t creastat, Int_t errstat, const char *message,...)
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
Int_t GetCurrentIndex() const
Definition: TGo4MainTree.h:66
virtual ~TGo4TreeSource()
TTree * GetTree() const
Definition: TGo4MainTree.h:39
TGo4MainTree * fxSingletonTree
#define GO4TRACE(X)
Definition: TGo4Log.h:25