StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
getBranchSizes.C
1 //
2 // $Id: getBranchSizes.C,v 3.1 2003/02/05 23:06:19 magestro Exp $
3 // $Log: getBranchSizes.C,v $
4 // Revision 3.1 2003/02/05 23:06:19 magestro
5 // Calculate sizes of branches in a TTree
6 //
7 //
8 //======================================================================
9 //
10 // getBranchSizes(TTree*)
11 //
12 // This function takes a TTree as argument and returns a formatted list of
13 // data containers with the file size of each container. For a container
14 // to print, it must have a minimum size of 64 kB otherwise it doesn't get
15 // compressed and GetZipBytes() returns zero.
16 //
17 // - Dan Magestro, Feb. 5, 2003
18 
19 void getBranchSizes(TTree *tree) {
20 
21  printf("\n");
22  printf("File: %s \n",tree->GetCurrentFile()->GetName());
23  printf(" (%i entries) \n",(int) tree->GetEntries());
24  printf("\n");
25  printf(" Container File Size Size/evt\n");
26  printf(" --------------- ------------------ ------------\n");
27 
28  Int_t nBytes = 0, nBytesBranch2 = 0;
29  TObjArray *array2 = 0, *array3 = 0, *array4 = 0;
30  TBranch *branch1 = 0, *branch2 = 0, *branch3 = 0, *branch4 = 0;
31 
32  TObjArray *fBranches = tree->GetListOfBranches();
33 
34  for(Int_t i=0;i<fBranches->GetEntries();i++) {
35 
36  branch1 = (TBranch*) fBranches->At(i);
37  array2 = branch1->GetListOfBranches();
38 
39  nBytesBranch2 = 0;
40  for(Int_t j=0;j<array2->GetEntries();j++) {
41 
42  branch2 = (TBranch*) array2->At(j);
43  nBytesBranch2 += (int) branch2->GetZipBytes();
44  array3 = branch2->GetListOfBranches();
45  Int_t nBranch2 = array3->GetEntries();
46 
47  for(Int_t k=0;k<nBranch2;k++) {
48 
49  branch3 = (TBranch*) array3->At(k);
50  nBytesBranch2 += (int) branch3->GetZipBytes();
51  }
52  }
53 
54  if(nBytesBranch2) printf(" %20s %11i (%4.1f%%) %6.1f bytes\n",
55  branch1->GetName(),nBytesBranch2,
56  nBytesBranch2*100./tree->GetZipBytes(),
57  nBytesBranch2/branch1->GetEntries() );
58 
59  nBytes += nBytesBranch2;
60  }
61 
62  printf(" ------------------ ------------\n");
63  printf(" %11i (%4.1f%%) %6.3f kB/event\n",
64  nBytes,nBytes*100./tree->GetZipBytes(), nBytes/branch1->GetEntries()/1024. );
65  printf("\n");
66 
67 }