RootSizeOnDisk.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Root_RootSizeOnDisk_h
2 #define art_Framework_IO_Root_RootSizeOnDisk_h
3 //
4 // Collect information about the disk space used by the top tier and second
5 // tier objects inside an art format root event-data file.
6 //
7 // This is known to work for root 5.34.*
8 //
9 // The available information is:
10 //
11 // filename - The name of the root file
12 // size - The size on disk according to the file system; equivalent to
13 // ls -l sum - The sum of the sizes of all top tier TTree objects.
14 // Some day this may include the sizes of top tier objects that
15 // are not TTrees.
16 // fraction - The ratio of sum()/size()
17 // contents - Detailed information about each TTree, including the size of
18 // each branch.
19 //
20 
21 #include <ostream>
22 #include <string>
23 #include <vector>
24 
25 #include "TFile.h"
26 #include "TTree.h"
27 
28 namespace art {
29 
31  public:
32  RootSizeOnDisk(std::string const& aFileName, TFile* aFile);
33 
34  // Information about a top tier or second tier object in an art format root
35  // event-data file.
36  class Record {
37  public:
38  Record(std::string const& aname,
39  std::string const& aclassName,
40  Long64_t asize = 0,
41  double afraction = 0.);
42 
43  bool
44  operator<(Record const& rhs) const
45  {
46  return name() < rhs.name();
47  }
48  bool
49  isTree() const
50  {
51  return className_ == "TTree";
52  }
53  bool
54  isTKey() const
55  {
56  return className_ == "TKey";
57  }
58 
59  std::string const&
60  name() const
61  {
62  return name_;
63  }
64  std::string const&
65  className() const
66  {
67  return className_;
68  }
69  Long64_t
70  size() const
71  {
72  return size_;
73  }
74  double
75  fraction() const
76  {
77  return fraction_;
78  }
79  std::vector<Record> const&
80  contents() const
81  {
82  return contents_;
83  }
84 
85  // Modifiers
86  void
87  size(Long64_t const s)
88  {
89  size_ = s;
90  }
91  void
92  fraction(double const f)
93  {
94  fraction_ = f;
95  }
96  void
97  contents(std::vector<Record>& c)
98  {
99  contents_.swap(c);
100  }
101 
102  private:
105  Long64_t size_;
106  double fraction_;
107 
108  std::vector<Record> contents_;
109  }; // end RootSizeOnDisk::Record
110 
111  using Records_t = std::vector<Record>;
112 
113  std::string const&
114  filename() const
115  {
116  return fileName_;
117  }
118  Long64_t
119  size() const
120  {
121  return size_;
122  }
123  Long64_t
124  sum() const
125  {
126  return sum_;
127  }
128  double
129  fraction() const
130  {
131  return fraction_;
132  }
133  Records_t const&
134  contents() const
135  {
136  return contents_;
137  }
138 
139  void print(std::ostream& os, double minimumFraction) const;
140 
141  private:
143  Long64_t size_;
144  Long64_t sum_;
145  double fraction_;
147 
148  void fillLevel2(Record&, TTree*);
149  };
150 
151  // Compare two RootSizeOnDisk::Record objects to select the one with the
152  // larger size.
153  bool greaterBySize(RootSizeOnDisk::Record const& lhs,
154  RootSizeOnDisk::Record const& rhs);
155 
156 } // namespace art
157 
158 #endif /* art_Framework_IO_Root_RootSizeOnDisk_h */
159 
160 // Local Variables:
161 // mode: c++
162 // End:
void contents(std::vector< Record > &c)
void fillLevel2(Record &, TTree *)
std::vector< Record > const & contents() const
std::string string
Definition: nybbler.cc:12
Record(std::string const &aname, std::string const &aclassName, Long64_t asize=0, double afraction=0.)
double fraction() const
void print(std::ostream &os, double minimumFraction) const
std::string const & filename() const
Long64_t sum() const
Long64_t size() const
bool operator<(Record const &rhs) const
std::string const & className() const
std::vector< Record > contents_
std::vector< Record > Records_t
void size(Long64_t const s)
void fraction(double const f)
std::string const & name() const
bool greaterBySize(RootSizeOnDisk::Record const &lhs, RootSizeOnDisk::Record const &rhs)
RootSizeOnDisk(std::string const &aFileName, TFile *aFile)
static const double s
Definition: Units.h:99
Records_t const & contents() const