StatisticOutput.hh 2.71 KB
/**
 * StatisticOutput.hh
 *
 *  Created on: 04 nov. 2014
 *      Author: AKKA
 */

#ifndef STATISTICOUTPUT_HH_
#define STATISTICOUTPUT_HH_

#include "ParamOutput.hh"
#include "StatisticProperties.hh"
#include "StatisticLogger.hh"
#include "StatisticProcess.hh"
#include "Catalog.hh"

#include <memory>

namespace AMDA {
namespace ParamOutputImpl {
namespace Statistic {

/**
 * @class StatisticOutput
 * @brief Implementation of a ParamOutput to apply statistic processes on parameters.
 * @details
 */
class StatisticOutput: public AMDA::Parameters::ParamOutput {
public:
	/*
	 * @brief Working structure to describe a process
	 */
	typedef struct {
		std::string _paramId;
		std::string _functionName;
		std::string _dataKey;
		std::string _coverageKey;
		int _index;
		std::shared_ptr<AMDA::Parameters::StatisticProcess> _statisticProcesSPtr;
	} ProcessDescription;

	/*
	 * @brief Constructor
	 */
	StatisticOutput(AMDA::Parameters::ParameterManager& pParameterManager);

	/*
	 * @brief Destructor
	 */
	virtual ~StatisticOutput();

	/**
	 * @overload DataClient::establishConnection()
	 */
	virtual void establishConnection();

	/*
	 * @brief Get properties of the statistic request
	 */
	StatisticProperties& getStatisticProperties()
	{
			return _statisticProperties;
	}

	/*
	 * @brief Set properties of the statistic request
	 */
	void setStatisticProperties(const StatisticProperties& statisticProperties)
	{
		_statisticProperties = statisticProperties;
	}

protected:
	/**
	 * @overload ParamOutput::init()
	 */
	virtual void init();

	/**
	 * @overload ParamOutput::apply()
	 */
	virtual void apply();

private:
	/*
	 * @brief apply one file output structure
	 */
	void applyOneFile(bool isFirstInterval);

	/*
	 * @brief apply one file per parameter output structure
	 */
	void applyOneFilePerParameter(bool isFirstInterval);

	/*
	 * @brief Init a catalog if need
	 */
	void initCatalog(std::string paramId);

	/*
	 * @brief Get catalog name
	 */
	std::string getCatalogName(std::string paramId);

	/*
	 * @brief Add a process description in catalog
	 */
	void addProcessDescriptionInCatalog(TimeTableCatalog::Catalog* pCatalog, ProcessDescription* pProcDesc);

	/**
	 * Statistic properties
	 */
	StatisticProperties _statisticProperties;

	/*
	 * @brief Index of current interval
	 */
	int _currentIntervalIndex;

	/*
	 * @brief List of process description
	 */
	std::vector<ProcessDescription> _processDescriptionList;

	/*
	 * @brief Map of catalog used to write statistic results.
	 * The key is the paramId or, for output structure ONE-FILE, an empty string
	 */
	std::map<std::string,TimeTableCatalog::Catalog> _statisticCatalogMap;
};

} /* namespace Statistic */
} /* namespace ParamOutputImpl */
} /* namespace AMDA */

#endif /* STATISTICOUTPUT_HH_ */