GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TXXXStore.cxx
Go to the documentation of this file.
1 // $Id: TXXXStore.cxx 3010 2021-02-18 10:53:20Z 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 "TXXXStore.h"
15 
16 #include "TFile.h"
17 #include "TTree.h"
18 #include "TROOT.h"
19 #include "TBranch.h"
20 
21 #include "TGo4Log.h"
22 #include "TGo4Status.h"
23 #include "TGo4UserStoreParameter.h"
24 #include "TGo4EventElement.h"
25 #include "TXXXEvent.h"
26 
27 
29  TGo4EventStore("User custom store"),
30  fxFile(0),
31  fxTree(0),
32  fxEvent(0),
33  fbBranchExists(kFALSE)
34 {
35  GO4TRACE((15,"TXXXStore::TXXXStore()", __LINE__, __FILE__));
36  // public default ctor for streamer
37 }
38 
40  TGo4EventStore("User custom store"),
41  fxFile(0),
42  fxTree(0),
43  fxEvent(0),
44  fbBranchExists(kFALSE)
45 {
46  GO4TRACE((15,"TXXXStore::TXXXStore(TGo4UserStoreParameter* par)", __LINE__, __FILE__));
47 
48  if (!par) {
49  TGo4Log::Error("TGo4UserStoreParameter is not specified in TXXXStore constructor");
50  return;
51  }
52 
53  SetName(par->GetName());
54 
55  TString fname = par->GetName();
56  if (!fname.Contains(".root")) fname.Append(".root");
57 
58  fxFile = TFile::Open(fname.Data(), "RECREATE");
59  TGo4Log::Info("TXXXStore: Open file %s RECREATE", fname.Data());
60 
61  fxTree = new TTree("Custom", "Custom go4 store");
62  fxTree->Write();
63 }
64 
66 {
67  if (fxFile && fxTree) {
68  fxFile = fxTree->GetCurrentFile(); // for file split after 1.8 Gb!
69  fxFile->cd();
70  fxTree->Write(0, TObject::kOverwrite);
71  delete fxFile; // closes File, fxTree is removed from memory then
72  fxFile = 0;
73  fxTree = 0;
74  }
75 }
76 
78 {
79  GO4TRACE((12,"TXXXStore::Store(TGo4EventElement*)", __LINE__, __FILE__));
80 
81  TXXXEvent *custom = dynamic_cast<TXXXEvent *>(event); // address of next event into event pointer
82  if (!custom) return 1; // error
83 
84  if(!fbBranchExists) {
85  fxEvent = custom;
86  fxTree->Branch("Crate1", fxEvent->fCrate1, "Create1[8]/F");
87  fxTree->Branch("Crate2", fxEvent->fCrate2, "Create2[8]/F");
88  fbBranchExists = kTRUE;
89  } else if (fxEvent != custom) {
90  TGo4Log::Info("TXXXStore: Event pointer changed");
91  return 1; // error, should never happen
92  }
93 
94  fxTree->Fill();
95  return 0;
96 }
TFile * fxFile
Definition: TXXXStore.h:52
Bool_t fbBranchExists
current event
Definition: TXXXStore.h:56
virtual Int_t Store(TGo4EventElement *event)
Definition: TXXXStore.cxx:77
TTree * fxTree
file
Definition: TXXXStore.h:53
Float_t fCrate1[8]
Definition: TXXXEvent.h:28
TXXXEvent * fxEvent
tree
Definition: TXXXStore.h:55
#define GO4TRACE(X)
Definition: TGo4Log.h:26
Float_t fCrate2[8]
Definition: TXXXEvent.h:29
static void Error(const char *text,...)
Definition: TGo4Log.cxx:323
static void Info(const char *text,...)
Definition: TGo4Log.cxx:297
virtual ~TXXXStore()
Definition: TXXXStore.cxx:65