#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <TFile.h>
#include <TTree.h>
#include <TString.h>
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 13 of file txt2root.cxx.
00013 { 00014 if(argc<2){ 00015 cout << "please append txt file name" << endl; 00016 return 1; 00017 } 00018 00019 TString str_txt_file(argv[1]); 00020 TString str_root_file(str_txt_file); 00021 str_root_file.ReplaceAll(".txt", ".root"); 00022 TFile f(str_root_file, "recreate"); 00023 TTree *tree = new TTree("track", "track"); 00024 int run(0), event(0); 00025 tree->Branch("run", &run, "run/I"); 00026 tree->Branch("event", &event, "event/I"); 00027 // read in txt file and assign the numbers to run and event 00028 ifstream in(str_txt_file); 00029 if(!in){ 00030 cout << "cannot open " << str_txt_file << endl; 00031 return 0; 00032 } 00033 char str[255]; 00034 while(in){ 00035 in.getline(str, 255); 00036 sscanf(str ,"%d %d", &run, &event); 00037 if(!run) continue; // protect of read at the end 00038 tree->Fill(); 00039 } 00040 00041 tree->Write(); 00042 f.Close(); 00043 00044 return 0; 00045 }