int main(int,char**) { ////////////////////////////////////////////////////////// /// create a .csv file : ///////////////////////////////// ////////////////////////////////////////////////////////// std::ofstream writer("out_bkg.csv"); if(writer.fail()) { std::cout << "can't open out_bkg.csv." << std::endl; return EXIT_FAILURE; } unsigned int entries = 1000; tools::random::gauss rg(1,2); tools::randf::bw rbw(0,1); ////////////////////////////////////////////////////////// /// create a ntuple_booking object : ///////////////////// ////////////////////////////////////////////////////////// tools::ntuple_booking nbk; nbk.add_column<unsigned int>("index"); nbk.add_column<double>("rgauss"); nbk.add_column<float>("rbw"); //nbk.add_column<bool>("not_handled"); ////////////////////////////////////////////////////////// /// create and write a ntuple : ////////////////////////// ////////////////////////////////////////////////////////// tools::wcsv::ntuple ntu(writer,std::cout,nbk); //default sep is ',' if(ntu.columns().size()) { tools::wcsv::ntuple::column<unsigned int>* col_index = ntu.find_column<unsigned int>("index"); tools::wcsv::ntuple::column<double>* col_rgauss = ntu.find_column<double>("rgauss"); tools::wcsv::ntuple::column<float>* col_rbw = ntu.find_column<float>("rbw"); // fill : for(unsigned int count=0;count<entries;count++) { col_index->fill(count); col_rgauss->fill(rg.shoot()); col_rbw->fill(rbw.shoot()); ntu.add_row(); // it will write columns data as a row in the file. } } ////////////////////////////////////////////////////////// /// close file : ///////////////////////////////////////// ////////////////////////////////////////////////////////// writer.close(); return EXIT_SUCCESS; }
int main(int,char**) { ////////////////////////////////////////////////////////// /// create a .csv file : ///////////////////////////////// ////////////////////////////////////////////////////////// std::ofstream writer("out.csv"); if(writer.fail()) { std::cout << "can't open out.csv." << std::endl; return EXIT_FAILURE; } unsigned int entries = 1000; tools::random::gauss rg(1,2); tools::randf::bw rbw(0,1); ////////////////////////////////////////////////////////// /// create and write a ntuple : ////////////////////////// ////////////////////////////////////////////////////////// //tools::wcsv::ntuple ntu(writer,'\t'); tools::wcsv::ntuple ntu(writer); //default sep is ',' // create some columns with basic types : tools::wcsv::ntuple::column<unsigned int>* col_index = ntu.create_column<unsigned int>("index"); tools::wcsv::ntuple::column<double>* col_rgauss = ntu.create_column<double>("rgauss"); tools::wcsv::ntuple::column<float>* col_rbw = ntu.create_column<float>("rbw"); // fill : for(unsigned int count=0;count<entries;count++) { col_index->fill(count); col_rgauss->fill(rg.shoot()); col_rbw->fill(rbw.shoot()); ntu.add_row(); // it will write columns data as a row in the file. } ////////////////////////////////////////////////////////// /// close file : ///////////////////////////////////////// ////////////////////////////////////////////////////////// writer.close(); return EXIT_SUCCESS; }
int main(int,char**) { #ifdef INLIB_MEM inlib::mem::set_check_by_class(true);{ #endif //INLIB_MEM ////////////////////////////////////////////////////////// /// create a .root file : //////////////////////////////// ////////////////////////////////////////////////////////// std::string file = "wroot_tree.root"; inlib::wroot::file rfile(std::cout,file); rfile.add_ziper('Z',exlib::compress_buffer); rfile.set_compression(9); ////////////////////////////////////////////////////////// /// create and fill a tree : ///////////////////////////// ////////////////////////////////////////////////////////// {//WARNING : the tree can't be on the stack. It is owned // by the directory. inlib::wroot::tree* tr = new inlib::wroot::tree(rfile.dir(),"tree","first tree"); inlib::wroot::branch* br = tr->create_branch("branch"); inlib::wroot::leaf<int>* leaf_index = br->create_leaf<int>("index","index"); inlib::wroot::leaf<double>* leaf_rgauss = br->create_leaf<double>("rgauss","Random gaussian"); inlib::wroot::leaf<float>* leaf_rbw = br->create_leaf<float>("rbw","Random BW"); inlib::rgaussd rg(1,2); inlib::rbwf rbw(0,1); // fill : unsigned int entries = 1000000; //unsigned int entries = 400000000; //to test >2Gbytes file. //br->set_basket_size(1000000); for(unsigned int count=0;count<entries;count++) { //inlib::count_out<unsigned int>(std::cout,count,1000000); leaf_index->fill(count); leaf_rgauss->fill(rg.shoot()); leaf_rbw->fill(rbw.shoot()); inlib::uint32 n; if(!tr->fill(n)) { std::cout << "tree fill failed." << std::endl; break; } }} ////////////////////////////////////////////////////////// /// write and close file : /////////////////////////////// ////////////////////////////////////////////////////////// {unsigned int n; if(!rfile.write(n)) { std::cout << "file write failed." << std::endl; }} rfile.close(); ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// #ifdef INLIB_MEM }inlib::mem::balance(std::cout); #endif //INLIB_MEM return EXIT_SUCCESS; }