MexVexElsDecode.hh
4.56 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
/*
* MexVexElsDecode.hh
*
* Created on: Oct 13, 2016
* Author: elena / benjamin
*/
#ifndef MEXVEXELSDECODE_HH_
#define MEXVEXELSDECODE_HH_
#include "Parameter.hh"
#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "Operation.hh"
namespace AMDA {
namespace Parameters {
namespace MexVexElsDecode {
/**
* @class MexVexElsDecode
* @brief
* @details This class implement the interface Operation.
*/
template <typename TInputParamData, typename TOutputParamData>
class MexVexElsDecode : public Operation {
typedef typename TInputParamData::ElementType ElemType;
public:
/**
* @brief Constructor.
* @details Create the ParamData type of the input ParamData.
*/
MexVexElsDecode(Process& pProcess, TInputParamData& paramInput, ParamDataScalaireShort& energyTableInput)
: Operation(pProcess),
_paramInput(paramInput),
_energyTableInput(energyTableInput),
_paramOutput(new TOutputParamData()) {
_paramDataOutput=_paramOutput;
}
virtual ~MexVexElsDecode() {
}
/**
* @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
*/
void write(ParamDataIndexInfo &pParamDataIndexInfo) {
for (unsigned int _index = pParamDataIndexInfo._startIndex ;
_index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess;
++_index)
{
double crtTime = _paramInput.getTime(_index);
ElemType inputElt = _paramInput.get(_index);
short mode = _energyTableInput.get(_index);
if (isNAN(mode)) {
_paramOutput->pushTime(crtTime);
inputElt << NotANumber();
pushDataForMode0Or2(inputElt);
}
else if (mode == 1) {
for (int i = 0; i < 4; ++i){
_paramOutput->pushTime(crtTime+i);
pushDataForMode1 (inputElt, i);
}
}
else if (mode == 0 || mode == 2)
{
_paramOutput->pushTime(crtTime);
pushDataForMode0Or2(inputElt);
}
}
}
template<typename Type>
void pushDataForMode1(Type& elt, int /*index*/) {
_paramOutput->getDataList().push_back((int)elt);
}
template<typename Type>
void pushDataForMode0Or2(Type& elt) {
_paramOutput->getDataList().push_back((int)elt);
}
template<typename Type>
void pushDataForMode1(std::vector<Type>& elt, int index) {
typename std::vector<Type>::const_iterator first = elt.begin() + 32 * index;
typename std::vector<Type>::const_iterator last = elt.begin() + 32 * (index + 1) - 1;
std::vector<int> splitVec;
splitVec.resize(128);
splitVec << NotANumber();
int i = 0;
for (typename std::vector<Type>::const_iterator it = first; it != last; ++it) {
splitVec[i] = (int)(*it);
++i;
}
_paramOutput->getDataList().push_back(splitVec);
}
template<typename Type>
void pushDataForMode0Or2(std::vector<Type>& elt) {
std::vector<int> vec;
vec.resize(elt.size());
vec << NotANumber();
int i = 0;
for (typename std::vector<Type>::const_iterator it = elt.begin(); it != elt.end(); ++it) {
vec[i] = (int)(*it);
++i;
}
_paramOutput->getDataList().push_back(vec);
}
template<typename Type>
void pushDataForMode1(Tab2DData<Type>& elt, int index) {
Tab2DData<int> newElt(elt.getDim1Size(),31);
for(int i = 0; i < elt.getDim1Size(); ++i) {
std::vector<Type> eltVector = elt[i];
typename std::vector<Type>::const_iterator first = eltVector.begin() + 32 * index;
typename std::vector<Type>::const_iterator last = eltVector.begin() + 32 * (index + 1) - 1;
std::vector<int> splitVec;
splitVec.resize(31);
splitVec << NotANumber();
int j = 0;
for (typename std::vector<Type>::const_iterator it = first; it != last; ++it) {
splitVec[j] = (int)(*it);
++j;
}
newElt[i] = splitVec;
}
_paramOutput->getDataList().push_back(newElt);
}
template<typename Type>
void pushDataForMode0Or2(Tab2DData<Type>& elt) {
Tab2DData<int> newElt(elt.getDim1Size(),elt.getDim2Size());
for(int i = 0; i < elt.getDim1Size(); ++i) {
std::vector<Type> eltVector = elt[i];
std::vector<int> vec;
vec.resize(eltVector.size());
vec << NotANumber();
int j = 0;
for (typename std::vector<Type>::const_iterator it = eltVector.begin(); it != eltVector.end(); ++it) {
vec[j] = (int)(*it);
++j;
}
newElt[i] = vec;
}
_paramOutput->getDataList().push_back(newElt);
}
private:
/**<
* @brief It is the channel of data derived
*/
TInputParamData& _paramInput;
ParamDataScalaireShort& _energyTableInput;
/**<
* @brief It is the channel of the data derived
*/
TOutputParamData* _paramOutput;
};
} /* namespace MexVexElsDecode */
} /* namespace Parameters */
} /* namespace AMDA */
#endif /* MEXVEXELSDECODE_HH_ */