/* * ParameterData.hh * * Created on: 10 déc. 2013 * Author: CS */ #ifndef PARAMETERDATA_HH_ #define PARAMETERDATA_HH_ #include #include #include #include #include #include "ParameterIndexesTool.hh" namespace plot { /** * @brief Structure that holds a parameter component values. */ class ComponentParameterData { public: ComponentParameterData(); virtual ~ComponentParameterData(); /** * @brief Component min value. */ double _min; /** * @brief Component min strictly positive value (use to determine range of a logarithmic axis). */ double _minStrictPos; /** * @brief Component max value. */ double _max; /** * @brief Adds a value and updates min and max values. */ void addValue(double value_); /** * @brief Returns a pointer to the first component value at * given index (default is 0). */ double* getValues(int index_ = 0) { return &_values[index_]; } /** * Gets number of parameter values. */ size_t getNumberOfData(){ return _values.size(); } /* * @brief */ void preAllocate(int nbData); bool noData() { return _noData; } private: /** * @brief Values container */ std::vector _values; /** * @brief Flag used to know if the component have data */ bool _noData; }; /** * @brief Structure that holds parameter values by component */ class ParameterData { public: ParameterData(); virtual ~ParameterData(); /** * @brief Add a new time record to parameter */ void addTime(double time, double sampling, bool &gapDetected); /** * @brief Add a component value */ void addValue(double value_, AMDA::Common::ParameterIndexComponent& index_, bool gapDetected); /** * @brief Returns a pointer to the given component value * (index_) since from_ index. */ double* getValues(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1), int from_ = 0) { if (_values.empty()) return NULL; return _values[componentToValuesIndex(index_)].getValues(from_); } /** * @bried Return true when no data */ bool noData(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) { if (_values.empty()) return true; return _values[componentToValuesIndex(index_)].noData(); } /** * @brief */ double* getIntervalValues(double startTime, double stopTime, AMDA::Common::ParameterIndexComponent index_, int& startIndex, int& nbData) { nbData = 0; if (stopTime <= startTime) return NULL; startIndex = indexOf(startTime); int indexOfStopTime = indexOf(stopTime); int lastIndex; if (indexOfStopTime == -1) lastIndex = getSize() - 1; else { lastIndex = indexOfStopTime; if (_dates[lastIndex] > stopTime) lastIndex -= 1; } if (startIndex > lastIndex) return NULL; nbData = lastIndex - startIndex + 1; return getValues(index_, startIndex); } /** * @brief Returns minimum value of component. */ double getMin(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) { if (_values.empty()) return nan(""); return _values[componentToValuesIndex(index_)]._min; } /** * @brief Returns min strictly positive value (use to determine range of a logarithmic axis) */ double getMinStrictPos(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) { if (_values.empty()) return nan(""); return _values[componentToValuesIndex(index_)]._minStrictPos; } /** * @brief Returns maximum value of component. */ double getMax(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) { if (_values.empty()) return nan(""); return _values[componentToValuesIndex(index_)]._max; } int getSize() { return _dates.size(); } /** * @brief Returns a pointer to the first time equals or * just after a given time */ double* getTimes(double time_ = nan("")) { if (_dates.empty()) return NULL; return &_dates[indexOf(time_)]; } /* * @brief Get dim1 size */ int getDim1Size() { return _dim1Size; } /* * @brief Set dim1 size */ void setDim1Size(int dim1Size) { _dim1Size = dim1Size; } /* * @brief Get dim2 size */ int getDim2Size() { return _dim2Size; } /* * @brief Set dim2 size */ void setDim2Size(int dim2Size) { _dim2Size = dim2Size; } /* * @brief Get param gap size (in seconds) */ double getParamGapSize() { return _paramGapSize; } /* * @brief Set param gap size */ void setParamGapSize(double gapSize) { _paramGapSize = gapSize; } /** * Gets the index of the given time (or just after) in time array, * returns -1 if not found */ int indexOf(double time_); /** * @brief Computes an interpolated value at a given time */ double getInterpolatedValue (double atTime = nan(""), AMDA::Common::ParameterIndexComponent index = AMDA::Common::ParameterIndexComponent(-1,-1)); /* * @brief Reset ParamData */ void reset() { _values.clear(); _dates.clear(); _minTime = nan(""); _maxTime = nan(""); } /* * @brief */ void preAllocate(int nbData); /** * Dump properties, for TU */ void dump(std::ostream&, std::string& prefix_); /** * @brief List of component indexes, empty if scalar parameter */ std::vector _indexes; /** * @brief Min value time */ double _minTime; /** * @brief Max value time */ double _maxTime; protected: int componentToValuesIndex(AMDA::Common::ParameterIndexComponent index) { if ((index.getDim1Index() == -1) && (index.getDim2Index() == -1)) return 0; if (index.getDim2Index() == -1) return index.getDim1Index(); if (index.getDim1Index() == -1) return index.getDim2Index(); return index.getDim1Index() * _dim2Size + index.getDim2Index(); } private: /** * @brief Values container, by component */ std::vector _values; /** * @brief Dates container, synchronized with values container */ std::vector _dates; /* * @brief Dim 1 Size */ int _dim1Size; /* * @brief Dim 2 Size */ int _dim2Size; /* * @brief Param gap size (in seconds) */ double _paramGapSize; }; } /* namespace plot */ #endif /* PARAMETERDATA_HH_ */