Blame view

src/InternLib/ProcessSamplingClassic.cc 3.71 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * ProcessSamplingClassic.cc
 *
 *  Created on: Dec 11, 2012
 *      Author: AKKA IS
 */
#include <stdlib.h>
#include <string>

#include "ProcessSamplingClassic.hh"
#include "Parameter.hh"
#include "ParameterManager.hh"
#include "ParameterCreatorFromExpression.hh"
#include "Resampling.hh"
#include "ParamMgr.hh"

using namespace std;
using namespace boost;
using namespace log4cxx;

namespace AMDA {
namespace Parameters {

ProcessSamplingClassic::ProcessSamplingClassic(Parameter &parameter) :
		SingleParamProcess_CRTP(parameter) {

}

ProcessSamplingClassic::ProcessSamplingClassic(const ProcessSamplingClassic& pProcess, Parameter &parameter)
: SingleParamProcess_CRTP(pProcess,parameter) {
}

ProcessSamplingClassic::~ProcessSamplingClassic() {
}

TimeStamp ProcessSamplingClassic::init() {
	//LOG4CXX_DEBUG(_logger, "BRE - ProcessSamplingClassic::init - 1");
	/// Init input parameter
	TimeStamp timeStamp = _parameterInput->init( this, _timeIntervalList);
	 /// Calibration information copy
	Parameter::InfoList lInfoList = _parameterInput->getInfoList();
	_parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end());
	_paramInput = _parameterInput->getParamData(this).get();


	//GET Sampling
	if (_attributList.size() != 2) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSamplingClassic required attributes: sampling and threshold")));
	}
	double sampling = atof(_attributList.begin()->c_str());
	if ( sampling == 0) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("Sampling must be different of 0")));
	}
	double threshold = atof((++(_attributList.begin()))->c_str());

c391ab45   Benjamin Renard   computedGapSize o...
56
	double newThreshold = threshold * _paramInput->getMinSampling() / sampling;
fbe3c2bb   Benjamin Renard   First commit
57
58
	double computedGapSize = _parameterInput->getParameterManager().getComputedGapSize(threshold, _paramInput->getMinSampling());

c391ab45   Benjamin Renard   computedGapSize o...
59
60
61
62
63
64
65
66
	if (computedGapSize < sampling) {
		//If computedGapSize < sampling, set computedGapSize to sampling value (else, each interval between data will be considered as a gap)
		newThreshold = 1;
		computedGapSize = sampling;
	}

	_parameter.setGapThreshold(newThreshold);

fbe3c2bb   Benjamin Renard   First commit
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
	// ProcessSamplingClassic _operation creation
	Resampling::CreateResampling lCreateResampling( *this, _timeIntervalList, sampling, computedGapSize, *_paramInput, _parameterInput->getDataWriterTemplate()->useNearestValue());
	_operation = lCreateResampling.getResampling();
	static_cast<Resampling::ResamplingAbstract*>(_operation)->init();

	/// Get result ParamData
	_paramData = ParamDataSPtr(_operation->getParamOutput());
	_paramData->setMinSampling(static_cast<Resampling::ResamplingAbstract*>(_operation)->getSampling());
	return timeStamp;
}

/**
 * @overload SingleParamProcess_CRTP::updateInfo update parameter info in relation to the sampling process
 */
void ProcessSamplingClassic::updateInfo(Parameter & parameter)
{
	LOG4CXX_DEBUG(_logger, "ProcessSamplingClassic::updateInfo - " << parameter.getId());

	SingleParamProcess::updateInfo(parameter);

	//Param info
	AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(parameter.getInfoId());

	if (paramInfo == nullptr)
		return;

	std::string processInfo = "Resampling of '";
	processInfo += _parameterInput->getId();
	processInfo += "' with sampling time '";
	processInfo += _attributList.begin()->c_str();
	processInfo += " s'";

	if (_parameterInput->getDataWriterTemplate()->useNearestValue())
		processInfo += ". Use nearest value.";

	paramInfo->setProcessInfo(processInfo);
}

double ProcessSamplingClassic::getMinSampling()
{
	if (_attributList.size() != 2)
		return 0;
	return atof(_attributList.begin()->c_str());
}

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