BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
check_missing_files.C
Go to the documentation of this file.
2
3#include <algorithm>
4#include <unordered_set>
5
6// get the numbers of the runs described in the Electronic Logbook for the period with one query
7// returns the number of the logbook records of the period, or -1 if getting the records failed
8int get_logbook_runs(int period_number, unordered_set<int>& run_numbers)
9{
11 period_number);
12 TObjArray* records = ElogRecord::Search(condition);
13 if (records == nullptr)
14 return -1;
15
16 int record_count = records->GetEntriesFast();
17 for (const auto& obj : *records) {
18 int* run_number = ((ElogRecord*)obj)->GetRunNumber();
19 if (run_number != nullptr) {
20 run_numbers.insert(*run_number);
21 delete run_number;
22 }
23 }
24 delete records; // the array owns the records
25
26 return record_count;
27}
28
29// function for checking files from a list in the given text file,
30// whether the corresponding run is missing in the Electronic Logbook;
31// all logbook records of the period are read with one query, and the list is checked in memory
32// returns the success code: 0 - without errors, error_code - otherwise
33int check_missing_files(TString list_file_path, int period_number = 9)
34{
35 gSystem->ExpandPathName(list_file_path);
36
37 list<string> file_list;
38 ifstream list_file(list_file_path.Data());
39 string s;
40 while (getline(list_file, s))
41 file_list.push_back(s);
42 if (file_list.empty()) {
43 cout << "WARNING: There are no files in the list of the input text file: " << list_file_path << endl;
44 return 0;
45 }
46 cout << "Total records in the input text file: " << file_list.size() << endl;
47
48 unordered_set<int> logbook_runs;
49 int record_count = get_logbook_runs(period_number, logbook_runs);
50 if (record_count < 0) {
51 cout << "ERROR: getting the records of period " << period_number << " from the Electronic Logbook failed"
52 << endl;
53 return -1;
54 }
55 cout << "Logbook records of period " << period_number << ": " << record_count << " (" << logbook_runs.size()
56 << " runs)" << endl;
57
58 vector<string> missing_files;
59 vector<string> existing_files;
60 // distinct run numbers of the listed files, for the statistics
61 unordered_set<int> missing_runs, existing_runs;
62 int skipped_files = 0;
63 for (auto const& cur_file_path : file_list) {
64 string file_name_wo_ext = get_file_name(cur_file_path);
65 // parse a run number from the name
66 string str_run_number = find_first_number(file_name_wo_ext);
67 if (str_run_number == "") {
68 cout << "ERROR: No run number found in the file name: " << cur_file_path << ", skipping.." << endl;
69 skipped_files++;
70 continue;
71 }
72 int run_number = stoi(str_run_number);
73
74 // search the run number among the runs of the Electronic Logbook
75 if (logbook_runs.count(run_number) == 0) {
76 missing_files.push_back(cur_file_path);
77 missing_runs.insert(run_number);
78 } else {
79 existing_files.push_back(cur_file_path);
80 existing_runs.insert(run_number);
81 }
82 } // for file list
83
84 // print the resulting lists in alphabetical order
85 sort(missing_files.begin(), missing_files.end());
86 sort(existing_files.begin(), existing_files.end());
87
88 if (!missing_files.empty()) {
89 cout << endl << "Files not corresponding any run in the logbook:" << endl;
90 for (auto const& cur_file_path : missing_files)
91 cout << cur_file_path << endl;
92 cout << endl;
93 }
94 if (!existing_files.empty()) {
95 cout << endl << "Files for runs described in the logbook:" << endl;
96 for (auto const& cur_file_path : existing_files)
97 cout << cur_file_path << endl;
98 cout << endl;
99 }
100
101 // statistics
102 cout << "Files: " << existing_files.size() << " present in the logbook, " << missing_files.size() << " missing";
103 if (skipped_files > 0)
104 cout << ", " << skipped_files << " skipped (no run number in the file name)";
105 cout << endl;
106 cout << "Runs: " << existing_runs.size() << " present in the logbook, " << missing_runs.size() << " missing"
107 << endl;
108
109 return 0;
110}
R__EXTERN TSystem * gSystem
ElogRecord.h Class for the table: record_.
Definition ElogRecord.h:20
static TObjArray * Search(const ElogSearchCondition &search_condition)
get ELOG records corresponding to the specified single condition
Int_t GetEntriesFast() const
const char * Data() const
int get_logbook_runs(int period_number, unordered_set< int > &run_numbers)
int check_missing_files(TString list_file_path, int period_number=9)
string find_first_number(string const &str, bool isOnlyPositive=true)
string get_file_name(string path)