00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4MainTree.h"
00017
00018 #include "TTree.h"
00019 #include "TFile.h"
00020
00021 #include "TGo4Log.h"
00022 #include "Go4Exceptions.h"
00023
00024
00025 TGo4MainTree * TGo4MainTree::fxInstance= 0;
00026
00027 const Text_t TGo4MainTree::fgcTREENAME[] = "Main";
00028 const Text_t TGo4MainTree::fgcFILENAME[] = "Go4MainTree.root";
00029
00030 const Int_t TGo4MainTree::fgiCOMPRESS = 5;
00031 const Int_t TGo4MainTree::fgiAUTOSAVESIZE = 10000000;
00032
00033 TGo4MainTree::TGo4MainTree() :
00034 TObject(),
00035 fxTree(0),
00036 fiMaxIndex(0),
00037 fiCurrentIndex(0)
00038 {
00039 TRACE((15,"TGo4MainTree::TGo4MainTree()", __LINE__, __FILE__));
00040
00041 fxFile = new TFile(fgcFILENAME, "UPDATE");
00042 fxFile->SetCompressionLevel(fgiCOMPRESS);
00043
00044 fxTree= dynamic_cast<TTree*> (fxFile->Get(fgcTREENAME));
00045 if(fxTree)
00046 {
00047 TGo4Log::Debug(" MainTree has been found in file %s ",fgcFILENAME);
00048 }
00049 else
00050 {
00051 fxTree = new TTree(fgcTREENAME, "The Go4 Tree");
00052 fxTree->SetAutoSave(fgiAUTOSAVESIZE);
00053 TGo4Log::Debug(" MainTree has been created in file %s ",fgcFILENAME);
00054 }
00055 fiMaxIndex= (Int_t ) fxTree->GetEntries();
00056
00057 }
00058
00059 TGo4MainTree::~TGo4MainTree()
00060 {
00061 TRACE((15,"TGo4MainTree::~TGo4MainTree()", __LINE__, __FILE__));
00062 Write();
00063 delete fxFile;
00064
00065 }
00066
00067
00068 TGo4MainTree * TGo4MainTree::Instance()
00069 {
00070 TRACE((12,"TGo4MainTree::Instance()", __LINE__, __FILE__));
00071 if (fxInstance == 0)
00072 {
00073 fxInstance = new TGo4MainTree();
00074 }
00075 else { }
00076 return fxInstance;
00077 }
00078
00079 void TGo4MainTree::SetAutoSave(Int_t bytesinterval)
00080 {
00081 TRACE((15,"TGo4MainTree::SetAutoSave(Int_t)", __LINE__, __FILE__));
00082 Instance();
00083 fxTree->SetAutoSave(bytesinterval);
00084 }
00085
00086 Int_t TGo4MainTree::Write(const char* , Int_t , Int_t )
00087 {
00088 TRACE((12,"TGo4MainTree::Write()", __LINE__, __FILE__));
00089 fxFile->cd();
00090 fxTree->Write(0, TObject::kOverwrite);
00091 return 0;
00092 }
00093
00094 Int_t TGo4MainTree::Write(const char* , Int_t , Int_t ) const
00095 {
00096 TRACE((12,"TGo4MainTree::Write()", __LINE__, __FILE__));
00097 fxFile->cd();
00098 fxTree->Write(0, TObject::kOverwrite);
00099 return 0;
00100 }
00101
00102 void TGo4MainTree::Update()
00103 {
00104 TRACE((12,"TGo4MainTree::Update()", __LINE__, __FILE__));
00105 if( GetCurrentIndex() >= GetMaxIndex() )
00106 {
00107
00108
00109 fxTree->SetBranchStatus("*",0);
00110 fxTree->Fill();
00111 fxTree->SetBranchStatus("*",1);
00112 }
00113 else
00114 { }
00115 IncCurrentIndex();
00116 }
00117
00118 Int_t TGo4MainTree::GetMaxIndex()
00119 {
00120 fiMaxIndex = (fxTree==0) ? 0 : fxTree->GetEntries();
00121 return fiMaxIndex;
00122 }
00123
00124
00125
00126