13 #include "boost/filesystem.hpp" 14 #include "boost/format.hpp" 21 #include "TObjArray.h" 31 MyObjects(set<art::RootSizeOnDisk::Record>& akeys) :
keys(akeys) {}
34 operator()(TObject* aObj)
36 TKey*
key = (TKey*)aObj;
42 set<art::RootSizeOnDisk::Record>&
keys;
50 double const afraction)
51 : name_(aname), className_(aclassName), size_(asize), fraction_(afraction)
65 os <<
"\nSize on disk for the file: " <<
filename() <<
"\n" 66 <<
"Total size on disk: " <<
size() <<
"\n" 68 os << setw(18) <<
"Size in bytes" << setw(10) <<
" Fraction" 69 <<
" TTree/TKey Name" << endl;
71 if (key.isTree() || key.isTKey()) {
72 os << setw(18) << key.size() <<
" " 73 <<
boost::format(
"%10.3f") % key.fraction() <<
" " << key.name()
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;
82 os <<
"------------------------------\n" 87 os <<
"Details for each TTree that occupies more than the fraction " 88 << minimumFraction <<
" of the size on disk.\n" 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;
98 for (
auto const& branch : key.contents()) {
100 os << setw(18) << branch.size() <<
" " 102 << branch.name() << endl;
104 double ratio = double(sum) / double(key.size());
105 os <<
"------------------------------\n" 106 << setw(18) << sum <<
" " <<
boost::format(
"%10.3f") % ratio <<
" " 123 set<RootSizeOnDisk::Record> topKeys;
124 TList*
keys = file->GetListOfKeys();
126 for_each(iter.Begin(),
TIter::End(), MyObjects(topKeys));
129 contents_.assign(topKeys.begin(), topKeys.end());
135 file->GetObject(key.name().c_str(),
tree);
138 double const f = double(size) / double(
size_);
142 }
else if (key.isTKey()) {
143 TKey* tkey = file->FindKey(key.name().c_str());
144 Long64_t
const size = tkey->GetNbytes();
146 double const f = double(size) / double(
size_);
162 TObjArray* branches = tree->GetListOfBranches();
163 size_t n = branches->GetEntries();
167 for (
size_t i = 0;
i <
n; ++
i) {
168 auto subbr =
static_cast<TBranch*
>(branches->At(
i));
170 double const f = double(size) / double(key.
size());
171 branchInfo.emplace_back(subbr->GetName(),
"TBranch",
size,
f);
void fillLevel2(Record &, TTree *)
std::vector< Record > const & contents() const
Record(std::string const &aname, std::string const &aclassName, Long64_t asize=0, double afraction=0.)
void print(std::ostream &os, double minimumFraction) const
std::string const & filename() const
void sort_all(RandCont &)
std::vector< Record > Records_t
Long64_t sizeOnDisk(TTree *t)
bool greaterBySize(RootSizeOnDisk::Record const &lhs, RootSizeOnDisk::Record const &rhs)
static std::string format(PyObject *obj, unsigned int pos, unsigned int indent, unsigned int maxlen)
RootSizeOnDisk(std::string const &aFileName, TFile *aFile)