Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4MainTree.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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    // check if tree already exists...
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* /*dummy*/, Int_t /*option*/, Int_t /*bufsize*/)
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* /*dummy*/, Int_t /*option*/, Int_t /*bufsize*/) 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          // if we are at the end of the tree, increment TTree fEvents counter
00108          // without affecting the branches:
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 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:08 2008 for Go4-v3.04-1 by  doxygen 1.4.2