Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
printSizes.C File Reference

Detailed Description

View in nbviewer Open in SWAN
This macro can be used to get aggregate information on the size take on disk or in memory by the various branches in a TTree.

For example:

root [] printTreeSummary(tree);
The TTree "T" takes 3764343 bytes on disk
Its branch "event" takes 3760313 bytes on disk
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t bytes
A TTree represents a columnar dataset.
Definition TTree.h:79
root [] printBranchSummary(tree->GetBranch("event"));
The branch "event" takes 3760313 bytes on disk
Its sub-branch "TObject" takes 581 bytes on disk
Its sub-branch "fType[20]" takes 640 bytes on disk
Its sub-branch "fEventName" takes 855 bytes on disk
Its sub-branch "fNtrack" takes 506 bytes on disk
Its sub-branch "fNseg" takes 554 bytes on disk
Its sub-branch "fNvertex" takes 507 bytes on disk
Its sub-branch "fFlag" takes 420 bytes on disk
Its sub-branch "fTemperature" takes 738 bytes on disk
Its sub-branch "fMeasures[10]" takes 1856 bytes on disk
Its sub-branch "fMatrix[4][4]" takes 4563 bytes on disk
Its sub-branch "fClosestDistance" takes 2881 bytes on disk
Its sub-branch "fEvtHdr" takes 847 bytes on disk
Its sub-branch "fTracks" takes 3673982 bytes on disk
Its sub-branch "fHighPt" takes 59640 bytes on disk
Its sub-branch "fMuons" takes 1656 bytes on disk
Its sub-branch "fLastTrack" takes 785 bytes on disk
Its sub-branch "fWebHistogram" takes 596 bytes on disk
Its sub-branch "fH" takes 10076 bytes on disk
Its sub-branch "fTriggerBits" takes 1699 bytes on disk
Its sub-branch "fIsValid" takes 366 bytes on disk
#include "TTree.h"
#include "TBranch.h"
#include "Riostream.h"
#include "TMemFile.h"
#include "TKey.h"
#include "TBranchRef.h"
Long64_t GetTotalSize(TBranch * b, bool ondisk, bool inclusive);
Long64_t GetBasketSize(TBranch * b, bool ondisk, bool inclusive);
void printSizes() {
}
Long64_t GetBasketSize(TObjArray * branches, bool ondisk, bool inclusive) {
size_t n = branches->GetEntries();
for( size_t i = 0; i < n; ++ i ) {
result += GetBasketSize( dynamic_cast<TBranch*>( branches->At( i ) ), ondisk, inclusive );
}
return result;
}
Long64_t GetBasketSize(TBranch * b, bool ondisk, bool inclusive) {
if (b) {
if (ondisk && b->GetZipBytes() > 0) {
result = b->GetZipBytes();
} else {
result = b->GetTotBytes();
}
if (inclusive) {
result += GetBasketSize(b->GetListOfBranches(), ondisk, true);
}
return result;
}
return result;
}
Long64_t GetTotalSize( TBranch * br, bool ondisk, bool inclusive ) {
TMemFile f("buffer","CREATE");
if (br->GetTree()->GetCurrentFile()) {
f.SetCompressionSettings(br->GetTree()->GetCurrentFile()->GetCompressionSettings());
}
f.WriteObject(br,"thisbranch");
TKey* key = f.GetKey("thisbranch");
if (ondisk)
size = key->GetNbytes();
else
size = key->GetObjlen();
return GetBasketSize(br, ondisk, inclusive) + size;
}
Long64_t GetTotalSize( TObjArray * branches, bool ondisk ) {
size_t n = branches->GetEntries();
for( size_t i = 0; i < n; ++ i ) {
result += GetTotalSize( dynamic_cast<TBranch*>( branches->At( i ) ), ondisk, true );
cerr << "After " << branches->At( i )->GetName() << " " << result << endl;
}
return result;
}
Long64_t GetTotalSize(TTree *t, bool ondisk) {
TKey *key = 0;
if (t->GetDirectory()) {
key = t->GetDirectory()->GetKey(t->GetName());
}
Long64_t ondiskSize = 0;
Long64_t totalSize = 0;
if (key) {
ondiskSize = key->GetNbytes();
totalSize = key->GetObjlen();
} else {
TMemFile f("buffer","CREATE");
if (t->GetCurrentFile()) {
f.SetCompressionSettings(t->GetCurrentFile()->GetCompressionSettings());
}
f.WriteTObject(t);
key = f.GetKey(t->GetName());
ondiskSize = key->GetNbytes();
totalSize = key->GetObjlen();
}
if (t->GetBranchRef() ) {
if (ondisk) {
ondiskSize += GetBasketSize(t->GetBranchRef(), true, true);
} else {
totalSize += GetBasketSize(t->GetBranchRef(), false, true);
}
}
if (ondisk) {
return ondiskSize + GetBasketSize(t->GetListOfBranches(), /* ondisk */ true, /* inclusive */ true);
} else {
return totalSize + GetBasketSize(t->GetListOfBranches(), /* ondisk */ false, /* inclusive */ true);
}
}
Long64_t sizeOnDisk(TTree *t) {
// Return the size on disk on this TTree.
return GetTotalSize(t, true);
}
Long64_t sizeOnDisk(TBranch *branch, bool inclusive)
{
// Return the size on disk on this branch.
// If 'inclusive' is true, include also the size
// of all its sub-branches.
return GetTotalSize(branch, true, inclusive);
}
void printBranchSummary(TBranch *br)
{
cout << "The branch \"" << br->GetName() << "\" takes " << sizeOnDisk(br,true) << " bytes on disk\n";
size_t n = br->GetListOfBranches()->GetEntries();
for( size_t i = 0; i < n; ++ i ) {
TBranch *subbr = dynamic_cast<TBranch*>(br->GetListOfBranches()->At(i));
cout << " Its sub-branch \"" << subbr->GetName() << "\" takes " << sizeOnDisk(subbr,true) << " bytes on disk\n";
}
}
void printTreeSummary(TTree *t)
{
cout << "The TTree \"" << t->GetName() << "\" takes " << sizeOnDisk(t) << " bytes on disk\n";
size_t n = t->GetListOfBranches()->GetEntries();
for( size_t i = 0; i < n; ++ i ) {
TBranch *br =dynamic_cast<TBranch*>(t->GetListOfBranches()->At(i));
cout << " Its branch \"" << br->GetName() << "\" takes " << sizeOnDisk(br,true) << " bytes on disk\n";
}
}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
long long Long64_t
Definition RtypesCore.h:69
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
A TTree is a list of TBranches.
Definition TBranch.h:93
TTree * GetTree() const
Definition TBranch.h:252
TObjArray * GetListOfBranches()
Definition TBranch.h:246
virtual TKey * GetKey(const char *, Short_t=9999) const
Definition TDirectory.h:221
Int_t GetCompressionSettings() const
Definition TFile.h:397
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
Int_t GetObjlen() const
Definition TKey.h:87
Int_t GetNbytes() const
Definition TKey.h:86
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition TMemFile.h:19
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:456
TFile * GetCurrentFile() const
Return pointer to the current file.
Definition TTree.cxx:5469
TDirectory * GetDirectory() const
Definition TTree.h:462
virtual TBranchRef * GetBranchRef() const
Definition TTree.h:450
virtual TObjArray * GetListOfBranches()
Definition TTree.h:528
const Int_t n
Definition legend1.C:16
Author

Definition in file printSizes.C.