BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
TangoData.h
Go to the documentation of this file.
1/****************************************************************************
2 This interface can be used to get hardware detector data
3 from Tango (Slow Control System) database
4****************************************************************************/
5#ifndef TANGODATA_H
6#define TANGODATA_H 1
7
8#include "TDatime.h"
9#include "TObjArray.h"
10#include "TString.h"
11
12#include <vector>
13
14// type of the Tango parameter defined by the table of the Tango database where the parameter is stored
15// (values greater than 10 correspond to array parameters, i.e. several channels at every time point)
16// The current Tango database (PgSQL) contains only scalar parameters, the arrays are used in the old MySQL database
18{
19 Tango_Bool = 1, // boolean value (att_scalar_devboolean table)
20 Tango_Double = 2, // numeric value: double (att_scalar_devdouble table), e.g. GEM voltage (vmon_N), or
21 // integer (att_scalar_devshort, devlong, devlong64 and devstate tables), e.g. GEM
22 // channel power (pw_N) or device state; devstate value is the number of Tango
23 // DevState (0 - ON, 1 - OFF, 8 - FAULT, 11 - ALARM, 13 - UNKNOWN, see tango.idl)
24 Tango_Bool_Array = 11, // array of boolean values (att_array_devboolean table of the old MySQL database),
25 // e.g. GEM trips in old periods
26 Tango_Double_Array = 12 // array of double values (att_array_devdouble table of the old MySQL database)
27};
28
29// value(s) of the Tango parameter at a time point, i.e. one element of the Tango data array of TangoData
30// The time point is a transition to a new value: the value is valid up to the next time point
32{
33 public:
34 // parameter time
36 // parameter type
38 // parameter values for every channel (one value for a scalar parameter): bool_parameter_value is filled only for
39 // boolean parameters, double_parameter_value - for all the types (boolean values are stored as 0 and 1)
40 std::vector<bool> bool_parameter_value;
41 std::vector<double> double_parameter_value;
42
43 /** Default constructor **/
45 /** Initialization constructor **/
47 /** Copy constructor **/
49
50 /** Destructor **/
51 virtual ~TangoTimeParameter();
52
54};
55
56// time interval from start_time to end_time, e.g. an interval where a Tango parameter satisfies a condition
57// (result of TangoData::SearchTangoIntervals) or the time interval of a run
59{
60 public:
63
64 /** Default constructor **/
66
67 /** Initialization constructor **/
68 TangoTimeInterval(TDatime start_time_interval, TDatime end_time_interval);
69
70 /** Destructor **/
71 virtual ~TangoTimeInterval();
72
74};
75
76// class used to get hardware detector data from Tango database and to display results in console or graphs
77// An object stores the values of one Tango parameter (domain/member/attribute) for a time interval or a run range
78// as TObjArray of TangoTimeParameter objects (see GetTangoData), prints and draws them, calculates their average
79// values and searches the time intervals satisfying a condition; static functions work with a set of parameters,
80// e.g. all channels of the FHCal or GEM high voltage
81// NOTE: the last archived value is extended up to the end time, even if the archiving was stopped before it
83{
84 public:
85 // conditions for SearchTangoIntervals function comparing the parameter values with a numeric value
86 // (conditionLike, conditionNull and conditionNotNull are not supported)
99
100 /** Time Range Constructor: fill Tango data array according to the given parameters
101 * Tango database connection is defined in the 'tango_db_settings.h' file
102 * Parameters:
103 * start_date - time from which to start reading the parameter, format: "YYYY-MM-DD HH:MM:SS"
104 * (e.g. "2015-03-13 23:00:00")
105 * end_date - end time of reading the parameter, the same format (e.g. "2015-03-13 24:00:00")
106 * system_name - name of the system, i.e. Tango domain (e.g. "magnet", "fhcal" or "gem")
107 * parameter_name - name of hardware parameter stored in Tango, i.e. Tango attribute
108 * (e.g. "vch_2_1" for FHCal or "vmon_0" for GEM)
109 * member_name - name of the Tango member, i.e. device (e.g. "hv_1" for FHCal or "mod_0" for GEM),
110 * it can be given with the Tango family as "family/member" if the member name is not unique
111 * in the domain (e.g. "caen_232/mod_2" for CSC or "plane1_top/adcsc_7_temp" for FSD),
112 * empty string - the member is not used
113 **/
114 TangoData(const char* start_date,
115 const char* end_date,
116 const char* system_name,
117 const char* parameter_name,
118 const char* member_name = "",
119 int verbose = 0);
120
121 /** Run Range Constructor: fill Tango data array for the time interval from the start time of the first run
122 * to the end time of the last run of the given range (the gaps between runs are included)
123 * The run times are taken from the Unified Condition Database
124 * Parameters:
125 * period_number - period (session) number of the runs (e.g. 8)
126 * start_run - number of the first run of the range (e.g. 6000)
127 * end_run - number of the last run of the range (set equal to start_run to read a single run)
128 * system_name, parameter_name, member_name, verbose - the same as in the constructor above
129 * Use GetRunAverageTangoData() to average the parameter only over the time of the runs
130 **/
131 TangoData(int period_number,
132 int start_run,
133 int end_run,
134 const char* system_name,
135 const char* parameter_name,
136 const char* member_name = "",
137 int verbose = 0);
138 // empty destructor
139 virtual ~TangoData();
140
142
148 // period and run range set by the Run Range Constructor (-1 if the object was created for a time interval)
150 int GetStartRun() { return iStartRun; }
151 int GetEndRun() { return iEndRun; }
153 void SetUserName(TString user_name) { strUserName = user_name; }
155
156 // Function displays hardware data obtained from Tango, e.g. FHCal voltage in time interval, in console
158 // Function displays a set of "simple" parameters obtained from Tango, e.g. GEMs high voltages voltage, in console
159 static void PrintTangoArrayConsole(std::vector<TangoData*> vecTangoData);
160 // Function displays hardware vector data obtained from Tango, e.g. FHCal voltage in time interval, graphically as
161 // 2D Surface Graph Parameter: y_axis - label of Y axis
162 void PrintTangoDataSurface(const char* y_axis = "tango parameter");
163 // Function displays hardware vector data obtained from Tango, e.g. FHCal voltage in time interval, graphically as a
164 // set of Line Graphs Parameters: y_axis - label of Y axis, is3D - whether show in 3D view Returns: 0 - in case of
165 // the success, < 0 - if an error occured
166 // The values are drawn as steps: every value is held up to the time point of the next one
167 int PrintTangoDataMultiGraph(const char* y_axis = "parameter", bool is3D = false);
168 // Function displays a set of "simple" parameters obtained from Tango, e.g. GEMs high voltages voltage, graphically
169 // as a set of Line Graphs
170 // The values are drawn as steps: every value is held up to the time point of the next one
171 static int PrintTangoArrayMultiGraph(std::vector<TangoData*> vecTangoData,
172 const char* y_axis = "parameter",
173 bool is3D = false);
174 /** Function displays a set of "simple" parameters obtained from Tango, e.g. FHCal or GEM high voltages,
175 * graphically as 2D Surface (X - time, Y - channel, i.e. index of the parameter in the array, Z - parameter value)
176 * The time interval of the first parameter is divided into equal time bins, and every bin is filled with
177 * the time-weighted average value of the channel in the bin (every value is valid up to the next time point)
178 * Parameters:
179 * z_axis - label of Z axis (parameter values), y_axis - label of Y axis (channels)
180 * draw_option - draw option of the 2D histogram: "SURF1" - surface (default), "LEGO2" - columns,
181 * "COLZ" - 2D color map, etc.
182 * time_bins - number of the time bins
183 * Returns: 0 - in case of the success, < 0 - if an error occured
184 **/
185 static int PrintTangoArraySurface(std::vector<TangoData*> vecTangoData,
186 const char* z_axis = "parameter",
187 const char* y_axis = "channel",
188 const char* draw_option = "SURF1",
189 int time_bins = 100);
190
191 // Function calculates and returns average value for Tango data array (result vector with size > 1 is used in case
192 // of many channels)
193 std::vector<double> GetAverageTangoData();
194 // Function calculates and returns time-weighted average value for Tango data array only over the time of the runs,
195 // i.e. the gaps between runs are excluded (result vector with size > 1 is used in case of many channels)
196 // It is available only if the object was created by the Run Range Constructor
197 std::vector<double> GetRunAverageTangoData();
198
199 /** Function SearchTangoIntervals gets time intervals for defined condition on the parameter values
200 * (e.g. the intervals where a GEM channel was switched off: pw_N parameter, conditionEqual, value = 0)
201 * NOTE: it works only if channel count is constant during given time period
202 * Parameters:
203 * condition - condition of time interval sampling, default: conditionEqual (the possible list is presented above
204 * in 'enumConditions', except conditionLike, conditionNull and conditionNotNull)
205 * value - numeric value for the condition with which the comparison is performed, default: 1 (true);
206 * boolean values of the parameter are compared as 0 (false) and 1 (true)
207 * mapChannel - vector of integer values (map) to change the order of result TObjArray-s in the common result
208 * array, if, for example, channels go in a different sequence; nullptr - if not used
209 * Returns common TObjArray with TObjArray objects containing TangoTimeInterval for every channel
210 * (i.e. conditionally TObjArray<TObjArray<TangoTimeInterval*>>). If there are no intervals found, it returns
211 * an empty TObjArray with zero elements. In case of errors it returns nullptr
212 **/
214 double value = 1,
215 std::vector<int>* mapChannel = nullptr);
216 /** Function displays (in console) time intervals obtained from Tango for a defined condition
217 * Parameters:
218 * tango_intervals - TObjArray with TObjArray objects containing TangoTimeInterval objects obtained from
219 *'SearchTangoIntervals' function channel_name - name of the dimension to display on the screen, default: Channel
220 * isShowOnlyExists - if true, print only intervals which satisfy the condition (skip empty intervals)
221 **/
222 void PrintTangoIntervalConsole(TObjArray* tango_intervals,
223 TString channel_name = "Channel",
224 bool isShowOnlyExists = false);
225
226 private:
227 bool IsOldMySQL = false;
232 // period and run range, and time intervals of the runs (set only by the Run Range Constructor)
233 int iPeriodNumber = -1, iStartRun = -1, iEndRun = -1;
234 std::vector<TangoTimeInterval> vecRunIntervals;
235
236 // non-user function SetRunRangeDates sets strStartDate and strEndDate to the start time of the first run
237 // and the end time of the last run existing in the given run range of the period,
238 // and fills vecRunIntervals with the time intervals of the runs (runs without end time are skipped)
239 // The last successfully read run range is cached, so the objects for the same runs do not request the database
240 // Returns: 0 - in case of the success, < 0 - if an error occured
241 int SetRunRangeDates(int period_number, int start_run, int end_run);
242
243 // non-user function InitTangoData selects the Tango database (MySQL before 2020-03-25, PgSQL after)
244 // by the start date and fills the Tango data array
245 void InitTangoData();
246
247 // non-user function GetTimeWeightedAverage calculates average value for Tango data array over the given time
248 // intervals, where every value is weighted by the length of its validity period inside the intervals
249 // Returns empty vector in case of errors
250 std::vector<double> GetTimeWeightedAverage(const std::vector<TangoTimeInterval>& time_intervals);
251
252 // non-user function GetValuePeriod gets the time period where the value of the i-th Tango time point is valid:
253 // from its time point to the next one, the first value is also used from the start date (data_start),
254 // the last one - up to the end date (data_end)
255 void GetValuePeriod(int i, UInt_t data_start, UInt_t data_end, UInt_t& value_start, UInt_t& value_end);
256
257 // non-user function GetTangoParameter gets hardware data from the Tango database and write to the arrTangoData
258 // First, name of the target table with required parameter is extracted from the Tango Base Table,
259 // then required data are selected from the target table corresponding the given time interval.
260 // Returns: 0 - in case of the success, < 0 - if an error occured
261 int GetTangoParameter();
262
263 // delete Tango parameter
265
267};
268
269#endif
int i
Definition P4_F32vec4.h:22
unsigned int UInt_t
#define ClassDef(name, id)
TString strMemberName
Definition TangoData.h:228
TString GetEndDate()
Definition TangoData.h:144
TString GetSystemName()
Definition TangoData.h:145
void GetValuePeriod(int i, UInt_t data_start, UInt_t data_end, UInt_t &value_start, UInt_t &value_end)
int iStartRun
Definition TangoData.h:233
TString GetFullName()
int GetEndRun()
Definition TangoData.h:151
std::vector< double > GetAverageTangoData()
TString strParameterName
Definition TangoData.h:228
TObjArray * arrTangoData
Definition TangoData.h:230
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.
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()
std::vector< double > GetTimeWeightedAverage(const std::vector< TangoTimeInterval > &time_intervals)
int GetStartRun()
Definition TangoData.h:150
static void PrintTangoArrayConsole(std::vector< TangoData * > vecTangoData)
TString strEndDate
Definition TangoData.h:229
int SetRunRangeDates(int period_number, int start_run, int end_run)
std::vector< TangoTimeInterval > vecRunIntervals
Definition TangoData.h:234
void PrintTangoDataConsole()
void InitTangoData()
TString strStartDate
Definition TangoData.h:228
TString GetStartDate()
Definition TangoData.h:143
@ conditionLike
Definition TangoData.h:95
@ conditionGreaterOrEqual
Definition TangoData.h:94
@ conditionNull
Definition TangoData.h:96
@ conditionGreater
Definition TangoData.h:93
@ conditionLess
Definition TangoData.h:89
@ conditionLessOrEqual
Definition TangoData.h:90
@ conditionNotEqual
Definition TangoData.h:92
@ conditionNotNull
Definition TangoData.h:97
@ conditionEqual
Definition TangoData.h:91
int iEndRun
Definition TangoData.h:233
int GetTangoParameter()
void DeleteTangoParameter()
virtual ~TangoData()
bool IsOldMySQL
Definition TangoData.h:227
TString strUserName
Definition TangoData.h:228
void SetUserName(TString user_name)
Definition TangoData.h:153
void PrintTangoDataSurface(const char *y_axis="tango parameter")
TObjArray * GetTangoData()
Definition TangoData.h:141
TString strSystemName
Definition TangoData.h:228
int PrintTangoDataMultiGraph(const char *y_axis="parameter", bool is3D=false)
TString GetParameterName()
Definition TangoData.h:146
int iVerbose
Definition TangoData.h:231
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...
Definition TangoData.cxx:80
TString GetMemberName()
Definition TangoData.h:147
static int PrintTangoArrayMultiGraph(std::vector< TangoData * > vecTangoData, const char *y_axis="parameter", bool is3D=false)
TString GetUserName()
Definition TangoData.h:152
int GetPeriodNumber()
Definition TangoData.h:149
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:...
int iPeriodNumber
Definition TangoData.h:233
TangoTimeInterval()
Default constructor.
Definition TangoData.cxx:52
TDatime start_time
Definition TangoData.h:61
virtual ~TangoTimeInterval()
Destructor.
Definition TangoData.cxx:60
std::vector< bool > bool_parameter_value
Definition TangoData.h:40
Tango_Parameter_Type parameter_type
Definition TangoData.h:37
TangoTimeParameter()
Default constructor.
Definition TangoData.cxx:32
std::vector< double > double_parameter_value
Definition TangoData.h:41
TDatime parameter_time
Definition TangoData.h:35
virtual ~TangoTimeParameter()
Destructor.
Definition TangoData.cxx:50
Tango_Parameter_Type
Definition TangoData.h:18
@ Tango_Bool
Definition TangoData.h:19
@ Tango_Bool_Array
Definition TangoData.h:24
@ Tango_Double
Definition TangoData.h:20
@ Tango_Double_Array
Definition TangoData.h:26
Tango_Parameter_Type
Definition TangoData.h:18