#include #include #include #include #include #include #include "TreeClass2.h" void treesort2() { //example of script illustrating how to sort entries in a Tree in ONE file //the algorithm assumes that all buffers of one branch can fit in memory //This algorithm should be modified in case of one single top level branch //in case the buffers do not fit in memory. Instead one should loop //on its sub-branches. //This algorithm cannot be used to sort entries in a TChain. You should merge //your files in the TChain into one single big file first. TFile *fin = new TFile("small.root"); //the input file TTree *Tin = (TTree*)fin->Get("ntp1"); //get the input Tree TFile *fout = new TFile("small_sorted2.root","recreate"); TTree *Tout = Tin->CloneTree(0); Long64_t N = Tin->GetEntries(); TreeClass2 looper(Tin); Int_t *table = new Int_t[N]; Int_t *sorted = new Int_t[N]; Long64_t index; std::cout<<"Reading Run numbers"<GetListOfBranches()); TBranch *bin, *bout; while ((bin = (TBranch*)next())) { bout = Tout->GetBranch(bin->GetName()); printf("processing branch: %s\n",bin->GetName()); //load all baskets of this branch in memory (for performance) bin->LoadBaskets(); //loop on entries and fill output Tree for (index=0;indexGetEntry(sorted[index]); bout->Fill(); } bin->DropBaskets(); Tout->AutoSave(); } Tout->SetEntries(N); Tout->Print(); Tout->AutoSave(); fout->Close(); }