ParamGetConstant.cc
5.83 KB
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
56
57
58
59
60
61
62
63
64
65
66
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
* ParamGetConstant.cc
*
* Created on: 18 sep. 2018
* Author: AKKA
*/
#include "ParamGetConstant.hh"
#include "ConstantInterfaceConfig.hh"
#include <stdlib.h>
#include "Parameter.hh"
#include "ParamData.hh"
#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "DicError.hh"
#include "TimeUtil.hh"
#include "Helper.hh"
namespace AMDA {
namespace ConstantInterface {
ParamGetConstant::ParamGetConstant(Parameter ¶meter) :
ParamGet_CRTP<ParamGetConstant>(parameter), _sampling(0.), _type(TYPE_FLOAT), _container(CONTAINER_SCALAR), _value(0.), _dim1(1), _dim2(1), _pusher(NULL)
{
}
ParamGetConstant::ParamGetConstant(const ParamGetConstant &pParamGetConstant, Parameter ¶meter) :
ParamGet_CRTP<ParamGetConstant>(pParamGetConstant, parameter),
_sampling(pParamGetConstant._sampling), _type(pParamGetConstant._type), _container(pParamGetConstant._container), _value(pParamGetConstant._value), _dim1(pParamGetConstant._dim1), _dim2(pParamGetConstant._dim2),
_pusher(pParamGetConstant._pusher)
{
}
ParamGetConstant::~ParamGetConstant()
{
//delete the pusher if needed
if (_pusher != NULL)
delete _pusher;
}
TimeStamp ParamGetConstant::init()
{
LOG4CXX_DEBUG(gLogger, "ParamGetConstant::init");
if (_dim1 * _dim2 == 1) {
_container = CONTAINER_SCALAR;
}
else if ((_dim1 > 1) && (_dim2 > 1)) {
_container = CONTAINER_MATRIX;
}
else {
_container = CONTAINER_VECTOR;
}
_currentInterval = _timeIntervalList->begin();
//create pusher
switch (_container) {
case CONTAINER_SCALAR :
switch (_type) {
case TYPE_FLOAT :
_pusher = new Pusher<TYPE_FLOAT, CONTAINER_SCALAR>(_sampling, _value);
break;
case TYPE_DOUBLE :
_pusher = new Pusher<TYPE_DOUBLE, CONTAINER_SCALAR>(_sampling, _value);
break;
case TYPE_SHORT :
_pusher = new Pusher<TYPE_SHORT, CONTAINER_SCALAR>(_sampling, _value);
break;
case TYPE_INT :
_pusher = new Pusher<TYPE_INT, CONTAINER_SCALAR>(_sampling, _value);
break;
}
break;
case CONTAINER_VECTOR :
switch (_type) {
case TYPE_FLOAT :
_pusher = new Pusher<TYPE_FLOAT, CONTAINER_VECTOR>(_sampling, _value, _dim1);
break;
case TYPE_DOUBLE :
_pusher = new Pusher<TYPE_DOUBLE, CONTAINER_VECTOR>(_sampling, _value, _dim1);
break;
case TYPE_SHORT :
_pusher = new Pusher<TYPE_SHORT, CONTAINER_VECTOR>(_sampling, _value, _dim1);
break;
case TYPE_INT :
_pusher = new Pusher<TYPE_INT, CONTAINER_VECTOR>(_sampling, _value, _dim1);
break;
}
break;
case CONTAINER_MATRIX :
switch (_type) {
case TYPE_FLOAT :
_pusher = new Pusher<TYPE_FLOAT, CONTAINER_MATRIX>(_sampling, _value, _dim1, _dim2);
break;
case TYPE_DOUBLE :
_pusher = new Pusher<TYPE_DOUBLE, CONTAINER_MATRIX>(_sampling, _value, _dim1, _dim2);
break;
case TYPE_SHORT :
_pusher = new Pusher<TYPE_SHORT, CONTAINER_MATRIX>(_sampling, _value, _dim1, _dim2);
break;
case TYPE_INT :
_pusher = new Pusher<TYPE_INT, CONTAINER_MATRIX>(_sampling, _value, _dim1, _dim2);
break;
}
break;
}
if (_pusher == NULL)
{
BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_TYPE_DATA_UNKNOWN) << AMDA::ex_msg(std::string("Cannot create param data")));
}
//set link to the param data
_paramData = ParamDataSPtr(_pusher->getParamData());
_paramData->setMinSampling(_sampling);
TimeStamp timeStamp = 0;
if (_signatureTrigger != "") {
// _signatureTrigger must be a name of xml parameter file
timeStamp = AMDA::Helpers::Helper::dateOfFile(
_signatureTrigger.c_str());
}
setGlobalStart(0.);
// 01/01/2038
setGlobalStop(2145913200.);
return timeStamp;
}
unsigned int ParamGetConstant::write()
{
unsigned int result = 0;
if (_currentInterval == _timeIntervalList->end()) {
_paramData->getIndexInfo()._noMoreTimeInt = true;
return result;
}
//get packet and push it in ParamData
LOG4CXX_DEBUG(gLogger, "ParamGetConstant::write ");
int crtRefIndex = 0;
if (!_paramData->getIndexInfo()._endTimeIntIndexList.empty()) {
crtRefIndex = _paramData->getIndexInfo()._endTimeIntIndexList.back();
}
result += _pusher->put(_currentInterval->_startTime, _currentInterval->_stopTime, _paramData->getDataNumber() - crtRefIndex);
// Push up the information if all time interval was processed.
_paramData->getIndexInfo()._timeIntToProcessChanged = (result == 0);
if (result == 0) {
++_currentInterval;
_paramData->getIndexInfo()._noMoreTimeInt = (_currentInterval == _timeIntervalList->end());
}
_paramData->getIndexInfo()._nbDataToProcess = result;
// if time interval changed store index which delimit the end of the time interval.
if (_paramData->getIndexInfo()._timeIntToProcessChanged) {
unsigned int lEndTimeIntIndex = _paramData->getIndexInfo()._nbDataToProcess;
_paramData->getIndexInfo()._endTimeIntIndexList.push_back(lEndTimeIntIndex);
}
else {
// Nothing to do.
}
return result;
}
/*
* @overload DataWriter::getMinSampling
*/
double ParamGetConstant::getMinSampling()
{
return _sampling;
}
void ParamGetConstant::updateInfo(Parameter & parameter)
{
LOG4CXX_DEBUG(gLogger, "ParamGetConstant::updateInfo - " << parameter.getId());
if (parameter.getInfoId().empty())
parameter.setInfoId(parameter.getId());
//Param info
AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(parameter.getInfoId(),true);
if (paramInfo == nullptr)
return;
paramInfo->setFillValue(NAN);
//Add parameter info id as parameter name if no exist
//if (paramInfo->getName().empty())
// paramInfo->setName(_paramId);
//Add parameter info id as parameter short name if no exist
//if (paramInfo->getShortName().empty())
// paramInfo->setShortName(_paramId);
}
} /* namespace ConstantInterface */
} /* namespace AMDA */