LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
rootFileSizeTools.cc
Go to the documentation of this file.
2 
3 #include "Riostream.h"
4 #include "TBranchRef.h"
5 #include "TKey.h"
6 #include "TMemFile.h"
7 
8 #include <ostream>
9 
10 Long64_t
11 art::detail::GetBasketSize(TObjArray* branches, bool ondisk, bool inclusive)
12 {
13  Long64_t result = 0;
14  size_t n = branches->GetEntries();
15  for (size_t i = 0; i < n; ++i) {
16  result +=
17  GetBasketSize(static_cast<TBranch*>(branches->At(i)), ondisk, inclusive);
18  }
19  return result;
20 }
21 
22 Long64_t
23 art::detail::GetBasketSize(TBranch* b, bool ondisk, bool inclusive)
24 {
25  Long64_t result = 0;
26  if (b) {
27  if (ondisk && b->GetZipBytes() > 0) {
28  result = b->GetZipBytes();
29  } else {
30  result = b->GetTotBytes();
31  }
32  if (inclusive) {
33  result += GetBasketSize(b->GetListOfBranches(), ondisk, true);
34  }
35  return result;
36  }
37  return result;
38 }
39 
40 Long64_t
41 art::detail::GetTotalSize(TBranch* br, bool ondisk, bool inclusive)
42 {
43  TMemFile f("buffer", "CREATE");
44  if (br->GetTree()->GetCurrentFile()) {
45  f.SetCompressionSettings(
46  br->GetTree()->GetCurrentFile()->GetCompressionSettings());
47  }
48  f.WriteObject(br, "thisbranch");
49  TKey* key = f.GetKey("thisbranch");
50  Long64_t size;
51  if (ondisk)
52  size = key->GetNbytes();
53  else
54  size = key->GetObjlen();
55  return GetBasketSize(br, ondisk, inclusive) + size;
56 }
57 
58 Long64_t
59 art::detail::GetTotalSize(TObjArray* branches, bool ondisk)
60 {
61  Long64_t result = 0;
62  size_t n = branches->GetEntries();
63  for (size_t i = 0; i < n; ++i) {
64  result +=
65  GetTotalSize(static_cast<TBranch*>(branches->At(i)), ondisk, true);
66  }
67  return result;
68 }
69 
70 Long64_t
71 art::detail::GetTotalSize(TTree* t, bool ondisk)
72 {
73  TKey* key = 0;
74  if (t->GetDirectory()) {
75  key = t->GetDirectory()->GetKey(t->GetName());
76  }
77  Long64_t ondiskSize = 0;
78  Long64_t totalSize = 0;
79  if (key) {
80  ondiskSize = key->GetNbytes();
81  totalSize = key->GetObjlen();
82  } else {
83  TMemFile f("buffer", "CREATE");
84  if (t->GetCurrentFile()) {
85  f.SetCompressionSettings(t->GetCurrentFile()->GetCompressionSettings());
86  }
87  f.WriteTObject(t);
88  key = f.GetKey(t->GetName());
89  ondiskSize = key->GetNbytes();
90  totalSize = key->GetObjlen();
91  }
92  if (t->GetBranchRef()) {
93  if (ondisk) {
94  ondiskSize += GetBasketSize(t->GetBranchRef(), true, true);
95  } else {
96  totalSize += GetBasketSize(t->GetBranchRef(), false, true);
97  }
98  }
99  if (ondisk) {
100  return ondiskSize + GetBasketSize(t->GetListOfBranches(),
101  /* ondisk */ true,
102  /* inclusive */ true);
103  } else {
104  return totalSize + GetBasketSize(t->GetListOfBranches(),
105  /* ondisk */ false,
106  /* inclusive */ true);
107  }
108 }
109 
110 Long64_t
112 {
113  // Return the size on disk on this TTree.
114 
115  return GetTotalSize(t, true);
116 }
117 
118 Long64_t
119 art::detail::sizeOnDisk(TBranch* branch, bool inclusive)
120 {
121  // Return the size on disk on this branch.
122  // If 'inclusive' is true, include also the size
123  // of all its sub-branches.
124 
125  return GetTotalSize(branch, true, inclusive);
126 }
127 
128 void
129 art::detail::printBranchSummary(std::ostream& os, TBranch* br)
130 {
131  os << "The branch \"" << br->GetName() << "\" takes " << sizeOnDisk(br, true)
132  << " bytes on disk\n";
133  size_t n = br->GetListOfBranches()->GetEntries();
134  for (size_t i = 0; i < n; ++i) {
135  TBranch* subbr = static_cast<TBranch*>(br->GetListOfBranches()->At(i));
136  os << " It's sub-branch \"" << subbr->GetName() << "\" takes "
137  << sizeOnDisk(subbr, true) << " bytes on disk\n";
138  }
139 }
140 
141 void
142 art::detail::printTreeSummary(std::ostream& os, TTree* t)
143 {
144  os << "The TTree \"" << t->GetName() << "\" takes " << sizeOnDisk(t)
145  << " bytes on disk\n";
146  size_t n = t->GetListOfBranches()->GetEntries();
147  for (size_t i = 0; i < n; ++i) {
148  TBranch* br = static_cast<TBranch*>(t->GetListOfBranches()->At(i));
149  os << " It's branch \"" << br->GetName() << "\" takes "
150  << sizeOnDisk(br, true) << " bytes on disk\n";
151  }
152 }
Long64_t GetTotalSize(TBranch *br, bool ondisk, bool inclusive)
void printBranchSummary(std::ostream &os, TBranch *br)
TFile f
Definition: plotHisto.C:6
Long64_t GetBasketSize(TObjArray *branches, bool ondisk, bool inclusive)
void printTreeSummary(std::ostream &os, TTree *t)
Long64_t sizeOnDisk(TTree *t)
Char_t n[5]