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