GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4BackStore.cxx
Go to the documentation of this file.
1 // $Id: TGo4BackStore.cxx 2719 2020-03-11 15:53:34Z linev $
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(0),
34  fbBranchExists(kFALSE),
35  fxEvent(0),
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(0),
47  fbBranchExists(kFALSE),
48  fxEvent(0),
49  fiSplit(1),
50  fiBufsize(0),
51  fiFillCount(0)
52 {
53  GO4TRACE((15,"TGo4BackStore::TGo4BackStore(TGo4BackStoreParameter* par)", __LINE__, __FILE__));
54 
55  if (par==0) {
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!=0)
69  {
70  oldname=lastname+1;
71  lastname=strstr(oldname,"/");
72  }
73  TString buffer = oldname;
74  buffer+=fgcTREESUF;
75  TDirectory *dirsav = gDirectory;
76  gROOT->cd();
77  fxTree = new TTree(buffer.Data(), "Go4BackStore");
80  TGo4Log::Debug(" Tree %s has been created in memory ",buffer.Data());
81  dirsav->cd();
82 }
83 
85 {
86  GO4TRACE((15,"TGo4BackStore::~TGo4BackStore()", __LINE__, __FILE__));
87  delete fxTree;
88 
89 }
90 
91 void TGo4BackStore::Reset(Bool_t onlyclearflag)
92 {
93  if(fxTree!=0) {
94 
95  if(!onlyclearflag)
96  {
97  fxTree->Reset();
99  }
100  else
101  {
103  }
104  }
105 }
106 
108 {
109  return 0;
110 }
111 
113 {
114  return 0;
115 }
116 
118 {
119  return 0;
120 }
121 
122 Int_t TGo4BackStore::Store(TFolder* foldy)
123 {
124  return 0;
125 }
126 
127 
129 {
130  GO4TRACE((12,"TGo4BackStore::Store(TGo4EventElement*)", __LINE__, __FILE__));
131 
132  fxEvent=event; // address of next event into event pointer
133  if(!fbBranchExists)
134  {
135  // first call of Store, create new branch
136  //std::cout << "**********************Creating new branch!"<< std::endl;
137  if(fxEvent)
138  {
139  TString topbranchname(fxEvent->GetName());
140  topbranchname+=".";
141  TBranch* go4branch= fxTree->GetBranch(topbranchname.Data());
142  if(go4branch)
143  {
144  // tree already had branch of our name, check it
145  TGo4Log::Debug(" BackStore: Found existing branch %s , continue filling ",topbranchname.Data() );
146  // here we might check the classname of the stored events inbranch
147  go4branch->SetAddress(&fxEvent);
148  fbBranchExists=kTRUE;
149 
150  }
151  else
152  {
153  // no such branch existing, create a new one
154  TBranch *topbranch =
155  fxTree->Branch(topbranchname.Data(), fxEvent->ClassName(), &fxEvent, fiBufsize, fiSplit);
156  TGo4Log::Debug(" BackStore: Created new branch %s ", topbranchname.Data());
157  fbBranchExists = kTRUE;
158  fxEvent->makeBranch(topbranch);
159  } // if(go4branch)
160  }
161  else
162  {
163  // this is an error....
164  return 1;
165  }
166  } // if(!fbEventBranchExists)
167  else
168  {
169  // need not to create a branch, use existing one
170  }
171  // check if autosave threshold is reached, reset tree before autosave is performed:
172  Double_t totbytes=fxTree->GetTotBytes();
173  if(totbytes>TGo4BackStore::fgiMAXAUTOBYTES)
174  {
175  fxTree->Reset();
176  TGo4Log::Debug(" BackStore: Tree %s was Reset after %f bytes ",
177  fxTree->GetName(), totbytes);
178  }
179  fxTree->Fill();
180  return 0;
181 }
182 
183 
184 
185 
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 const char * fgcEVBRANCHNAME
Definition: TGo4BackStore.h:65
TTree * fxTree
Definition: TGo4BackStore.h:76
#define GO4TRACE(X)
Definition: TGo4Log.h:26
virtual Int_t Store(TGo4EventElement *event)
virtual ~TGo4BackStore()
static void Error(const char *text,...)
Definition: TGo4Log.cxx:313
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:274