7 #include "TDirectory.h" 12 int main(
int argc,
char *argv[]){
14 cerr <<
"Error: 2 arguments required." << endl;
15 cerr <<
"Usage: example_converter.exe input_file_name output_file_name" << endl;
19 if(
string(argv[1]) ==
string(argv[2])){
20 cerr <<
"Input and output file are the same: " << argv[1] <<
'.' << endl;
24 TFile in_file(argv[1],
"read");
25 if(in_file.IsZombie() || !in_file.IsOpen()){
26 cerr <<
"Could not open input file " << argv[1] <<
'.' << endl;
30 string cfa =
"configurableAnalysis";
31 TDirectory *dir =
static_cast<TDirectory*
>(in_file.Get(cfa.c_str()));
34 dir =
static_cast<TDirectory*
>(in_file.Get(cfa.c_str()));
36 cerr <<
"File " << argv[1] <<
" has nither a cfA nor a configurableAnalysis TDirectory." << endl;
41 TTree *event_a =
static_cast<TTree*
>(dir->Get(
"eventA"));
43 cerr <<
"Could not find eventA in subdirectory " << cfa <<
" in file " << argv[1] <<
'.' << endl;
47 TTree *event_b =
static_cast<TTree*
>(dir->Get(
"eventB"));
49 cerr <<
"Could not find eventB in subdirectory " << cfa <<
" in file " << argv[1] <<
'.' << endl;
53 TTree *event_a_out = event_a->CloneTree(0);
55 cerr <<
"Could not clone eventA." << endl;
59 TTree *event_b_out = event_b->CloneTree(0);
61 cerr <<
"Could not clone eventB." << endl;
65 TFile out_file(argv[2],
"recreate");
66 if(out_file.IsZombie() || !out_file.IsOpen()){
67 cerr <<
"Could not open output file " << argv[2] <<
'.' << endl;
71 cerr <<
"Could not cd into " << argv[2] <<
'.' << endl;
75 TDirectory *out_dir = out_file.mkdir(cfa.c_str());
77 cerr <<
"Could not create TDirectory " << cfa <<
'.' << endl;
82 cerr <<
"Could not cd into " << cfa <<
'.' << endl;
86 if(!event_a_out->Write()){
87 cerr <<
"Could not write eventA." << endl;
91 if(!event_b_out->Write()){
92 cerr <<
"Could not write eventB." << endl;
int main(int argc, char *argv[])