BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
txt2root.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <iomanip>
4#include <cstring>
5#include <string>
6#include <vector>
7#include <TFile.h>
8#include <TTree.h>
9#include <TString.h>
10
11using namespace std;
12
13int main(int argc, char* argv[]){
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}
46
int main()
Definition: test_IFile.cxx:11