BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
move_field_2_parameter.C
Go to the documentation of this file.
1// macro for moving magnetic field voltage from table RUN_ to parameter values
3void move_field_2_parameter(int period)
4{
5 UniqueRunNumber* run_numbers = nullptr;
6 int run_count = UniRun::GetRunNumbers(run_numbers, period, 1, period, 100000);
7 if (run_count <= 0)
8 return;
9
10 const char* detector_name = "magnet";
11 const char* parameter_name = "field_voltage";
12
13 for (int i = 0; i < run_count; i++) {
14 // get run time
15 UniRun* pRun = UniRun::GetRun(run_numbers[i].period_number, run_numbers[i].run_number);
16 if (pRun == nullptr) {
17 cout << "The function encountered with errors: no experimental run was found ("
18 << run_numbers[i].period_number << ":" << run_numbers[i].run_number << "). This run will be skipped!"
19 << endl;
20 continue;
21 }
22
23 double* field_voltage = pRun->GetFieldVoltage();
24 if (field_voltage == nullptr) {
25 cout << "No field current in the database for this run (" << run_numbers[i].period_number << ":"
26 << run_numbers[i].run_number << "). This run will be skipped!" << endl;
27 delete pRun;
28 continue;
29 }
30 delete pRun;
31
32 // check if magnet exists in the database
33 if (!UniDetector::CheckDetectorExists(detector_name)) {
34 UniDetector* pDetector = UniDetector::CreateDetector(detector_name, nullptr);
35 if (pDetector == nullptr) {
36 cout << "\nMacro finished with errors" << endl;
37 return;
38 }
39
40 cout << "The magnet was added to detectors in the database" << endl;
41 delete pDetector;
42 }
43
44 // check if 'field_current' parameter exists in the database
45 if (!UniParameter::CheckParameterExists(parameter_name)) {
46 UniParameter* pParameter = UniParameter::CreateParameter(parameter_name, DoubleType);
47 if (pParameter == nullptr) {
48 cout << "\nMacro finished with errors" << endl;
49 return;
50 }
51
52 cout << "The 'average_field_mv' parameter was added to the database" << endl;
53 delete pParameter;
54 }
55
56 // writing magnetic field current as parameter to the Unified Condition Database
57 DoubleValue dValue;
58 dValue.value = *field_voltage;
60 detector_name, parameter_name, run_numbers[i].period_number, run_numbers[i].run_number,
61 run_numbers[i].period_number, run_numbers[i].run_number, &dValue);
62 if (pDetectorParameter == nullptr) {
63 cout << "\nMacro finished with errors" << endl;
64 return;
65 }
66
67 cout << "Field current was written to the database (" << run_numbers[i].period_number << ":"
68 << run_numbers[i].run_number << ")" << endl;
69 delete pDetectorParameter;
70 }
71
72 delete run_numbers;
73 cout << "Macro finished successfully" << endl;
74}
75
76void print_parameter(int period)
77{
78 UniqueRunNumber* run_numbers = nullptr;
79 int run_count = UniRun::GetRunNumbers(run_numbers, period, 1, period, 100000);
80 if (run_count <= 0)
81 return;
82
83 const char* detector_name = "magnet";
84 const char* parameter_name = "field_current";
85
86 for (int i = 0; i < run_count; i++) {
88 detector_name, parameter_name, run_numbers[i].period_number, run_numbers[i].run_number);
89 if (pDetectorParameter == nullptr) {
90 cout << "No field current was found (" << run_numbers[i].period_number << ":" << run_numbers[i].run_number
91 << ")" << endl;
92 continue;
93 }
94
95 cout << "Field current for run " << run_numbers[i].period_number << ":" << run_numbers[i].run_number << " "
96 << ((DoubleValue*)pDetectorParameter->GetValue())->value << endl;
97 delete pDetectorParameter;
98 }
99
100 delete run_numbers;
101 cout << "Macro finished successfully" << endl;
102}
int i
Definition P4_F32vec4.h:22
int GetValue(vector< UniValue * > &parameter_value)
get value of detector parameter presented by an array
static UniDetectorParameter * GetDetectorParameter(int value_id)
get detector parameter from the database
static UniDetectorParameter * CreateDetectorParameter(TString detector_name, int parameter_id, int start_period, int start_run, int end_period, int end_run, int value_key, unsigned char *parameter_value, Long_t size_parameter_value, TDatime *expiry_date)
add new detector parameter to the database
UniDetector.h Class for the table: detector_.
Definition UniDetector.h:18
static int CheckDetectorExists(TString detector_name)
check detector exists in the database: 1- true, 0 - false, <0 - database operation error
static UniDetector * CreateDetector(TString detector_name, TString *detector_desc)
add new detector to the database
static UniParameter * CreateParameter(TString parameter_name, int parameter_type, bool is_array)
add new parameter to the database
static int CheckParameterExists(int parameter_id)
check parameter exists in the database: 1- true, 0 - false, <0 - database operation error
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
double * GetFieldVoltage()
get field voltage of the current run
Definition UniRun.h:121
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
Definition UniRun.cxx:804
@ DoubleType
void print_parameter(int period)
void move_field_2_parameter(int period)