BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
postrun_check.C
Go to the documentation of this file.
1#define PARITY 2
2
3// matching event numbers and summary count in 'raw file' records with run metadata, as well as time intervals
4// possible errors: starting not from 1, more than 1 event between raw files, sum of the event count of the raw files <>
5// event count of the corresponding run time of the first and last raw files are not corresponding start and end time of
6// the run
7int check_event_and_time(int period_number, int start_run, int end_run)
8{
9 // get the given period
10 UniRunPeriod* pCurrentPeriod = UniRunPeriod::GetRunPeriod(period_number);
11 if (pCurrentPeriod == nullptr) {
12 cout << "The function encountered with errors: no experimental period was found with number " << period_number
13 << endl;
14 return -1;
15 }
16
17 TDatime period_start_time = pCurrentPeriod->GetStartDatetime();
18 TDatime* period_end_time = pCurrentPeriod->GetEndDatetime();
19 delete pCurrentPeriod;
20 if (period_end_time == nullptr) {
21 cout << "ERROR: there is no end time for Period " << period_number << "Exiting..." << endl;
22 return -2;
23 }
24
25 UniqueRunNumber* run_numbers;
26 int run_count = UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
27 if (run_count <= 0)
28 return -1;
29
30 // cycle by all runs for the given period
31 int critical_errors = 0, no_event_count_run = 0, out_start_run_time = 0, out_end_run_time = 0, no_end_time_run = 0,
32 no_raw_files_run = 0, out_start_raw_time = 0, out_end_raw_time = 0, first_event_gt1 = 0, event_gap = 0,
33 parity_event_gap = 0, event_sum_mismatch = 0, time_interval_mismatch = 0;
34 for (int i = 0; i < run_count; i++) {
35 bool is_success = true;
36
37 // get the current run
38 UniRun* pCurrentRun = UniRun::GetRun(run_numbers[i].period_number, run_numbers[i].run_number);
39 if (pCurrentRun == nullptr) {
40 cout << "The function encountered with errors: no experimental run was found ("
41 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
42 << endl;
43 critical_errors++;
44 continue;
45 }
46 cout << endl << "Period:Run " << run_numbers[i].period_number << ":" << run_numbers[i].run_number << endl;
47
48 int* run_event_count = pCurrentRun->GetEventCount();
49 if (run_event_count == nullptr) {
50 is_success = false;
51 no_event_count_run++;
52 cout << "ERROR: there is no event count in the run" << endl;
53 }
54
55 TDatime run_start_time = pCurrentRun->GetStartDatetime();
56 if ((run_start_time < period_start_time) || (run_start_time > (*period_end_time))) {
57 is_success = false;
58 out_start_run_time++;
59 cout << "ERROR: the start time of the run is out of range: " << run_start_time.AsSQLString() << endl;
60 }
61 TDatime* run_end_time = pCurrentRun->GetEndDatetime();
62 if (run_end_time == nullptr) {
63 is_success = false;
64 no_end_time_run++;
65 cout << "ERROR: there is no end time of the run" << endl;
66 } else {
67 if (((*run_end_time) < period_start_time) || ((*run_end_time) > (*period_end_time))) {
68 is_success = false;
69 out_end_run_time++;
70 cout << "ERROR: the end time of the run is out of range: " << run_end_time->AsSQLString() << endl;
71 }
72 }
73
74 // get all raw files for the current run
75 TObjArray* raw_files = pCurrentRun->GetRawFiles();
76 delete pCurrentRun;
77 if (raw_files == nullptr) {
78 no_raw_files_run++;
79 cout << "ERROR: there are no raw files in the run" << endl;
80 continue;
81 }
82
83 // cycle by all raw files for the current run
84 int sum_event_count = 0;
85 TDatime min_start_time("2100-01-01 00:00:00"), max_end_time("1995-01-01 00:00:00");
86 vector<int> v_start_event, v_end_event;
87 for (const auto& j : *raw_files) {
88 UniRawFile* pRawFile = (UniRawFile*)j;
89
90 int file_start_event = pRawFile->GetStartEvent();
91 int file_end_event = pRawFile->GetEndEvent();
92 int file_event_count = pRawFile->GetEventCount();
93 if (pRawFile->GetStartDatetime() < min_start_time)
94 min_start_time = pRawFile->GetStartDatetime();
95 if (pRawFile->GetEndDatetime() > max_end_time)
96 max_end_time = pRawFile->GetEndDatetime();
97
98 // check the start time of the current raw file
99 if ((pRawFile->GetStartDatetime() < period_start_time)
100 || (pRawFile->GetStartDatetime() > (*period_end_time)))
101 {
102 is_success = false;
103 out_start_raw_time++;
104 cout << "ERROR: the start time of the raw file is out of range: "
105 << pRawFile->GetStartDatetime().AsSQLString() << endl;
106 }
107
108 // check the emd time of the current raw file
109 if ((pRawFile->GetEndDatetime() < period_start_time) || (pRawFile->GetEndDatetime() > (*period_end_time))) {
110 is_success = false;
111 out_end_raw_time++;
112 cout << "ERROR: the end time of the raw file is out of range: "
113 << pRawFile->GetEndDatetime().AsSQLString() << endl;
114 }
115
116 // check first event
117 if (v_start_event.empty() && (file_start_event != 1)) {
118 is_success = false;
119 first_event_gt1++;
120 cout << "ERROR: first event > 1 (first_event = " << file_start_event << ")" << endl;
121 }
122
123 // check "previous" event: "current start - "parity previous" end == PARITY"
124 if (v_start_event.size() > PARITY) {
125 int prev_end_event = v_end_event[v_end_event.size() - PARITY];
126 int event_gap = file_start_event - prev_end_event;
127 if (event_gap != PARITY) {
128 is_success = false;
129 event_gap++;
130 cout << "ERROR: event gap > " << PARITY << " (current_event = " << file_start_event
131 << ", previous event = " << prev_end_event << endl;
132 }
133 }
134
135 // check parity event (should be increased by 1)
136 if ((PARITY > 1) && (v_start_event.size() % PARITY != 0)) {
137 int parity_start_event = v_start_event[v_start_event.size() - 1];
138 int parity_gap = file_start_event - parity_start_event;
139 if (parity_gap != 1) {
140 is_success = false;
141 parity_event_gap++;
142 cout << "ERROR: parity event gap > 1 (current_event = " << file_start_event
143 << ", parity start event = " << parity_start_event << endl;
144 }
145 }
146
147 sum_event_count += file_event_count;
148
149 v_start_event.push_back(file_start_event);
150 v_end_event.push_back(file_end_event);
151 } // for (const auto& j : *raw_files)
152
153 if ((run_event_count != nullptr) && ((*run_event_count) != sum_event_count)) {
154 is_success = false;
155 event_sum_mismatch++;
156 cout << "ERROR: raw event sum is different from run event count (" << sum_event_count << " <> "
157 << *run_event_count << ")" << endl;
158 }
159 if ((run_end_time != nullptr) && ((run_start_time != min_start_time) || ((*run_end_time) != max_end_time))) {
160 is_success = false;
161 // TString time_format("%d.%m.%Y %H:%M:%S");
162 time_interval_mismatch++;
163 cout << "ERROR: run time interval (" << run_start_time.AsSQLString() << " - " << run_end_time->AsSQLString()
164 << ") is different from raw file time (" << min_start_time.AsSQLString() << " - "
165 << max_end_time.AsSQLString() << ")" << endl;
166 }
167
168 if (is_success)
169 cout << "Event numbers and time intervals were successfully matched" << endl;
170 } // for (int i = 0; i < run_count; i++)
171
172 cout << endl;
173 if (critical_errors > 0)
174 cout << "Critical Errors: " << critical_errors << endl;
175 if (no_event_count_run > 0)
176 cout << "No event count in " << no_event_count_run << " run(s)" << endl;
177 if (out_start_run_time > 0)
178 cout << "The start time of the run is out of range in " << out_start_run_time << " run(s)" << endl;
179 if (no_end_time_run > 0)
180 cout << "There is no end time in " << no_end_time_run << " run(s)" << endl;
181 if (out_end_run_time > 0)
182 cout << "The end time of the run is out of range in " << out_end_run_time << " run(s)" << endl;
183 if (no_raw_files_run > 0)
184 cout << "No raw files in " << no_raw_files_run << " run(s)" << endl;
185 if (out_start_raw_time > 0)
186 cout << "The start time of the raw file is out of range in " << out_start_raw_time << " run(s)" << endl;
187 if (out_end_raw_time > 0)
188 cout << "The end time of the raw file is out of range in " << out_end_raw_time << " run(s)" << endl;
189 if (first_event_gt1 > 0)
190 cout << "First event > 1 in " << first_event_gt1 << " run(s)" << endl;
191 if (event_gap > 0)
192 cout << "Event gap > 1 in " << event_gap << " run(s)" << endl;
193 if (parity_event_gap > 0)
194 cout << "Parity event gap > 1 in " << parity_event_gap << " run(s)" << endl;
195 if (event_sum_mismatch > 0)
196 cout << "Raw event sum is different from run event count in " << event_sum_mismatch << " run(s)" << endl;
197 if (time_interval_mismatch > 0)
198 cout << "Run time interval is different from raw file time in " << time_interval_mismatch << " run(s)" << endl;
199
200 return 0;
201}
202
203/**
204 * Main post run checking procedure to match run metadata and parameters of the raw files
205 **/
206int postrun_check(int period_number = 8, int start_run = 6310, int end_run = 8427)
207{
208 check_event_and_time(period_number, start_run, end_run);
209
210 return 0;
211}
int i
Definition P4_F32vec4.h:22
const char * AsSQLString() const
/home/soul/bmnroot/database/uni_db1/UniRawFile.h Class for the table: raw_file
Definition UniRawFile.h:19
int GetEventCount()
get event count of the current raw file
Definition UniRawFile.h:112
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
int GetEndEvent()
get end event of the current raw file
Definition UniRawFile.h:104
int GetStartEvent()
get start event of the current raw file
Definition UniRawFile.h:102
UniRunPeriod.h Class for the table: run_period.
TDatime * GetEndDatetime()
get end datetime of the current run period
static UniRunPeriod * GetRunPeriod(int period_number)
get run period from the database
TDatime GetStartDatetime()
get start datetime of the current run period
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
TDatime * GetEndDatetime()
get end datetime of the current run
Definition UniRun.h:101
TDatime GetStartDatetime()
get start datetime of the current run
Definition UniRun.h:99
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
int * GetEventCount()
get event count of the current run
Definition UniRun.h:129
int check_event_and_time(int period_number, int start_run, int end_run)
int postrun_check(int period_number=8, int start_run=6310, int end_run=8427)
Main post run checking procedure to match run metadata and parameters of the raw files.
#define PARITY