BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
show_raw_stats.C
Go to the documentation of this file.
1// limits to define out-of-range values and to exclude them while calculating the averages
2#define MIN_EVENT_SIZE_KB 30
3#define MAX_EVENT_SIZE_KB 1100
4#define MIN_FILE_SIZE_MB 1
5#define MAX_FILE_SIZE_GB 60
6#define MIN_FILE_DUR_SEC 6
7#define MAX_FILE_DUR_MIN 8
8#define MIN_EVENT_RATE 100
9#define MAX_EVENT_RATE 3600
10
11class UniqueRunNumber;
12/**
13 * Function for creating statistics histograms on raw file sizes, event sizes, raw file durations
14 * for runs stored in the UniConDa Database for a specified Run/Period (or run interval)
15 * 'instead_show_stream' flag switches to showing average stream (event/sec) for raw files
16 */
17void show_raw_stats(int period = 8, int start_run = 6587, int end_run = -1, bool show_only_wrong = false)
18{
19 UniqueRunNumber* run_numbers;
20 int run_count = UniRun::GetRunNumbers(run_numbers, period, start_run, period, end_run);
21 if (run_count <= 0)
22 return;
23
24 // bool isTerminal = isatty(fileno(stdout));
25 const string red("\033[0;91m"), orange("\033[0;33m"), cyan("\033[0;96m"), reset("\033[0m");
26
27 TH1D* hist_file_size = new TH1D("hist_file_size", TString::Format("Raw file sizes for Period %d", period),
29 TAxis* xaxis_file_size = hist_file_size->GetXaxis();
30 xaxis_file_size->SetTitle("Raw File Size, GB");
31
32 TH1D* hist_file_duration =
33 new TH1D("hist_file_duration", TString::Format("Raw file duration for Period %d", period),
34 2 * MAX_FILE_DUR_MIN * 60, 0, MAX_FILE_DUR_MIN * 60);
35 TAxis* xaxis_file_duration = hist_file_duration->GetXaxis();
36 xaxis_file_duration->SetTitle("Raw File Duration, sec");
37
38 TH1D* hist_event_size = new TH1D("hist_event_size", TString::Format("Event sizes for Period %d", period),
40 TAxis* xaxis_event_size = hist_event_size->GetXaxis();
41 xaxis_event_size->SetTitle("Event Sizes, KB");
42
43 TH1D* hist_stream_ev =
44 new TH1D("hist_avg_stream_ev", TString::Format("Event count per second for Period %d", period), 500,
46 TAxis* xaxis_stream_ev = hist_stream_ev->GetXaxis();
47 xaxis_stream_ev->SetTitle("Event stream, event/sec");
48
49 TH1D* hist_stream_mb = new TH1D("hist_avg_stream_mb", TString::Format("Megabytes per second for Period %d", period),
51 TAxis* xaxis_stream_mb = hist_stream_mb->GetXaxis();
52 xaxis_stream_mb->SetTitle("Binary stream, MB/sec");
53
54 int correct_file_count = 0;
55 int64_t sum_file_sec = 0, sum_event_count = 0;
56 double sum_file_size_mb = 0, sum_event_size_kb = 0;
57 map<TString, double> wrong_files;
58 map<TString, double> wrong_events;
59 map<TString, int> wrong_time;
60 // cycle by all runs for the given period
61 for (int i = 0; i < run_count; i++) {
62 // get the current run
63 UniRun* pRun = UniRun::GetRun(run_numbers[i].period_number, run_numbers[i].run_number);
64 if (pRun == nullptr) {
65 cout << "The function encountered with errors: no experimental run was found ("
66 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
67 << endl;
68 continue;
69 }
70
71 // get all raw files for the current run
72 TObjArray* raw_files = pRun->GetRawFiles();
73 delete pRun;
74 if (raw_files == nullptr)
75 continue;
76
77 // cycle by all raw files for the current run
78 bool is_run_wrong = false;
79 double sum_run_size_mb = 0;
80 for (const auto& j : *raw_files) {
81 int is_file_wrong = 0;
82 UniRawFile* pRawFile = (UniRawFile*)j;
83
84 // get file size, file duration in seconds and event count
85 TDatime file_start_time = pRawFile->GetStartDatetime();
86 TDatime file_end_time = pRawFile->GetEndDatetime();
87 UInt_t file_duration_sec = 0, end_seconds = file_end_time.Convert(),
88 start_seconds = file_start_time.Convert();
89 if (end_seconds < start_seconds) {
90 is_file_wrong = 1, is_run_wrong = true;
91 file_duration_sec = start_seconds - end_seconds;
92 wrong_time.insert(pair<TString, int>(pRawFile->GetFilePath(), -1 * file_duration_sec));
93 } else
94 file_duration_sec = end_seconds - start_seconds;
95
96 int64_t file_size_byte = pRawFile->GetFileSize();
97 double file_size_mb = file_size_byte / 1024.0 / 1024.0;
98 double file_size_gb = file_size_mb / 1024.0;
99 int event_count = pRawFile->GetEventCount();
100 double event_size_kb = file_size_byte / 1024.0 / event_count;
101 if (file_size_gb > MAX_FILE_SIZE_GB) {
102 is_file_wrong = 1, is_run_wrong = true;
103 wrong_files.insert(pair<TString, double>(pRawFile->GetFilePath(), file_size_mb));
104 }
105
106 double events_per_second = event_count / (double)file_duration_sec;
107 double mb_per_second = file_size_mb / (double)file_duration_sec;
108
109 // do not take into account files with size < MIN_FILE_SIZE_MB
110 if (file_size_mb < MIN_FILE_SIZE_MB) {
111 is_file_wrong = 2, is_run_wrong = true;
112 wrong_files.insert(pair<TString, double>(pRawFile->GetFilePath(), file_size_mb));
113 }
114 // do not take into account files with duration < MIN_FILE_DUR_SEC or > MIN_FILE_DUR_SEC
115 else if ((file_duration_sec < MIN_FILE_DUR_SEC) || (file_duration_sec / 60 > MAX_FILE_DUR_MIN))
116 {
117 is_file_wrong = 2, is_run_wrong = true;
118 wrong_time.insert(pair<TString, double>(pRawFile->GetFilePath(), file_duration_sec));
119 }
120 // do not take into account files with event size < MIN_EVENT_SIZE_KB or > MAX_EVENT_SIZE_KB
121 else if (((event_size_kb < MIN_EVENT_SIZE_KB)) || (event_size_kb > MAX_EVENT_SIZE_KB))
122 {
123 is_file_wrong = 2, is_run_wrong = true;
124 wrong_events.insert(pair<TString, double>(pRawFile->GetFilePath(), event_size_kb));
125 } else {
126 sum_run_size_mb += file_size_mb;
127 sum_file_size_mb += file_size_mb;
128 sum_file_sec += file_duration_sec;
129 sum_event_size_kb += event_size_kb;
130 sum_event_count += event_count;
131 correct_file_count++;
132 }
133
134 if (is_file_wrong == 1)
135 cout << orange;
136 else if (is_file_wrong == 2)
137 cout << red;
138 if (!(show_only_wrong && (is_file_wrong == 0))) {
139 cout << "Current file '" << pRawFile->GetFilePath() << "':" << endl;
140 cout << "File size: " << file_size_gb << " GB (event size = " << event_size_kb << " KB)" << endl;
141 cout << "Duration: " << file_duration_sec << " sec" << endl;
142 cout << "Events/second: " << events_per_second << " (" << mb_per_second << " MB/s)" << endl << endl;
143 }
144 if (is_file_wrong > 0)
145 cout << reset;
146
147 hist_file_size->Fill(file_size_gb);
148 hist_file_duration->Fill(file_duration_sec);
149 hist_event_size->Fill(event_size_kb);
150 hist_stream_ev->Fill(events_per_second);
151 hist_stream_mb->Fill(mb_per_second);
152 }
153 if (!(show_only_wrong && !is_run_wrong))
154 cout << "Run size for " << run_numbers[i].period_number << "-" << run_numbers[i].run_number << ": "
155 << sum_run_size_mb << " MB" << endl
156 << endl;
157 }
158
159 double average_file_size = sum_file_size_mb / correct_file_count;
160 double average_file_duration = sum_file_sec / (double)correct_file_count;
161 double average_event_size = sum_event_size_kb / correct_file_count;
162 double average_event_stream = sum_event_count / (double)sum_file_sec;
163 double average_mb_stream = sum_file_size_mb / sum_file_sec;
164 cout << cyan << "-------------------------------------------------------" << endl;
165 cout << "Average file size for period " << period << ": " << round(average_file_size) << " MB" << endl;
166 cout << "Average file duration for period " << period << ": " << round(average_file_duration) << " sec" << endl;
167 cout << "Average event size for period " << period << ": " << round(average_event_size) << " KB" << endl;
168 cout << "Average event stream for period " << period << ": " << round(average_event_stream) << " event/sec" << endl;
169 cout << "Average binary stream for period " << period << ": " << round(average_mb_stream) << " MB/sec" << endl;
170 cout << "-------------------------------------------------------" << endl << reset;
171
172 if (wrong_files.size() > 0) {
173 cout << endl
174 << "Wrong file size: (< " << MIN_FILE_SIZE_MB << " MB or > " << MAX_FILE_SIZE_GB << " GB):" << endl;
175 for (auto it = wrong_files.begin(); it != wrong_files.end(); ++it)
176 cout << "File '" << (*it).first << "': " << (*it).second << " MB" << endl;
177 cout << red;
178 cout << "Total wrong file size: " << wrong_files.size() << endl;
179 cout << reset;
180 }
181 cout << endl;
182 if (wrong_events.size() > 0) {
183 cout << endl
184 << "Wrong event size: (< " << MIN_EVENT_SIZE_KB << " KB or > " << MAX_EVENT_SIZE_KB << " KB):" << endl;
185 for (auto it = wrong_events.begin(); it != wrong_events.end(); ++it)
186 cout << "File '" << (*it).first << ": " << (*it).second << " KB" << endl;
187 cout << red;
188 cout << "Total wrong event size: " << wrong_events.size() << endl;
189 cout << reset;
190 }
191 cout << endl;
192 if (wrong_time.size() > 0) {
193 cout << endl
194 << "Wrong file duration: (< " << MIN_FILE_DUR_SEC << " sec or > " << MAX_FILE_DUR_MIN
195 << " minutes):" << endl;
196 for (auto it = wrong_time.begin(); it != wrong_time.end(); ++it)
197 cout << "File '" << (*it).first << ": " << (*it).second << " seconds" << endl;
198 cout << red;
199 cout << "Total wrong file duration: " << wrong_time.size() << endl;
200 cout << reset;
201 }
202 cout << endl;
203
204 delete run_numbers;
205
206 TCanvas* canvas_size = new TCanvas("canvas_size", "canvas_size", 1200, 640);
207 canvas_size->Divide(2, 1);
208 canvas_size->cd(1);
209 hist_file_size->Draw();
210 canvas_size->cd(2);
211 hist_event_size->Draw();
212 TCanvas* canvas_file_duration = new TCanvas("canvas_file_duration", "canvas_file_duration");
213 canvas_file_duration->cd();
214 hist_file_duration->Draw();
215 TCanvas* canvas_stream = new TCanvas("canvas_stream", "canvas_stream", 1200, 640);
216 canvas_stream->Divide(2, 1);
217 canvas_stream->cd(1);
218 hist_stream_ev->Draw();
219 canvas_stream->cd(2);
220 hist_stream_mb->Draw();
221
222 cout << "Macro finished successfully" << endl;
223}
int i
Definition P4_F32vec4.h:22
unsigned int UInt_t
TVirtualPad * cd(Int_t subpadnumber=0) override
UInt_t Convert(Bool_t toGMT=kFALSE) const
TAxis * GetXaxis()
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void SetTitle(const char *title="")
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
static TString Format(const char *fmt,...)
/home/soul/bmnroot/database/uni_db1/UniRawFile.h Class for the table: raw_file
Definition UniRawFile.h:19
int64_t GetFileSize()
get file size of the current raw file
Definition UniRawFile.h:114
int GetEventCount()
get event count of the current raw file
Definition UniRawFile.h:112
TString GetFilePath()
get file path of the current raw file
Definition UniRawFile.h:110
TDatime GetStartDatetime()
get start datetime of the current raw file
Definition UniRawFile.h:106
TDatime GetEndDatetime()
get end datetime of the current raw file
Definition UniRawFile.h:108
UniRun.h Class for the table: run_.
Definition UniRun.h:21
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
TObjArray * GetRawFiles()
get array of raw files (UniRawFile*) corresponding to the run (return nullptr if an error occured)
Definition UniRun.cxx:798
static int GetRunNumbers(UniqueRunNumber *&run_numbers, int start_period, int start_run=0, int end_period=-1, int end_run=-1)
get numbers of runs stored in the Database for a selected range
Definition UniRun.cxx:804
#define MIN_EVENT_RATE
#define MIN_EVENT_SIZE_KB
void show_raw_stats(int period=8, int start_run=6587, int end_run=-1, bool show_only_wrong=false)
Function for creating statistics histograms on raw file sizes, event sizes, raw file durations for ru...
#define MIN_FILE_SIZE_MB
#define MIN_FILE_DUR_SEC
#define MAX_FILE_DUR_MIN
#define MAX_FILE_SIZE_GB
#define MAX_EVENT_RATE
#define MAX_EVENT_SIZE_KB
RVec< PromoteType< T > > round(const RVec< T > &v)