Blame view

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

#ifndef GetClbInfo_HH_
#define GetClbInfo_HH_

#include "vector"

#include <boost/algorithm/string.hpp>

#include "AMDA_exception.hh"
#include "DicError.hh"

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

using namespace std;
using namespace boost;
using namespace AMDA::Parameters;

namespace AMDA {
namespace GetClbInfo {

namespace Base {
/**
 * @class Base::GetClbInfo
 * @brief It is responsible to shift data of any ParamData type.
 * @details This class implement the interface Operation.
 */
		class GetClbInfo : public Operation {
		public:

			/**
			 * @brief Default Constructor.
			 */
			GetClbInfo(Process& pProcess) : Operation(pProcess) {}

			/**
			 * @brief Destructor.
			 */
			virtual ~GetClbInfo() {}

			/**
			 * @brief initialize the operation .
			 * @detail initialize the operation with information stored in pInput.getInfoList() and pAttribute.
			 */
			virtual void init(Parameter& input, Process::AttributeList& pAttribute)	= 0;

		protected:
		};
	}


/**
 * @class GetClbInfo
 * @brief It is responsible to shift data of any ParamData type.
 * @details This class implement the interface Operation for a TParamData.
 */
template<class TParamData>
class GetClbInfo : public Base::GetClbInfo {
public:
e7d009ea   Benjamin Renard   Fix GetClbInfo wh...
67
68
  typedef typename TParamData::ElementType ElementType;

fbe3c2bb   Benjamin Renard   First commit
69
70
71
72
73
	/**
	 * @brief Constructor.
	 * @details Create the ParamData type of the input ParamData.
	 */
  GetClbInfo(Process& pProcess, TParamData& paramInput)
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
74
	: Base::GetClbInfo(pProcess), _paramInput(paramInput), _paramOutput(new ParamDataTab1DDouble()), _maxSize(0) {
fbe3c2bb   Benjamin Renard   First commit
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
	  _paramDataOutput=_paramOutput;
	  }

  /**
   *
	 * @overload Base::GetClbInfo::init()
   */
  void init(Parameter& pInput, Process::AttributeList& pAttribute) {
	  Parameter::InfoList& lInfoList = pInput.getInfoList();
	  std::vector <std::string> fields;
	  for(auto pair : pAttribute) {
		  split( fields, pair, is_any_of( ":" ) );
		  // Check format
		  if (fields.size() != 2) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("GetClbInfo bad format: ") + pair));
		  }
		  // Check consistency
		  auto lIt = lInfoList.find(fields[1]);
		  if ( lIt == lInfoList.end()) {
			 BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("GetClbInfo calibration info: '") + fields[1] + "' not found."));
		  }
		  _calibrationInfoList[atoi(fields[0].c_str())]=lIt->second.get();
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
97
		  _maxSize = std::max(_maxSize, (int)_calibrationInfoList[atoi(fields[0].c_str())]->size());
fbe3c2bb   Benjamin Renard   First commit
98
99
100
101
102
103
104
105
106
107
	  }
  }

  /**
	 * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
	 */
  void  write(ParamDataIndexInfo &pParamDataIndexInfo) {
    unsigned int index = pParamDataIndexInfo._startIndex;
    for (; index< pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; index++) {
    	_paramOutput->pushTime(_paramInput.getTime(index));
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
108

e7d009ea   Benjamin Renard   Fix GetClbInfo wh...
109
	ElementType value = _paramInput.getDataList()[index];
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
110
111
	std::vector<double> calib;
	calib.resize(_maxSize, std::nan(""));
d7f0e3d7   Benjamin Renard   Fix GetCalibInfo
112
113
114
115
116
117
118
119
120
121
	int clb_index = (int)floor(value);
	if (!isNAN(value) && (clb_index >= 0) && (clb_index < _calibrationInfoList.size())) {
		Parameter::InfoValues* info = _calibrationInfoList[clb_index];

		if (info != NULL) {
			int i = 0;
			for (std::vector<double>::iterator it = info->begin(); it != info->end(); ++it) {
				calib[i]  = (*it);
				++i;
			}
e7d009ea   Benjamin Renard   Fix GetClbInfo wh...
122
		}
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
123
124
125
	}

    	_paramOutput->getDataList().push_back(calib);
fbe3c2bb   Benjamin Renard   First commit
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    }
  }

private:
	/**
	 * @brief It is the channel of calibration.
	 */
  TParamData &_paramInput;

	/**
	 * @brief It is the channel of the data shifted.
	 */
  ParamDataTab1DDouble *_paramOutput;


	/**
	 * @brief map of calibrationInfo.
	 * @detail for expression #getClbInfo($ETableN;0:ImaEner_0;1:ImaEner_1)
	 * the key of map is 0 respectively  1
	 * the value of map is  the value of attributes  ImaEner[0] respectively and ImaEner[0]
	 */
  std::map<unsigned int , Parameter::InfoValues*> _calibrationInfoList;
3a91e5e3   Benjamin Renard   Fix mex/vex els p...
148
149

  int _maxSize;
fbe3c2bb   Benjamin Renard   First commit
150
151
152
153
154
};

} /* namespace GetClbInfo */
} /* namespace AMDA */
#endif /* GetClbInfo_HH_ */