BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
runs_to_skip.C
Go to the documentation of this file.
1#include <map>
2
3// run type and data quality values of the 'run_' table in UniConDa (see database/uni_db/scheme/uniconda.sql)
4const int RUN_TYPE_TEST = 3;
5const int RUN_QUALITY_POOR = 3;
6
7// get the name of a run type
8TString run_type_name(int run_type)
9{
10 switch (run_type) {
11 case 1:
12 return "physics";
13 case 2:
14 return "calibration";
15 case 3:
16 return "test";
17 default:
18 return TString::Format("unknown (%d)", run_type);
19 }
20}
21
22// get the name of a data quality value
23TString run_quality_name(int run_quality)
24{
25 switch (run_quality) {
26 case 1:
27 return "good";
28 case 2:
29 return "medium";
30 case 3:
31 return "poor";
32 default:
33 return TString::Format("unknown (%d)", run_quality);
34 }
35}
36
37// add runs of the period with the given value of the column to the map: run number -> (run type, data quality)
38// returns false if getting the runs from the Database failed
39bool add_runs(int period_number, UniSearchCondition::enumColumns column, int value, map<int, pair<int, int>>& runs)
40{
41 TObjArray conditions;
43 period_number));
44 conditions.Add(new UniSearchCondition(column, UniSearchCondition::conditionEqual, value));
45
46 TObjArray* run_array = UniRun::Search(conditions);
47 if (run_array == nullptr)
48 return false;
49
50 for (const auto& obj : *run_array) {
51 UniRun* pRun = (UniRun*)obj;
52 runs[pRun->GetRunNumber()] = make_pair(pRun->GetRunType(), pRun->GetRunQuality());
53 }
54 delete run_array; // the array owns the runs
55
56 return true;
57}
58
59// open the output text file if its path is given: returns false if the file cannot be opened
60bool open_output_file(TString& file_path, ofstream& output_file)
61{
62 if (file_path == "")
63 return true;
64
65 gSystem->ExpandPathName(file_path);
66 output_file.open(file_path.Data());
67 if (!output_file.is_open()) {
68 cout << "ERROR: cannot open the output file: " << file_path << endl;
69 return false;
70 }
71
72 return true;
73}
74
75// List the runs of the given period that should not be processed - test runs and runs with poor data quality -
76// and, as a separate list, their raw files from UniConDa.
77// Parameters:
78// period_number - period (session) number
79// run_list_path - if not empty, the run numbers are also written to this text file, one number per line
80// file_list_path - if not empty, the raw file paths are also written to this text file, one path per line
81// Returns 0 on success, or a negative code on error (Database error / cannot write an output file).
82int runs_to_skip(int period_number, TString run_list_path = "", TString file_list_path = "")
83{
84 // run number -> (run type, data quality), the map keeps the runs sorted
85 map<int, pair<int, int>> runs;
88 {
89 cout << "ERROR: getting the runs from the Database failed" << endl;
90 return -1;
91 }
92 if (runs.empty()) {
93 cout << "There are no test runs or runs with poor data quality in period " << period_number << endl;
94 return 0;
95 }
96
97 ofstream run_list_file, file_list_file;
98 if (!open_output_file(run_list_path, run_list_file) || !open_output_file(file_list_path, file_list_file))
99 return -2;
100
101 // list of the runs
102 cout << "Runs of period " << period_number
103 << " that should not be processed (test type or poor data quality):" << endl;
104 int test_runs = 0, poor_runs = 0;
105 for (auto const& [run_number, type_quality] : runs) {
106 auto const& [run_type, run_quality] = type_quality;
107 if (run_type == RUN_TYPE_TEST)
108 test_runs++;
109 if (run_quality == RUN_QUALITY_POOR)
110 poor_runs++;
111 cout << run_number << " type - " << run_type_name(run_type) << ", data quality - "
112 << run_quality_name(run_quality) << endl;
113 if (run_list_file.is_open())
114 run_list_file << run_number << endl;
115 }
116
117 // list of the raw files of these runs
118 cout << endl << "Raw files of these runs:" << endl;
119 int file_count = 0;
120 vector<int> runs_without_files;
121 for (auto const& run : runs) {
122 int run_number = run.first;
123 TObjArray* raw_files = UniRawFile::GetRawFiles(period_number, run_number);
124 if (raw_files == nullptr) {
125 cout << "ERROR: getting the raw files from the Database failed for run " << run_number << endl;
126 return -1;
127 }
128 if (raw_files->IsEmpty())
129 runs_without_files.push_back(run_number);
130 for (const auto& obj : *raw_files) {
131 TString file_path = ((UniRawFile*)obj)->GetFilePath();
132 cout << file_path << endl;
133 if (file_list_file.is_open())
134 file_list_file << file_path << endl;
135 file_count++;
136 }
137 raw_files->Delete();
138 delete raw_files;
139 }
140
141 // a run can be both a test run and a run with poor data quality
142 cout << endl
143 << "Total: " << runs.size() << " runs (test runs - " << test_runs << ", poor data quality - " << poor_runs
144 << "), " << file_count << " raw files" << endl;
145 if (!runs_without_files.empty()) {
146 cout << "Runs without raw files:";
147 for (int run_number : runs_without_files)
148 cout << " " << run_number;
149 cout << endl;
150 }
151 if (run_list_file.is_open())
152 cout << "The run numbers were written to: " << run_list_path << endl;
153 if (file_list_file.is_open())
154 cout << "The raw file paths were written to: " << file_list_path << endl;
155
156 return 0;
157}
R__EXTERN TSystem * gSystem
void Delete(Option_t *option="") override
Bool_t IsEmpty() const override
void Add(TObject *obj) override
const char * Data() const
static TString Format(const char *fmt,...)
/home/soul/bmnroot/database/uni_db1/UniRawFile.h Class for the table: raw_file
Definition UniRawFile.h:19
static TObjArray * GetRawFiles(int period_number, int run_number)
get array of raw files (UniRawFile*) corresponding to the period:run number ordered by start_event as...
UniRun.h Class for the table: run_.
Definition UniRun.h:21
int GetRunType()
get run type of the current run
Definition UniRun.h:97
int GetRunNumber()
get run number of the current run
Definition UniRun.h:95
static TObjArray * Search(UniSearchCondition &search_condition)
get runs corresponding to the specified single condition (the condition stays owned by the caller)
Definition UniRun.cxx:1164
int GetRunQuality()
get run quality of the current run
Definition UniRun.h:137
int runs_to_skip(int period_number, TString run_list_path="", TString file_list_path="")
const int RUN_QUALITY_POOR
Definition runs_to_skip.C:5
bool add_runs(int period_number, UniSearchCondition::enumColumns column, int value, map< int, pair< int, int > > &runs)
bool open_output_file(TString &file_path, ofstream &output_file)
const int RUN_TYPE_TEST
Definition runs_to_skip.C:4
TString run_type_name(int run_type)
Definition runs_to_skip.C:8
TString run_quality_name(int run_quality)