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