Blame view

src/InternLib/ProcessSamplingUnderRefParam.cc 6.46 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
/**
 * ProcessSamplingUnderTimeList.cc
 *
 *  Created on: Jul 25, 2014
 *      Author: AKKA IS
 */
#include <stdlib.h>
#include <string>

#include "ProcessSamplingUnderRefParam.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 {

ProcessSamplingUnderRefParam::ProcessSamplingUnderRefParam(Parameter &parameter) :
		SingleParamProcess_CRTP(parameter), _paramRefInput(NULL) {
}

ProcessSamplingUnderRefParam::ProcessSamplingUnderRefParam(const ProcessSamplingUnderRefParam& pProcess, Parameter &parameter)
: SingleParamProcess_CRTP(pProcess,parameter), _paramRefInput(pProcess._paramRefInput) {
d1d8375e   Benjamin Renard   Fix a bug with sa...
30
    establishConnection(); 
fbe3c2bb   Benjamin Renard   First commit
31
32
33
34
35
36
37
38
39
40
41
}

ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() {
	if (_refParameterSPtr != nullptr)
	{
		_refParameterSPtr->closeConnection(this);
	}
}


void ProcessSamplingUnderRefParam::establishConnection() {
d1d8375e   Benjamin Renard   Fix a bug with sa...
42
43
    if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) {
    	_refParameterSPtr->openConnection(this);
deefda79   Benjamin Renard   Addapt resampling...
44
	}
fbe3c2bb   Benjamin Renard   First commit
45
46

	SingleParamProcess_CRTP::establishConnection();
d1d8375e   Benjamin Renard   Fix a bug with sa...
47
    
deefda79   Benjamin Renard   Addapt resampling...
48
49
	if ((_refParameterSPtr == nullptr) && (_attributList.size() == 1) ) {
		_refParameterSPtr =  _parameterInput->getParameterManager().getParameter(_attributList[0]);
d1d8375e   Benjamin Renard   Fix a bug with sa...
50
51
    	if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) {
    		_refParameterSPtr->openConnection(this);
deefda79   Benjamin Renard   Addapt resampling...
52
53
		}
	}
fbe3c2bb   Benjamin Renard   First commit
54
55
56
}

TimeStamp ProcessSamplingUnderRefParam::init() {
d1d8375e   Benjamin Renard   Fix a bug with sa...
57
    /// Init input parameter
fbe3c2bb   Benjamin Renard   First commit
58
	TimeStamp timeStamp = _parameterInput->init( this, _timeIntervalList);
d1d8375e   Benjamin Renard   Fix a bug with sa...
59
60

    /// Calibration information copy
fbe3c2bb   Benjamin Renard   First commit
61
62
63
	Parameter::InfoList lInfoList = _parameterInput->getInfoList();
	_parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end());
	_paramInput = _parameterInput->getParamData(this).get();
d1d8375e   Benjamin Renard   Fix a bug with sa...
64
    
fbe3c2bb   Benjamin Renard   First commit
65
66
67
68
69
	// check reference parameter
	if (_refParameterSPtr == nullptr) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSamplingUnderRefParam : cannot retrieve reference parameter ")));
	}

d1d8375e   Benjamin Renard   Fix a bug with sa...
70
71
72
73
    if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) {
        timeStamp = std::max(timeStamp, _refParameterSPtr->init( this, _timeIntervalList));
    }
    
fbe3c2bb   Benjamin Renard   First commit
74
75
76
	_paramRefInput = _refParameterSPtr->getParamData(this).get();

	double computedGapSize = _refParameterSPtr->getParameterManager().getComputedGapSize(_parameterInput->getGapThreshold(), _paramInput->getMinSampling());
46ee40b3   Benjamin Renard   Fix reference fil...
77
	//_parameter.setGapThreshold(computedGapSize/_paramRefInput->getMinSampling());
d1d8375e   Benjamin Renard   Fix a bug with sa...
78
    
fbe3c2bb   Benjamin Renard   First commit
79
80
	// ProcessSamplingClassic _operation creation
	Resampling::CreateResampling lCreateResampling(*this, _timeIntervalList,
3ff2d228   Benjamin Renard   Fix bug in sampli...
81
			*_paramInput, *_paramRefInput, computedGapSize, _parameterInput->getDataWriterTemplate()->useNearestValue(), _refParameterSPtr == _parameterInput);
fbe3c2bb   Benjamin Renard   First commit
82
	_operation = lCreateResampling.getResampling();
3ff2d228   Benjamin Renard   Fix bug in sampli...
83

fbe3c2bb   Benjamin Renard   First commit
84
	static_cast<Resampling::ResamplingAbstract*>(_operation)->init();
d1d8375e   Benjamin Renard   Fix a bug with sa...
85
    
fbe3c2bb   Benjamin Renard   First commit
86
87
88
89
	/// Get result ParamData
	_paramData = ParamDataSPtr(_operation->getParamOutput());

	_paramData->setMinSampling(static_cast<Resampling::ResamplingAbstract*>(_operation)->getSampling());
98295b6e   Benjamin Renard   Fix gap threshold...
90
	_parameter.setGapThreshold(_refParameterSPtr->getGapThreshold());
