/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Mdc/DedxCalibAlg/DedxCalibAlg-00-01-15/share/shell/genRawScript/txt2root.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <iomanip>
00004 #include <cstring>
00005 #include <string>
00006 #include <vector>
00007 #include <TFile.h>
00008 #include <TTree.h>
00009 #include <TString.h>
00010 
00011 using namespace std;
00012 
00013 int main(int argc, char* argv[]){
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 }
00046 

Generated on Tue Nov 29 23:12:45 2016 for BOSS_7.0.2 by  doxygen 1.4.7