21 bool isShowElog =
true,
22 bool isOnlyDifferent =
true)
26 if (pCurrentPeriod ==
nullptr) {
27 cout <<
"The function encountered with errors: no experimental period was found with number " << period_number
31 const string red(
"\033[0;91m"), orange(
"\033[0;33m"), cyan(
"\033[0;96m"), reset(
"\033[0m");
35 delete pCurrentPeriod;
36 if (period_end_time ==
nullptr) {
37 cout <<
"ERROR: there is no end time for Period " << period_number <<
"Exiting..." << endl;
46 int out_start_run_time = 0, no_end_time_run = 0, out_end_run_time = 0, no_field_elog = 0, diff_count = 0;
47 for (
int i = 0;
i < run_count;
i++) {
50 if (pRun ==
nullptr) {
51 cout <<
"The function encountered with errors: no experimental run was found ("
60 if ((startDate < period_start_time) || (startDate > (*period_end_time))) {
62 cout <<
"ERROR: the start time of the run is out of range: " << startDate.
AsSQLString() << endl;
68 if (endDate ==
nullptr) {
70 cout <<
"The function encountered with errors: no end datetime in the database for the run ("
77 if (((*endDate) < period_start_time) || ((*endDate) > (*period_end_time))) {
79 cout <<
"ERROR: the end time of the run is out of range: " << endDate->
AsSQLString() << endl;
91 cout <<
"The function encountered with errors: result Tango data is null (" << run_numbers[
i].
period_number
92 <<
":" << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl;
97 if (vec_average.empty()) {
98 cout <<
"The function encountered with errors: Tango data is empty or average value is wrong ("
106 double average_field = vec_average[0];
107 double average_current = average_field * 900 / 55.87;
108 double average_coeff = average_field / 55.87;
112 <<
" (number of time counts: " << data_count <<
")" << endl;
113 cout <<
"Average magnetic field from Tango: " << average_field <<
" mV" << endl;
114 cout <<
"Calculated current: " << average_current <<
" A (ratio: " << average_coeff <<
")" << endl << endl;
120 if (arrayRecords ==
nullptr) {
121 cout <<
"The function encountered with errors: no e-Log record was found (" << run_numbers[
i].
period_number
122 <<
":" << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl
126 int* pField =
nullptr;
130 if (pField !=
nullptr)
134 if (pField ==
nullptr) {
136 cout <<
"The function encountered with errors: no SP-41 field set in e-Log ("
144 double elog_voltage = (*pField) * 55.87 / 900;
148 bool isDifferent =
false;
149 if (
fabs(average_field - elog_voltage) > 5)
151 if ((isOnlyDifferent) && (!isDifferent)) {
157 cout <<
"Average Tango magnetic field: " << average_field <<
" mV (" << data_count <<
" counts)." << endl;
158 cout <<
"e-Log magnetic field: " << elog_voltage <<
" mV (" << (*pField) <<
" A)" << endl;
159 if (
fabs(average_field - elog_voltage) > 5) {
161 cout <<
"ERROR: e-Log and Tango magnetic fields differ by more than 5 mV!" << endl;
169 if (out_start_run_time > 0)
170 cout <<
"The start time of the run is out of range in " << out_start_run_time <<
" run(s)" << endl;
171 if (no_end_time_run > 0)
172 cout <<
"There is no end time in " << no_end_time_run <<
" run(s)" << endl;
173 if (out_end_run_time > 0)
174 cout <<
"The end time of the run is out of range in " << out_end_run_time <<
" run(s)" << endl;
175 if (no_field_elog > 0)
176 cout <<
"There is no field value (e-Log) in " << no_field_elog <<
" run(s)" << endl;
178 cout <<
"e-Log and Tango magnetic fields differ in " << diff_count <<
" run(s)" << endl;
182 cout <<
"Macro finished successfully" << endl;
191int show_field_graph(
int start_period = 8,
int start_run = 6866,
int end_period = -1,
int end_run = -1)
195 if (pStartRun ==
nullptr) {
196 cout <<
"Macro finished with errors: no experimental run was found - " << start_period <<
":" << start_run
197 <<
" (period:run)" << endl;
205 if ((end_period == -1) && (end_run == -1))
208 if (end_period == -1)
209 end_period = start_period;
213 if (pEndRun ==
nullptr) {
214 cout <<
"Macro finished with errors: no experimental run was found - " << end_period <<
":" << end_run
215 <<
" (period:run)" << endl;
223 if (endDate ==
nullptr) {
224 cout <<
"Macro finished with errors: no end datetime in the database for this run" << endl;
229 cout << endl <<
"Time interval: " << strStartDate <<
" - " << strEndDate << endl;
235 cout <<
"Macro finished with errors: return Tango data is null" << endl;
240 if (!vec_average.empty()) {
243 double average_field = vec_average[0];
244 double average_current = average_field * 900 / 55.87;
245 double average_coeff = average_field / 55.87;
247 cout <<
"Average magnetic field from Tango for the interval: " << average_field <<
" mV"
248 <<
" (number of counts: " << data_count <<
")" << endl;
249 cout <<
"Calculated current: " << average_current <<
" A (ratio: " << average_coeff <<
")" << endl << endl;
270 cout <<
"Macro finished with errors: return Tango data is null" << endl;
275 if (!vec_average.empty()) {
278 double average_field = vec_average[0];
279 double average_current = average_field * 900 / 55.87;
280 double average_coeff = average_field / 55.87;
282 cout <<
"Average magnetic field from TangoDB for the interval: " << average_field
283 <<
" mV. Calculated current: " << average_current <<
" A. Ratio: " << average_coeff
284 <<
". Number of counts: " << data_count << endl;
298 int end_run = 100000,
299 bool is_rewrite =
true,
300 float allowed_tolerance_pct = 10)
303 int run_count =
UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
308 for (
int i = 0;
i < run_count;
i++) {
311 if (pRun ==
nullptr) {
312 cout <<
"The function encountered with errors: no experimental run was found ("
322 if (endDate ==
nullptr) {
323 cout <<
"The function encountered with errors: no end datetime in the database ("
332 cout <<
"The function encountered with errors: run duration <= 1 seconds (" << run_numbers[
i].
period_number
333 <<
":" << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl;
340 cout <<
"The function encountered with errors: return data is null (" << run_numbers[
i].
period_number <<
":"
341 << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl;
346 if (vec_average.empty()) {
347 cout <<
"The function encountered with errors: Tango data is empty or average value is wrong ("
353 double average_field = vec_average[0];
357 <<
": " << average_field <<
" mV (" << data_count <<
" counts)." << endl;
362 cout <<
"Average magnetic field has been written to UniConDa" << endl << endl;
363 }
else if (is_rewrite) {
366 if ((cur_voltage_value == 0) and (average_field < 0.6))
367 cur_voltage_value = average_field;
368 double cur_tolerance_pct = std::abs(cur_voltage_value - average_field) / cur_voltage_value * 100;
369 if (cur_tolerance_pct > allowed_tolerance_pct) {
370 cout <<
"ERROR: admissible tolerance (" << allowed_tolerance_pct
371 <<
"%) is exceeded, the current voltage value = " << cur_voltage_value <<
" mV, run period from "
372 << strStartDate.
Data() <<
" to " << strEndDate.
Data() << endl
376 if (cur_tolerance_pct > 0.001)
377 cout <<
"ATTENTION: the current voltage value (" << cur_voltage_value
378 <<
" mV) will be rewritten with the new one within acceptable tolerance ("
379 << allowed_tolerance_pct <<
"%)" << endl;
381 cout <<
"Average magnetic field has been written to UniConDa" << endl << endl;
389 cout <<
"The count of exceeding the tolerance (skipped runs): " << error_count << endl;
392 cout <<
"Macro finished successfully" << endl;
400 int run_count =
UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
403 const string red(
"\033[0;91m"), orange(
"\033[0;33m"), cyan(
"\033[0;96m"), reset(
"\033[0m");
405 int no_elog_record = 0, no_field_elog = 0, no_field_uniconda = 0;
407 bool* run_error =
new bool[run_count];
408 for (
int i = 0;
i < run_count;
i++) {
413 if (arrayRecords ==
nullptr) {
416 cout <<
"The function encountered with errors: no e-Log record was found (" << run_numbers[
i].
period_number
417 <<
":" << run_numbers[
i].
run_number <<
"). This run will be skipped!" << endl
422 int* pField =
nullptr;
426 if (pField !=
nullptr)
429 if (pField ==
nullptr) {
432 cout <<
"The function encountered with errors: no SP-41 field was set in e-Log ("
439 double elog_voltage = (*pField) * 55.87 / 900;
444 if (pRun ==
nullptr) {
445 if (run_error[
i] == 1)
449 cout <<
"The function encountered with errors: no experimental run was found ("
457 if (avg_field ==
nullptr) {
459 if (run_error[
i] == 1)
463 cout <<
"The function encountered with errors: no magnet field in the BM@N database ("
469 double average_field = *avg_field;
472 cout <<
"Magnetic field current from e-Log: " << (*pField) <<
" A, " << elog_voltage <<
" mV" << endl;
473 cout <<
"Average magnetic field voltage from Tango: " << average_field <<
" mV" << endl << endl;
475 x.push_back(*pField);
476 y.push_back(average_field);
480 TCanvas* c1 =
new TCanvas(
"c1",
"U/I dependence", 100, 70, 700, 500);
494 cout <<
"p1 = " << par1 <<
". p1_error = " << err1 <<
". p0 = " << par0 <<
". p0_error = " << err0 << endl;
497 double* x2 =
new double[run_count];
498 double* y2 =
new double[run_count];
500 for (
int i = 0;
i < run_count;
i++) {
501 if (run_error[
i] == 0) {
503 y2[
i] = y[iter] - par1 * x[iter] - par0;
511 TCanvas* c2 =
new TCanvas(
"c2",
"The search for wrong field values", 200, 250, 1600, 600);
519 for (
int i = 0;
i < run_count;
i++) {
520 if (run_error[
i] != 0)
522 else if ((y2[
i] > 7) || (y2[
i] < -7))
529 if (no_elog_record > 0)
530 cout <<
"No e-Log record was found in " << no_elog_record <<
" run(s)" << endl;
531 if (no_field_elog > 0)
532 cout <<
"There is no field value (e-Log) in " << no_field_elog <<
" run(s)" << endl;
533 if (no_field_uniconda > 0)
534 cout <<
"There is no field value (UniConDa) in " << no_field_uniconda <<
" run(s)" << endl;
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...
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)