ParamOutput.cc 2 KB
/**
 * ParamOutput.cc
 *
 *  Created on: 18 oct. 2012
 *      Author: AKKA IS
 */

#include "ParamOutput.hh"
#include "DicError.hh"

//#include "TimeTableCatalogFactory.hh"
//#include "TimeInterval.hh"

namespace AMDA {
namespace Parameters {

using namespace TimeTableCatalog;

log4cxx::LoggerPtr ParamOutput::_logger(log4cxx::Logger::getLogger("AMDA-Kernel.ParamOutput"));

ParamOutput::ParamOutput(ParameterManager& pParameterManager) : DataClient(),
		_samplingMode(""),
		_samplingValue(0.0),
		_gapThreshold(0.0),
		_parameterManager(pParameterManager)  {
}

ParamOutput::~ParamOutput() {
}

void ParamOutput::init(TimeIntervalListSPtr pTimeIntervalList) {
	// Separate short time interval.
	if (_samplingValue == 0) {
		LOG4CXX_WARN(_logger, "Sampling time is equal to 0. Time interval too short separation mechanism not taken into account");
	}

	_timeIntervalList.reset (new TimeIntervalList);
	_timeIntervalListTooSmall.reset (new TimeIntervalList);

	for(TimeIntervalList::iterator it = pTimeIntervalList->begin(); it != pTimeIntervalList->end(); ++it) {
		if ( (it->_stopTime - it->_startTime) < _samplingValue ) {
			_timeIntervalListTooSmall->push_back(*it);
		} else {
			_timeIntervalList->push_back(*it);
		}
	}

	_currentTimeInterval = _timeIntervalList->begin();

	// Update params time restrictions
	std::map<std::string, double> paramsTimeRestrictions = _parameterManager.getParamsTimeRestrictions();
	for (std::map<std::string, double>::iterator it = paramsTimeRestrictions.begin(); it != paramsTimeRestrictions.end(); ++it) {
		try {
			ParameterSPtr p = _parameterManager.getParameter(it->first);
			if (p != nullptr) {
				p->setTimeRestriction(it->second);
			}
		}
		catch (...) {
		}
	}

	init();
}

void ParamOutput::process() {
	apply();
}

void ParamOutput::terminate() {
	applyPostProcessing();
}


/**
 * @brief Search for a sampling time
 */
double getSamplingInTreeParameter (ParameterSPtr pParam) {
	return pParam->getDataWriterTemplate()->getMinSampling();
}

} /* namespace Parameters */
} /* namespace AMDA */