fbe3c2bb   Benjamin Renard   First commit
91
92
93
94
95
96

	return timeStamp;
}

unsigned int ProcessSamplingUnderRefParam::write()
{
fbe3c2bb   Benjamin Renard   First commit
97
	int ret = 0;
a6490f4d   Benjamin Renard   Do not throw an e...
98
	unsigned int nbDataBeforeCallProcess = _paramData->getDataNumber();
deefda79   Benjamin Renard   Addapt resampling...
99

3ff2d228   Benjamin Renard   Fix bug in sampli...
100
101
102
103
104
105
106
107
108
109
110
	ParamDataIndexInfo lParamDataIndexInfo;
	if (_refParameterSPtr != _parameterInput) {
		if (static_cast<Resampling::ResamplingAbstract*>(_operation)->isNewInt()) {
			_paramRefInput = _refParameterSPtr->getParamData(this).get();
			ParamDataIndexInfo lRefParamDataIndexInfo;
			do {
				lRefParamDataIndexInfo = _refParameterSPtr->getAsync(this).get();
				for (unsigned int index = lRefParamDataIndexInfo._startIndex; index < lRefParamDataIndexInfo._startIndex + lRefParamDataIndexInfo._nbDataToProcess; index++) {
					static_cast<Resampling::ResamplingAbstract*>(_operation)->pushTime(_paramRefInput->getTime(index));
				}
			} while (!lRefParamDataIndexInfo._timeIntToProcessChanged && !lRefParamDataIndexInfo._noMoreTimeInt);
deefda79   Benjamin Renard   Addapt resampling...
111
112
113
		}
	}

3ff2d228   Benjamin Renard   Fix bug in sampli...
114
115
	lParamDataIndexInfo = _parameterInput->getAsync(this).get();

bb672c4c   Benjamin Renard   Fix side effect i...
116
117
	_operation->write(lParamDataIndexInfo);
	ret = _paramData->getDataNumber() - nbDataBeforeCallProcess;
a6490f4d   Benjamin Renard   Do not throw an e...
118

c2fa3b5d   Benjamin Renard   Rework of legend ...
119
120
121
122
	bool updateDims = (nbDataBeforeCallProcess == 0) && (ret > 0);
	if (updateDims)
		_paramData->updateDims();

a6490f4d   Benjamin Renard   Do not throw an e...
123
124
125
126
127
128
	// Reset operation to prepare static data for the next TimeInterval.
	if (lParamDataIndexInfo._timeIntToProcessChanged) {
		_paramData->getIndexInfo()._endTimeIntIndexList.push_back(_paramData->getDataNumber());
		_operation->reset();
	}
	// There is no more time interval to process
fa4b7852   Benjamin Renard   Fix bug around ti...
129
	else if (lParamDataIndexInfo._noMoreTimeInt) {
a6490f4d   Benjamin Renard   Do not throw an e...
130
131
132
133
134
135
136
		_paramData->getIndexInfo()._endTimeIntIndexList.push_back(_paramData->getDataNumber());
	} else {
		// Nothing to do.
	}

	// Pull up information on which time interval changed.
	_paramData->getIndexInfo()._timeIntToProcessChanged = lParamDataIndexInfo._timeIntToProcessChanged;
fa4b7852   Benjamin Renard   Fix bug around ti...
137
	_paramData->getIndexInfo()._noMoreTimeInt = lParamDataIndexInfo._noMoreTimeInt;
a6490f4d   Benjamin Renard   Do not throw an e...
138
139

	return ret;
fbe3c2bb   Benjamin Renard   First commit
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
}

/*
 * @brief Get min sampling
 */
double ProcessSamplingUnderRefParam::getMinSampling()
{
	if (_refParameterSPtr == nullptr)
		return 0;
	if (_refParameterSPtr->getDataWriterTemplate() == nullptr)
		return 0;
	return _refParameterSPtr->getDataWriterTemplate()->getMinSampling();
}

/**
 * @overload SingleParamProcess_CRTP::updateInfo update parameter info in relation to the sampling process
 */
void ProcessSamplingUnderRefParam::updateInfo(Parameter & parameter)
{
	LOG4CXX_DEBUG(_logger, "ProcessSamplingUnderRefParam::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 += "' under times list of '";
	processInfo += _refParameterSPtr->getId();
	processInfo += "'";

d1d8375e   Benjamin Renard   Fix a bug with sa...
175
    if (_parameterInput->getDataWriterTemplate()->useNearestValue())
fbe3c2bb   Benjamin Renard   First commit
176
177
178
179
180
			processInfo += ". Use nearest value.";

	paramInfo->setProcessInfo(processInfo);
}

69f40c91   Benjamin Renard   Fix gap propagation
181
182
183
184
185
186
double ProcessSamplingUnderRefParam::getGapThreshold() {
	double gapSize = _parameterInput->getGapThreshold() * _parameterInput->getDataWriterTemplate()->getMinSampling();
	
	return gapSize / this->getMinSampling();
}

fbe3c2bb   Benjamin Renard   First commit
187
188
} /* namespace Parameters */
} /* namespace AMDA */