//.x C:/Code/MultiTreeDemo/ForumEntryTestFullWriteHasFriends.cpp { string base_data_dir = "C:/Code/MultiTreeDemo/"; string file_name = base_data_dir + "FriendForestTest_main.root"; string friend_file_name = base_data_dir + "FriendForestTest_friend.root"; bool verbose_output = true; TFile * file = 0; TFile * friend_file = 0; int n_branches = 53; int n_fr_branches = 3; int n_total_branches = n_branches + n_fr_branches; /////Start of File Write Block //In this block we create the base file and the friend file int n_trees = 10708;//Total number of trees. int n_entries_per_tree = 155;//number of branches per tree. Minimum is 1 file= new TFile(file_name.c_str(),"RECREATE"); friend_file= new TFile(friend_file_name.c_str(),"RECREATE"); TRandom r; vector data, fr_data;//create data buffers data.resize(n_branches); fr_data.resize(n_fr_branches); double * data_root = &(data[0]); double * fr_data_root = &(fr_data[0]); int j = 0, k =0; int write_frequency = 1000; try { for(k=1;k<=n_trees;k++) { stringstream tree_name_builder; tree_name_builder<<"Tree_"<cd();//CD to the main file TTree * tree = new TTree(tree_name.c_str(), "Main tree");//create main tree for(int l=0;lBranch(branch_name_builder.str().c_str(), l + data_root , "DataValue/D"); } TTree * friend_tree = NULL; //create friend tree friend_file->cd(); friend_tree = new TTree(tree_name.c_str(),"Computed friend file");//create friend tree friend_tree->Branch("GeomMean", 0 + fr_data_root , "DataValue/D");//add friend tree branches friend_tree->Branch("LocMin", 1 + fr_data_root , "DataValue/D"); friend_tree->Branch("LocMax", 2 + fr_data_root , "DataValue/D"); TFriendElement * elm = tree->AddFriend(friend_tree ,"Computed tree"); //Make friends j =0; for(j=1;j<=n_entries_per_tree;j++) { r.RndmArray(data.size(),data_root );//fill vector with random data fr_data[0] = TMath::GeomMean(data.size(),data_root );//calculate some values and store them fr_data[1] = TMath::LocMin(data.size(),data_root ); fr_data[2] = TMath::LocMax(data.size(),data_root ); tree->Fill(); friend_tree->Fill(); } if(k%write_frequency ==0)//write every 1000 entries { int nbytes = file->Write(); cout <<"File Write out ["<Flush(); file->Close(); delete file; file= new TFile(file_name.c_str(),"UPDATE"); friend_file->Flush(); friend_file->Close(); delete friend_file; friend_file= new TFile(friend_file_name.c_str(),"UPDATE"); } } } catch() { cout <<"Exception["<