GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4BackStore.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 "TGo4BackStore.h"
15 
16 #include "TTree.h"
17 #include "TDirectory.h"
18 #include "TROOT.h"
19 #include "TBranch.h"
20 
21 #include "TGo4Log.h"
22 #include "TGo4Status.h"
23 #include "TGo4BackStoreParameter.h"
24 #include "TGo4EventElement.h"
25 
26 const char *TGo4BackStore::fgcTREESUF = "xTree";
27 const char *TGo4BackStore::fgcEVBRANCHNAME = "Go4EventBranch.";
28 
29 const Int_t TGo4BackStore::fgiMAXAUTOBYTES = 100000000;
30 
32  TGo4EventStore("Go4 Default Back Store"),
33  fxTree(nullptr),
34  fbBranchExists(kFALSE),
35  fxEvent(nullptr),
36  fiSplit(1),
37  fiBufsize(0),
38  fiFillCount(0)
39 {
40  GO4TRACE((15,"TGo4BackStore::TGo4BackStore()", __LINE__, __FILE__));
41  // public default ctor for streamer
42 }
43 
45  TGo4EventStore("dummy"),
46  fxTree(nullptr),
47  fbBranchExists(kFALSE),
48  fxEvent(nullptr),
49  fiSplit(1),
50  fiBufsize(0),
51  fiFillCount(0)
52 {
53  GO4TRACE((15,"TGo4BackStore::TGo4BackStore(TGo4BackStoreParameter* par)", __LINE__, __FILE__));
54 
55  if (!par) {
56  TGo4Log::Error("TGo4BackStoreParameter is not specified in TGo4BackStore constructor");
57  return;
58  }
59 
60  fiSplit = par->GetSplitlevel();
61  fiBufsize = par->GetBufsize();
62 
63  SetName(par->GetName());
64  // strip any path information from treename (could be identical with filename!)
65  const char *lastname = par->GetTitle();
66  const char *oldname = lastname;
67  lastname = strstr(oldname,"/");
68  while (lastname != nullptr) {
69  oldname = lastname + 1;
70  lastname = strstr(oldname, "/");
71  }
72  TString buffer = oldname;
73  buffer+=fgcTREESUF;
74  TDirectory *dirsav = gDirectory;
75  gROOT->cd();
76  fxTree = new TTree(buffer.Data(), "Go4BackStore");
79  TGo4Log::Debug(" Tree %s has been created in memory ",buffer.Data());
80  dirsav->cd();
81 }
82 
84 {
85  GO4TRACE((15,"TGo4BackStore::~TGo4BackStore()", __LINE__, __FILE__));
86  delete fxTree;
87  fxTree = nullptr;
88 }
89 
90 void TGo4BackStore::Reset(Bool_t onlyclearflag)
91 {
92  if (fxTree) {
93  if (!onlyclearflag) {
94  fxTree->Reset();
96  } else {
98  }
99  }
100 }
101 
103 {
104  return 0;
105 }
106 
108 {
109  return 0;
110 }
111 
113 {
114  return 0;
115 }
116 
117 Int_t TGo4BackStore::Store(TFolder *foldy)
118 {
119  return 0;
120 }
121 
122 
124 {
125  GO4TRACE((12, "TGo4BackStore::Store(TGo4EventElement *)", __LINE__, __FILE__));
126 
127  fxEvent = event; // address of next event into event pointer
128  if (!fbBranchExists) {
129  // first call of Store, create new branch
130  if (fxEvent) {
131  TString topbranchname(fxEvent->GetName());
132  topbranchname += ".";
133  TBranch *go4branch = fxTree->GetBranch(topbranchname.Data());
134  if (go4branch) {
135  // tree already had branch of our name, check it
136  TGo4Log::Debug(" BackStore: Found existing branch %s, continue filling ", topbranchname.Data());
137  // here we might check the classname of the stored events inbranch
138  go4branch->SetAddress(&fxEvent);
139  fbBranchExists = kTRUE;
140 
141  } else {
142  // no such branch existing, create a new one
143  TBranch *topbranch =
144  fxTree->Branch(topbranchname.Data(), fxEvent->ClassName(), &fxEvent, fiBufsize, fiSplit);
145  TGo4Log::Debug(" BackStore: Created new branch %s ", topbranchname.Data());
146  fbBranchExists = kTRUE;
147  fxEvent->makeBranch(topbranch);
148  } // if(go4branch)
149  } else {
150  // this is an error....
151  return 1;
152  }
153  }
154  // check if autosave threshold is reached, reset tree before autosave is performed:
155  Double_t totbytes = fxTree->GetTotBytes();
156  if (totbytes > TGo4BackStore::fgiMAXAUTOBYTES) {
157  fxTree->Reset();
158  TGo4Log::Debug(" BackStore: Tree %s was Reset after %f bytes ", fxTree->GetName(), totbytes);
159  }
160  fxTree->Fill();
161  return 0;
162 }
virtual void makeBranch(TBranch *parent)
Bool_t fbBranchExists
Definition: TGo4BackStore.h:80
TGo4EventElement * fxEvent
Definition: TGo4BackStore.h:83
void Reset(Bool_t onlyclearflag=kFALSE)
static const char * fgcTREESUF
Definition: TGo4BackStore.h:68
static const Int_t fgiMAXAUTOBYTES
Definition: TGo4BackStore.h:72
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
static const char * fgcEVBRANCHNAME
Definition: TGo4BackStore.h:65
Int_t Store(TGo4EventElement *event) override
static void Error(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:320
TTree * fxTree
Definition: TGo4BackStore.h:76
#define GO4TRACE(X)
Definition: TGo4Log.h:25
virtual ~TGo4BackStore()