82 const char* system_name,
83 const char* parameter_name,
84 const char* member_name,
110 const char* system_name,
111 const char* parameter_name,
112 const char* member_name,
157 if (start_run > end_run) {
158 cout <<
"ERROR: start run (" << start_run <<
") cannot be greater than end run (" << end_run <<
")" << endl;
167 cout <<
"Run range " << period_number <<
":" << start_run <<
"-" << end_run
168 <<
" (from the cache) corresponds"
175 int run_count =
UniRun::GetRunNumbers(run_numbers, period_number, start_run, period_number, end_run);
177 cout <<
"ERROR: getting run numbers from the Unified Database has been failed" << endl;
180 if (run_count == 0) {
181 delete[] run_numbers;
182 cout <<
"ERROR: there are no runs in the range " << period_number <<
":" << start_run <<
"-" << end_run
183 <<
" in the Unified Database" << endl;
190 for (
int i = 0;
i < run_count;
i++) {
193 if (pRun ==
nullptr) {
194 cout <<
"ERROR: run " << period_number <<
":" << run_number <<
" was not found in the Unified Database"
196 delete[] run_numbers;
206 if (run_end ==
nullptr) {
208 if (
i == run_count - 1) {
209 cout <<
"ERROR: there is no end time for the last run " << period_number <<
":" << run_number
210 <<
" in the Unified Database" << endl;
211 delete[] run_numbers;
215 cout <<
"WARNING: there is no end time for the run " << period_number <<
":" << run_number
216 <<
" in the Unified Database, it is excluded from the run time intervals" << endl;
219 if (
i == run_count - 1)
225 delete[] run_numbers;
230 cout <<
"Run range " << period_number <<
":" << first_run <<
"-" << last_run <<
" (" << run_count
247 cout <<
"Old MySQL Database is used to get Tango data" << endl;
249 cout <<
"PostgreSQL Database is used to get Tango data" << endl;
261 cout <<
"Input Start Date = " <<
strStartDate.Data() << endl;
263 cout <<
"Input End Date = " <<
strEndDate.Data() << endl;
265 cout <<
"ERROR: start datetime and end datetime should not be empty!" << endl;
269 cout <<
"ERROR: start date cannot be less than 2000 year" << endl;
276 start_date_new +=
" Europe/Moscow", end_date_new +=
" Europe/Moscow";
285 if (connDb ==
nullptr)
288 if (db_server ==
nullptr)
299 "SELECT att_conf_id, data_type "
300 "FROM att_conf ac join att_conf_data_type acdt on ac.att_conf_data_type_id = acdt.att_conf_data_type_id "
301 "WHERE family='%s' and name='%s' ",
306 "WHERE domain='%s' and name='%s' ",
312 if (slash_pos !=
kNPOS) {
316 if (family_name !=
"")
317 strStatement +=
TString::Format(
"and family = '%s' ", family_name.Data());
318 if (member_name !=
"")
320 strStatement +=
"ORDER BY att_conf_id";
324 cout <<
"Processing the following SQL request to get info on the Tango parameter:" << endl
325 << strStatement << endl;
328 cout <<
"ERROR: getting info on parameter from Tango has been failed: " <<
GetFullName() << endl;
335 cout <<
"ERROR: There is no Tango parameter '" <<
GetFullName() << endl;
343 <<
" detector" << endl;
349 int parameter_id = stmt_select->
GetInt(0);
353 cout <<
"WARNING: several Tango parameters correspond to '" <<
GetFullName()
354 <<
"', the first one is used. Specify the family in the member name as \"family/member\"" << endl;
358 cout <<
"Found Data Table name = " << table_name <<
". Parameter ID = " << parameter_id << endl;
365 if (table_name.
Contains(
"array_devdouble"))
367 else if (table_name.
Contains(
"array_devboolean"))
369 else if (table_name.
Contains(
"scalar_devdouble") || table_name.
Contains(
"scalar_devshort")
370 || table_name.
Contains(
"scalar_devlong") || table_name.
Contains(
"scalar_devstate"))
372 else if (table_name.
Contains(
"scalar_devboolean"))
375 cout <<
"ERROR: This Tango type is not supported: '" << table_name <<
"'" << endl;
380 TString array_columns = (par_type > 10) ?
", dim_x_r, dim_x_w, idx" :
"";
383 query_data =
"SELECT date_format(data_time, '%Y-%m-%d %H:%i:%S'), value_r" + array_columns +
" ";
387 "WHERE att_conf_id='%d' and ((data_time > '%s' and data_time <= '%s') "
388 "or (data_time = (SELECT max(data_time) FROM %s WHERE att_conf_id='%d' and data_time "
389 "<= '%s' and value_r is not null))) "
390 "and value_r is not null ",
391 table_name.
Data(), parameter_id, start_date_new.Data(), end_date_new.
Data(),
392 table_name.
Data(), parameter_id, start_date_new.Data());
402 const int search_window_sec = 24 * 3600;
405 TString prev_time_query =
TString::Format(
"SELECT data_time FROM %s WHERE att_conf_id='%d' and data_time <= "
406 "'%s' and value_r is not null ",
407 table_name.
Data(), parameter_id, start_date_new.Data());
409 "SELECT to_char(data_time, 'YYYY-MM-DD HH24:MI:SS.MS'), value_r%s "
410 "FROM ((SELECT data_time, value_r%s FROM %s "
411 "WHERE att_conf_id='%d' and value_r is not null and data_time = (SELECT COALESCE("
412 "(%sand data_time > '%s' ORDER BY data_time DESC LIMIT 1), "
413 "(%sORDER BY data_time DESC LIMIT 1)))) "
415 "(SELECT data_time, value_r%s FROM %s "
416 "WHERE att_conf_id='%d' and value_r is not null and data_time > '%s' and data_time <= '%s')) "
418 array_columns.
Data(), array_columns.
Data(), table_name.
Data(), parameter_id, prev_time_query.
Data(),
419 search_start_date.
Data(), prev_time_query.
Data(), array_columns.
Data(), table_name.
Data(), parameter_id,
420 start_date_new.Data(), end_date_new.
Data());
424 query_data +=
"ORDER BY data_time,idx";
426 query_data +=
"ORDER BY data_time";
429 cout <<
"Query data with the following SQL request:" << endl << query_data << endl;
430 stmt_select = db_server->
Statement(query_data);
432 cout <<
"ERROR: getting parameter values from Tango has been failed" << endl;
447 const char* pc_datetime = stmt_select->
GetString(0);
450 if ((cur_num == 0) && (strcmp(pc_datetime,
strStartDate) < 0))
455 i_par_len = stmt_select->
GetInt(2);
456 if (i_par_len == 0) {
457 cout <<
"ERROR: Parameter length cannot be equal 0" << endl;
463 int i_real_par_len = 1;
465 i_real_par_len = stmt_select->
GetInt(3);
466 if (i_real_par_len == 0) {
467 cout <<
"ERROR: Real parameter length cannot be equal 0" << endl;
475 for (
int ind = 0; ind < i_par_len; ind++) {
481 i_idx = stmt_select->
GetInt(4);
484 cout <<
"ERROR: idx should be equal index of the parameter array" << endl;
490 if (ind >= i_real_par_len)
496 bool b_val = (str_val ==
"t") || (str_val ==
"true") || (str_val.
Atoi() != 0);
501 double d_val = stmt_select->
GetDouble(1);
531 cout <<
"ERROR: Tango parameter has not been obtained" << endl;
535 int def_precision = cout.precision();
545 for (
int j = 0; j < par_length; j++)
547 cout <<
"" << endl << endl;
550 cout.precision(def_precision);
557 for (
const auto& tango_data : vecTangoData) {
558 cout <<
"The current parameter: " << tango_data->GetFullName() << endl;
559 tango_data->PrintTangoDataConsole();
589 return TString::Format(
"_t%d_%04d_%d_%04d", start_date.GetDate(), start_date.GetTime() / 100, end_date.
GetDate(),
605 TangoData *pFirst = vecTangoData.front(), *pLast = vecTangoData.back();
606 if (vecTangoData.size() == 1)
622 TangoData *pFirst = vecTangoData.front(), *pLast = vecTangoData.back();
623 if (vecTangoData.size() == 1)
632 title = pFirst->
GetFullName() +
" - " + pLast->GetFullName();
641 TString canvas_name = data_name +
"_" + view_name;
644 if (!isalnum(canvas_name[
i]))
645 canvas_name[
i] =
'_';
647 return new TCanvas(canvas_name, canvas_name, 800, 600);
655 cout <<
"ERROR: Tango parameter has not been obtained" << endl;
669 for (
int j = 0; j < par_length; j++) {
673 tango_graph->
SetPoint(
i * par_length + j, cur_time, j + 1, value);
677 tango_graph->
Draw(
"SURF1");
711 int n = graph.
GetN();
712 if ((n > 0) && (graph.
GetY()[n - 1] != y)) {
713 double previous_y = graph.
GetY()[n - 1];
726 cout <<
"ERROR: Tango parameter has not been obtained" << endl;
731 cout <<
"WARNING: There are no elements in the Tango array" << endl;
742 for (
int j = 0; j < par_length; j++) {
744 if ((color == 0) || (color == 10) || ((color > 16) && (color < 20)))
754 for (
int j = 0; j < par_length; j++) {
756 double x = is3D ? ((double)cur_time - start_time) / 3600 : cur_time;
764 for (
int j = 0; j < par_length; j++) {
765 tango_multi->
Add(&tango_graphs[j]);
814 if (vecTangoData.size() < 1) {
815 cout <<
"WARNING: There are no parameters in the specified array" << endl;
820 for (
const auto& current_parameter : vecTangoData) {
821 if ((current_parameter->GetTangoData() ==
nullptr) || (current_parameter->GetTangoData()->IsEmpty())) {
822 cout <<
"ERROR: There are no elements in the parameter (" << current_parameter->GetFullName() <<
")"
827 if ((((
TangoTimeParameter*)current_parameter->GetTangoData()->At(0))->double_parameter_value.size()) != 1) {
828 cout <<
"ERROR: the parameter " << current_parameter->GetFullName() <<
" must have single value" << endl;
834 int par_length = vecTangoData.size();
841 for (j = 0; j < par_length; j++) {
843 if ((color == 0) || (color == 10) || ((color > 16) && (color < 20)))
849 TString start_date = vecTangoData[0]->GetStartDate();
852 for (
const auto& current_parameter : vecTangoData) {
856 double x = is3D ? ((double)cur_time - start_time) / 3600 : cur_time;
865 for (j = 0; j < par_length; j++) {
866 tango_multi->
Add(&tango_graphs[j]);
925 const char* draw_option,
928 if (vecTangoData.size() < 1) {
929 cout <<
"WARNING: There are no parameters in the specified array" << endl;
933 cout <<
"ERROR: the number of time bins should be greater than 0" << endl;
938 for (
const auto& current_parameter : vecTangoData) {
939 if ((current_parameter->GetTangoData() ==
nullptr) || (current_parameter->GetTangoData()->IsEmpty())) {
940 cout <<
"ERROR: There are no elements in the parameter (" << current_parameter->GetFullName() <<
")"
945 if ((((
TangoTimeParameter*)current_parameter->GetTangoData()->At(0))->double_parameter_value.size()) != 1) {
946 cout <<
"ERROR: the parameter " << current_parameter->GetFullName() <<
" must have single value" << endl;
954 if (end_time <= start_time) {
955 cout <<
"ERROR: the end time should be greater than the start time of the parameters" << endl;
958 int channel_count = vecTangoData.size();
959 double bin_width = (double)(end_time - start_time) / time_bins;
964 TH2D* tango_hist =
new TH2D(
"tango_surface",
GetArrayTitle(vecTangoData), time_bins, start_time, end_time,
965 channel_count, -0.5, channel_count - 0.5);
968 vector<double> bin_sum(time_bins), bin_sec(time_bins);
969 for (
int j = 0; j < channel_count; j++) {
970 TangoData* current_parameter = vecTangoData[j];
974 fill(bin_sum.begin(), bin_sum.end(), 0);
975 fill(bin_sec.begin(), bin_sec.end(), 0);
977 UInt_t value_start, value_end;
978 current_parameter->
GetValuePeriod(
i, data_start, data_end, value_start, value_end);
982 int first_bin =
max(0, (
int)
floor(((
double)value_start - start_time) / bin_width));
983 int last_bin =
min(time_bins - 1, (
int)
floor(((
double)value_end - start_time) / bin_width));
984 for (
int b = first_bin; b <= last_bin; b++) {
985 double bin_start = start_time + b * bin_width, bin_end = bin_start + bin_width;
986 double overlap =
min((
double)value_end, bin_end) -
max((
double)value_start, bin_start);
989 bin_sum[b] += value * overlap;
990 bin_sec[b] += overlap;
994 for (
int b = 0; b < time_bins; b++)
996 tango_hist->
SetBinContent(b + 1, j + 1, bin_sum[b] / bin_sec[b]);
1000 TString view_name(draw_option);
1032 tango_hist->
Draw(draw_option);
1041 vector<double> result;
1043 cout <<
"ERROR: Tango parameter has not been obtained" << endl;
1048 cout <<
"strStartDateAvg = " <<
strStartDate.Data() << endl;
1050 cout <<
"strEndDateAvg = " <<
strEndDate.Data() << endl;
1056 for (
int i = 0;
i < time_count;
i++) {
1067 for (
size_t j = 0; j < result.size(); j++)
1068 result[j] /= time_count;
1084 cout <<
"ERROR: Tango parameter has not been obtained" << endl;
1085 return vector<double>();
1088 cout <<
"ERROR: there are no run time intervals, the object should be created by the Run Range Constructor"
1090 return vector<double>();
1103 vector<double> result;
1105 if (time_count == 0) {
1106 cout <<
"ERROR: there are no elements in the Tango array" << endl;
1111 result.assign(channel_count, 0);
1113 double total_sec = 0;
1114 for (
int i = 0;
i < time_count;
i++) {
1117 cout <<
"ERROR: channel count of the Tango parameter is not constant during the time interval" << endl;
1122 UInt_t value_start, value_end;
1126 for (
const auto& time_interval : time_intervals) {
1127 UInt_t overlap_start =
max(value_start, time_interval.start_time.Convert());
1128 UInt_t overlap_end =
min(value_end, time_interval.end_time.Convert());
1129 if (overlap_end <= overlap_start)
1132 UInt_t sec = overlap_end - overlap_start;
1133 for (
size_t j = 0; j < channel_count; j++)
1139 if (total_sec == 0) {
1140 cout <<
"ERROR: the total time of the intervals for the average value is equal 0" << endl;
1145 cout <<
"Total time of " << time_intervals.size() <<
" interval(s) used for the average value = " << total_sec
1148 for (
size_t j = 0; j < channel_count; j++)
1149 result[j] /= total_sec;
1160 value_end = data_end;
1161 if ((
i == 0) && (data_start < value_start))
1162 value_start = data_start;
1183 cout <<
"ERROR: Tango parameter has not been obtained" << endl;
1187 cout <<
"ERROR: comparison operator in the searching of intervals is not supported" << endl;
1196 if (time_count == 0)
1197 return pTimeIntervals;
1201 for (
size_t j = 0; j < channel_count; j++) {
1204 pTimeIntervals->
Add(pChannel);
1208 auto AddInterval = [&](
size_t j,
TDatime start_interval,
TDatime end_interval) {
1209 int real_channel = j;
1210 if (mapChannel !=
nullptr) {
1211 if (mapChannel->size() > j) {
1212 real_channel = mapChannel->at(j);
1214 cout <<
"CRITICAL WARNING: Tango array size is less than the corrected channel: " << real_channel
1219 cout <<
"CRITICAL WARNING: map channel size is less than the current channel: " << j << endl;
1224 auto GetStartTime = [&](
int start_i) {
1230 return start_interval;
1234 vector<int> vecStart(channel_count, -1);
1235 for (
int i = 0;
i < time_count;
i++) {
1238 cout <<
"ERROR: channel count of the Tango parameter is not constant during the time interval" << endl;
1239 delete pTimeIntervals;
1244 for (
size_t j = 0; j < channel_count; j++) {
1246 bool isCondition =
false;
1247 switch (condition) {
1249 isCondition = cur_value < value;
1252 isCondition = cur_value <= value;
1255 isCondition = cur_value == value;
1258 isCondition = cur_value != value;
1261 isCondition = cur_value > value;
1264 isCondition = cur_value >= value;
1272 if (vecStart[j] < 0)
1276 else if (vecStart[j] >= 0)
1279 TDatime end_interval(uiEndTime - 1);
1283 AddInterval(j, GetStartTime(vecStart[j]), end_interval);
1291 for (
size_t j = 0; j < channel_count; j++)
1292 if (vecStart[j] >= 0)
1293 AddInterval(j, GetStartTime(vecStart[j]), end_time);
1295 return pTimeIntervals;
1309 if (!isShowOnlyExists)
1310 cout << channel_name.
Data() <<
" " <<
i <<
":" << endl
1311 <<
" No intervals correspond to the specified conditions" << endl;
1314 cout << channel_name.
Data() <<
" " <<
i <<
":" << endl;
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
R__EXTERN TRandom * gRandom
static int cached_end_run
const char *const TANGO_DB_USERNAME_b2020
static TString GetRangeSuffix(TangoData *pTangoData)
static TString cached_end_date
const char *const TANGO_DB_NAME_b2020
const char *const TANGO_DB_PASSWORD_b2020
static void AddStepPoint(TGraph &graph, double x, double y)
const char *const TANGO_DB_HOST_b2020
static TString GetArrayDataName(vector< TangoData * > &vecTangoData)
static TString GetArrayTitle(vector< TangoData * > &vecTangoData)
static TString cached_start_date
static TString GetSourceName(TangoData *pTangoData)
static TString GetDataName(TangoData *pTangoData)
static vector< TangoTimeInterval > cached_run_intervals
static int cached_start_run
static TCanvas * CreateTangoCanvas(TString data_name, TString view_name)
virtual void SetTitleOffset(Float_t offset=1)
virtual void SetLabelSize(Float_t size=0.04)
virtual void SetLabelOffset(Float_t offset=0.005)
virtual void SetNdivisions(Int_t n1, Int_t n2, Int_t n3, Bool_t optim=kTRUE)
virtual void SetLineWidth(Width_t lwidth)
virtual void SetLineColor(Color_t lcolor)
virtual void SetRightMargin(Float_t rightmargin)
virtual void SetTimeOffset(Double_t toffset, Option_t *option="local")
void CenterLabels(Bool_t center=kTRUE)
virtual void SetTimeDisplay(Int_t value)
void CenterTitle(Bool_t center=kTRUE)
virtual void SetTimeFormat(const char *format="")
virtual void SetOwner(Bool_t enable=kTRUE)
const char * AsSQLString() const
UInt_t Convert(Bool_t toGMT=kFALSE) const
void SetTitle(const char *title="") override
virtual void SetPoint(Int_t point, Double_t x, Double_t y, Double_t z)
void Draw(Option_t *option="P0") override
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
void SetTitle(const char *title="") override
static void AddDirectory(Bool_t add=kTRUE)
void Draw(Option_t *option="") override
virtual void SetMinimum(Double_t minimum=-1111)
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
static Bool_t AddDirectoryStatus()
virtual void SetStats(Bool_t stats=kTRUE)
void SetBinContent(Int_t bin, Double_t content) override
void SetMargin(Float_t margin)
virtual void Add(TGraph *graph, Option_t *chopt="")
void Draw(Option_t *chopt="") override
virtual void SetTitle(const char *title="")
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
void Add(TObject *obj) override
TLegend * BuildLegend(Double_t x1=0.3, Double_t y1=0.21, Double_t x2=0.3, Double_t y2=0.21, const char *title="", Option_t *option="") override
void Modified(Bool_t flag=true) override
const char * GetDB() const
virtual TSQLResult * GetTables(const char *dbname, const char *wild=nullptr)=0
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 Bool_t Process()=0
virtual Double_t GetDouble(Int_t)
virtual Bool_t StoreResult()=0
const char * Data() const
static TString Format(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TSQLServer * GetSQLServer()
static TangoConnection * Open()
void GetValuePeriod(int i, UInt_t data_start, UInt_t data_end, UInt_t &value_start, UInt_t &value_end)
std::vector< double > GetAverageTangoData()
TObjArray * SearchTangoIntervals(enumConditions condition=conditionEqual, double value=1, std::vector< int > *mapChannel=nullptr)
Function SearchTangoIntervals gets time intervals for defined condition on the parameter values (e....
std::vector< double > GetRunAverageTangoData()
static void PrintTangoArrayConsole(std::vector< TangoData * > vecTangoData)
int SetRunRangeDates(int period_number, int start_run, int end_run)
void PrintTangoDataConsole()
@ conditionGreaterOrEqual
std::vector< double > GetTimeWeightedAverage(const std::vector< TangoTimeInterval > &time_intervals)
void DeleteTangoParameter()
std::vector< TangoTimeInterval > vecRunIntervals
static int PrintTangoArraySurface(std::vector< TangoData * > vecTangoData, const char *z_axis="parameter", const char *y_axis="channel", const char *draw_option="SURF1", int time_bins=100)
Function displays a set of "simple" parameters obtained from Tango, e.g.
void PrintTangoDataSurface(const char *y_axis="tango parameter")
TObjArray * GetTangoData()
static int PrintTangoArrayMultiGraph(std::vector< TangoData * > vecTangoData, const char *y_axis="parameter", bool is3D=false)
int PrintTangoDataMultiGraph(const char *y_axis="parameter", bool is3D=false)
TString GetParameterName()
TangoData(const char *start_date, const char *end_date, const char *system_name, const char *parameter_name, const char *member_name="", int verbose=0)
Time Range Constructor: fill Tango data array according to the given parameters Tango database connec...
void PrintTangoIntervalConsole(TObjArray *tango_intervals, TString channel_name="Channel", bool isShowOnlyExists=false)
Function displays (in console) time intervals obtained from Tango for a defined condition Parameters:...
TangoTimeInterval()
Default constructor.
virtual ~TangoTimeInterval()
Destructor.
std::vector< double > double_parameter_value
Tango_Parameter_Type parameter_type
TangoTimeParameter()
Default constructor.
std::vector< bool > bool_parameter_value
virtual ~TangoTimeParameter()
Destructor.
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
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
RVec< PromoteType< T > > floor(const RVec< T > &v)