#include #include #include #include #include #include "TFile.h" #include "TTree.h" int mass_mas12_to_str(std::vector< std::vector >& ele_str_org) { std::ifstream ifs("./mass.mas12"); // format : a1,i3,i5,i5,i5,1x,a3,a4,1x,f13.5,f11.5,f11.3,f9.3,1x,a2,f11.3,f9.3,1x,i3,1x,f12.5,f11.5 // cc NZ N Z A el o mass unc binding unc B beta unc atomic_mass unc const unsigned int number_of_columns = 17; unsigned int column_end_points[number_of_columns] = {0,3,8,13,18,22,26,40,51,62,71,74,85,94,98,111,122}; // 0 origin if (ifs.fail()) { std::cerr << "Fail to read the file" << std::endl; return -1; } std::string buf; for (unsigned int i=1; i <=39; i++) { getline(ifs, buf); std::cout << "Skipped: " << buf << std::endl; } while (getline(ifs, buf)) { std::vector str_tmp; unsigned int column_start_point = 0; //std::cout << "buf.length()" << buf.length() < >& ele_str_org, std::vector< std::vector >& ele_str, std::vector< std::vector >& ele_int, std::vector< std::vector >& ele_double, std::vector< std::vector >& ele_flag) { ele_str = ele_str_org; // resize of 2-dimensional vector ele_int.resize(ele_str_org.size(), std::vector(ele_str_org.front().size(), 0)); ele_double.resize(ele_str_org.size(), std::vector(ele_str_org.front().size(), 0.0)); ele_flag.resize(ele_str_org.size(), std::vector(ele_str_org.front().size(), 0)); for (unsigned int i=0; i> ele_int[i][j]; // convert string to double stringstream ss2; ss2 << ele_str[i][j]; ss2 >> ele_double[i][j]; // if there is a value, ele_flag = 1 if (ele_flag[i][j] == 0) { ele_flag[i][j] = 1; } } } } //for (unsigned int i=0; i > ele_str_org; std::vector< std::vector > ele_str; std::vector< std::vector > ele_int; std::vector< std::vector > ele_double; std::vector< std::vector > ele_flag; mass_mas12_to_str(ele_str_org); str_to_val(ele_str_org, ele_str, ele_int, ele_double, ele_flag); TFile *f = new TFile("tree_mass_mas12.root","recreate"); TTree *t = new TTree("mass_mas12","mass.mas12 tree"); Int_t NZ; Int_t N; Int_t Z; Int_t A; std::string EL; std::string O; Double_t ME, BE, DE, AM; Double_t ME_err, BE_err, DE_err, AM_err; Int_t ME_flag, BE_flag, DE_flag, AM_flag; t->Branch("NZ", &NZ, "NZ/I"); t->Branch("N", &N, "N/I"); t->Branch("Z", &Z, "Z/I"); t->Branch("A", &A, "A/I"); t->Branch("EL", &EL); t->Branch("O", &O); t->Branch("ME", &ME, "ME/D"); t->Branch("ME_err", &ME_err, "ME_err/D"); t->Branch("ME_flag", &ME_flag, "ME_flag/I"); t->Branch("BE", &BE, "BE/D"); t->Branch("BE_err", &BE_err, "BE_err/D"); t->Branch("BE_flag", &BE_flag, "BE_flag/I"); t->Branch("DE", &DE, "DE/D"); t->Branch("DE_err", &DE_err, "DE_err/D"); t->Branch("DE_flag", &DE_flag, "DE_flag/I"); t->Branch("AM", &AM, "AM/D"); t->Branch("AM_err", &AM_err, "AM_err/D"); t->Branch("AM_flag", &AM_flag, "AM_flag/I"); for (unsigned int i=0; iFill(); } f->Write(); f->Close(); return 0; }