2#define MIN_FILE_SIZE_MB 1
3#define MAX_FILE_SIZE_GB 4
4#define MIN_EVENT_SIZE_KB 1
5#define MAX_EVENT_SIZE_KB 200
12 const char* root_tree_name,
14 TH1F* hist_event_size,
15 double& sum_file_size_mb,
16 double& sum_event_size_kb,
17 int& correct_file_count,
18 map<TString, double>& wrong_files,
19 map<TString, double>& wrong_events);
28 cout <<
"ERROR: Directory path was not specified" << endl;
31 gSystem->ExpandPathName(dir_path);
33 TH1F* hist_file_size =
36 xaxis1->
SetTitle(
"ROOT FIle Size, MB");
42 int correct_file_count = 0;
43 double sum_file_size_mb = 0, sum_event_size_kb = 0;
44 map<TString, double> wrong_files;
45 map<TString, double> wrong_events;
46 calculate_size(dir_path, root_tree_name, hist_file_size, hist_event_size, sum_file_size_mb, sum_event_size_kb,
47 correct_file_count, wrong_files, wrong_events);
49 if (correct_file_count > 0) {
50 double average_file_size = sum_file_size_mb / correct_file_count;
51 double average_event_size = sum_event_size_kb / correct_file_count;
53 cout <<
cyan <<
"-------------------------------------------------------" << endl;
54 cout << correct_file_count <<
" ROOT files have been successfully processed (dir: " << dir_path <<
")" << endl;
55 cout <<
"Average ROOT file size: " << average_file_size <<
" MB" << endl;
56 cout <<
"Average event size: " << average_event_size <<
" KB" << endl;
57 cout <<
"-------------------------------------------------------" << endl <<
reset;
59 TCanvas* canvas_size =
new TCanvas(
"canvas_size",
"canvas_size", 1200, 640);
62 hist_file_size->
Draw();
64 hist_event_size->
Draw();
67 if (wrong_files.size() > 0) {
70 for (
auto it = wrong_files.begin(); it != wrong_files.end(); ++it)
71 cout <<
"File '" << (*it).first <<
"': " << (*it).second <<
" MB" << endl;
73 cout <<
"Total wrong file size: " << wrong_files.size() << endl;
77 if (wrong_events.size() > 0) {
80 for (
auto it = wrong_events.begin(); it != wrong_events.end(); ++it)
81 cout <<
"File '" << (*it).first <<
": " << (*it).second <<
" KB" << endl;
83 cout <<
"Total wrong event size: " << wrong_events.size() << endl;
94 const char* root_tree_name,
96 TH1F* hist_event_size,
97 double& sum_file_size_mb,
98 double& sum_event_size_kb,
99 int& correct_file_count,
100 map<TString, double>& wrong_files,
101 map<TString, double>& wrong_events)
105 if (file_list ==
nullptr) {
106 cout <<
"WARNING: There are no files in the directory: " << dir_path << endl;
111 TIter iterFile(file_list);
114 if ((file_name ==
".") || (file_name ==
".."))
120 calculate_size(file_dir, root_tree_name, hist_file_size, hist_event_size, sum_file_size_mb,
121 sum_event_size_kb, correct_file_count, wrong_files, wrong_events);
123 TString file_path = file_dir +
"/" + file_name;
124 if (file_name.EndsWith(
".root")) {
126 Long_t id = 0, flags = 0, modtime = 0;
127 gSystem->GetPathInfo(file_path.
Data(), &
id, &file_size_bytes, &flags, &modtime);
129 TFile root_file(file_path);
131 if (root_tree ==
nullptr) {
132 cout <<
"ERROR: there are no tree '" << root_tree_name <<
"' in file: " << file_path << endl;
137 double file_size_mb = file_size_bytes / 1024.0 / 1024.0;
138 double file_size_gb = file_size_mb / 1024.0;
140 double event_size_kb = file_size_bytes / 1024.0 / event_count;
142 int is_file_wrong = 0;
145 wrong_files.insert(pair<TString, double>(file_path, file_size_mb));
150 wrong_files.insert(pair<TString, double>(file_path, file_size_mb));
156 wrong_events.insert(pair<TString, double>(file_path, event_size_kb));
158 sum_file_size_mb += file_size_mb;
159 sum_event_size_kb += event_size_kb;
160 correct_file_count++;
163 if (is_file_wrong == 1)
165 else if (is_file_wrong == 2)
167 cout << file_path <<
" size: " << file_size_mb <<
" MB (event size = " << event_size_kb <<
" KB)"
169 if (is_file_wrong > 0)
172 hist_file_size->
Fill(file_size_mb);
173 hist_event_size->
Fill(event_size_kb);
R__EXTERN TSystem * gSystem
TVirtualPad * cd(Int_t subpadnumber=0) override
T * Get(const char *namecycle)
void Close(Option_t *option="") override
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void SetTitle(const char *title="")
const char * GetName() const override
const char * GetTitle() const override
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
const char * Data() const
virtual TList * GetListOfFiles() const
virtual Bool_t IsDirectory(const char *dir=nullptr) const
virtual Long64_t GetEntries() const
#define MIN_EVENT_SIZE_KB
#define MAX_EVENT_SIZE_KB
int calculate_size(TString dir_path, const char *root_tree_name, TH1F *hist_file_size, TH1F *hist_event_size, double &sum_file_size_mb, double &sum_event_size_kb, int &correct_file_count, map< TString, double > &wrong_files, map< TString, double > &wrong_events)
const string reset("\033[0m")
int show_root_stats(TString dir_path, const char *root_tree_name="bmndata")
Function for creating histograms on sizes of ROOT (digit) files stored in a specified directory amd e...
const string cyan("\033[0;96m")
const string red("\033[0;91m")
const string orange("\033[0;33m")