Blame view

src/InternLib/ProcessSamplingClassic.cc 3.81 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
/**
 * 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
dc91ef9d   Benjamin Renard   Retrieve the inpu...
47
48
	if (_attributList.size() < 1) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSamplingClassic required attribute sampling")));
fbe3c2bb   Benjamin Renard   First commit
49
50
51
52
53
	}
	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")));
	}
dc91ef9d   Benjamin Renard   Retrieve the inpu...
54
55
56
57
58
59
60
61
	//GET Threshold
	double threshold = 0;
	if (_attributList.size() == 2) {
		threshold = atof((++(_attributList.begin()))->c_str());
	}
	else {
		threshold = _parameterInput->getGapThreshold();
	}
fbe3c2bb   Benjamin Renard   First commit
62

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

c391ab45   Benjamin Renard   computedGapSize o...
66
67
68
69
70
71
72
73
	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
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()
{
71753215   Benjamin Renard   Fix getMinSamplin...
114
	if (_attributList.empty())
fbe3c2bb   Benjamin Renard   First commit
115
116
117
118
119
120
		return 0;
	return atof(_attributList.begin()->c_str());
}

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