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 ";
1009 strCondition +=
"run_type ";
1012 strCondition +=
"run_quality ";
1016 cout <<
"ERROR: the column in the search condition was not defined, the condition is skipped" << endl;
1022 strCondition +=
"< ";
1025 strCondition +=
"<= ";
1028 strCondition +=
"= ";
1031 strCondition +=
"<> ";
1034 strCondition +=
"> ";
1037 strCondition +=
">= ";
1040 strCondition +=
"like ";
1043 strCondition +=
"is null ";
1046 strCondition +=
"is not null ";
1049 cout <<
"ERROR: the comparison operator in the search condition was not defined, the condition is "
1077 cout <<
"ERROR: the value type in the search condition was not found, the condition is skipped" << endl;
1087 sql += strCondition;
1089 sql +=
" order by period_number,run_number";
1096 cout <<
"ERROR: getting runs from the Unified Condition Database has been failed" << endl;
1111 if (connRun ==
nullptr) {
1112 cout <<
"ERROR: the connection to the Unified Condition Database for the selected run was failed" << endl;
1118 int tmp_period_number;
1119 tmp_period_number = stmt->
GetInt(0);
1121 tmp_run_number = stmt->
GetInt(1);
1123 tmp_run_type = stmt->
GetInt(2);
1125 tmp_start_datetime = stmt->
GetDatime(3);
1128 tmp_end_datetime =
nullptr;
1134 tmp_target_particle = stmt->
GetString(6);
1137 tmp_energy =
nullptr;
1139 tmp_energy =
new double(stmt->
GetDouble(7));
1140 double* tmp_field_voltage;
1142 tmp_field_voltage =
nullptr;
1144 tmp_field_voltage =
new double(stmt->
GetDouble(8));
1145 int* tmp_event_count;
1147 tmp_event_count =
nullptr;
1149 tmp_event_count =
new int(stmt->
GetInt(9));
1150 int tmp_run_quality;
1151 tmp_run_quality = stmt->
GetInt(10);
1154 connRun, tmp_period_number, tmp_run_number, tmp_run_type, tmp_start_datetime, tmp_end_datetime,
1155 tmp_beam_particle, tmp_target_particle, tmp_energy, tmp_field_voltage, tmp_event_count, tmp_run_quality));
1167 search_conditions.
Add((
TObject*)&search_condition);
1181 if (!usePrevRunIfMissing)
1185 if (pRun ==
nullptr) {
1186 cout <<
"INFO: Trying to get the previous run number before " << period_number <<
":" << run_number <<
" run"
1189 if (res_prev_code != 0)
1191 cout <<
"INFO: The previous run number was defined: " << period_number <<
":" << run_number << endl;
1203 if (connDb ==
nullptr) {
1204 cout <<
"ERROR: connection to the Database was failed" << endl;
1210 TString sql =
"select period_number, run_number "
1212 if ((period_number > 0) and (run_number > 0))
1213 sql +=
TString::Format(
"where (period_number < %d) OR ((period_number = %d) AND (run_number < %d)) ",
1214 period_number, period_number, run_number);
1215 sql +=
"order by period_number desc, run_number desc "
1221 cout <<
"ERROR: getting previous run number from DB has been failed" << endl;
1232 cout <<
"ERROR: previous run was not found in the database" << endl;
1239 period_number = stmt->
GetInt(0);
1240 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
double * d_field_voltage
field voltage
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 (the condition stays owned by the caller)
UniConnection * connectionDB
connection to the database
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
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
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 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
int SetBeamParticle(TString beam_particle)
set beam particle of the current run
TDatime * ts_end_datetime
end datetime
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
int * i_event_count
event count
enumConditions GetCondition()
@ conditionGreaterOrEqual
unsigned int GetUIntValue()