Functions
paulbunyan.cxx File Reference
#include <TFile.h>
#include <TTree.h>
#include <iostream>
#include <string>
#include "garana/Processors/MillGenTree.h"
#include "garana/Processors/MillHeaderTree.h"

Go to the source code of this file.

Functions

std::string GetOutfileName (const char *inName)
 
int main (int argc, char *argv[])
 

Function Documentation

std::string GetOutfileName ( const char *  inName)

Definition at line 130 of file paulbunyan.cxx.

130  {
131 
132  string path(inName);
133  std::cout << "parsing file '" << path << "'" << std::endl;
134  string base = path;
135  while(base.find("/")!=string::npos){
136  base = base.substr(base.find("/")+1,base.size());
137  }
138 
139  base = base.substr(0,base.find("."));
140  path = path.substr(0,path.find(base));
141  string outstr = path+base+"_chopped.root";
142  std::cout << "generated output file path '" << outstr << "'" << std::endl;
143 
144  return outstr;
145 }//GetOutfileName
QTextStream & endl(QTextStream &s)
int main ( int  argc,
char *  argv[] 
)

Definition at line 28 of file paulbunyan.cxx.

28  {
29 
30  //// check we got what we need from the command line ////
31  if(argc==1) {
32  cerr << "ERROR(paulbunyan): you must specify a root file to analyze ->" << '\n'
33  << " usage: paulbunyan <my_structured_tree.root>" << endl;
34  return 1;
35  }
36 
37  if(argc>2) {
38  cerr << "ERROR(paulbunyan): too many arguments! using file name, "
39  << argv[1] << endl;
40  }
41 
42  // setup files
43  TFile* inFile = new TFile(argv[1],"READ"); //input file
44  try{
45  if(!inFile || !inFile->IsOpen())
46  throw(inFile);
47  }
48  catch(TFile* inFile){
49  cerr << "ERROR(paulbunyan): could not open file , '" << string(argv[1]) << "'" << endl;
50  return 2;
51  }
52 
53  // get trees produced by garsoft/Ana/StructuredTree_module.cc and flatten them
54  // headerTree
55  TTree* header = (TTree*)inFile->Get("structuredtree/headerTree"); //required;
56  try{
57  if(!header)
58  throw header;
59  std::cout << "INFO(paulbunyan): found (required) input headerTree" << std::endl;
60  }
61  catch(TTree* ptr){
62  cerr << "ERROR(paulbunyan): paulbunyan is not happy with your file. he does not want to chop your trees!" << '\n'
63  << " required 'headerTree' not found. fix your file and try again." << endl;
64  return 1;
65  }
66 
67  // following input (structured) trees may or may not be present
68  TTree* gen = (TTree*)inFile->Get("structuredtree/genTree");
69  TTree* g4 = (TTree*)inFile->Get("structuredtree/g4Tree");
70  TTree* det = (TTree*)inFile->Get("structuredtree/detTree");
71  TTree* reco = (TTree*)inFile->Get("structuredtree/recoTree");
72  TTree* display = (TTree*)inFile->Get("structuredtree/displayTree");
73 
74  //now write our flat trees to the output file
76  TFile* outFile = new TFile(outname.c_str(),"RECREATE"); //output file with chopped trees
77 
78  TTree* header_out = new TTree("headerTree", "sample provenance information");
79  outFile->cd();
80  header_out->SetDirectory(outFile);
81 
82  MillHeaderTree hmill(header,header_out);
83 
84  //// done with prerequisites. on to the optional trees.
85  // output (flat) trees
86  TTree* gen_out = new TTree("genTree", "generator level info"); //does this overwrite gen above?
87  //TTree* g4_out = nullptr;
88  //TTree* det_out = nullptr;
89  //TTree* reco_out = nullptr;
90  //TTree* display_out = nullptr;
91 
92  //chop genTree
93  if(gen){
94  std::cout << "INFO(paulbunyan): found input genTree" << std::endl;
95 
96  //gen_out = new TTree("genTree", "generator level info"); //does this overwrite gen above?
97  outFile->cd();
98  gen_out->SetDirectory(outFile);
99 
100  MillGenTree mill(gen,gen_out);
101  }//gen*/
102 
103  if(g4){
104  std::cout << "INFO(paulbunyan): found input g4Tree" << std::endl;
105  }
106  if(det){
107  std::cout << "INFO(paulbunyan): found input detTree" << std::endl;
108  }
109  if(reco){
110  std::cout << "INFO(paulbunyan): found input recoTree" << std::endl;
111  }
112 
113  if(display) {
114  std::cout << "INFO(paulbunyan): found input displayTree" << std::endl;
115  }
116 
117  //close input/output files and free memory from TTrees
118  inFile->Close();
119  outFile->Close();
120 
121  //free memory from TFiles
122  delete inFile;
123  delete outFile;
124 
125  return 0;
126 
127 }//main()
std::string string
Definition: nybbler.cc:12
TFile * outFile
Definition: makeDST.cxx:36
gen
Definition: demo.py:24
std::string GetOutfileName(const char *inName)
Definition: paulbunyan.cxx:130
TFile * inFile
Definition: makeDST.cxx:36
QTextStream & endl(QTextStream &s)
g4
Definition: tracks.py:87