FairRoot/PandaRoot
sizetree.C
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TTree.h"
3 #include "TBranch.h"
4 #include "TString.h"
5 #include "TKey.h"
6 
7 #include <iostream>
8 
9 int sizetree(TString fname)
10 {
11  int totsize = 0;
12  TString name[1000];
13  int size[1000];
14  int n[1000];
15  int br[1000];
16  int cnt=0;
17 
18  TFile *f=new TFile(fname,"READ");
19  if (!f->IsZombie())
20  {
21  TKey *key;
22  TIter next(f->GetListOfKeys());
23  while ( (key = (TKey*)next()) )
24  {
25  TObject *obj = key->ReadObj();
26 
27  if (!obj->InheritsFrom("TTree")) continue;
28 
29  name[cnt] = obj->GetName();
30  TTree* t = (TTree*) obj;
31 
32  n[cnt] = t->GetEntries();
33  br[cnt] = t->GetNbranches();
34  int s = 0;
35 
36  TObjArray* branches = t->GetListOfBranches();
37  for(int i=0; i<=branches->GetLast(); ++i)
38  {
39  TBranch* branch = (TBranch*)branches->UncheckedAt(i);
40  s += branch->GetZipBytes();
41  }
42  size[cnt++]=s;
43 
44  totsize += s;
45  }
46  }
47  f->Close();
48 
49  cout <<cnt<<endl;
50 
51  int ar[1000];
52  for (int i=0;i<cnt;++i) ar[i]=i;
53 
54  for (int i=cnt;i>1;--i)
55  {
56  for (int j=0;j<i-1;++j)
57  {
58  if (size[ar[j]]<size[ar[j+1]])
59  {
60  int tmp=ar[j];ar[j]=ar[j+1];ar[j+1]=tmp;
61  }
62  }
63  }
64 
65  for (int i=0;i<cnt;++i)
66  printf("%2d. %10s : N = %8d, BR = %5d, N*BR = %7dk, Size = %7dk\n",
67  ar[i],name[ar[i]].Data(), n[ar[i]], br[ar[i]], (n[ar[i]]*br[ar[i]])/1000, size[ar[i]]/1000);
68 
69  cout <<"total size: "<<totsize/1000<<"k"<<endl;
70  return 0;
71 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Int_t i
Definition: run_full.C:25
TLorentzVector s
Definition: Pnd2DStar.C:50
int n
int sizetree(TString fname)
Definition: sizetree.C:9
TFile * f
Definition: bump_analys.C:12
TString name
Int_t cnt
Definition: hist-t7.C:106
TTree * t
Definition: bump_analys.C:13
static int next[96]
Definition: ranlxd.cxx:374
PndAnaPidSelector *& obj