GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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"
24#include "TGo4EventElement.h"
25
26const char *TGo4BackStore::fgcTREESUF = "xTree";
27const char *TGo4BackStore::fgcEVBRANCHNAME = "Go4EventBranch.";
28
29const 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),
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),
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
90void 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
117Int_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}
#define GO4TRACE(X)
Definition TGo4Log.h:25
virtual ~TGo4BackStore()
Int_t Store(TGo4EventElement *event) override
Stores eventelement event into the storage implementation.
Int_t fiSplit
TBranch splitlevel.
static const char * fgcEVBRANCHNAME
Standard go4 name of the branch used in all treestore and treesource implementations.
Bool_t fbBranchExists
True if branch already exists.
static const char * fgcTREESUF
Standard go4 suffix for tree name.
TGo4EventElement * fxEvent
Points to event structure to be filled into branch.
Int_t fiBufsize
buffer size for tree branch.
Int_t fiFillCount
counter of filled events.
static const Int_t fgiMAXAUTOBYTES
Number of bytes for autosave attempt of tree.
void Reset(Bool_t onlyclearflag=kFALSE)
Dynamic list might reset backstore after processing.
Go4 condition class.
The abstract base class for the data elements of which the unpacked events (or detector structure dat...
Central class of Go4Fit package.
Definition TGo4Fitter.h:38
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
Definition TGo4Log.cxx:320
Base class for all parameter aggregations, e.g.
@ kGo4BackStoreReset
Definition TGo4Status.h:69