4 TPRegexp re_datetime(
"^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
6 if (!re_datetime.
MatchB(datetime_string)) {
7 cout <<
"ERROR: wrong datetime format (\"yyyy-mm-dd hh:mm:ss\" is expected): " << datetime_string << endl;
10 datetime.
Set(datetime_string.
Data());
18 if (!isPeriodExists) {
20 if (pPeriod ==
nullptr) {
21 cout <<
"ERROR: creating the run period " << period_number <<
" failed" << endl;
24 cout <<
"The run period " << period_number <<
" was created: " << start_datetime.
AsSQLString() <<
" - "
30 cout <<
"WARNING: the run period " << period_number
31 <<
" already exists, its start and end times will be set to the given ones" << endl;
33 if (pPeriod ==
nullptr) {
34 cout <<
"ERROR: getting the run period " << period_number <<
" failed" << endl;
38 cout <<
"ERROR: updating start and end times of the run period " << period_number <<
" failed" << endl;
52 cout <<
"ERROR: checking existence of the run " << period_number <<
":" << run_number <<
" failed" << endl;
56 cout <<
"WARNING: the run " << period_number <<
":" << run_number <<
" already exists, it is skipped" << endl;
61 UniRun* pRun =
UniRun::CreateRun(period_number, run_number, 0, start_datetime, &end_datetime,
"",
"",
"",
nullptr,
63 if (pRun ==
nullptr) {
64 cout <<
"ERROR: creating the fictitious run " << period_number <<
":" << run_number <<
" failed" << endl;
67 cout <<
"The fictitious run " << period_number <<
":" << run_number <<
" has been created" << endl;
83 bool isCopySingleRunValues =
false)
86 if (connDb ==
nullptr) {
87 cout <<
"ERROR: connection to the UniConDa database failed" << endl;
93 TString::Format(
"from detector_parameter dp join parameter_ p on dp.parameter_id = p.parameter_id "
94 "where dp.expiry_date is null "
96 "and ((dp.start_period < %d) or ((dp.start_period = %d) and (dp.start_run <= %d))) "
97 "and ((dp.end_period > %d) or ((dp.end_period = %d) and (dp.end_run >= %d))) "
99 "and not exists (select 1 from detector_parameter np "
100 "where np.detector_name = dp.detector_name and np.parameter_id = dp.parameter_id "
101 "and np.value_key = dp.value_key and np.expiry_date is null "
102 "and not (((np.end_period < %d) or ((np.end_period = %d) and (np.end_run < %d))) or "
103 "((np.start_period > %d) or ((np.start_period = %d) and (np.start_run > %d))))) ",
104 prev_period, prev_period, prev_run, prev_period, prev_period, prev_run, period_number,
105 period_number, start_run, period_number, period_number, end_run);
106 if (!isCopySingleRunValues)
107 sql_source +=
"and not ((dp.start_period = dp.end_period) and (dp.start_run = dp.end_run)) ";
110 TString sql =
"select dp.detector_name, p.parameter_name, dp.value_key, dp.start_period, dp.start_run, "
111 "dp.end_period, dp.end_run, length(dp.parameter_value) "
112 + sql_source +
"order by dp.detector_name, p.parameter_name, dp.value_key";
116 cout <<
"ERROR: getting detector parameters valid for the previous run failed" << endl;
125 if (value_count == 0)
126 cout <<
"Detector parameter values to be copied to " << period_number <<
":" << start_run <<
" - "
127 << period_number <<
":" << end_run << endl;
130 << stmt->
GetLong64(7) <<
" bytes)" << endl;
135 if (value_count == 0) {
136 cout <<
"WARNING: there are no detector parameter values to be copied from the run " << prev_period <<
":"
144 "insert into detector_parameter "
145 "(detector_name, parameter_id, start_period, start_run, end_period, end_run, value_key, parameter_value) "
146 "select dp.detector_name, dp.parameter_id, %d, %d, %d, %d, dp.value_key, dp.parameter_value ",
147 period_number, start_run, period_number, end_run)
153 cout <<
"ERROR: copying detector parameters to the new period failed" << endl;
185 int end_run = 100000,
186 bool isCopySingleRunValues =
false,
187 bool isUpdateExistingPeriod =
false)
189 TDatime period_start, period_end;
193 cout <<
"ERROR: start time of the period must be less than its end time" << endl;
196 if (start_run >= end_run) {
197 cout <<
"ERROR: start run number must be less than the end run number" << endl;
203 if (period_exists < 0) {
204 cout <<
"ERROR: checking existence of the run period " << period_number <<
" failed" << endl;
207 if ((period_exists > 0) && !isUpdateExistingPeriod) {
208 cout <<
"WARNING: the run period " << period_number <<
" already exists, nothing is changed. "
209 <<
"Set isUpdateExistingPeriod to true to update the existing period" << endl;
214 int prev_period = period_number, prev_run = start_run;
216 cout <<
"ERROR: no previous run was found to copy parameters for the period " << period_number << endl;
219 cout <<
"Detector parameters valid for the run " << prev_period <<
":" << prev_run <<
" will be copied" << endl;
221 if (
create_run_period(period_number, period_start, period_end, period_exists > 0) != 0)
const char * AsSQLString() const
UInt_t Convert(Bool_t toGMT=kFALSE) const
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
virtual TSQLStatement * Statement(const char *, Int_t=100)
virtual const char * GetString(Int_t)
virtual Bool_t NextResultRow()=0
virtual Int_t GetNumAffectedRows()
virtual Int_t GetInt(Int_t)
virtual Long64_t GetLong64(Int_t)
virtual Bool_t Process()=0
virtual Bool_t StoreResult()=0
TSubString Strip(EStripType s=kTrailing, char c=' ') const
const char * Data() const
static TString Format(const char *fmt,...)
static UniConnection * Open()
TSQLServer * GetSQLServer()
UniRunPeriod.h Class for the table: run_period.
static UniRunPeriod * GetRunPeriod(int period_number)
get run period from the database
int SetEndDatetime(TDatime *end_datetime)
set end datetime of the current run period
static int CheckRunPeriodExists(int period_number)
check run period exists in the database: 1- true, 0 - false, <0 - database operation error
int SetStartDatetime(TDatime start_datetime)
set start datetime of the current run period
static UniRunPeriod * CreateRunPeriod(int period_number, TDatime start_datetime, TDatime *end_datetime)
add new run period to the database
UniRun.h Class for the table: run_.
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
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_...
static int CheckRunExists(int period_number, int run_number)
check run exists in the database: 1- true, 0 - false, <0 - database operation error
int create_run_period(int period_number, TDatime start_datetime, TDatime end_datetime, bool isPeriodExists)
int copy_detector_parameters(int period_number, int start_run, int end_run, int prev_period, int prev_run, bool isCopySingleRunValues=false)
int create_fictitious_run(int period_number, int run_number, TDatime start_datetime, TDatime end_datetime)
int prerun_create(int period_number, TString start_datetime, TString end_datetime, int start_run=1, int end_run=100000, bool isCopySingleRunValues=false, bool isUpdateExistingPeriod=false)
Main pre-run procedure to prepare metadata parameters for a new Run:
bool parse_datetime(TString datetime_string, TDatime &datetime)