#include #include #include #include #include #include "TFile.h" #include "TTree.h" using namespace std; Int_t MakeStableNucleiRootFile() { ifstream ifs("./StableNuclei.txt"); string line; stringstream ss; char c; struct DataOfNuclei_t { Int_t A, Z, N; DataOfNuclei_t (): A(), Z(), N(){} }; DataOfNuclei_t nucdata; TFile *f = new TFile("StableNuclei.root","RECREATE"); TTree *tree = new TTree("StableNuclei","Stable Nuclei data from ascii file"); // create one branch with all information from the stucture tree->Branch("StableNuclei",&nucdata.A,"A/I:Z:N"); while( !ifs.eof() ){ c = ifs.peek(); getline(ifs, line); if ( (c < '0') || (c > '9') ) { continue; } ss.str(""); /* ss.clear(stringstream::goodbit); too slow to run by CINT!! */ ss << line.substr(0,3) << " " << line.substr(12,3) << " " << line.substr(16,3) << " " ; /* To privent to set "badbit" for ss */ ss >> nucdata.A >> nucdata.Z >> nucdata.N; // cout << nucdata.Z << " " << nucdata.N <Fill(); } tree->Print(); f->Write(); delete tree; delete f; return 0; }