13 {
14 if(argc<3){
15 cout << "please append path name and root file name [and tree names] [and tag name]" << endl;
16 return 1;
17 }
18
19 TString str_root_file(argv[1]);
20 str_root_file.Append(argv[2]);
21 TFile f(str_root_file);
23 if(argc>3)
t = (TTree*)f.Get(argv[3]);
24 else{
25 TList *l = f.GetListOfKeys();
26 if(l->GetEntries()<1){
27 cout << "the root file " << argv[2] << " is empty, check it!" << endl;
28 return 1;
29 }
30 else t = (TTree*)f.Get(l->At(0)->GetName());
31 }
32 Long_t m_totnum =
t->GetEntries();
33
34 int m_run(0), m_event(0), m_cur_run(0);
35 char str_run_name[20];
36 TString str_run_name_II("");
37 t->SetBranchAddress(
"run", &m_run);
38 t->SetBranchAddress(
"event", &m_event);
40 cout << "total events: " << m_totnum << endl;
41 for(Long_t i=0; i<m_totnum; i++){
42
44 if(i%10000==0) cout << "i = " << i << " run: " << m_run << " event: " << m_event << endl;
45 if(m_run != m_cur_run && m_run>1){
46 if(f_out.is_open()) f_out.close();
47 int m_temp_run = (int)m_run;
48 if(argc<5){
49 sprintf(str_run_name, "%d.txt", m_temp_run);
50 str_run_name_II = argv[2];
51 str_run_name_II.ReplaceAll("_","");
52 str_run_name_II.ReplaceAll(".root","_runnumber");
53 str_run_name_II.ReplaceAll("runnumber", str_run_name);
54 cout << "run file: " << str_run_name_II << endl;
55 f_out.open(str_run_name_II, ios::app);
56 }
57 else{
58 sprintf(str_run_name, "%s_%d.txt", argv[4], m_temp_run);
59 cout << "run file: " << str_run_name << endl;
60 f_out.open(str_run_name, ios::app);
61 }
62 m_cur_run = m_run;
63 }
64 if(!f_out.is_open()){ cout << "cannot open file " << endl; return 1; }
65 f_out << (long)m_run << " " << (long)m_event << endl;
66
67 }
68 f_out.close();
69
70 return 0;
71}