LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
art::RootSizeOnDisk Class Reference

#include "RootSizeOnDisk.h"

Classes

class  Record
 

Public Types

using Records_t = std::vector< Record >
 

Public Member Functions

 RootSizeOnDisk (std::string const &aFileName, TFile *aFile)
 
std::string const & filename () const
 
Long64_t size () const
 
Long64_t sum () const
 
double fraction () const
 
Records_t const & contents () const
 
void print (std::ostream &os, double minimumFraction) const
 

Private Member Functions

void fillLevel2 (Record &, TTree *)
 

Private Attributes

std::string fileName_
 
Long64_t size_
 
Long64_t sum_
 
double fraction_
 
Records_t contents_
 

Detailed Description

Definition at line 30 of file RootSizeOnDisk.h.

Member Typedef Documentation

using art::RootSizeOnDisk::Records_t = std::vector<Record>

Definition at line 111 of file RootSizeOnDisk.h.

Constructor & Destructor Documentation

art::RootSizeOnDisk::RootSizeOnDisk ( std::string const &  aFileName,
TFile *  aFile 
)

Definition at line 113 of file RootSizeOnDisk.cc.

References contents_, f, fileName_, fillLevel2(), fraction_, art::greaterBySize(), size(), size_, art::detail::sizeOnDisk(), and sum_.

114  : fileName_(aFileName), size_(0), sum_(0), fraction_(0)
115 {
116 
117  // File size on disk, in bytes.
118  size_ = boost::filesystem::file_size(fileName_.c_str());
119 
120  // Extract info about top level objects.
121  // There are usually Multiple cycles of these objects; we only want each name
122  // once.
123  set<RootSizeOnDisk::Record> topKeys;
124  TList* keys = file->GetListOfKeys();
125  TIter iter(keys);
126  for_each(iter.Begin(), TIter::End(), MyObjects(topKeys));
127 
128  // Copy to a vector since we will want to sort them by size.
129  contents_.assign(topKeys.begin(), topKeys.end());
130 
131  // Compute sizes of each top level TTree and TKey.
132  for (auto& key : contents_) {
133  if (key.isTree()) {
134  TTree* tree;
135  file->GetObject(key.name().c_str(), tree);
136  Long64_t const size = detail::sizeOnDisk(tree);
137  sum_ += size;
138  double const f = double(size) / double(size_);
139  key.size(size);
140  key.fraction(f);
141  fillLevel2(key, tree);
142  } else if (key.isTKey()) {
143  TKey* tkey = file->FindKey(key.name().c_str());
144  Long64_t const size = tkey->GetNbytes();
145  sum_ += size;
146  double const f = double(size) / double(size_);
147  key.size(size);
148  key.fraction(f);
149  }
150  }
151 
152  // Sort by decreasing size.
153  cet::sort_all(contents_, greaterBySize);
154 
155  fraction_ = double(sum_) / double(size_);
156 }
void fillLevel2(Record &, TTree *)
typename BeginEndPackage< L >::End End
TFile f
Definition: plotHisto.C:6
Long64_t size() const
Long64_t sizeOnDisk(TTree *t)
TFile * file
bool greaterBySize(RootSizeOnDisk::Record const &lhs, RootSizeOnDisk::Record const &rhs)

Member Function Documentation

Records_t const& art::RootSizeOnDisk::contents ( ) const
inline

Definition at line 134 of file RootSizeOnDisk.h.

References art::RootSizeOnDisk::Record::contents_, and print().

135  {
136  return contents_;
137  }
std::string const& art::RootSizeOnDisk::filename ( ) const
inline

Definition at line 114 of file RootSizeOnDisk.h.

References fileName_.

Referenced by print().

115  {
116  return fileName_;
117  }
void art::RootSizeOnDisk::fillLevel2 ( Record key,
TTree *  tree 
)
private

Definition at line 160 of file RootSizeOnDisk.cc.

References art::RootSizeOnDisk::Record::contents(), f, art::greaterBySize(), n, art::RootSizeOnDisk::Record::size(), size(), and art::detail::sizeOnDisk().

Referenced by RootSizeOnDisk().

