EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RootOut.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RootOut.cxx
1 
2 //_____________________________________________________________________________
3 //
4 // helper class for ROOT TTree output
5 //_____________________________________________________________________________
6 
7 //local classes
8 #include "RootOut.h"
9 
10 //ROOT
11 #include "TFile.h"
12 #include "TTree.h"
13 #include "TClass.h"
14 #include "TROOT.h"
15 #include "TSystem.h"
16 
17 //C++
18 #include <iostream>
19 #include <string>
20 
21 
22 using namespace std;
23 
24 //_____________________________________________________________________________
25 RootOut::RootOut(): fOut(0), fDetTree(0) {
26 
27  //default name for output file
28  fOutputName = "lmon.root";
29 
30 
31 
32 }//RootOut
33 
34 //_____________________________________________________________________________
35 void RootOut::Open() {
36 
37  std::string nam(fOutputName.data());
38 
39  cout << "RootOut::Open, " << nam << endl;
40 
41  //create directory for the output
42  if( nam.find_last_of("/") != string::npos ) {
43  string dir = nam.substr(0, nam.find_last_of("/"));
44  if(!dir.empty()) gSystem->MakeDirectory(dir.c_str());
45  }
46 
47  //create the output file
48  fOut = new TFile(nam.c_str(), "recreate");
49 
50  //test if file exists
51  if(!fOut->IsOpen()) {
52  string description = "Can't open output: " + fOutputName;
53  exit(1);
54  }
55 
56  //output detector tree
57  fDetTree = new TTree("DetectorTree", "DetectorTree");
58 
59 }//Open
60 
61 //_____________________________________________________________________________
63 
64  fDetTree->Fill();
65 
66 }//FillTree
67 
68 //_____________________________________________________________________________
70  fOut->cd();
71  //write the tree
72  if(fDetTree) fDetTree->Write();
73 
74  //close the output file
75  if(fOut) fOut->Close();
76 
77 }//Close
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94