Parameter.hh 8.27 KB
/**
 * Parameter.hh
 *
 *  Created on: 16 oct. 2012
 *      Author: AKKA IS
 */

#ifndef PARAMETER_HH_
#define PARAMETER_HH_

#include <set>
#include <string>
#include <map>

#include <boost/thread/future.hpp>
#include <boost/shared_ptr.hpp>

#include "DataWriter.hh"
#include "ParamDataIndexInfo.hh"
#include "TimeStamp.hh"

namespace AMDA {
    namespace Parameters {

        class Parameter;
        class ParamOutput;
        class ParamData;
        class DataClient;
        class ParameterManager;
        class ParamInterval;
        class CalibrationInfoWriter;

        typedef boost::shared_ptr<Parameter> ParameterSPtr;
        typedef boost::shared_ptr<ParamOutput> ParamOutputSPtr;
        typedef boost::shared_ptr<ParamData> ParamDataSPtr;
        typedef boost::shared_ptr<DataClient> DataClientSPtr;
        typedef boost::shared_ptr<DataWriter> DataWriterSPtr;

        struct SemiVariableTable {
            std::vector<std::string> tabHeader;
            std::map<std::string, std::vector<double>> tabValues;
            bool calculateBounds = true;
        };

        /**
         * AMDA::Parameters::Parameter
         */
        class Parameter {
        public:
            typedef std::set<ParameterSPtr> ParameterList;
            typedef std::list<CalibrationInfoWriter*> CalibrationInfoWriterList;
            typedef std::vector<double> InfoValues;
            typedef boost::shared_ptr<InfoValues> InfoValuesSPtr;
            typedef std::map<std::string, InfoValuesSPtr> InfoList;

            Parameter(ParameterManager& pParamMng, std::string idParam);

            virtual ~Parameter();

            // Get methods
            /**
             * Get ParamData for DataClient
             */
            ParamDataSPtr& getParamData(DataClient*);

            /**
             * get sampling value in sec
             */
            double getTimeResolution() {
                return _timeResolution;
            }

            /**
             * get gap threshold factor
             */
            double getGapThreshold() {
                return _gapThreshold;
            }

	    std::string getReferenceParameter() {
		return _referenceParameter;
	    }

            /**
             * @brief get  list of CalibrationInfoWriter
             */
            const CalibrationInfoWriterList& getCalibrationInfoWriterList() const {
                return _calibrationInfoWriterList;
            }

            CalibrationInfoWriterList& getCalibrationInfoWriterList() {
                return _calibrationInfoWriterList;
            }

            /**
             * Get additional information list.
             */
            const InfoList& getInfoList() const {
                return _infoList;
            }

            InfoList& getInfoList() {
                return _infoList;
            }

            // Set methods

            /**
             * Set the DataWriter to fill the ParamData
             */
            void setDataWriter(const DataWriterSPtr& dataWriter) {
                _dataWriter = dataWriter;
            }

            /**
             * set sampling value in sec
             */
            void setTimeResolution(double pTimeResolution) {
                _timeResolution = pTimeResolution;
            }

            /**
             * set gap threshold factor
             */
            void setGapThreshold(double pGapThreshold) {
                _gapThreshold = pGapThreshold;
            }

	    void setReferenceParameter(std::string& pReferenceParameter) {
		_referenceParameter = pReferenceParameter;
	    }

            /**
             * Add additional Information values.
             */
            void setInfoValues(std::string pInfoName, InfoValuesSPtr& pInfoValues) {
                _infoList.insert(std::pair<std::string, InfoValuesSPtr>(pInfoName, pInfoValues));
            }

            // Others methods

            void openConnection(DataClient *);
            void closeConnection(DataClient *);

            const std::string& getId() const {
                return _id;
            }

            const std::string& getInfoId() const {
                return _infoId;
            }

            void setInfoId(const std::string& infoId) {
                _infoId = infoId;
            }

            /**
             *@brief  get _dataWriter
             *@details can be a copy after establishConnection phase
             */
            DataWriterSPtr& getDataWriterTemplate() {
                return _dataWriter;
            }

            /**
             * @brief Place interval on existing or creates
             * @return the last time of all file object which can modify the type of ParamData of Parameter
             */
            TimeStamp init(DataClient* pDataClient, TimeIntervalListSPtr pTimeIntervalList);

            /**
             * @return nbData Available or 0 if no Data
             *  blocking operation
             */
            boost::shared_future<ParamDataIndexInfo> getAsync(DataClient * pClient);

            ParameterManager& getParameterManager() {
                return _parameterManager;
            }

            void addParameter(ParameterSPtr pParentParameter) {
                _parameterList.insert(pParentParameter);
            }

            ParameterList& getParameterList() {
                return _parameterList;
            }

            void delegateOtherTaskTo(ParameterSPtr& pParam);

            void setIsTableIndexParam(bool isTableIndexParam) {
                _isTableIndexParam = isTableIndexParam;
            }

            bool isTableIndexParam() {
                return _isTableIndexParam;
            }

	    void setTimeRestriction(double restriction) {
		_timeRestriction = restriction;
	    }

	    double getTimeRestriction() {
		return _timeRestriction;
	    }
            
                         std::string getNormalisation(){
                return _normalisation;
                
            }
            
            void setNormalisation(std::string normalisation){
                _normalisation = normalisation;
            }


        protected:

            typedef std::map<DataClient *, ParamInterval*> DataClientList;
            typedef std::vector<ParamInterval*> IntervalList;

        private:

            /**
             * Id of parameter (name of xml file)
             */
            std::string _id;

            /**
             * info id of parameter
             */
            std::string _infoId;

            /**
             * The implementation is responssable to get Data
             * This acquisition must be make by ParamGet to get data in base
             * or Process to computed data.
             */
            DataWriterSPtr _dataWriter;

            /**
             * an instance of parameter manager
             */
            ParameterManager& _parameterManager;

            /**
             *
             */
            ParameterList _parameterList;

            /**
             * Stored for each DataClient, information of this DataClient (startTime, IntTime, ...)
             */
            IntervalList _intervalList;

            /**
             * DataClient list , this data client used ParamData. For each DataClient, Parameter stored data of this client.
             * The client  subscribe via openConnection. after, it's put information via init method.
             */
            DataClientList _dataClientList
            /**
             * when ( _clientInitCall == _dataClientList.size())  _intervalList is activ
             */;
            unsigned int _clientInitCall;

            /**
             * ask sampling, give by xml parameter file
             */
            double _timeResolution;

            /**
             * ask gap threshold, give by xml parameter file
             */
            double _gapThreshold;

	    std::string _referenceParameter;

            /**
             * list of functor to write callibration info
             */
            CalibrationInfoWriterList _calibrationInfoWriterList;

            /**
             * List of additional information
             */
            InfoList _infoList;

            static bool _isTableIndexParam;


	    double _timeRestriction;
            
           std::string _normalisation;

        private:
            bool establishConnectionToDo;
        };

    } /* namespace Parameters */
} /* namespace AMDA */
#endif /* PARAMETER_HH_ */