GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4BackStore.cxx
Go to the documentation of this file.
1 // $Id: TGo4BackStore.cxx 2130 2018-08-14 10:13:11Z 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 f�r 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 
20 #include "TGo4Log.h"
21 #include "TGo4Status.h"
22 #include "TGo4BackStoreParameter.h"
23 #include "TGo4EventElement.h"
24 
25 const char* TGo4BackStore::fgcTREESUF = "xTree";
26 const char* TGo4BackStore::fgcEVBRANCHNAME = "Go4EventBranch.";
27 
28 const Int_t TGo4BackStore::fgiMAXAUTOBYTES = 100000000;
29 
31  TGo4EventStore("Go4 Default Back Store"),
32  fxTree(0),
33  fbBranchExists(kFALSE),
34  fxEvent(0),
35  fiSplit(1),
36  fiBufsize(0),
37  fiFillCount(0)
38 {
39  GO4TRACE((15,"TGo4BackStore::TGo4BackStore()", __LINE__, __FILE__));
40  // public default ctor for streamer
41 }
42 
44  TGo4EventStore("dummy"),
45  fxTree(0),
46  fbBranchExists(kFALSE),
47  fxEvent(0),
48  fiSplit(1),
49  fiBufsize(0),
50  fiFillCount(0)
51 {
52  GO4TRACE((15,"TGo4BackStore::TGo4BackStore(TGo4BackStoreParameter* par)", __LINE__, __FILE__));
53 
54  if (par==0) {
55  TGo4Log::Error("TGo4BackStoreParameter is not specified in TGo4BackStore constructor");
56  return;
57  }
58 
59  fiSplit = par->GetSplitlevel();
60  fiBufsize = par->GetBufsize();
61 
62  SetName(par->GetName());
63  // strip any path information from treename (could be identical with filename!)
64  const char* lastname = par->GetTitle();
65  const char* oldname = lastname;
66  lastname=strstr(oldname,"/");
67  while(lastname!=0)
68  {
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 
88 }
89 
90 void TGo4BackStore::Reset(Bool_t onlyclearflag)
91 {
92  if(fxTree!=0) {
93 
94  if(!onlyclearflag)
95  {
96  fxTree->Reset();
98  }
99  else
100  {
102  }
103  }
104 }
105 
107 {
108  return 0;
109 }
110 
112 {
113  return 0;
114 }
115 
117 {
118  return 0;
119 }
120 
121 Int_t TGo4BackStore::Store(TFolder* foldy)
122 {
123  return 0;
124 }
125 
126 
128 {
129  GO4TRACE((12,"TGo4BackStore::Store(TGo4EventElement*)", __LINE__, __FILE__));
130 
131  fxEvent=event; // address of next event into event pointer
132  if(!fbBranchExists)
133  {
134  // first call of Store, create new branch
135  //std::cout << "**********************Creating new branch!"<< std::endl;
136  if(fxEvent)
137  {
138  TString topbranchname(fxEvent->GetName());
139  topbranchname+=".";
140  TBranch* go4branch= fxTree->GetBranch(topbranchname.Data());
141  if(go4branch)
142  {
143  // tree already had branch of our name, check it
144  TGo4Log::Debug(" BackStore: Found existing branch %s , continue filling ",topbranchname.Data() );
145  // here we might check the classname of the stored events inbranch
146  go4branch->SetAddress(&fxEvent);
147  fbBranchExists=kTRUE;
148 
149  }
150  else
151  {
152  // no such branch existing, create a new one
153  TBranch *topbranch =
154  fxTree->Branch(topbranchname.Data(), fxEvent->ClassName(), &fxEvent, fiBufsize, fiSplit);
155  TGo4Log::Debug(" BackStore: Created new branch %s ", topbranchname.Data());
156  fbBranchExists = kTRUE;
157  fxEvent->makeBranch(topbranch);
158  } // if(go4branch)
159  }
160  else
161  {
162  // this is an error....
163  return 1;
164  }
165  } // if(!fbEventBranchExists)
166  else
167  {
168  // need not to create a branch, use existing one
169  }
170  // check if autosave threshold is reached, reset tree before autosave is performed:
171  Double_t totbytes=fxTree->GetTotBytes();
172  if(totbytes>TGo4BackStore::fgiMAXAUTOBYTES)
173  {
174  fxTree->Reset();
175  TGo4Log::Debug(" BackStore: Tree %s was Reset after %f bytes ",
176  fxTree->GetName(), totbytes);
177  }
178  fxTree->Fill();
179  return 0;
180 }
181 
182 
183 
184 
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:309
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:270