26 ss.imbue(std::locale(
""));
27 ss << std::fixed << value;
38 TObjArray* arr_save_hist = save_hist.Tokenize(
";,");
39 TString save_hist1 =
"", save_hist2 =
"";
46 if (connDb ==
nullptr)
51 if ((str_date_start ==
"") || (str_date_end ==
"")) {
52 int start_run_number = 0;
53 if (period_number == 8)
54 start_run_number = 5301;
57 "select date(min(record_date) - interval '1 DAY'), date(max(record_date) + interval '1 DAY') "
59 "where period_number = %d and run_number >= %d and ((lower(replace(record_comment, ' ', ''))) ~ '\\d+k')",
60 period_number, start_run_number);
65 cout <<
"ERROR: getting record from the database has been failed" << endl;
74 cout <<
"ERROR: max and min record date was not found in the database" << endl;
80 if (str_date_start ==
"")
82 if (str_date_end ==
"")
88 TPRegexp sql_date_format(
"^\\d{4}\\-(0[1-9]|1[012])\\-(0[1-9]|[12][0-9]|3[01])$");
89 if ((!str_date_start.Contains(sql_date_format)) || (!str_date_end.Contains(sql_date_format))) {
90 cout <<
"ERROR: 'date_start' or 'date_end' format is not correct, please, set them as \"YYYY-MM-DD\"" << endl;
96 str_date_start +=
" 00:00:00";
97 str_date_end +=
" 23:59:59";
98 TDatime date_start(str_date_start), date_end(str_date_end);
99 if (date_start >= date_end) {
100 cout <<
"ERROR: 'date_end' must be greater than 'date_end'" << endl;
107 " (coalesce(sum(rtrim(substring(lower(regexp_replace(record_comment, ' |mv', '', 'gi')), "
108 "'(\\d+((\\.|,)\\d+)?)k'), 'k') :: float),0) + "
109 " (coalesce(sum(rtrim(substring(lower(regexp_replace(record_comment, ' |mv', '', 'gi')), "
110 "'(\\d+((\\.|,)\\d+)?)m'), 'm') :: float),0)*1000)) "
112 "from record_ r join type_ t on r.type_id = t.type_id "
113 "where period_number = %d and run_number is not null and "
114 " record_date >= '%s' and record_date <= '%s' and "
115 " ((lower(regexp_replace(record_comment, ' |mv', '', 'gi'))) ~ '\\d+((\\.|,)\\d+)?(k|m)') "
116 "group by date(record_date), type_text "
117 "order by date(record_date)",
118 period_number, str_date_start.Data(), str_date_end.Data());
124 cout <<
"ERROR: getting record from the database has been failed" << endl;
135 TCanvas* c1 =
new TCanvas(
"c1",
"Event statistics by different types", 1000, 500);
139 int bin_count = (date_end.
Convert() - date_start.Convert() + 1) / 24 / 3600;
142 TH1I* hEventByDatePhys =
new TH1I(
"hEventByDatePhys",
"", bin_count, date_start.Convert(), date_end.
Convert() + 1);
161 TH1I* hEventByDateTest = (
TH1I*)hEventByDatePhys->
Clone(
"hEventByDateTest");
162 TH1I* hEventByDateCalib = (
TH1I*)hEventByDatePhys->
Clone(
"hEventByDateCalib");
173 int total_phys_events = 0, total_test_events = 0, total_calib_events = 0;
174 cout << endl <<
"|date |type |event_number|" << endl;
175 cout <<
"|-----------|----------------|------------|" << endl;
179 TDatime record_date(str_record_date +
" 00:00:00");
181 int event_count = stmt->
GetInt(2);
183 for (
int i = str_event_count.
Length();
i < 12;
i++)
184 str_event_count +=
" ";
186 cout <<
"|" << str_record_date <<
" |" << type_text.
Data();
187 if (type_text ==
"Physics Run") {
188 hEventByDatePhys->
Fill(record_date.
Convert(), event_count * 1000);
189 cout <<
" " <<
" |" << str_event_count <<
"|" << endl;
190 total_phys_events += event_count * 1000;
191 }
else if (type_text ==
"Test Run") {
192 hEventByDateTest->
Fill(record_date.
Convert(), event_count * 1000);
193 cout <<
" " <<
" |" << str_event_count <<
"|" << endl;
194 total_test_events += event_count * 1000;
195 }
else if (type_text ==
"Calibration Run") {
196 hEventByDateCalib->
Fill(record_date.
Convert(), event_count * 1000);
197 cout <<
" |" << str_event_count <<
"|" << endl;
198 total_calib_events += event_count * 1000;
200 for (
int i = type_text.
Length();
i < 15;
i++)
202 cout <<
" |" << str_event_count <<
"|" << endl;
203 cout <<
"WARNING: Incorrect type of the record with event number is \"" << type_text <<
"\"" << endl;
209 <<
"Total calibration events - " <<
FormatWithCommas(total_calib_events) << endl;
211 TString hist_options =
"bar2,hist,text";
212 TH1* h1 = hEventByDatePhys->
DrawCopy(hist_options);
213 TH1* h2 = hEventByDateTest->
DrawCopy(hist_options +
",same");
214 TH1* h3 = hEventByDateCalib->
DrawCopy(hist_options +
",same");
217 legend->
AddEntry(h1,
"Physics Events",
"f");
218 legend->
AddEntry(h2,
"Test Events",
"f");
219 legend->
AddEntry(h3,
"Calibration Events",
"f");
222 if (save_hist1 !=
"")
226 TH1F* hIntegralPhys =
new TH1F(
"hIntegralPhys",
"", bin_count, date_start.Convert(), date_end.
Convert() + 1);
233 TCanvas* c2 =
new TCanvas(
"c2",
"Integral statistics of physics events", 1000, 500);
247 hIntegralPhys->
GetYaxis()->
SetTitle(
"Integral statistics, events #times 10^{6}");
256 hIntegralPhys->
Draw(
"");
258 if (save_hist2 !=
"")
259 c2->
SaveAs(save_hist2.Data());
269 if (connDb ==
nullptr)
273 if ((str_date_start ==
"") || (str_date_end ==
"")) {
274 int start_run_number = 0;
275 if (period_number == 8)
276 start_run_number = 5301;
278 "select date(min(record_date) - interval '1 DAY'), date(max(record_date) + interval '1 DAY') "
280 "where period_number = %d and run_number >= %d and ((lower(replace(record_comment, ' ', ''))) ~ '\\d+k')",
281 period_number, start_run_number);
286 cout <<
"ERROR: getting record from the database has been failed" << endl;
295 cout <<
"ERROR: max and min record date was not found in the database" << endl;
300 if (str_date_start ==
"")
301 str_date_start = stmt_date->
GetString(0);
302 if (str_date_end ==
"")
307 TPRegexp sql_date_format(
"^\\d{4}\\-(0[1-9]|1[012])\\-(0[1-9]|[12][0-9]|3[01])$");
308 if ((!str_date_start.Contains(sql_date_format)) || (!str_date_end.Contains(sql_date_format))) {
309 cout <<
"ERROR: 'date_start' or 'date_end' format is not correct, please, set them as \"YYYY-MM-DD\"" << endl;
314 str_date_start +=
" 00:00:00";
315 str_date_end +=
" 23:59:59";
316 TDatime date_start(str_date_start), date_end(str_date_end);
317 if (date_start >= date_end) {
318 cout <<
"ERROR: 'date_end' must be greater than 'date_end'" << endl;
324 TString::Format(
"select date(record_date), trunc((date_part('hour', record_date) / 8)), type_text, "
325 " (coalesce(sum(rtrim(substring(lower(regexp_replace(record_comment, ' |mv', '', 'gi')), "
326 "'(\\d+((\\.|,)\\d+)?)k'), 'k') :: float),0) + "
327 " (coalesce(sum(rtrim(substring(lower(regexp_replace(record_comment, ' |mv', '', 'gi')), "
328 "'(\\d+((\\.|,)\\d+)?)m'), 'm') :: float),0)*1000)) "
330 "from record_ r join type_ t on r.type_id = t.type_id "
331 "where period_number = %d and run_number is not null and "
332 " record_date >= '%s' and record_date <= '%s' and "
333 " ((lower(regexp_replace(record_comment, ' |mv', '', 'gi'))) ~ '\\d+((\\.|,)\\d+)?(k|m)') "
334 "group by date(record_date), trunc((date_part('hour', record_date) / 8)), type_text "
335 "order by date(record_date)",
336 period_number, str_date_start.Data(), str_date_end.Data());
342 cout <<
"ERROR: getting record from the database has been failed" << endl;
353 TCanvas* c1 =
new TCanvas(
"c1",
"Event Acquisition Histogram", 1000, 600);
357 int bin_count = (date_end.
Convert() - date_start.Convert() + 1) / 8 / 3600;
360 TH1I* hEventByDatePhys =
new TH1I(
"hEventByDatePhys",
"", bin_count, date_start.Convert(), date_end.
Convert() + 1);
378 TH1I* hEventByDateTest = (
TH1I*)hEventByDatePhys->
Clone(
"hEventByDateTest");
379 TH1I* hEventByDateCalib = (
TH1I*)hEventByDatePhys->
Clone(
"hEventByDateCalib");
390 int total_phys_events = 0, total_test_events = 0, total_calib_events = 0;
391 cout << endl <<
"|shift |type |event_number|" << endl;
392 cout <<
"|-------------------|----------------|------------|" << endl;
396 int shift_num = stmt->
GetInt(1);
400 record_date.
Set(str_record_date +
" 04:00:00");
401 str_shift_time =
" 00h-08h";
405 record_date.
Set(str_record_date +
" 12:00:00");
406 str_shift_time =
" 08h-16h";
410 record_date.
Set(str_record_date +
" 20:00:00");
411 str_shift_time =
" 16h-24h";
416 int event_count = stmt->
GetInt(3);
418 for (
int i = str_event_count.
Length();
i < 12;
i++)
419 str_event_count +=
" ";
421 cout <<
"|" << str_record_date << str_shift_time <<
" |" << type_text.
Data();
422 if (type_text ==
"Physics Run") {
423 hEventByDatePhys->
Fill(record_date.
Convert(), event_count * 1000);
424 cout <<
" " <<
" |" << str_event_count <<
"|" << endl;
425 total_phys_events += event_count * 1000;
426 }
else if (type_text ==
"Test Run") {
427 hEventByDateTest->
Fill(record_date.
Convert(), event_count * 1000);
428 cout <<
" " <<
" |" << str_event_count <<
"|" << endl;
429 total_test_events += event_count * 1000;
430 }
else if (type_text ==
"Calibration Run") {
431 hEventByDateCalib->
Fill(record_date.
Convert(), event_count * 1000);
432 cout <<
" |" << str_event_count <<
"|" << endl;
433 total_calib_events += event_count * 1000;
435 for (
int i = type_text.
Length();
i < 15;
i++)
437 cout <<
" |" << str_event_count <<
"|" << endl;
438 cout <<
"WARNING: Incorrect type of the record with event number is \"" << type_text <<
"\"" << endl;
444 <<
"Total calibration events - " <<
FormatWithCommas(total_calib_events) << endl;
446 TString hist_options =
"bar2,hist,text";
447 TH1* h1 = hEventByDatePhys->
DrawCopy(hist_options);
448 TH1* h2 = hEventByDateTest->
DrawCopy(hist_options +
",same");
449 TH1* h3 = hEventByDateCalib->
DrawCopy(hist_options +
",same");
452 legend->
AddEntry(h1,
"Physics Events",
"f");
453 legend->
AddEntry(h2,
"Test Events",
"f");
454 legend->
AddEntry(h3,
"Calibration Events",
"f");
458 c1->
SaveAs(save_hist.Data());
R__EXTERN TStyle * gStyle
static ElogConnection * Open()
TSQLServer * GetSQLServer()
virtual void SetLabelSize(Float_t size=0.04)
virtual void SetTitleFont(Style_t font=62)
virtual void SetTitleSize(Float_t size=0.04)
virtual void SetNdivisions(Int_t n1, Int_t n2, Int_t n3, Bool_t optim=kTRUE)
virtual void SetFillColor(Color_t fcolor)
virtual void SetFillStyle(Style_t fstyle)
virtual void SetLineWidth(Width_t lwidth)
virtual void SetLineColor(Color_t lcolor)
virtual void SetMarkerSize(Size_t msize=1)
void CenterLabels(Bool_t center=kTRUE)
virtual void SetTimeDisplay(Int_t value)
void CenterTitle(Bool_t center=kTRUE)
virtual void SetTimeFormat(const char *format="")
TVirtualPad * cd(Int_t subpadnumber=0) override
UInt_t Convert(Bool_t toGMT=kFALSE) const
virtual void SetLabelFont(Style_t font=62, Option_t *axis="X")
virtual void SetBarOffset(Float_t offset=0.25)
virtual Int_t GetNbinsX() const
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void SetBinContent(Int_t bin, Double_t content)
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
virtual Double_t GetBinContent(Int_t bin) const
virtual void SetTitleFont(Style_t font=62, Option_t *axis="X")
TObject * Clone(const char *newname="") const override
virtual void LabelsDeflate(Option_t *axis="X")
virtual void SetBarWidth(Float_t width=0.5)
virtual void SetStats(Bool_t stats=kTRUE)
void Draw(Option_t *option="") override
TLegendEntry * AddEntry(const char *name, const char *label="", Option_t *option="lpf")
virtual void SetTitle(const char *title="")
Int_t GetEntries() const override
void SaveAs(const char *filename="", Option_t *option="") const override
virtual TSQLStatement * Statement(const char *, Int_t=100)
virtual const char * GetString(Int_t)
virtual Bool_t NextResultRow()=0
virtual Int_t GetInt(Int_t)
virtual Bool_t Process()=0
virtual Bool_t StoreResult()=0
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
TSubString Strip(EStripType s=kTrailing, char c=' ') const
const char * Data() const
static TString Format(const char *fmt,...)
string FormatWithCommas(T value)
void event_shift_hist(int period_number=8, TString str_date_start="", TString str_date_end="", TString save_hist="")
void event_date_hist(int period_number=9, TString str_date_start="", TString str_date_end="", TString save_hist="")