GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4MainTree.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 "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(nullptr),
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 
59 {
60  GO4TRACE((12, "TGo4MainTree::Instance()", __LINE__, __FILE__));
61  if (!fxInstance)
62  fxInstance = new TGo4MainTree();
63  return fxInstance;
64 }
65 
66 void TGo4MainTree::SetAutoSave(Int_t bytesinterval)
67 {
68  GO4TRACE((15,"TGo4MainTree::SetAutoSave(Int_t)", __LINE__, __FILE__));
69  Instance();
70  fxTree->SetAutoSave(bytesinterval);
71 }
72 
73 Int_t TGo4MainTree::Write(const char */*dummy*/, Int_t /*option*/, Int_t /*bufsize*/)
74 {
75  GO4TRACE((12,"TGo4MainTree::Write()", __LINE__, __FILE__));
76  fxFile->cd();
77  fxTree->Write(nullptr, TObject::kOverwrite);
78  return 0;
79 }
80 
81 Int_t TGo4MainTree::Write(const char */*dummy*/, Int_t /*option*/, Int_t /*bufsize*/) const
82 {
83  GO4TRACE((12,"TGo4MainTree::Write()", __LINE__, __FILE__));
84  fxFile->cd();
85  fxTree->Write(nullptr, TObject::kOverwrite);
86  return 0;
87 }
88 
90 {
91  GO4TRACE((12, "TGo4MainTree::Update()", __LINE__, __FILE__));
92  if (GetCurrentIndex() >= GetMaxIndex()) {
93  // if we are at the end of the tree, increment TTree fEvents counter
94  // without affecting the branches:
95  fxTree->SetBranchStatus("*", 0);
96  fxTree->Fill();
97  fxTree->SetBranchStatus("*", 1);
98  }
100 }
101 
103 {
104  fiMaxIndex = !fxTree ? 0 : fxTree->GetEntries();
105  return fiMaxIndex;
106 }
static TGo4MainTree * Instance()
static const Int_t fgiCOMPRESS
Definition: TGo4MainTree.h:54
void SetAutoSave(Int_t bytesinterval)
static void Info(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:294
Int_t GetMaxIndex()
Int_t IncCurrentIndex()
Definition: TGo4MainTree.h:71
virtual ~TGo4MainTree()
Int_t Write(const char *dummy=nullptr, Int_t option=0, Int_t bufsize=0) override
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
TTree * fxTree
Definition: TGo4MainTree.h:95
TFile * fxFile
Definition: TGo4MainTree.h:93
static const char * fgcTREENAME
Definition: TGo4MainTree.h:48
Int_t GetCurrentIndex() const
Definition: TGo4MainTree.h:66
static TGo4MainTree * fxInstance
Definition: TGo4MainTree.h:91
Int_t fiMaxIndex
Definition: TGo4MainTree.h:99
static const char * fgcFILENAME
Definition: TGo4MainTree.h:51
#define GO4TRACE(X)
Definition: TGo4Log.h:25
static const Int_t fgiAUTOSAVESIZE
Definition: TGo4MainTree.h:57