star-travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StiTreeMaker.cxx
Go to the documentation of this file.
2 
3 #include "TBranch.h"
4 #include "TSystem.h"
5 
6 #include "StBFChain/StBFChain.h"
7 #include "StEvent/StEnumerations.h"
8 #include "StEvent/StEnumerations.h"
9 
11 
12 
13 StiTreeMaker::StiTreeMaker(const std::string &name, const std::string &suffix) : StMaker(name.c_str()),
14  fFile(nullptr),
15  fSuffix(suffix),
16  fTree(new TTree("t", "TTree with HFT hits and tracks")),
17  fEvent(nullptr)
18 {
19 }
20 
21 
23 {
24  if (fFile) fFile->Close();
25 
26  delete fFile; fFile = nullptr;
27  delete fTree; fTree = nullptr;
28  delete fEvent; fEvent = nullptr;
29 }
30 
31 
39 {
40  StBFChain *bfChain = (StBFChain *) StMaker::GetChain();
41 
42  if (!bfChain) return kStFatal;
43 
44  // Authorize Trees up to 2 Terabytes (if the system can do it)
45  TTree::SetMaxTreeSize(1000 * Long64_t(2000000000));
46 
47  TString fileName( gSystem->BaseName(bfChain->GetFileOut().Data()) );
48 
49  // Form a new name for the output file
50  fileName += "." + fSuffix + ".root";
51 
52  fFile = new TFile(fileName, "RECREATE", "TTree with HFT hits and tracks");
53  fFile->SetCompressionLevel(1); // Set file compression level
54 
55  SetEventTree();
56 
57  fTree->SetDirectory(fFile);
58 
59  return kStOK;
60 }
61 
62 
64 {
65  fFile = fTree->GetCurrentFile(); //just in case we switched to a new file
66  fFile->Write();
67 
68  if (GetDebug() >= 1)
69  fTree->Print();
70 
71  return kStOK;
72 }
73 
74 
76 void StiTreeMaker::Clear(Option_t *opt)
77 {
78  fEvent->Clear();
79 }
TFile * fFile
Definition: StiTreeMaker.h:28
virtual void Clear(Option_t *opt="")
Definition: TStiEvent.cxx:95
virtual ~StiTreeMaker()
virtual void SetEventTree()=0
TTree * fTree
Definition: StiTreeMaker.h:30
virtual void Clear(Option_t *opt="")
Clear the container for the next event.
virtual Int_t Init()
Creates an output ROOT file and a ROOT tree with a user defined structure.
virtual Int_t Finish()
TStiEvent * fEvent
Definition: StiTreeMaker.h:31
ClassImp(StiTreeMaker) StiTreeMaker
std::string fSuffix
A string to append to the output file name.
Definition: StiTreeMaker.h:29