//.x C:/Code/MultiTreeDemo/ForumEntryTestRead.cpp { //Create a list of files to read string base_data_dir = "C:/Code/MultiTreeDemo/"; vector files; files.push_back(base_data_dir + "ForestTest.root"); files.push_back(base_data_dir + "FriendForestTest_main.root"); bool delete_ptr_after_use = false;//Set this to true to delete the tree and friend tree pointers after use bool verbose_output = true;//Set this to true to get more output int report_frequency = 1000;//Reduces the amount of output by doiong a full report for the last Tree in a group of 1000 cout<<"Number of file to read : "<GetListOfKeys()); // key iterator vector rd_data; //This vector will be used to retrieve the data double * rd_data_root;//This will be used to read the data //file.Dump(); int k =0; while ((pKey = static_cast(NextKey()))) // loop over the object keys in the file { if (!strcmp("TTree", pKey->GetClassName())) // an object of type TTree is found { k++; bool reporting_period_reached = (k%report_frequency == 0); if(reporting_period_reached) cout<<"Name:"<< pKey->GetName()<<",Title: "<GetTitle()<<",NBytes : "<< pKey->GetNbytes()<<",ObjLen:"<GetObjlen()<(pKey->ReadObj()); // return the address of that tree TTree * friend_tree = static_cast(t->GetFriend(t->GetName())); int n_total_branches = t->GetListOfBranches()->GetEntries();//Calculate total number of branches if(friend_tree) n_total_branches += friend_tree->GetListOfBranches()->GetEntries(); if(rd_data.size() != n_total_branches)//resize read buffer if required { rd_data.resize(n_total_branches); rd_data_root = &(rd_data[0]); } TIter NextBranchKey(t->GetListOfBranches());// branch iterator int branch_idx=0; vector branch_names; while ((b = static_cast(NextBranchKey())))// loop over every branch and 1. retrieve its name 2. set the buffer address to which data will be read { b->SetAddress(branch_idx + rd_data_root); branch_names.push_back(b->GetName()); branch_idx++; } if(friend_tree)// do the same loop as above but for friend branches { TIter NextFriendBranchKey(friend_tree->GetListOfBranches()); while ((f_b = static_cast(NextFriendBranchKey()))) { f_b->SetAddress(branch_idx + rd_data_root); branch_names.push_back(f_b->GetName()); branch_idx++; } } int bytes = t->GetEntry(0);//read the data if(reporting_period_reached) cout<<" name:"<GetName()<<", bytes:"<GetEntry(0);//read friend data if(reporting_period_reached)cout<<", f_bytes:"<DropBranchFromCache("*",true);//drop all reset buffers and backets friend_tree->DropBuffers(bytes); friend_tree->DropBaskets(); friend_tree->Reset(); } t->DropBranchFromCache("*",true);//drop all reset buffers and backets t->DropBuffers(bytes); t->DropBaskets(); t->Reset(); if(reporting_period_reached) { if(verbose_output)//print the data values out { cout<<", data :"<GetCurrentFile(); delete friend_file->Remove(friend_tree); } if(t) { if(reporting_period_reached && verbose_output)cout<<"Delete t ptr"<Remove(t); } } } } if(file)//delete file ptr since it is not used anymore { if(verbose_output)cout<<"Delete file ptr"<GetName()<