41 if (pCurrentPeriod ==
nullptr) {
42 cout <<
"The function encountered with errors: no experimental period was found with number " << period_number
49 delete pCurrentPeriod;
50 if (period_end_time ==
nullptr) {
51 cout <<
"ERROR: there is no end time for Period " << period_number <<
". Exiting..." << endl;
58 delete period_end_time;
82 const char* error_names[kErrorTypeCount] = {
"no event count of the run",
83 "start time of the run is out of the period",
84 "no end time of the run",
85 "end time of the run is out of the period",
86 "raw files were not read (database error)",
88 "start time of a raw file is out of the period",
89 "end time of a raw file is out of the period",
90 "first event is not 1",
94 "stream ends earlier",
95 "event sum of raw files differs from the run",
96 "run time differs from the raw file time"};
97 int error_run_count[kErrorTypeCount] = {};
99 vector<pair<int, TString>> error_runs;
100 int not_found_run = 0, success_runs = 0, raw_file_count = 0;
103 for (
int i = 0;
i < run_count;
i++) {
106 if (pCurrentRun ==
nullptr) {
107 cout <<
"The function encountered with errors: no experimental run was found ("
111 error_runs.push_back({
i,
"run not found in UniConDa (not checked)"});
117 map<int, vector<TString>> run_errors;
120 if (run_event_count ==
nullptr) {
122 cout <<
"ERROR: there is no event count in the run" << endl;
126 if ((run_start_time < period_start_time) || (run_start_time > (*period_end_time))) {
128 cout <<
"ERROR: the start time of the run is out of range: " << run_start_time.
AsSQLString() << endl;
131 if (run_end_time ==
nullptr) {
133 cout <<
"ERROR: there is no end time of the run" << endl;
135 if (((*run_end_time) < period_start_time) || ((*run_end_time) > (*period_end_time))) {
137 cout <<
"ERROR: the end time of the run is out of range: " << run_end_time->
AsSQLString() << endl;
144 int file_count = (raw_files ==
nullptr) ? 0 : raw_files->
GetEntriesFast();
145 raw_file_count += file_count;
146 if (raw_files ==
nullptr) {
148 cout <<
"ERROR: the raw files of the run were not read" << endl;
149 }
else if (file_count == 0) {
151 cout <<
"ERROR: there are no raw files in the run" << endl;
154 int first_event = ((
UniRawFile*)raw_files->
At(0))->GetStartEvent();
155 int stream_count = 1;
156 while ((stream_count < file_count)
157 && (((
UniRawFile*)raw_files->
At(stream_count))->GetStartEvent() == first_event + stream_count))
159 cout <<
"Raw files: " << file_count <<
" in " << stream_count <<
" stream(s)" << endl;
162 if (first_event != 1) {
164 cout <<
"ERROR: the first event of the run is " << first_event <<
" instead of 1" << endl;
169 vector<vector<UniRawFile*>> streams(stream_count);
170 int sum_event_count = 0;
171 TDatime min_start_time, max_end_time;
172 for (
int j = 0; j < file_count; j++) {
175 if ((j == 0) || (file_start_time < min_start_time))
176 min_start_time = file_start_time;
177 if ((j == 0) || (file_end_time > max_end_time))
178 max_end_time = file_end_time;
180 if ((file_start_time < period_start_time) || (file_start_time > (*period_end_time))) {
182 cout <<
"ERROR: the start time of the raw file " <<
RawFileName(pRawFile)
183 <<
" is out of range: " << file_start_time.
AsSQLString() << endl;
185 if ((file_end_time < period_start_time) || (file_end_time > (*period_end_time))) {
187 cout <<
"ERROR: the end time of the raw file " <<
RawFileName(pRawFile)
188 <<
" is out of range: " << file_end_time.AsSQLString() << endl;
193 if (file_event_count > 0) {
194 long expected_end_event = pRawFile->
GetStartEvent() + (long)stream_count * (file_event_count - 1);
195 if (pRawFile->
GetEndEvent() != expected_end_event) {
197 cout <<
"ERROR: the raw file " <<
RawFileName(pRawFile) <<
" ends with event "
198 << pRawFile->
GetEndEvent() <<
" instead of " << expected_end_event <<
" (start event "
199 << pRawFile->
GetStartEvent() <<
", " << file_event_count <<
" events with step "
200 << stream_count <<
")";
204 if ((file_event_count > 1) && (event_range % (file_event_count - 1) == 0)
205 && (event_range / (file_event_count - 1) > stream_count))
206 cout <<
", the events have step " << event_range / (file_event_count - 1)
207 <<
": probably, not all streams are in the database";
212 sum_event_count += file_event_count;
213 streams[(pRawFile->
GetStartEvent() - first_event) % stream_count].push_back(pRawFile);
217 size_t max_part_count = 0;
218 for (
auto& stream : streams)
219 max_part_count =
max(max_part_count, stream.size());
220 for (
int k = 0; k < stream_count; k++) {
223 for (
size_t p = 1; p < streams[k].size(); p++) {
224 int event_gap = streams[k][p]->GetStartEvent() - streams[k][p - 1]->GetEndEvent();
225 if (event_gap != stream_count) {
227 cout <<
"ERROR: event gap between the parts of the stream is " << event_gap <<
" instead of "
228 << stream_count <<
" (" <<
RawFileName(streams[k][p - 1]) <<
" ends with event "
229 << streams[k][p - 1]->GetEndEvent() <<
", " <<
RawFileName(streams[k][p])
230 <<
" starts with event " << streams[k][p]->GetStartEvent() <<
")" << endl;
235 if (streams[k].size() < max_part_count) {
237 cout <<
"ERROR: the stream ends after " << streams[k].size() <<
" of " << max_part_count
238 <<
" parts: the last raw file " <<
RawFileName(streams[k].back()) <<
" ends with event "
239 << streams[k].back()->GetEndEvent() << endl;
245 for (
size_t p = 0; p < max_part_count; p++) {
247 for (
int k = 0; k < stream_count; k++) {
248 if (p >= streams[k].size())
250 if (ref_stream < 0) {
254 UniRawFile* pRefFile = streams[ref_stream][p];
255 int expected_event = pRefFile->
GetStartEvent() + (k - ref_stream);
256 if (streams[k][p]->GetStartEvent() != expected_event) {
258 cout <<
"ERROR: the raw file " <<
RawFileName(streams[k][p]) <<
" starts with event "
259 << streams[k][p]->GetStartEvent() <<
" instead of " << expected_event <<
" ("
266 if ((run_event_count !=
nullptr) && ((*run_event_count) != sum_event_count)) {
268 cout <<
"ERROR: raw event sum is different from run event count (" << sum_event_count <<
" <> "
269 << *run_event_count <<
")" << endl;
271 if ((run_end_time !=
nullptr) && ((run_start_time != min_start_time) || ((*run_end_time) != max_end_time)))
274 cout <<
"ERROR: run time interval (" << run_start_time.
AsSQLString() <<
" - "
275 << run_end_time->
AsSQLString() <<
") is different from raw file time ("
280 if (run_errors.empty()) {
282 cout <<
"Event numbers and time intervals were successfully matched" << endl;
286 for (
auto& run_error : run_errors) {
287 error_run_count[run_error.first]++;
288 if (run_description !=
"")
289 run_description +=
"; ";
290 run_description += error_names[run_error.first];
291 if (!run_error.second.empty())
292 run_description +=
": " +
FileList(run_error.second);
294 error_runs.push_back({
i, run_description});
297 delete run_event_count;
299 if (raw_files !=
nullptr)
305 int checked_runs = run_count - not_found_run;
307 <<
"Summary for " << run_count <<
" runs (" << period_number <<
":" << run_numbers[0].
run_number <<
" - "
308 << period_number <<
":" << run_numbers[run_count - 1].
run_number <<
"):" << endl;
309 cout <<
TString::Format(
" %-50s %6d",
"checked runs", checked_runs) << endl;
310 cout <<
TString::Format(
" %-50s %6d",
"checked raw files", raw_file_count) << endl;
311 cout <<
TString::Format(
" %-50s %6d",
"successfully matched runs", success_runs) << endl;
312 cout <<
TString::Format(
" %-50s %6d",
"runs with errors", checked_runs - success_runs) << endl;
313 for (
int t = 0; t < kErrorTypeCount; t++)
314 if (error_run_count[t] > 0)
315 cout <<
TString::Format(
" %-48s %6d", error_names[t], error_run_count[t]) << endl;
316 if (not_found_run > 0)
317 cout <<
TString::Format(
" %-50s %6d",
"runs not found in UniConDa (not checked)", not_found_run) << endl;
320 if (!error_runs.empty()) {
321 cout << endl <<
"Runs with errors:" << endl;
322 for (
auto& error_run : error_runs) {
330 delete[] run_numbers;
331 delete period_end_time;
int check_event_and_time(int period_number, int start_run, int end_run)
TString FileList(const vector< TString > &files)
int postrun_check(int period_number=9, int start_run=1, int end_run=100000)
Main post run checking procedure to match run metadata and parameters of the raw files.
void AddRunError(map< int, vector< TString > > &run_errors, int error_type, TString file_name="")