CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
txt2root.cxx File Reference
#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[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 13 of file txt2root.cxx.

13 {
14 if(argc<2){
15 cout << "please append txt file name" << endl;
16 return 1;
17 }
18
19 TString str_txt_file(argv[1]);
20 TString str_root_file(str_txt_file);
21 str_root_file.ReplaceAll(".txt", ".root");
22 TFile f(str_root_file, "recreate");
23 TTree *tree = new TTree("track", "track");
24 int run(0), event(0);
25 tree->Branch("run", &run, "run/I");
26 tree->Branch("event", &event, "event/I");
27 // read in txt file and assign the numbers to run and event
28 ifstream in(str_txt_file);
29 if(!in){
30 cout << "cannot open " << str_txt_file << endl;
31 return 0;
32 }
33 char str[255];
34 while(in){
35 in.getline(str, 255);
36 sscanf(str ,"%d %d", &run, &event);
37 if(!run) continue; // protect of read at the end
38 tree->Fill();
39 }
40
41 tree->Write();
42 f.Close();
43
44 return 0;
45}