Blame view

src/ExternLib/Boxcar/Boxcar.hh 3.53 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
30
/*
 * Boxcar.hh
 *
 *  Created on: Dec 3, 2012
 *      Author: f.casimir
 */

#ifndef Boxcar_HH_
#define Boxcar_HH_

#include "Parameter.hh"
#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "Operation.hh"

namespace AMDA {
namespace Parameters {

/**
 * @class Boxcar
 * @brief It is responsible to shift data of any ParamData type.
 * @details This class implement the interface Operation.
 */
template<class TParamData>
class Boxcar : public Operation {
public:
	/**
	 * @brief Constructor.
	 * @details Create the ParamData type of the input ParamData.
	 */
35e5427c   Benjamin Renard   Fix boxcar (#7318)
31
  Boxcar(Process& pProcess, TParamData& paramInput, TimeIntervalListSPtr pTimeIntervalList, double second)
fbe3c2bb   Benjamin Renard   First commit
32
33
34
	: Operation(pProcess),
	  _paramInput(paramInput),
	  _paramOutput(new TParamData()),
35e5427c   Benjamin Renard   Fix boxcar (#7318)
35
36
	  _timeIntervalList(pTimeIntervalList),
	  _currentTimeInterval(_timeIntervalList->begin()),
fbe3c2bb   Benjamin Renard   First commit
37
38
39
40
41
42
43
44
45
46
47
	  _second(second),
	  _nb(0),
	  _lastTime(0.0){
	  _sum << elemNull;
	  _paramDataOutput=_paramOutput;
  }

	/**
	 * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
	 */
  void  write(ParamDataIndexInfo &pParamDataIndexInfo) {
fbe3c2bb   Benjamin Renard   First commit
48
   //first call
91acc36e   Benjamin Renard   Fix boxcar proces...
49
50
    if((_lastTime == 0.0) && (pParamDataIndexInfo._nbDataToProcess > 0)) {
    	_lastTime = _paramInput.getTime(pParamDataIndexInfo._startIndex);
fbe3c2bb   Benjamin Renard   First commit
51
    	//To create a _sum with the good dimention
91acc36e   Benjamin Renard   Fix boxcar proces...
52
    	_sum =  _paramInput.getDataList()[pParamDataIndexInfo._startIndex];
fbe3c2bb   Benjamin Renard   First commit
53
54
    	_sum << elemNull;
    }
91acc36e   Benjamin Renard   Fix boxcar proces...
55
56
    for (unsigned int index = pParamDataIndexInfo._startIndex;
		index< pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; index++) {
fbe3c2bb   Benjamin Renard   First commit
57
58
59
60
61
62
63
64
    	if(_paramInput.getTime(index) - _lastTime >= _second) {
        	pushData();
          	_lastTime = _paramInput.getTime(index);
    	}
    	_nb++;
    	_sum =_sum + _paramInput.getDataList()[index];
    	_timeMemory.push_back(_paramInput.getTime(index));
    }
91acc36e   Benjamin Renard   Fix boxcar proces...
65
    if (pParamDataIndexInfo._timeIntToProcessChanged || pParamDataIndexInfo._noMoreTimeInt) {
fbe3c2bb   Benjamin Renard   First commit
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    	pushData();
    }
  }

  /**
   * @overload Operation::reset(double pStartTime, double pTimeInt)
   * @brief reset static data to process another TimeInterval
   */
  virtual  void  reset() {
	  Operation::reset();
	  _nb = 0;
	  _lastTime = 0.0;
	  _sum << elemNull;
	  _timeMemory.clear();
35e5427c   Benjamin Renard   Fix boxcar (#7318)
80
81
	  if (_currentTimeInterval != _timeIntervalList->end())
		++_currentTimeInterval;
fbe3c2bb   Benjamin Renard   First commit
82
83
84
85
86
87
88
89
90
91
92
  }

private:

  /**
   * @brief write time and data in _paramOutput
   */
  inline void pushData() {

		typename TParamData::ElementType lMean = _sum / _nb;
		for(unsigned indexLocal = 0; indexLocal < _nb; ++indexLocal) {
35e5427c   Benjamin Renard   Fix boxcar (#7318)
93
94
95
96
97
98
			double crtTime = _timeMemory[indexLocal];
			if ((crtTime >= (*_currentTimeInterval)._startTime) && (crtTime <= (*_currentTimeInterval)._stopTime)) {
				_paramOutput->pushTime(crtTime);
				_paramOutput->getDataList().push_back(lMean);
			}

fbe3c2bb   Benjamin Renard   First commit
99
100
101
102
103
104
105
106
107
108
109
110
111
		}
  	_sum << elemNull ;
  	_nb = 0;
  	_timeMemory.clear();
  }
	/**
	 * @brief It is the channel of data to shift.
	 */
  TParamData &_paramInput;
	/**
	 * @brief It is the channel of the data shifted.
	 */
  TParamData *_paramOutput;
35e5427c   Benjamin Renard   Fix boxcar (#7318)
112
113
114
115
116

  TimeIntervalListSPtr _timeIntervalList;

  TimeIntervalList::iterator _currentTimeInterval;

fbe3c2bb   Benjamin Renard   First commit
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
  /**
   * @brief laps time to shift data.
   */
  double _second;

  /**
   * @brief sum of data to compute mean = _sum / _nb.
   */
  typename TParamData::ElementType _sum;

  /**
   * @brief number of data to compute mean = _sum / _nb.
   */
  unsigned int _nb;

  /**
   * @brief time memory.
   */
  std::vector <double > _timeMemory;

  /**
   * @brief last start time of mean compute .
   */
  double _lastTime;
};

} /* namespace Parameters */
} /* namespace AMDA */
#endif /* Boxcar_HH_ */