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

TGo4BackStore.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 "TGo4BackStore.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TTree.h"
00021 #include "TDirectory.h"
00022 #include "TROOT.h"
00023 #include "snprintf.h"
00024 
00025 #include "TGo4Log.h"
00026 #include "TGo4Status.h"
00027 #include "TGo4BackStoreParameter.h"
00028 #include "TGo4EventElement.h"
00029 #include "TGo4CompositeEvent.h"
00030 
00031 const Text_t TGo4BackStore::fgcTREESUF[] = "xTree";
00032 const Text_t TGo4BackStore::fgcEVBRANCHNAME[] = "Go4EventBranch.";
00033 
00034 const Int_t TGo4BackStore::fgiMAXAUTOBYTES = 100000000;
00035 
00036 TGo4BackStore::TGo4BackStore() :
00037    TGo4EventStore("Go4 Default Back Store"),
00038    fxTree(0),
00039    fbBranchExists(kFALSE),
00040    fxEvent(0),
00041    fiSplit(1),
00042    fiBufsize(0),
00043    fiFillCount(0)
00044 {
00045    TRACE((15,"TGo4BackStore::TGo4BackStore()", __LINE__, __FILE__));
00046    // public default ctor for streamer
00047 }
00048 
00049 TGo4BackStore::TGo4BackStore(TGo4BackStoreParameter* par) :
00050    TGo4EventStore("dummy"),
00051    fxTree(0),
00052    fbBranchExists(kFALSE),
00053    fxEvent(0),
00054    fiSplit(1),
00055    fiBufsize(0),
00056    fiFillCount(0)
00057 {
00058    TRACE((15,"TGo4BackStore::TGo4BackStore(TGo4BackStoreParameter* par)", __LINE__, __FILE__));
00059 
00060    if (par==0) {
00061       TGo4Log::Error("TGo4BackStoreParameter is not specified in TGo4BackStore constructor");
00062       return;
00063    }
00064 
00065    fiSplit = par->GetSplitlevel();
00066    fiBufsize = par->GetBufsize();
00067 
00068    SetName(par->GetName());
00069      // strip any path information from treename (could be identical with filename!)
00070    const char* lastname = par->GetTitle();
00071    const char* oldname = lastname;
00072    lastname=strstr(oldname,"/");
00073    while(lastname!=0)
00074       {
00075          oldname=lastname+1;
00076          lastname=strstr(oldname,"/");
00077       }
00078    TString buffer = oldname;
00079    buffer+=fgcTREESUF;
00080    TDirectory *dirsav = gDirectory;
00081    gROOT->cd();
00082    fxTree = new TTree(buffer.Data(), "Go4BackStore");
00083    fxTree->SetBit(TGo4Status::kGo4BackStoreReset);
00084    fxTree->SetAutoSave(TGo4BackStore::fgiMAXAUTOBYTES);
00085    TGo4Log::Debug(" Tree %s has been created in memory ",buffer.Data());
00086    dirsav->cd();
00087 }
00088 
00089 TGo4BackStore::~TGo4BackStore()
00090 {
00091    TRACE((15,"TGo4BackStore::~TGo4BackStore()", __LINE__, __FILE__));
00092    delete fxTree;
00093 
00094 }
00095 
00096 void TGo4BackStore::Reset(Bool_t onlyclearflag)
00097 {
00098    if(fxTree!=0) {
00099 
00100       if(!onlyclearflag)
00101          {
00102          fxTree->Reset();
00103          fxTree->SetBit(TGo4Status::kGo4BackStoreReset);
00104          }
00105      else
00106          {
00107          fxTree->ResetBit(TGo4Status::kGo4BackStoreReset);
00108          }
00109    }
00110 }
00111 
00112 Int_t TGo4BackStore::Store(TGo4Parameter* cali)
00113 {
00114    return 0;
00115 }
00116 
00117 Int_t TGo4BackStore::Store(TGo4Condition* conny)
00118 {
00119    return 0;
00120 }
00121 
00122 Int_t TGo4BackStore::Store(TGo4Fitter* fitty)
00123 {
00124    return 0;
00125 }
00126 
00127 Int_t TGo4BackStore::Store(TFolder* foldy)
00128 {
00129    return 0;
00130 }
00131 
00132 
00133 Int_t TGo4BackStore::Store(TGo4EventElement* event)
00134 {
00135    TRACE((12,"TGo4BackStore::Store(TGo4EventElement*)", __LINE__, __FILE__));
00136 
00137    fxEvent=event; // address of next event into event pointer
00138    if(!fbBranchExists)
00139       {
00140          // first call of Store, create new branch
00141          //cout << "**********************Creating new branch!"<< endl;
00142          if(fxEvent)
00143             {
00144                TString topbranchname(fxEvent->GetName());
00145                topbranchname+=".";
00146                TBranch*   go4branch= fxTree->GetBranch(topbranchname.Data());
00147                if(go4branch)
00148                   {
00149                      // tree already had branch of our name, check it
00150                      TGo4Log::Debug(" BackStore: Found existing branch %s , continue filling ",topbranchname.Data() );
00151                      // here we might check the classname of the stored events inbranch
00152                      go4branch->SetAddress(&fxEvent);
00153                      fbBranchExists=kTRUE;
00154 
00155                   }
00156                else
00157                   {
00158                      // no such branch existing, create a new one
00159                      TBranch *topbranch=
00160                      fxTree->Branch(topbranchname.Data(), fxEvent->ClassName(), &fxEvent, fiBufsize, fiSplit);
00161                      TGo4Log::Debug(" BackStore: Created new branch %s ", topbranchname.Data());
00162                      fbBranchExists=kTRUE;
00163                      if (fxEvent->InheritsFrom(TGo4CompositeEvent::Class()))
00164                       dynamic_cast<TGo4CompositeEvent*>  (fxEvent)->makeBranch(topbranch);
00165                   } // if(go4branch)
00166             }
00167          else
00168             {
00169                // this is an error....
00170                return 1;
00171             }
00172       } // if(!fbEventBranchExists)
00173    else
00174       {
00175            // need not to create a branch, use existing one
00176       }
00177    // check if autosave threshold is reached, reset tree before autosave is performed:
00178    Double_t totbytes=fxTree->GetTotBytes();
00179    if(totbytes>TGo4BackStore::fgiMAXAUTOBYTES)
00180       {
00181           fxTree->Reset();
00182           TGo4Log::Debug(" BackStore: Tree %s was Reset after %f bytes ",
00183              fxTree->GetName(), totbytes);
00184       }
00185    fxTree->Fill();
00186    return 0;
00187 }
00188 
00189 
00190 
00191 
00192 
00193 //----------------------------END OF GO4 SOURCE FILE ---------------------

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