GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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
23const char *TGo4MainTree::fgcTREENAME = "Main";
24const char *TGo4MainTree::fgcFILENAME = "Go4MainTree.root";
25
26const Int_t TGo4MainTree::fgiCOMPRESS = 5;
27const Int_t TGo4MainTree::fgiAUTOSAVESIZE = 10000000;
28
30 TObject(),
31 fxTree(nullptr),
32 fiMaxIndex(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)
63 return fxInstance;
64}
65
66void TGo4MainTree::SetAutoSave(Int_t bytesinterval)
67{
68 GO4TRACE((15,"TGo4MainTree::SetAutoSave(Int_t)", __LINE__, __FILE__));
69 Instance();
70 fxTree->SetAutoSave(bytesinterval);
71}
72
73Int_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
81Int_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}
#define GO4TRACE(X)
Definition TGo4Log.h:25
static void Info(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 1.
Definition TGo4Log.cxx:294
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
Singleton containing and managing the main tree of the go4 analysis.
Int_t fiMaxIndex
Number of events stored in the Tree.
void SetAutoSave(Int_t bytesinterval)
Set the tree autosave byte interval.
static const Int_t fgiCOMPRESS
Default compression level.
virtual ~TGo4MainTree()
Int_t Write(const char *dummy=nullptr, Int_t option=0, Int_t bufsize=0) override
Write tree content to file.
static TGo4MainTree * Instance()
TTree * fxTree
static TGo4MainTree * fxInstance
TFile * fxFile
Int_t GetCurrentIndex() const
static const char * fgcTREENAME
Standard go4 name of the main tree.
static const char * fgcFILENAME
Standard suffix for file name.
void Update()
Update the tree entry information without processing any branch.
static const Int_t fgiAUTOSAVESIZE
Default tree autosave size.
Int_t fiCurrentIndex
Index number of the current event.
Int_t IncCurrentIndex()
Increments current index in the main tree by one.
Int_t GetMaxIndex()