Blame view

src/ExternLib/mexvex_els_decode/MexVexElsDecode.hh 4.56 KB
35de3ffa   Elena.Budnik   mexvex_els
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
/*
 * 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.
 */

404c4140   Benjamin Renard   Fix mexvex_els_de...
26
template <typename TInputParamData, typename TOutputParamData> 
35de3ffa   Elena.Budnik   mexvex_els
27
28
class MexVexElsDecode : public Operation {
	
6a28e3ab   Benjamin Renard   Fix Mex/Vex ELS p...
29
typedef typename TInputParamData::ElementType ElemType;
35de3ffa   Elena.Budnik   mexvex_els
30
31
32
33
34
35

public:
	/**
	 * @brief Constructor.
	 * @details Create the ParamData type of the input ParamData.
	 */
6a28e3ab   Benjamin Renard   Fix Mex/Vex ELS p...
36
	MexVexElsDecode(Process& pProcess, TInputParamData& paramInput,  ParamDataScalaireShort& energyTableInput)
35de3ffa   Elena.Budnik   mexvex_els
37
38
	: Operation(pProcess),
	  _paramInput(paramInput),
6a28e3ab   Benjamin Renard   Fix Mex/Vex ELS p...
39
	  _energyTableInput(energyTableInput),
404c4140   Benjamin Renard   Fix mexvex_els_de...
40
	  _paramOutput(new TOutputParamData()) {
35de3ffa   Elena.Budnik   mexvex_els
41
42
43
44
45
46
47
48
49
50
51
52
53
	  _paramDataOutput=_paramOutput;
	}

	virtual ~MexVexElsDecode() {
		
	}

	/**
	 * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
	 */
  
	void write(ParamDataIndexInfo &pParamDataIndexInfo) {
	  
35de3ffa   Elena.Budnik   mexvex_els
54
55
56
57
58
59
60
		for (unsigned int _index = pParamDataIndexInfo._startIndex ;
			_index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess;
			++_index)
		{
			double crtTime = _paramInput.getTime(_index);
			ElemType inputElt = _paramInput.get(_index);
		
8ef8eb7c   Benjamin Renard   Fix mexvex_els_de...
61
62
63
64
65
66
67
68
			short mode = _energyTableInput.get(_index);

			if (isNAN(mode)) {
				_paramOutput->pushTime(crtTime);
				inputElt << NotANumber();
				pushDataForMode0Or2(inputElt);
			}
			else if (mode == 1) {
35de3ffa   Elena.Budnik   mexvex_els
69
70
71
72
73
74
75
76
				for (int i = 0; i < 4; ++i){			       
					_paramOutput->pushTime(crtTime+i);
					pushDataForMode1 (inputElt, i);				 
				}
			}
			else if (mode == 0 || mode == 2)			
			{
				_paramOutput->pushTime(crtTime);
404c4140   Benjamin Renard   Fix mexvex_els_de...
77
				pushDataForMode0Or2(inputElt);
35de3ffa   Elena.Budnik   mexvex_els
78
79
80
			}
		}		
	}
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
81

35de3ffa   Elena.Budnik   mexvex_els
82
	template<typename Type>
6a28e3ab   Benjamin Renard   Fix Mex/Vex ELS p...
83
	void pushDataForMode1(Type& elt, int /*index*/) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
84
		_paramOutput->getDataList().push_back((int)elt);
404c4140   Benjamin Renard   Fix mexvex_els_de...
85
86
87
88
	}

	template<typename Type>
	void pushDataForMode0Or2(Type& elt) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
89
		_paramOutput->getDataList().push_back((int)elt);
35de3ffa   Elena.Budnik   mexvex_els
90
	}
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
91

35de3ffa   Elena.Budnik   mexvex_els
92
93
	template<typename Type>
	void pushDataForMode1(std::vector<Type>& elt, int index) {
5fd5fc53   Elena.Budnik   ELS splitted 4,31
94
95
		typename std::vector<Type>::const_iterator first = elt.begin() + 32 * index;
		typename std::vector<Type>::const_iterator last = elt.begin() + 32 * (index + 1) - 1;
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
96
		std::vector<int> splitVec;
6a28e3ab   Benjamin Renard   Fix Mex/Vex ELS p...
97
98
		splitVec.resize(128);
		splitVec << NotANumber();
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
99
100
101

		int i = 0;
		for (typename std::vector<Type>::const_iterator it = first; it != last; ++it) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
102
			splitVec[i] = (int)(*it);
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
103
104
105
			++i;
		}

