27 double* field_voltage,
70 double* field_voltage,
75 if (connDb ==
nullptr)
80 TString sql =
TString::Format(
"insert into run_(period_number, run_number, run_type, start_datetime, end_datetime, "
81 "beam_particle, target_particle, energy, field_voltage, event_count, run_quality) "
82 "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)");
86 stmt->
SetInt(0, period_number);
87 stmt->
SetInt(1, run_number);
90 if (end_datetime ==
nullptr)
96 if (energy ==
nullptr)
100 if (field_voltage ==
nullptr)
104 if (event_count ==
nullptr)
107 stmt->
SetInt(9, *event_count);
108 stmt->
SetInt(10, run_quality);
112 cout <<
"ERROR: inserting new run to the Database has been failed" << endl;
120 int tmp_period_number;
121 tmp_period_number = period_number;
123 tmp_run_number = run_number;
125 tmp_run_type = run_type;
127 tmp_start_datetime = start_datetime;
129 if (end_datetime ==
nullptr)
130 tmp_end_datetime =
nullptr;
132 tmp_end_datetime =
new TDatime(*end_datetime);
134 tmp_beam_particle = beam_particle;
136 tmp_target_particle = target_particle;
138 if (energy ==
nullptr)
139 tmp_energy =
nullptr;
141 tmp_energy =
new double(*energy);
142 double* tmp_field_voltage;
143 if (field_voltage ==
nullptr)
144 tmp_field_voltage =
nullptr;
146 tmp_field_voltage =
new double(*field_voltage);
147 int* tmp_event_count;
148 if (event_count ==
nullptr)
149 tmp_event_count =
nullptr;
151 tmp_event_count =
new int(*event_count);
153 tmp_run_quality = run_quality;
155 return new UniRun(connDb, tmp_period_number, tmp_run_number, tmp_run_type, tmp_start_datetime, tmp_end_datetime,
156 tmp_beam_particle, tmp_target_particle, tmp_energy, tmp_field_voltage, tmp_event_count,
164 if (connDb ==
nullptr)
170 TString::Format(
"select period_number, run_number, run_type, start_datetime, end_datetime, beam_particle, "
171 "target_particle, energy, field_voltage, event_count, run_quality "
173 "where period_number = %d and run_number = %d",
174 period_number, run_number);
179 cout <<
"ERROR: getting run from the database has been failed" << endl;
191 cout <<
"ERROR: run was not found in the database" << endl;
198 int tmp_period_number;
199 tmp_period_number = stmt->
GetInt(0);
201 tmp_run_number = stmt->
GetInt(1);
203 tmp_run_type = stmt->
GetInt(2);
208 tmp_end_datetime =
nullptr;
214 tmp_target_particle = stmt->
GetString(6);
217 tmp_energy =
nullptr;
219 tmp_energy =
new double(stmt->
GetDouble(7));
220 double* tmp_field_voltage;
222 tmp_field_voltage =
nullptr;
224 tmp_field_voltage =
new double(stmt->
GetDouble(8));
225 int* tmp_event_count;
227 tmp_event_count =
nullptr;
229 tmp_event_count =
new int(stmt->
GetInt(9));
231 tmp_run_quality = stmt->
GetInt(10);
235 return new UniRun(connDb, tmp_period_number, tmp_run_number, tmp_run_type, tmp_start_datetime, tmp_end_datetime,
236 tmp_beam_particle, tmp_target_particle, tmp_energy, tmp_field_voltage, tmp_event_count,
244 if (connDb ==
nullptr)
251 "where period_number = %d and run_number = %d",
252 period_number, run_number);
257 cout <<
"ERROR: getting run from the database has been failed" << endl;
284 if (connDb ==
nullptr)
290 "where period_number = $1 and run_number = $2");
294 stmt->
SetInt(0, period_number);
295 stmt->
SetInt(1, run_number);
299 cout <<
"ERROR: deleting run from the dataBase has been failed" << endl;
315 if (connDb ==
nullptr)
321 TString::Format(
"select period_number, run_number, run_type, start_datetime, end_datetime, beam_particle, "
322 "target_particle, energy, field_voltage, event_count, run_quality "
328 cout <<
"ERROR: getting all 'runs' from the dataBase has been failed" << endl;
339 cout <<
"Table 'run_':" << endl;
341 cout <<
"period_number: ";
342 cout << (stmt->
GetInt(0));
343 cout <<
", run_number: ";
344 cout << (stmt->
GetInt(1));
345 cout <<
", run_type: ";
346 cout << (stmt->
GetInt(2));
347 cout <<
", start_datetime: ";
348 cout << (stmt->
GetDatime(3)).AsSQLString();
349 cout <<
", end_datetime: ";
354 cout <<
", beam_particle: ";
356 cout <<
", target_particle: ";
358 cout <<
", energy: ";
363 cout <<
", field_voltage: ";
368 cout <<
", event_count: ";
373 cout <<
", run_quality: ";
374 cout << (stmt->
GetInt(10));
388 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
395 "set period_number = $1 "
396 "where period_number = $2 and run_number = $3");
400 stmt->
SetInt(0, period_number);
406 cout <<
"ERROR: updating information about run has been failed" << endl;
421 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
428 "set run_number = $1 "
429 "where period_number = $2 and run_number = $3");
433 stmt->
SetInt(0, run_number);
439 cout <<
"ERROR: updating information about run has been failed" << endl;
454 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
462 "where period_number = $2 and run_number = $3");
466 stmt->
SetInt(0, run_type);
472 cout <<
"ERROR: updating information about run has been failed" << endl;
487 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
494 "set start_datetime = $1 "
495 "where period_number = $2 and run_number = $3");
505 cout <<
"ERROR: updating information about run has been failed" << endl;
520 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
527 "set end_datetime = $1 "
528 "where period_number = $2 and run_number = $3");
532 if (end_datetime ==
nullptr)
541 cout <<
"ERROR: updating information about run has been failed" << endl;
549 if (end_datetime ==
nullptr)
561 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
568 "set beam_particle = $1 "
569 "where period_number = $2 and run_number = $3");
579 cout <<
"ERROR: updating information about run has been failed" << endl;
594 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
601 "set target_particle = $1 "
602 "where period_number = $2 and run_number = $3");
612 cout <<
"ERROR: updating information about run has been failed" << endl;
627 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
635 "where period_number = $2 and run_number = $3");
639 if (energy ==
nullptr)
648 cout <<
"ERROR: updating information about run has been failed" << endl;
656 if (energy ==
nullptr)
668 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
675 "set field_voltage = $1 "
676 "where period_number = $2 and run_number = $3");
680 if (field_voltage ==
nullptr)
689 cout <<
"ERROR: updating information about run has been failed" << endl;
697 if (field_voltage ==
nullptr)
709 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
716 "set event_count = $1 "
717 "where period_number = $2 and run_number = $3");
721 if (event_count ==
nullptr)
724 stmt->
SetInt(0, *event_count);
730 cout <<
"ERROR: updating information about run has been failed" << endl;
738 if (event_count ==
nullptr)
750 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
757 "set run_quality = $1 "
758 "where period_number = $2 and run_number = $3");
762 stmt->
SetInt(0, run_quality);
768 cout <<
"ERROR: updating information about run has been failed" << endl;
783 cout <<
"Table 'run_'";
786 <<
". end_datetime: " << (
ts_end_datetime ==
nullptr ?
"nullptr" : (*ts_end_datetime).AsSQLString())
807 if (connDb ==
nullptr) {
808 cout <<
"ERROR: connection to the database was failed" << endl;
814 if (end_period == -1)
815 end_period = start_period;
817 "select period_number, run_number "
819 "where (not (((%d < period_number) or ((%d = period_number) and (%d <> -1) and (%d < run_number))) "
820 "or ((%d > period_number) or ((%d = period_number) and (%d > run_number))))) "
821 "order by period_number, run_number",
822 end_period, end_period, end_run, end_run, start_period, start_period, start_run);
827 cout <<
"ERROR: getting run numbers from the database has been failed" << endl;
836 vector<int> vecPeriods;
839 vecPeriods.push_back(stmt->
GetInt(0));
840 vecRuns.push_back(stmt->
GetInt(1));
846 int run_count = vecPeriods.size();
848 for (
int i = 0;
i < run_count;
i++) {
860 if (connDb ==
nullptr) {
861 cout <<
"ERROR: connection to the database was failed" << endl;
869 "order by period_number, run_number");
874 cout <<
"ERROR: getting run numbers from the database has been failed" << endl;
883 vector<int> vecPeriods;
886 vecPeriods.push_back(stmt->
GetInt(0));
887 vecRuns.push_back(stmt->
GetInt(1));
893 int run_count = vecPeriods.size();
895 for (
int i = 0;
i < run_count;
i++) {
911 if (connDb ==
nullptr)
916 TString sql(
"select period_number, run_number, field_voltage "
918 if ((period_number > 0) and (run_number > 0))
920 "where period_number < %d OR (period_number = %d and run_number < %d) and field_voltage is not NULL ",
921 period_number, period_number, run_number);
922 sql +=
"order by period_number desc, run_number desc "
928 cout <<
"ERROR: getting previous field_voltage from the database has been failed" << endl;
945 period_number = stmt->
GetInt(0);
946 run_number = stmt->
GetInt(1);
947 double field_voltage = stmt->
GetDouble(2);
952 return field_voltage;
961 if (connDb ==
nullptr) {
962 cout <<
"ERROR: connection to the Unified Condition Database was failed" << endl;
968 TString sql =
TString::Format(
"select period_number, run_number, run_type, start_datetime, end_datetime, "
969 "beam_particle, target_particle, energy, field_voltage, event_count, run_quality "
974 TIter next(&search_conditions);
981 strCondition +=
"run_number ";
984 strCondition +=
"period_number ";
988 strCondition +=
"lower(beam_particle) ";
991 strCondition +=
"lower(target_particle) ";
994 strCondition +=
"energy ";
997 strCondition +=
"start_datetime ";
1000 strCondition +=
"end_datetime ";
1003 strCondition +=
"event_count ";
1006 strCondition +=
"field_voltage ";
1010 cout <<
"ERROR: the column in the search condition was not defined, the condition is skipped" << endl;
1016 strCondition +=
"< ";
1019 strCondition +=
"<= ";
1022 strCondition +=
"= ";
1025 strCondition +=
"<> ";
1028 strCondition +=
"> ";
1031 strCondition +=
">= ";
1034 strCondition +=
"like ";
1037 strCondition +=
"is null ";
1040 strCondition +=
"is not null ";
1043 cout <<
"ERROR: the comparison operator in the search condition was not defined, the condition is "
1071 cout <<
"ERROR: the value type in the search condition was not found, the condition is skipped" << endl;
1081 sql += strCondition;
1083 sql +=
" order by period_number,run_number";
1090 cout <<
"ERROR: getting runs from the Unified Condition Database has been failed" << endl;
1105 if (connRun ==
nullptr) {
1106 cout <<
"ERROR: the connection to the Unified Condition Database for the selected run was failed" << endl;
1110 int tmp_period_number;
1111 tmp_period_number = stmt->
GetInt(0);
1113 tmp_run_number = stmt->
GetInt(1);
1115 tmp_run_type = stmt->
GetInt(2);
1117 tmp_start_datetime = stmt->
GetDatime(3);
1120 tmp_end_datetime =
nullptr;
1126 tmp_target_particle = stmt->
GetString(6);
1129 tmp_energy =
nullptr;
1131 tmp_energy =
new double(stmt->
GetDouble(7));
1132 double* tmp_field_voltage;
1134 tmp_field_voltage =
nullptr;
1136 tmp_field_voltage =
new double(stmt->
GetDouble(8));
1137 int* tmp_event_count;
1139 tmp_event_count =
nullptr;
1141 tmp_event_count =
new int(stmt->
GetInt(9));
1142 int tmp_run_quality;
1143 tmp_run_quality = stmt->
GetInt(10);
1146 connRun, tmp_period_number, tmp_run_number, tmp_run_type, tmp_start_datetime, tmp_end_datetime,
1147 tmp_beam_particle, tmp_target_particle, tmp_energy, tmp_field_voltage, tmp_event_count, tmp_run_quality));
1158 search_conditions.
Add((
TObject*)&search_condition);
1160 return Search(search_conditions);
1168 if (!usePrevRunIfMissing)
1172 if (pRun ==
nullptr) {
1173 cout <<
"INFO: Trying to get the previous run number before " << period_number <<
":" << run_number <<
" run"
1176 if (res_prev_code != 0)
1178 cout <<
"INFO: The previous run number was defined: " << period_number <<
":" << run_number << endl;
1190 if (connDb ==
nullptr) {
1191 cout <<
"ERROR: connection to the Database was failed" << endl;
1197 TString sql =
"select period_number, run_number "
1199 if ((period_number > 0) and (run_number > 0))
1200 sql +=
TString::Format(
"where (period_number < %d) OR ((period_number = %d) AND (run_number < %d)) ",
1201 period_number, period_number, run_number);
1202 sql +=
"order by period_number desc, run_number desc "
1208 cout <<
"ERROR: getting previous run number from DB has been failed" << endl;
1219 cout <<
"ERROR: previous run was not found in the database" << endl;
1226 period_number = stmt->
GetInt(0);
1227 run_number = stmt->
GetInt(1);
char * Form(const char *fmt,...)
virtual void SetOwner(Bool_t enable=kTRUE)
const char * AsSQLString() const
void Add(TObject *obj) override
virtual TSQLStatement * Statement(const char *, Int_t=100)
virtual const char * GetString(Int_t)
virtual Bool_t NextIteration()=0
virtual Bool_t NextResultRow()=0
virtual Bool_t SetString(Int_t, const char *, Int_t=256)
Bool_t SetDatime(Int_t, const TDatime &)
virtual Int_t GetInt(Int_t)
virtual Bool_t IsNull(Int_t)
virtual Bool_t SetDouble(Int_t, Double_t)
virtual Bool_t Process()=0
virtual Bool_t SetInt(Int_t, Int_t)
virtual Bool_t SetNull(Int_t)
virtual Double_t GetDouble(Int_t)
virtual Bool_t StoreResult()=0
const char * Data() const
static TString Format(const char *fmt,...)
static UniConnection * Open()
TSQLServer * GetSQLServer()
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...
static int PrintAll()
print all runs
void Print()
print information about current run
int i_run_number
run number
static UniRun * GetRun(int period_number, int run_number)
get run from the database
int SetEndDatetime(TDatime *end_datetime)
set end datetime of the current run
static TObjArray * Search(UniSearchCondition &search_condition)
get runs corresponding to the specified single condition and set owner for search_condition to kTRUE
int SetTargetParticle(TString target_particle)
set target particle of the current run
TObjArray * GetRawFiles()
get array of raw files (UniRawFile*) corresponding to the run (return nullptr if an error occured)
TString str_target_particle
target particle
TDatime ts_start_datetime
start datetime
int SetRunType(int run_type)
set run type of the current run
static int DeleteRun(int period_number, int run_number)
delete run from the database
double * d_field_voltage
field voltage
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 SetPeriodNumber(int period_number)
set period number of the current run
int i_run_quality
run quality
TDatime * ts_end_datetime
end datetime
UniRun(UniConnection *db_connect, int period_number, int run_number, int run_type, TDatime start_datetime, TDatime *end_datetime, TString beam_particle, TString target_particle, double *energy, double *field_voltage, int *event_count, int run_quality)
static UniRun * CreateRun(int period_number, int run_number, int run_type, TDatime start_datetime, TDatime *end_datetime, TString beam_particle, TString target_particle, double *energy, double *field_voltage, int *event_count, int run_quality)
add new run to the database
int SetEventCount(int *event_count)
set event count of the current run
int SetRunNumber(int run_number)
set run number of the current run
static double FindPreviousFieldVoltage(int &period_number, int &run_number)
get field voltage value if period_number > 0 and run_number > 0: from the closest previous run,...
static int FindPreviousRun(int &period_number, int &run_number)
get number of the closest run below the given one or return the latest run in the database if period_...
int * i_event_count
event count
int SetFieldVoltage(double *field_voltage)
set field voltage of the current run
int i_period_number
period number
int SetEnergy(double *energy)
set energy of the current run
int SetRunQuality(int run_quality)
set run quality of the current run
TString str_beam_particle
beam particle
UniConnection * connectionDB
connection to the database
int SetBeamParticle(TString beam_particle)
set beam particle of the current run
int SetStartDatetime(TDatime start_datetime)
set start datetime of the current run
static int CheckRunExists(int period_number, int run_number)
check run exists in the database: 1- true, 0 - false, <0 - database operation error
enumConditions GetCondition()
@ conditionGreaterOrEqual
unsigned int GetUIntValue()