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