GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4MainTree.cxx
Go to the documentation of this file.
1 // $Id: TGo4MainTree.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 "TGo4MainTree.h"
15 
16 #include "TTree.h"
17 #include "TFile.h"
18 
19 #include "TGo4Log.h"
20 #include "Go4Exceptions.h"
21 
22 
24 
25 const char* TGo4MainTree::fgcTREENAME = "Main";
26 const char* TGo4MainTree::fgcFILENAME = "Go4MainTree.root";
27 
28 const Int_t TGo4MainTree::fgiCOMPRESS = 5;
29 const Int_t TGo4MainTree::fgiAUTOSAVESIZE = 10000000;
30 
32  TObject(),
33  fxTree(0),
34  fiMaxIndex(0),
35  fiCurrentIndex(0)
36 {
37  GO4TRACE((15,"TGo4MainTree::TGo4MainTree()", __LINE__, __FILE__));
38 
39  fxFile = TFile::Open(fgcFILENAME, "UPDATE", "File for main Go4 tree", fgiCOMPRESS);
40  TGo4Log::Info("TGo4MainTree: Open file %s UPDATE", fgcFILENAME);
41  // check if tree already exists...
42  fxTree = dynamic_cast<TTree*> (fxFile->Get(fgcTREENAME));
43  if(fxTree) {
44  TGo4Log::Debug(" MainTree has been found in file %s ",fgcFILENAME);
45  } else {
46  fxTree = new TTree(fgcTREENAME, "The Go4 Tree");
47  fxTree->SetAutoSave(fgiAUTOSAVESIZE);
48  TGo4Log::Debug(" MainTree has been created in file %s ",fgcFILENAME);
49  }
50  fiMaxIndex = (Int_t) fxTree->GetEntries();
51 }
52 
54 {
55  GO4TRACE((15,"TGo4MainTree::~TGo4MainTree()", __LINE__, __FILE__));
56  Write();
57  delete fxFile;
58 
59 }
60 
61 
63 {
64  GO4TRACE((12,"TGo4MainTree::Instance()", __LINE__, __FILE__));
65  if (fxInstance == 0)
66  {
67  fxInstance = new TGo4MainTree();
68  }
69  else { }
70  return fxInstance;
71 }
72 
73 void TGo4MainTree::SetAutoSave(Int_t bytesinterval)
74 {
75  GO4TRACE((15,"TGo4MainTree::SetAutoSave(Int_t)", __LINE__, __FILE__));
76  Instance();
77  fxTree->SetAutoSave(bytesinterval);
78 }
79 
80 Int_t TGo4MainTree::Write(const char* /*dummy*/, Int_t /*option*/, Int_t /*bufsize*/)
81 {
82  GO4TRACE((12,"TGo4MainTree::Write()", __LINE__, __FILE__));
83  fxFile->cd();
84  fxTree->Write(0, TObject::kOverwrite);
85  return 0;
86 }
87 
88 Int_t TGo4MainTree::Write(const char* /*dummy*/, Int_t /*option*/, Int_t /*bufsize*/) const
89 {
90  GO4TRACE((12,"TGo4MainTree::Write()", __LINE__, __FILE__));
91  fxFile->cd();
92  fxTree->Write(0, TObject::kOverwrite);
93  return 0;
94 }
95 
97 {
98 GO4TRACE((12,"TGo4MainTree::Update()", __LINE__, __FILE__));
99  if( GetCurrentIndex() >= GetMaxIndex() )
100  {
101  // if we are at the end of the tree, increment TTree fEvents counter
102  // without affecting the branches:
103  fxTree->SetBranchStatus("*",0);
104  fxTree->Fill();
105  fxTree->SetBranchStatus("*",1);
106  }
107  else
108  { }
109  IncCurrentIndex();
110 }
111 
113 {
114  fiMaxIndex = (fxTree==0) ? 0 : fxTree->GetEntries();
115  return fiMaxIndex;
116 }
117 
118 
static TGo4MainTree * Instance()
static const Int_t fgiCOMPRESS
Definition: TGo4MainTree.h:54
void SetAutoSave(Int_t bytesinterval)
Int_t GetMaxIndex()
Int_t IncCurrentIndex()
Definition: TGo4MainTree.h:71
virtual ~TGo4MainTree()
TTree * fxTree
Definition: TGo4MainTree.h:95
TFile * fxFile
Definition: TGo4MainTree.h:93
static const char * fgcTREENAME
Definition: TGo4MainTree.h:48
static TGo4MainTree * fxInstance
Definition: TGo4MainTree.h:91
Int_t GetCurrentIndex() const
Definition: TGo4MainTree.h:66
Int_t fiMaxIndex
Definition: TGo4MainTree.h:99
static const char * fgcFILENAME
Definition: TGo4MainTree.h:51
virtual Int_t Write(const char *dummy=0, Int_t option=0, Int_t bufsize=0)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
static const Int_t fgiAUTOSAVESIZE
Definition: TGo4MainTree.h:57
static void Info(const char *text,...)
Definition: TGo4Log.cxx:283
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:270