susy_cfa  b611ccad937ea179f86a1f5663960264616c0a20
disk_usage.cxx
Go to the documentation of this file.
1 #include <locale>
2 #include <iostream>
3 #include <iomanip>
4 #include <string>
5 #include <set>
6 
7 #include "TChain.h"
8 #include "TBranch.h"
9 #include "TLeaf.h"
10 
11 using namespace std;
12 
13 struct Variable{
14  string name;
15  long zip_size, tot_size;
16 
17  bool operator<(const Variable &var) const{
18  return (zip_size<var.zip_size)
19  || (zip_size==var.zip_size && tot_size<var.tot_size)
20  || (zip_size==var.zip_size && tot_size==var.tot_size && name<var.name);
21  }
22 };
23 
24 class comma_numpunct : public numpunct<char>{
25 protected:
26  virtual char do_thousands_sep() const{
27  return ',';
28  }
29 
30  virtual string do_grouping() const{
31  return "\03";
32  }
33 };
34 
35 int main(int argc, char *argv[]){
36  cout.imbue(locale(locale(), new comma_numpunct));
37  for(int arg = 1; arg < argc; ++arg){
38  TChain chain;
39  if(!chain.Add(argv[arg])) continue;
40 
41  long zip_sum(0), tot_sum(0);
42  size_t max_length(0);
43 
44  set<Variable> vars;
45 
46  if(!chain.GetListOfLeaves()) continue;
47  for(int i = 0; i < chain.GetListOfLeaves()->GetSize(); ++i){
48  TBranch *b = static_cast<TLeaf*>(chain.GetListOfLeaves()->At(i))->GetBranch();
49  if(!b) continue;
50  Variable v;
51  v.name = b->GetName();
52  v.zip_size = b->GetZipBytes();
53  v.tot_size = b->GetTotBytes();
54  vars.insert(v);
55  zip_sum += v.zip_size;
56  tot_sum += v.tot_size;
57  if(v.name.size() > max_length) max_length = v.name.size();
58  }
59  cout << argv[arg] << endl;
60  cout << setw(max_length) << "Name" << ' '
61  << setw(16) << "Bytes" << ' '
62  << setw(16) << "Fraction (%)" << ' '
63  << setw(16) << "Cumulative" << endl;
64  cout << setw(max_length) << "Total" << ' '
65  << setw(16) << zip_sum << ' '
66  << setw(16) << "100.0" << ' '
67  << setw(16) << "-" << endl;
68  long running_total(0);
69  for(set<Variable>::const_reverse_iterator var = vars.rbegin(); var != vars.rend(); ++var){
70  running_total += var->zip_size;
71  double this_frac = (100.0*var->zip_size)/zip_sum;
72  double tot_frac = (100.0*running_total)/zip_sum;
73  cout << setw(max_length) << var->name << " "
74  << setw(16) << var->zip_size << " "
75  << setw(16) << this_frac << " "
76  << setw(16) << tot_frac << endl;
77  }
78  }
79 }
long zip_size
Definition: disk_usage.cxx:15
STL namespace.
virtual string do_grouping() const
Definition: disk_usage.cxx:30
virtual char do_thousands_sep() const
Definition: disk_usage.cxx:26
bool operator<(const Variable &var) const
Definition: disk_usage.cxx:17
long tot_size
Definition: disk_usage.cxx:15
int main(int argc, char *argv[])
Definition: disk_usage.cxx:35
string name
Definition: disk_usage.cxx:14