35de3ffa   Elena.Budnik   mexvex_els
106
		_paramOutput->getDataList().push_back(splitVec);
404c4140   Benjamin Renard   Fix mexvex_els_de...
107
108
109
110
	}

	template<typename Type>
	void pushDataForMode0Or2(std::vector<Type>& elt) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
111
		std::vector<int> vec;
404c4140   Benjamin Renard   Fix mexvex_els_de...
112
113
114
115
116
		vec.resize(elt.size());
		vec << NotANumber();

		int i = 0;
		for (typename std::vector<Type>::const_iterator it = elt.begin(); it != elt.end(); ++it) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
117
			vec[i] = (int)(*it);
404c4140   Benjamin Renard   Fix mexvex_els_de...
118
119
120
121
			++i;
		}
		_paramOutput->getDataList().push_back(vec);
	}
35de3ffa   Elena.Budnik   mexvex_els
122
123
124
	
	template<typename Type>  
	void pushDataForMode1(Tab2DData<Type>& elt, int index) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
125
		Tab2DData<int> newElt(elt.getDim1Size(),31); 
35de3ffa   Elena.Budnik   mexvex_els
126
		for(int i = 0; i < elt.getDim1Size(); ++i) {                        			
974b02df   Benjamin Renard   TabRow inherits f...
127
			std::vector<Type> eltVector = elt[i];
5fd5fc53   Elena.Budnik   ELS splitted 4,31
128
129
			typename std::vector<Type>::const_iterator first = eltVector.begin() + 32 * index;
			typename std::vector<Type>::const_iterator last =  eltVector.begin() + 32 * (index + 1) - 1;
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
130
			std::vector<int> splitVec;
404c4140   Benjamin Renard   Fix mexvex_els_de...
131
132
133
134
			splitVec.resize(31);
			splitVec << NotANumber();
			int j = 0;
			for (typename std::vector<Type>::const_iterator it = first; it != last; ++it) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
135
				splitVec[j] = (int)(*it);
404c4140   Benjamin Renard   Fix mexvex_els_de...
136
137
				++j;
			}
35de3ffa   Elena.Budnik   mexvex_els
138
139
140
141
			newElt[i] = splitVec;
		}                
		_paramOutput->getDataList().push_back(newElt);
	}
404c4140   Benjamin Renard   Fix mexvex_els_de...
142
143
144

	template<typename Type>
	void pushDataForMode0Or2(Tab2DData<Type>& elt) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
145
		Tab2DData<int> newElt(elt.getDim1Size(),elt.getDim2Size());
404c4140   Benjamin Renard   Fix mexvex_els_de...
146
147
		for(int i = 0; i < elt.getDim1Size(); ++i) {
			std::vector<Type> eltVector = elt[i];
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
148
			std::vector<int> vec;
404c4140   Benjamin Renard   Fix mexvex_els_de...
149
150
151
152
			vec.resize(eltVector.size());
			vec << NotANumber();
			int j = 0;
			for (typename std::vector<Type>::const_iterator it = eltVector.begin(); it != eltVector.end(); ++it) {
dc7412c8   Benjamin Renard   Fix mexvex_els_de...
153
				vec[j] = (int)(*it);
404c4140   Benjamin Renard   Fix mexvex_els_de...
154
155
156
157
158
159
				++j;
			}
			newElt[i] = vec;
		}
		_paramOutput->getDataList().push_back(newElt);
	}
35de3ffa   Elena.Budnik   mexvex_els
160
161
162
163
164
  
private:
	/**<
	 * @brief It is the channel of data derived
	 */
6a28e3ab   Benjamin Renard   Fix Mex/Vex ELS p...
165
166
167
	TInputParamData& _paramInput;

	ParamDataScalaireShort& _energyTableInput;
35de3ffa   Elena.Budnik   mexvex_els
168
169
170
171

	/**<
	 * @brief It is the channel of the data derived
	 */
404c4140   Benjamin Renard   Fix mexvex_els_de...
172
	TOutputParamData* _paramOutput;
35de3ffa   Elena.Budnik   mexvex_els
173
174
175
176
177
178
};  

} /* namespace MexVexElsDecode */
} /* namespace Parameters */
} /* namespace AMDA */
#endif /* MEXVEXELSDECODE_HH_ */