35 bool isShowElog =
true,
36 bool isOnlyDifferent =
true)
40 if (pCurrentPeriod ==
nullptr) {
41 cout <<
"The function encountered with errors: no experimental period was found with number " << period_number
48 delete pCurrentPeriod;
49 if (period_end_time ==
nullptr) {
50 cout <<
"ERROR: there is no end time for Period " << period_number <<
"Exiting..." << endl;
57 delete period_end_time;
62 int no_run = 0, out_start_run_time = 0, no_end_time_run = 0, out_end_run_time = 0, no_elog_record = 0,
63 no_field_elog = 0, no_tango_data = 0, diff_count = 0;
64 for (
int i = 0;
i < run_count;
i++) {
67 if (pRun ==
nullptr) {
69 cout <<
"The function encountered with errors: no experimental run was found ("
78 if ((startDate < period_start_time) || (startDate > (*period_end_time))) {
80 cout <<
"ERROR: the start time of the run is out of range: " << startDate.
AsSQLString() << endl;
86 if (endDate ==
nullptr) {
88 cout <<
"The function encountered with errors: no end datetime in the database for the run ("
95 if (((*endDate) < period_start_time) || ((*endDate) > (*period_end_time))) {
97 cout <<
"ERROR: the end time of the run is out of range: " << endDate->
AsSQLString() << endl;
111 if (arrayRecords ==
nullptr) {
113 cout <<
"The function encountered with errors: no e-Log record was found ("
115 <<
"). This run will be skipped!" << endl
119 int* pField =
nullptr;
123 if (pField !=
nullptr)
128 if (pField ==
nullptr) {
130 cout <<
"The function encountered with errors: no SP-41 field set in e-Log ("
132 <<
"). This run will be skipped!" << endl
136 elog_field = *pField;
144 cout <<
"The function encountered with errors: result Tango data is null (" << run_numbers[
i].
period_number
145 <<
":" << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl;
150 if (vec_average.empty()) {
152 cout <<
"The function encountered with errors: Tango data is empty or average value is wrong ("
160 double average_field = vec_average[0];
161 double average_current = average_field * 900 / 55.87;
162 double average_coeff = average_field / 55.87;
166 <<
" (number of time counts: " << data_count <<
")" << endl;
167 cout <<
"Average magnetic field from Tango: " << average_field <<
" mV" << endl;
168 cout <<
"Calculated current: " << average_current <<
" A (ratio: " << average_coeff <<
")" << endl << endl;
173 double elog_voltage = elog_field * 55.87 / 900;
174 bool isDifferent = (
fabs(average_field - elog_voltage) > 5);
175 if ((isOnlyDifferent) && (!isDifferent))
179 cout <<
"Average Tango magnetic field: " << average_field <<
" mV (" << data_count <<
" counts)." << endl;
180 cout <<
"e-Log magnetic field: " << elog_voltage <<
" mV (" << elog_field <<
" A)" << endl;
183 cout <<
"ERROR: e-Log and Tango magnetic fields differ by more than 5 mV!" << endl;
189 vector<pair<const char*, int>> skip_reasons = {{
"no run in UniConDa", no_run},
190 {
"the start time is out of the period", out_start_run_time},
191 {
"no end time in UniConDa", no_end_time_run},
192 {
"the end time is out of the period", out_end_run_time},
193 {
"no e-Log record", no_elog_record},
194 {
"no SP-41 field in e-Log", no_field_elog},
195 {
"no Tango data", no_tango_data}};
196 int skipped_count = 0;
197 for (
auto& reason : skip_reasons)
198 skipped_count += reason.second;
201 <<
"Summary for " << run_count <<
" runs (" << period_number <<
":" << run_numbers[0].
run_number <<
" - "
202 << period_number <<
":" << run_numbers[run_count - 1].
run_number <<
"):" << endl;
203 cout <<
TString::Format(
" %-48s %5d",
"processed runs", run_count - skipped_count) << endl;
204 cout <<
TString::Format(
" %-48s %5d",
"skipped runs", skipped_count) << endl;
205 for (
auto& reason : skip_reasons)
206 if (reason.second > 0)
207 cout <<
TString::Format(
" %-46s %5d", reason.first, reason.second) << endl;
209 cout <<
TString::Format(
" %-48s %5d",
"e-Log and Tango fields differ by more than 5 mV", diff_count) << endl;
212 delete[] run_numbers;
213 delete period_end_time;
214 cout <<
"Macro finished successfully" << endl;
223int show_field_graph(
int start_period = 8,
int start_run = 6866,
int end_period = -1,
int end_run = -1)
227 if (pStartRun ==
nullptr) {
228 cout <<
"Macro finished with errors: no experimental run was found - " << start_period <<
":" << start_run
229 <<
" (period:run)" << endl;
237 if ((end_period == -1) && (end_run == -1))
240 if (end_period == -1)
241 end_period = start_period;
245 if (pEndRun ==
nullptr) {
246 cout <<
"Macro finished with errors: no experimental run was found - " << end_period <<
":" << end_run
247 <<
" (period:run)" << endl;
255 if (endDate ==
nullptr) {
256 cout <<
"Macro finished with errors: no end datetime in the database for this run" << endl;
262 cout << endl <<
"Time interval: " << strStartDate <<
" - " << strEndDate << endl;
268 cout <<
"Macro finished with errors: return Tango data is null" << endl;
273 if (!vec_average.empty()) {
276 double average_field = vec_average[0];
277 double average_current = average_field * 900 / 55.87;
278 double average_coeff = average_field / 55.87;
280 cout <<
"Average magnetic field from Tango for the interval: " << average_field <<
" mV"
281 <<
" (number of counts: " << data_count <<
")" << endl;
282 cout <<
"Calculated current: " << average_current <<
" A (ratio: " << average_coeff <<
")" << endl << endl;
303 cout <<
"Macro finished with errors: return Tango data is null" << endl;
308 if (!vec_average.empty()) {
311 double average_field = vec_average[0];
312 double average_current = average_field * 900 / 55.87;
313 double average_coeff = average_field / 55.87;
315 cout <<
"Average magnetic field from TangoDB for the interval: " << average_field
316 <<
" mV. Calculated current: " << average_current <<
" A. Ratio: " << average_coeff
317 <<
". Number of counts: " << data_count << endl;
331 int end_run = 100000,
332 bool is_rewrite =
true,
333 float allowed_tolerance_pct = 10)
336 int run_count =
UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
341 int write_count = 0, new_count = 0, changed_count = 0;
342 vector<int> error_runs;
343 for (
int i = 0;
i < run_count;
i++) {
346 if (pRun ==
nullptr) {
347 cout <<
"The function encountered with errors: no experimental run was found ("
357 if (endDate ==
nullptr) {
358 cout <<
"The function encountered with errors: no end datetime in the database ("
370 cout <<
"The function encountered with errors: run duration <= 1 seconds (" << run_numbers[
i].
period_number
371 <<
":" << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl;
378 cout <<
"The function encountered with errors: return data is null (" << run_numbers[
i].
period_number <<
":"
379 << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl;
385 if (vec_average.empty()) {
386 cout <<
"The function encountered with errors: Tango data is empty or average value is wrong ("
393 double average_field = vec_average[0];
397 <<
": " << average_field <<
" mV (" << data_count <<
" counts)." << endl;
401 if (pCurrentVoltage ==
nullptr) {
403 cout <<
"Average magnetic field has been written to UniConDa" << endl << endl;
407 }
else if (is_rewrite) {
408 double cur_voltage_value = *pCurrentVoltage;
411 bool isSameValue = (std::abs(cur_voltage_value - average_field) <= std::abs(cur_voltage_value) * 0.00001);
413 if ((cur_voltage_value == 0) and (average_field < 0.6))
414 cur_voltage_value = average_field;
415 double cur_tolerance_pct = std::abs(cur_voltage_value - average_field) / cur_voltage_value * 100;
416 if (cur_tolerance_pct > allowed_tolerance_pct) {
417 cout <<
"ERROR: admissible tolerance (" << allowed_tolerance_pct
418 <<
"%) is exceeded, the current voltage value = " << cur_voltage_value <<
" mV, run period from "
419 << strStartDate.
Data() <<
" to " << strEndDate.
Data() << endl
421 error_runs.push_back(run_numbers[
i].run_number);
423 if (cur_tolerance_pct > 0.001)
424 cout <<
"ATTENTION: the current voltage value (" << cur_voltage_value
425 <<
" mV) will be rewritten with the new one within acceptable tolerance ("
426 << allowed_tolerance_pct <<
"%)" << endl;
428 cout <<
"Average magnetic field has been written to UniConDa" << endl << endl;
436 delete pCurrentVoltage;
440 cout <<
"The count of written values: " << write_count <<
" of " << run_count <<
" runs (new values: " << new_count
441 <<
", changed values: " << changed_count <<
", the same values: " << write_count - new_count - changed_count
443 if (!error_runs.empty()) {
444 cout <<
"The count of exceeding the tolerance (skipped runs): " << error_runs.size() <<
" (";
445 for (
size_t j = 0; j < error_runs.size(); j++)
446 cout << (j > 0 ?
", " :
"") << period_number <<
":" << error_runs[j];
450 delete[] run_numbers;
451 cout <<
"Macro finished successfully" << endl;
459 int run_count =
UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
464 int no_elog_record = 0, no_field_elog = 0, no_run = 0, no_field_uniconda = 0;
466 bool* run_error =
new bool[run_count];
467 for (
int i = 0;
i < run_count;
i++) {
472 if (arrayRecords ==
nullptr) {
475 cout <<
"The function encountered with errors: no e-Log record was found (" << run_numbers[
i].
period_number
476 <<
":" << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl
481 int* pField =
nullptr;
485 if (pField !=
nullptr)
488 if (pField ==
nullptr) {
491 cout <<
"The function encountered with errors: no SP-41 field was set in e-Log ("
498 int elog_field = *pField;
500 double elog_voltage = elog_field * 55.87 / 900;
505 if (pRun ==
nullptr) {
507 if (run_error[
i] == 1)
511 cout <<
"The function encountered with errors: no experimental run was found ("
519 if (avg_field ==
nullptr) {
521 if (run_error[
i] == 1)
525 cout <<
"The function encountered with errors: no magnet field in the BM@N database ("
531 double average_field = *avg_field;
535 cout <<
"Magnetic field current from e-Log: " << elog_field <<
" A, " << elog_voltage <<
" mV" << endl;
536 cout <<
"Average magnetic field voltage from Tango: " << average_field <<
" mV" << endl << endl;
538 x.push_back(elog_field);
539 y.push_back(average_field);
543 TCanvas* c1 =
new TCanvas(
"c1",
"U/I dependence", 100, 70, 700, 500);
557 cout <<
"p1 = " << par1 <<
". p1_error = " << err1 <<
". p0 = " << par0 <<
". p0_error = " << err0 << endl;
560 double* x2 =
new double[run_count];
561 double* y2 =
new double[run_count];
563 for (
int i = 0;
i < run_count;
i++) {
564 if (run_error[
i] == 0) {
566 y2[
i] = y[iter] - par1 * x[iter] - par0;
574 TCanvas* c2 =
new TCanvas(
"c2",
"The search for wrong field values", 200, 250, 1600, 600);
582 int deviation_count = 0;
583 for (
int i = 0;
i < run_count;
i++) {
584 if (run_error[
i] != 0)
586 else if ((y2[
i] > 7) || (y2[
i] < -7)) {
595 vector<pair<const char*, int>> skip_reasons = {{
"no e-Log record", no_elog_record},
596 {
"no SP-41 field in e-Log", no_field_elog},
597 {
"no run in UniConDa", no_run},
598 {
"no field value in UniConDa", no_field_uniconda}};
599 int skipped_count = 0;
600 for (
auto& reason : skip_reasons)
601 skipped_count += reason.second;
604 <<
"Summary for " << run_count <<
" runs (" << period_number <<
":" << run_numbers[0].
run_number <<
" - "
605 << period_number <<
":" << run_numbers[run_count - 1].
run_number <<
"):" << endl;
606 cout <<
TString::Format(
" %-48s %5d",
"compared runs", (
int)x.size()) << endl;
607 cout <<
TString::Format(
" %-48s %5d",
"skipped runs", skipped_count) << endl;
608 for (
auto& reason : skip_reasons)
609 if (reason.second > 0)
610 cout <<
TString::Format(
" %-46s %5d", reason.first, reason.second) << endl;
611 cout <<
TString::Format(
" %-48s %5d",
"runs deviating from the fit by more than 7 mV", deviation_count) << endl;
618 delete[] run_numbers;
friend F32vec4 fabs(const F32vec4 &a)
ElogRecord.h Class for the table: record_.
int * GetSp41()
get sp 41 of the current record
static TObjArray * GetRecords(int period_number, int run_number, int findNeighbourRun=0)
get array of ElogRecord-s for a given or a neighbour run (the same period) from the database if findN...
double Value(unsigned int i) const
virtual void SetMarkerStyle(Style_t mstyle=1)
virtual void SetBinLabel(Int_t bin, const char *label)
virtual void Set(Int_t nbins, const Double_t *xbins)
const char * AsSQLString() const
UInt_t Convert(Bool_t toGMT=kFALSE) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0)
void Draw(Option_t *chopt="") override
void SetTitle(const char *title="") override
virtual void SetTitle(const char *title="")
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
const char * Data() const
static TString Format(const char *fmt,...)
std::vector< double > GetAverageTangoData()
TObjArray * GetTangoData()
int PrintTangoDataMultiGraph(const char *y_axis="parameter", bool is3D=false)
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_.
static UniRun * GetRun(int period_number, int run_number)
get run from the database
TDatime * GetEndDatetime()
get end datetime of the current run
TDatime GetStartDatetime()
get start datetime of the current run
double * GetFieldVoltage()
get field voltage of the current run
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
int SetFieldVoltage(double *field_voltage)
set field voltage of the current run
int show_field_graph(int start_period=8, int start_run=6866, int end_period=-1, int end_run=-1)
Function to display magnetic field for a given time interval corresponding to the specified run range...
void write_avg_field_db(int period_number=9, int start_run=1, int end_run=100000, bool is_rewrite=true, float allowed_tolerance_pct=10)
Function to calculate and write Tango average magnetic field values for runs of the given period/sess...
int GetValueCount(TangoData &db_tango, const TString &end_date)
const char * parameter_name
int show_avg_field(int period_number=9, int start_run=8977, int end_run=9094, bool isShowElog=true, bool isOnlyDifferent=true)
Function to calculate and show average magnetic field values (voltage, mV) from Tango for runs of the...
int compare_avg_field(int period_number=9, int start_run=8977, int end_run=9094)