Commit 4be251060ac666c933a5aa496fff4b31df40bef6

Authored by Benjamin Renard
1 parent a40aa278

Rewrite deriv process + remove some debug logs

Showing 2 changed files with 94 additions and 101 deletions   Show diff stats
src/ExternLib/Deriv/Deriv.hh
... ... @@ -30,106 +30,109 @@ namespace Parameters {
30 30 template<class TParamData>
31 31 class Deriv : public Operation {
32 32 public:
33   - /**
34   - * @brief Constructor.
35   - * @details Create the ParamData type of the input ParamData.
36   - */
  33 + /**
  34 + * @brief Element type of paramData
  35 + */
  36 + typedef typename TParamData::ElementType ElementType;
  37 +
  38 + /**
  39 + * @brief Constructor.
  40 + * @details Create the ParamData type of the input ParamData.
  41 + */
37 42 Deriv(Process& pProcess, TParamData& paramInput)
38 43 : Operation(pProcess),
39 44 _paramInput(paramInput),
40 45 _paramOutput(new TParamData()),
41   - _index(0),
42   - _lastDataWrite(false) {
  46 + _firstPointComputed(false) {
43 47 _paramDataOutput=_paramOutput;
44 48 }
45 49  
46   - /**
47   - * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
48   - */
  50 + /**
  51 + * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
  52 + */
49 53 void write(ParamDataIndexInfo &pParamDataIndexInfo) {
50 54  
51   - typename TParamData::ElementType y0;
52   - typename TParamData::ElementType y1;
53   - typename TParamData::ElementType y2;
54   - typename TParamData::ElementType res;
55   - double x0 = 0;
56   - double x1 = 0;
57   - double x2 = 0;
58   - double x02 = 0;
59   - double x01 = 0;
60   - double x10 = 0;
61   - double x12 = 0;
62   - double x20 = 0;
63   - double x21 = 0;
64   - double _2x = 0;
65   - double x = 0;
66   - //if first compute
67   - if(_index == 0 ) {
68   - if ((pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess) > 2) {
69   - y0 = _paramInput.getDataList()[_index];
70   - y1 = _paramInput.getDataList()[_index + 1];
71   - y2 = _paramInput.getDataList()[_index + 2];
72   - x = x0 =_paramInput.getTime(_index) ;
73   - x1 = _paramInput.getTime(_index + 1) ;
74   - x2 = _paramInput.getTime(_index + 2) ;
75   - x02 = x0 -x2;
76   - x01 = x0 -x1;
77   - x10 = x1 -x0;
78   - x12 = x1 -x2;
79   - x20 =x2 - x0 ;
80   - x21 = x2 -x1;
81   - _2x = 2*x;
82   - res = y0*(_2x-x1-x2)/(x01*x02) + y1*(_2x-x0-x2)/(x10*x12)+y2*(_2x-x0-x1)/(x20*x21);
83   - _paramOutput->getDataList().push_back(res);
84   - _paramOutput->pushTime(x);
85   - ++_index;
  55 + //Store data in a working list
  56 +int tot = 0;
  57 + for (unsigned int index = pParamDataIndexInfo._startIndex;
  58 + index< pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; index++) {
  59 + _data.push_back(std::make_pair(_paramInput.getTime(index), _paramInput.getDataList()[index]));
  60 +++tot;
  61 + }
  62 +
  63 + ElementType res;
  64 + typename std::list<std::pair<double, ElementType> >::iterator itData0, itData1, itData2;
  65 +
  66 +tot = 0;
  67 + if (!_firstPointComputed && (_data.size() >= 3)) {
  68 + //First point calculation
  69 + itData0 = _data.begin();
  70 + itData1 = std::next(itData0, 1);
  71 + itData2 = std::next(itData0, 2);
  72 + res = computeDeriv(*itData0, *itData1, *itData2);
  73 + _paramOutput->getDataList().push_back(res);
  74 + _paramOutput->pushTime((*itData0).first);
  75 + _firstPointComputed = true;
  76 +++tot;
  77 + }
  78 +
  79 + while (_data.size() >= 3) {
  80 + //Calculation for other points than the first one or the last one
  81 + itData0 = _data.begin();
  82 + itData1 = std::next(itData0, 1);
  83 + itData2 = std::next(itData0, 2);
  84 + res = computeDeriv(*itData0, *itData1, *itData2);
  85 + _paramOutput->getDataList().push_back(res);
  86 + _paramOutput->pushTime((*itData1).first);
  87 + _lastPopData = *itData0;
  88 + _data.pop_front();
  89 +++tot;
  90 + }
  91 +
  92 + if (pParamDataIndexInfo._timeIntToProcessChanged || pParamDataIndexInfo._noMoreTimeInt) {
  93 + //Finish process for this interval
  94 + if (!_firstPointComputed) {
  95 + //Only one or two points => cannot compute deriv => set NaN values
  96 + while (!_data.empty()) {
  97 + res << NotANumber();
  98 + _paramOutput->getDataList().push_back(res);
  99 + _paramOutput->pushTime((*_data.begin()).first);
  100 + _data.pop_front();
  101 +++tot;
  102 + }
  103 +
86 104 }
87   - }
88   - //if last compute
89   - if( pParamDataIndexInfo._nbDataToProcess == 0 && !_lastDataWrite) {
90   -
91   - y0 = _paramInput.getDataList()[_index - 2];
92   - y1 = _paramInput.getDataList()[_index - 1];
93   - y2 = _paramInput.getDataList()[_index ];
94   - x0 =_paramInput.getTime(_index - 2) ;
95   - x1 = _paramInput.getTime(_index - 1) ;
96   - x = x2 = _paramInput.getTime(_index) ;
97   - x02 = x0 -x2;
98   - x01 = x0 -x1;
99   - x10 = x1 -x0;
100   - x12 = x1 -x2;
101   - x20 =x2 - x0 ;
102   - x21 = x2 -x1;
103   - _2x = 2*x;
104   - res = y0*(_2x-x1-x2)/(x01*x02) + y1*(_2x-x0-x2)/(x10*x12)+y2*(_2x-x0-x1)/(x20*x21);
105   - _paramOutput->getDataList().push_back(res);
106   - _paramOutput->pushTime(x);
107   - _lastDataWrite = true;
108   -
109   - }
110   - //classic compute
111   - while (_index< pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess - 1) {
112   - //df/dt = y0*(2x-x1-x2)/(x01*x02) + y1*(2x-x0-x2)/(x10*x12)+y2*(2x-x0-x1)/(x20*x21),
113   -
114   - y0 = _paramInput.getDataList()[_index - 1];
115   - y1 = _paramInput.getDataList()[_index ];
116   - y2 = _paramInput.getDataList()[_index + 1];
117   - x0 =_paramInput.getTime(_index - 1) ;
118   - x = x1 = _paramInput.getTime(_index) ;
119   - x2 = _paramInput.getTime(_index + 1) ;
120   - x02 = x0 -x2;
121   - x01 = x0 -x1;
122   - x10 = x1 -x0;
123   - x12 = x1 -x2;
124   - x20 =x2 - x0 ;
125   - x21 = x2 -x1;
126   - _2x = 2*x;
127   - res = y0*(_2x-x1-x2)/(x01*x02) + y1*(_2x-x0-x2)/(x10*x12)+y2*(_2x-x0-x1)/(x20*x21);
128   - _paramOutput->getDataList().push_back(res);
129   - _paramOutput->pushTime(x);
130   - ++_index;
  105 + else {
  106 + //Last point calculation
  107 + itData1 = _data.begin();
  108 + itData2 = std::next(itData1, 1);
  109 + res = computeDeriv(_lastPopData, *itData1, *itData2);
  110 + _paramOutput->getDataList().push_back(res);
  111 + _paramOutput->pushTime((*itData2).first);
  112 + _data.clear();
  113 +++tot;
131 114 }
  115 + }
  116 + }
  117 +
  118 + ElementType computeDeriv(std::pair<double, ElementType> data0, std::pair<double, ElementType> data1, std::pair<double, ElementType> data2) {
  119 + ElementType y0 = data0.second;
  120 + ElementType y1 = data1.second;
  121 + ElementType y2 = data2.second;
  122 + double x0 = data0.first;
  123 + double x1 = data1.first;
  124 + double x2 = data2.first;
132 125  
  126 + double x = x1;
  127 + double x02 = x0 -x2;
  128 + double x01 = x0 -x1;
  129 + double x10 = x1 -x0;
  130 + double x12 = x1 -x2;
  131 + double x20 =x2 - x0 ;
  132 + double x21 = x2 -x1;
  133 + double _2x = 2*x;
  134 +
  135 + return y0*(_2x-x1-x2)/(x01*x02) + y1*(_2x-x0-x2)/(x10*x12)+y2*(_2x-x0-x1)/(x20*x21);
133 136 }
134 137  
135 138 private:
... ... @@ -142,15 +145,9 @@ private:
142 145 */
143 146 TParamData *_paramOutput;
144 147  
145   - /**<
146   - * index current of compute
147   - */
148   - unsigned int _index ;
149   -
150   - /**<
151   - * true when last data is write.
152   - */
153   - bool _lastDataWrite;
  148 + bool _firstPointComputed;
  149 + std::pair<double, ElementType> _lastPopData;
  150 + std::list<std::pair<double, ElementType> > _data;
154 151 };
155 152  
156 153 } /* namespace Parameters */
... ...
src/InternLib/Resampling.hh
... ... @@ -271,7 +271,6 @@ public:
271 271 }
272 272 }
273 273 if (pParamDataIndexInfo._timeIntToProcessChanged || pParamDataIndexInfo._noMoreTimeInt) {
274   -std::cout << "BRE - TERMINATED" << std::endl;
275 274 terminated();
276 275 }
277 276 }
... ... @@ -280,15 +279,12 @@ std::cout &lt;&lt; &quot;BRE - TERMINATED&quot; &lt;&lt; std::endl;
280 279 * @brief compute and write last value, right effect
281 280 */
282 281 virtual void terminated() {
283   -std::cout << "BRE - A" << std::endl;
284 282 if (_markerPtr->isFinished()) {
285   -std::cout << "BRE - B" << std::endl;
286 283 return;
287 284 }
288 285 switch (_samplingMode)
289 286 {
290 287 case AVERAGE :
291   -std::cout << "BRE - C" << std::endl;
292 288 do {
293 289 if (!_mem.empty()) {
294 290 _val = average(_mem,_paramInput.getDim1(),_paramInput.getDim2());
... ...