BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
run_beam_info.C
Go to the documentation of this file.
1// #define ScaleBorderInfo
2
3R__ADD_INCLUDE_PATH($VMCWORKDIR)
4#include "database/uni_db/examples/trigger/ir/GemRun6VetoSpills.C"
5
6// print summary information about beam spill for a given run in a period (or for a whole period)
7// if 'run' parameter is zero or absent then all runs in the period will be shown
8void run_beam_info(int period = 7,
9 int run = 0,
10 TString target = "",
11 TString txtfile_path = "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run6/summary.txt",
12 TString scheme_path = "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run6/spill_run6.xslt")
13// TString txtfile_path= "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run7/summary_corr_v2.txt",
14// TString scheme_path = "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run7/spill_run7_bmn.xslt")
15// TString txtfile_path= "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run7/SRC_Data.txt",
16// TString scheme_path = "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run7/spill_run7_src_full.xslt")
17{
18 // get spill info
19 UniParser parser;
20 vector<structParseValue*> parse_values;
21 vector<structParseSchema> vecElements;
22 int res_code = parser.ParseTxt2Struct(txtfile_path, scheme_path, parse_values, vecElements);
23 if (res_code != 0) {
24 cout << endl << "Macro finished with errors: parser error (" << res_code << ")" << endl;
25 exit(-1);
26 }
27
28 if (parse_values.size() < 1) {
29 cout << endl << "Macro finished with errors: there are no lines to parse" << endl;
30 exit(-2);
31 }
32
33 UniqueRunNumber* run_numbers = nullptr;
34 TObjArray* pRunArray = nullptr;
35 int run_count = 1;
36 // get all runs for the given period if run_number = 0
37 if (run == 0) {
38 if (target == "") {
39 run_count = UniRunPeriod::GetRunNumbers(run_numbers, period);
40 if (run_count <= 0) {
41 cout << endl << "Macro finished with errors: no runs exists in the given period #" << period << endl;
42 exit(-3);
43 }
44 } else {
45 // select only with a given condition, e.g. target particle
46 TObjArray arrayConditions;
47 arrayConditions.SetOwner(kTRUE);
48
51 arrayConditions.Add((TObject*)searchCondition);
52 searchCondition =
54 target); // one can choose any condition: beam, energy...
55 arrayConditions.Add((TObject*)searchCondition);
56
57 pRunArray = UniRun::Search(arrayConditions);
58 run_count = pRunArray->GetEntriesFast();
59 if (run_count <= 0) {
60 cout << endl << "Macro finished with errors: no runs exists for the given target: " << target << endl;
61 exit(-4);
62 }
63 arrayConditions.Delete();
64 }
65 }
66
67 int sum_size = parse_values[0]->arrValues.size();
68 vector<Long64_t> total_columns;
69 for (int i_total = 0; i_total < sum_size; i_total++)
70 total_columns.push_back(0);
71 // cycle for all runs to sum the spill data
72 for (int i = 0; i < run_count; i++) {
73 if (run_numbers != nullptr)
74 run = run_numbers[i].run_number;
75 if (pRunArray != nullptr)
76 run = ((UniRun*)pRunArray->At(i))->GetRunNumber();
77
78 // get run time
79 UniRun* pRun = UniRun::GetRun(period, run);
80 if (pRun == nullptr) {
81 cout << endl
82 << "Macro finished with errors: no experimental run was found " << period << " : " << run << " / "
83 << ((UniRun*)pRunArray->At(i))->GetRunNumber() << endl;
84 if (run_numbers != nullptr)
85 delete[] run_numbers;
86 if (pRunArray != nullptr)
87 delete pRunArray;
88 exit(-5);
89 }
90
91 TDatime dtStart = pRun->GetStartDatetime();
92 TDatime* dateEnd = pRun->GetEndDatetime();
93 if (dateEnd == nullptr) {
94 cout << "Macro finished with errors: no end datetime in the database for this run" << endl;
95 delete pRun;
96 if (run_numbers != nullptr)
97 delete[] run_numbers;
98 if (pRunArray != nullptr)
99 delete pRunArray;
100 exit(-6);
101 }
102 TDatime dtEnd = *dateEnd;
103 delete pRun;
104
105 // get veto spills to skip
106 int current_spill = -1;
107 vector<int> veto_spills;
108 if (period == 6)
109 veto_spills = GemRun6VetoSpills(run);
110
111 vector<Long64_t> sum_columns;
112 for (int i_sum = 0; i_sum < sum_size; i_sum++)
113 sum_columns.push_back(0);
114 structParseValue* stPrevious;
115 bool isFound = false;
116 // cycle for all spills to sum for the given run
117 for (int ind = 0; ind < parse_values.size(); ind++) {
118 structParseValue* st = parse_values.at(ind);
119 // cout<<"dtStart = "<<dtStart.AsSQLString()<<" : dtEnd = "<<dtEnd.AsSQLString()<<". st->dtSpillEnd =
120 // "<<st->dtSpillEnd.AsSQLString()<<endl;
121 if (st->dtSpillEnd >= dtEnd) {
122 current_spill++;
123 if (isFound) {
124 stPrevious = parse_values.at(ind - 1);
125
126 // check for veto spills
127 if (find(veto_spills.begin(), veto_spills.end(), current_spill) != veto_spills.end()) {
128 // cout<<"SKIPPED: "<<current_spill<<endl;
129 break;
130 }
131
132#ifdef ScaleBorderInfo
133 // scale values
134 int sec1 = st->dtSpillEnd.Convert() - stPrevious->dtSpillEnd.Convert();
135 int sec2 = dtEnd.Convert() - stPrevious->dtSpillEnd.Convert();
136 double sec_ratio = sec2 / sec1;
137 // increase sum for columns
138 for (int i_sum = 0; i_sum < sum_size; i_sum++)
139 sum_columns[i_sum] +=
140 TMath::Nint(boost::any_cast<int>(st->arrValues[i_sum]) * sec_ratio); // fix (Int_t)
141#else
142 // increase sum for columns
143 for (int i_sum = 0; i_sum < sum_size; i_sum++)
144 sum_columns[i_sum] += boost::any_cast<int>(st->arrValues[i_sum]); // fix (Int_t)
145#endif
146 }
147 break;
148 }
149
150 if (st->dtSpillEnd > dtStart) {
151 current_spill++;
152 if (ind > 0) {
153 stPrevious = parse_values.at(ind - 1);
154
155 if (!isFound) {
156 isFound = true;
157
158 // check for veto spills
159 if (find(veto_spills.begin(), veto_spills.end(), current_spill) != veto_spills.end()) {
160 // cout<<"SKIPPED: "<<current_spill<<endl;
161 continue;
162 }
163
164#ifdef ScaleBorderInfo
165 // scale values
166 int sec1 = st->dtSpillEnd.Convert() - stPrevious->dtSpillEnd.Convert();
167 int sec2 = st->dtSpillEnd.Convert() - dtStart.Convert();
168 double sec_ratio = sec2 / sec1;
169 // increase sum for columns
170 for (int i_sum = 0; i_sum < sum_size; i_sum++)
171 sum_columns[i_sum] +=
172 TMath::Nint(boost::any_cast<int>(st->arrValues[i_sum]) * sec_ratio); // fix (Int_t)
173#endif
174 }
175 }
176
177 // check for veto spills
178 if (find(veto_spills.begin(), veto_spills.end(), current_spill) != veto_spills.end()) {
179 // cout<<"SKIPPED: "<<current_spill<<endl;
180 continue;
181 }
182
183 // increase sum for columns
184 for (int i_sum = 0; i_sum < sum_size; i_sum++)
185 sum_columns[i_sum] += boost::any_cast<int>(st->arrValues[i_sum]); // fix (Int_t)
186 } // if (st->dtSpillEnd > dtStart)
187 } // for (int ind = 0; ind < parse_values.size(); ind++)
188
189 for (int i_sum = 0; i_sum < sum_size; i_sum++)
190 total_columns[i_sum] += sum_columns[i_sum];
191
192 // PRINT SUMS FOR ALL COLUMNS
193 cout << endl << "Run #" << run << " (" << dtStart.AsSQLString() << " - " << dtEnd.AsSQLString() << ")" << endl;
194 if (isFound) {
195 int count_column = 0;
196 for (vector<structParseSchema>::iterator it = vecElements.begin(); it != vecElements.end(); ++it) {
197 if (count_column >= sum_size)
198 break;
199
200 structParseSchema schema = *it;
201 if (schema.isSkip)
202 continue;
203
204 if (schema.vecRows[0].strStatementType == "int") {
205 if (count_column > 0)
206 cout << ", ";
207 cout << "sum(" << schema.vecRows[0].strColumnName << "): " << sum_columns[count_column];
208 count_column++;
209 } else {
210 if (schema.vecRows[0].strStatementType == "double") {
211 cout << "ERROR: type of the column is not supported: " << schema.vecRows[0].strStatementType
212 << endl;
213 exit(-7);
214 }
215 }
216 }
217 cout << endl;
218 } else
219 cout << "No spill data in the file!" << endl;
220 }
221
222 // PRINT TOTAL FOR ALL COLUMNS
223 if (run_count > 1) {
224 cout << endl << "Total count for all runs:" << endl;
225 int count_column = 0;
226 for (vector<structParseSchema>::iterator it = vecElements.begin(); it != vecElements.end(); ++it) {
227 if (count_column >= sum_size)
228 break;
229
230 structParseSchema schema = *it;
231 if (schema.isSkip)
232 continue;
233
234 if (schema.vecRows[0].strStatementType == "int") {
235 if (count_column > 0)
236 cout << ", ";
237 cout << "total(" << schema.vecRows[0].strColumnName << "): " << total_columns[count_column];
238 count_column++;
239 } else {
240 if (schema.vecRows[0].strStatementType == "double") {
241 cout << "ERROR: type of the column is not supported: " << schema.vecRows[0].strStatementType
242 << endl;
243 exit(-8);
244 }
245 }
246 }
247 cout << endl << endl;
248 }
249
250 // cleaning memory after work
251 if (run_numbers != nullptr)
252 delete[] run_numbers;
253 if (pRunArray != nullptr)
254 delete pRunArray;
255
256 cout << "Macro finished successfully" << endl;
257}
int i
Definition P4_F32vec4.h:22
constexpr Bool_t kTRUE
#define R__ADD_INCLUDE_PATH(PATH)
virtual void SetOwner(Bool_t enable=kTRUE)
const char * AsSQLString() const
UInt_t Convert(Bool_t toGMT=kFALSE) const
Int_t GetEntriesFast() const
void Delete(Option_t *option="") override
TObject * At(Int_t idx) const override
void Add(TObject *obj) override
int ParseTxt2Struct(TString txtName, TString schemaPath, vector< structParseValue * > &parse_values, vector< structParseSchema > &vecElements, int iVerbose=1)
static int GetRunNumbers(UniqueRunNumber *&run_numbers, int period_number)
get numbers of runs existing in the Database for a selected 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
static TObjArray * Search(UniSearchCondition &search_condition)
get runs corresponding to the specified single condition and set owner for search_condition to kTRUE
Definition UniRun.cxx:1155
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
Int_t Nint(T x)
void run_beam_info(int period=7, int run=0, TString target="", TString txtfile_path="$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run6/summary.txt", TString scheme_path="$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run6/spill_run6.xslt")
vector< structParseRow > vecRows
Definition UniParser.h:71
TDatime dtSpillEnd
Definition UniParser.h:92
vector< boost::any > arrValues
Definition UniParser.h:93