Difference between revisions of "ReadingAODBranches ExampleCode"
From GridPP Wiki
Wahid bhimji (Talk | contribs) |
(No difference)
|
Latest revision as of 16:04, 18 February 2010
To read all the branches of an ATLAS AOD File
#include <TROOT.h> #include <TRFIOFile.h> #include <TFile.h> #include <TString.h> #include <TTreePerfStats.h> #include <TTree.h> TROOT canIUseSomeRootCommands("name","title"); int main(int argc, char *argv[]) { //RFIO example TFile *_file0 = TFile::Open("rfio://pool2.glite.ecdf.ed.ac.uk//gridstorage008/atlas/2009-11-14/AOD.065320._00159.pool.root.3.4504984.0", "READ"); //Local (or mounted) file: //TFile *_file0 = new TFile("/exports/work/physics_ifp_gridpp_pool/Test/AODClone.root.5371914.0", "READ"); TTree* T= (TTree*)_file0->Get("CollectionTree"); Long64_t nentries = T->GetEntries(); // Int_t cachesize=100000000; // T->SetCacheSize(cachesize); // if (cachesize > 0) { // T->SetCacheEntryRange(0,nentries); // T->AddBranchToCache("*",kTRUE); // } TTreePerfStats ps("ioperf",T); cout << "Total Entries: " << nentries << endl; for (Long64_t i=0; i<nentries ; i++){ if (i%100 == 0 ){ cout << "processed" << i << " entries" << endl; } T->GetEntry(i); } ps.SaveAs("aodperStraightRFIO.root"); ps.Print(); }
Compile using the Makefile like that below.
ROOTCFLAGS = $(shell root-config --cflags) ROOTGLIBS = $(shell root-config --glibs) CXX = g++ CXXFLAGS = -g -Wall -fPIC LD = g++ LDFLAGS = -g LDFLAGS += -m32 CXXFLAGS += $(ROOTCFLAGS) NGLIBS = $(ROOTGLIBS) NGLIBS += -lTreePlayer NGLIBS += -lEG NGLIBS += -lRFIO GLIBS = $(filter-out -lNew, $(NGLIBS)) .SUFFIXES: .cc,.C # ================================================ IOPerformer: IOPerformer.o # ------------------------- $(LD) $(LDFLAGS) -o IOPerformer IOPerformer.o aod/aod.so $(GLIBS) .cc.o: $(CXX) $(CXXFLAGS) -c $<
gmake ./IOPerfomer
Then you can view this file within Root and plot the access pattern
root aodperStraightRFIO.root root [0] ioperf.Draw()
Making the aod shared library to link above (within root)
TFile *f = TFile::Open("YourAODFile.root") f->MakeProject("aod","*","new++");
Reordering a file (within Root)
gSystem->Load("IOPerformer/aod/aod.so"); TFile *_file0 = new TFile("/scratch/wbhimji//AOD.065320._00159.pool.root.3.4504984.0", "READ"); TTree* T= (TTree*)_file0->Get("CollectionTree"); TFile *newfile = new TFile("AODClone.root","recreate"); TTree *newtree = T->CloneTree(-1,"SortBasketsByEntry"); newtree->Print(); newfile->Write();