21 std::string filename =
"tuple_thread_" + std::to_string(thread_id) +
".root";
23 TFile file(filename.c_str(),
"RECREATE");
24 if (file.IsZombie()) {
26 std::cerr <<
"Error opening file: " << filename << std::endl;
30 TTree tree(
"mytree",
"Thread-safe example TTree");
33 std::vector<float> values;
35 tree.Branch(
"ids", &ids);
36 tree.Branch(
"values", &values);
39 tree.SetAutoFlush(10 * 1024 * 1024);
40 tree.SetAutoSave(30 * 1024 * 1024);
42 const int total_events = 10000000;
43 for (
int entry = 0; entry < total_events; ++entry) {
48 for (
int i = 0; i < num_items; ++i) {
49 ids.push_back(entry * num_items + i);
50 values.push_back(1.23f * i + thread_id);
60 std::cout <<
"Thread " << thread_id <<
" wrote file: " << filename << std::endl;