161 {
162  TObjArray* branches = tree->GetListOfBranches();
163  size_t n = branches->GetEntries();
164 
165  Records_t branchInfo;
166 
167  for (size_t i = 0; i < n; ++i) {
168  auto subbr = static_cast<TBranch*>(branches->At(i));
169  Long64_t const size = detail::sizeOnDisk(subbr, true);
170  double const f = double(size) / double(key.size());
171  branchInfo.emplace_back(subbr->GetName(), "TBranch", size, f);
172  }
173 
174  cet::sort_all(branchInfo, greaterBySize);
175  key.contents(branchInfo);
176 }
TFile f
Definition: plotHisto.C:6
Long64_t size() const
std::vector< Record > Records_t
Long64_t sizeOnDisk(TTree *t)
bool greaterBySize(RootSizeOnDisk::Record const &lhs, RootSizeOnDisk::Record const &rhs)
Char_t n[5]
double art::RootSizeOnDisk::fraction ( ) const
inline

Definition at line 129 of file RootSizeOnDisk.h.

References art::RootSizeOnDisk::Record::fraction_.

130  {
131  return fraction_;
132  }
void art::RootSizeOnDisk::print ( std::ostream &  os,
double  minimumFraction 
) const

Definition at line 62 of file RootSizeOnDisk.cc.

References art::RootSizeOnDisk::Record::contents(), filename(), art::RootSizeOnDisk::Record::fraction(), art::RootSizeOnDisk::Record::size(), and sum().

Referenced by contents().

63 {
64 
65  os << "\nSize on disk for the file: " << filename() << "\n"
66  << "Total size on disk: " << size() << "\n"
67  << endl;
68  os << setw(18) << "Size in bytes" << setw(10) << " Fraction"
69  << " TTree/TKey Name" << endl;
70  for (RootSizeOnDisk::Record const& key : contents()) {
71  if (key.isTree() || key.isTKey()) {
72  os << setw(18) << key.size() << " "
73  << boost::format("%10.3f") % key.fraction() << " " << key.name()
74  << endl;
75  } else {
76  os << setw(18) << key.size() << " "
77  << boost::format("%10.3f") % key.fraction() << " " << key.name()
78  << " (skipped because not a TTree or a TKey; it is a"
79  << key.className() << ")" << endl;
80  }
81  }
82  os << "------------------------------\n"
83  << setw(18) << sum() << " " << boost::format("%10.3f") % fraction() << " "
84  << "Total\n"
85  << endl;
86 
87  os << "Details for each TTree that occupies more than the fraction "
88  << minimumFraction << " of the size on disk.\n"
89  << endl;
90 
91  for (RootSizeOnDisk::Record const& key : contents()) {
92  if (key.isTree() && (key.fraction() > minimumFraction)) {
93  os << "\nDetails for branch: " << key.name() << "\n" << endl;
94  os << setw(18) << "Size in bytes" << setw(10) << " Fraction"
95  << " Data Product Name" << endl;
96 
97  Long64_t sum(0);
98  for (auto const& branch : key.contents()) {
99  sum += branch.size();
100  os << setw(18) << branch.size() << " "
101  << boost::format("%10.3f") % branch.fraction() << " "
102  << branch.name() << endl;
103  }
104  double ratio = double(sum) / double(key.size());
105  os << "------------------------------\n"
106  << setw(18) << sum << " " << boost::format("%10.3f") % ratio << " "
107  << "Total\n"
108  << endl;
109  }
110  }
111 }
double fraction() const
std::string const & filename() const
Long64_t sum() const
Long64_t size() const
Records_t const & contents() const
Long64_t art::RootSizeOnDisk::size ( void  ) const
inline

Definition at line 119 of file RootSizeOnDisk.h.

References art::RootSizeOnDisk::Record::size_.

Referenced by fillLevel2(), and RootSizeOnDisk().

120  {
121  return size_;
122  }
Long64_t art::RootSizeOnDisk::sum ( ) const
inline

Definition at line 124 of file RootSizeOnDisk.h.

References sum_.

Referenced by print().

125  {
126  return sum_;
127  }

Member Data Documentation

Records_t art::RootSizeOnDisk::contents_
private

Definition at line 146 of file RootSizeOnDisk.h.

Referenced by RootSizeOnDisk().

std::string art::RootSizeOnDisk::fileName_
private

Definition at line 142 of file RootSizeOnDisk.h.

Referenced by filename(), and RootSizeOnDisk().

double art::RootSizeOnDisk::fraction_
private

Definition at line 145 of file RootSizeOnDisk.h.

Referenced by RootSizeOnDisk().

Long64_t art::RootSizeOnDisk::size_
private

Definition at line 143 of file RootSizeOnDisk.h.

Referenced by RootSizeOnDisk().

Long64_t art::RootSizeOnDisk::sum_
private

Definition at line 144 of file RootSizeOnDisk.h.

Referenced by RootSizeOnDisk(), and sum().


The documentation for this class was generated from the following files: