GetClbInfoByIndex.hh 3.52 KB
/*
 * GetClbInfoByIndex.hh
 *
 *  Created on: Sep 24, 2015
 *      Author: AKKA
 */

#ifndef GetClbInfoByIndex_HH_
#define GetClbInfoByIndex_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 GetClbInfoByIndex {

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

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

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

			/**
			 * @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 GetClbInfoByIndex
 * @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 GetClbInfoByIndex : public Base::GetClbInfoByIndex {
public:
	/**
	 * @brief Constructor.
	 * @details Create the ParamData type of the input ParamData.
	 */
  GetClbInfoByIndex(Process& pProcess, TParamData& paramInput)
	: Base::GetClbInfoByIndex(pProcess), _paramInput(paramInput), _paramOutput(new ParamDataTab1DDouble()) {
	  _paramDataOutput=_paramOutput;
	  }

  /**
   *
	 * @overload Base::GetClbInfoByIndex::init()
   */
  void init(Parameter& pInput, Process::AttributeList& pAttribute) {
	  Parameter::InfoList& lInfoList = pInput.getInfoList();

	  std::string clbInfoName = pAttribute[0];
	  int size = atoi(pAttribute[1].c_str());

	  for (unsigned int i=0; i < (unsigned int)size; ++i)
	  {
		  std::string clbInfoIndexName = clbInfoName;
		  clbInfoIndexName += "_";
		  clbInfoIndexName += std::to_string(i);
		  if (lInfoList.find(clbInfoIndexName) == lInfoList.end())
		  {
			  BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("GetClbInfoByIndex::init - Cannot find calibInfo "+clbInfoIndexName)));
		  }
		  _calibrationInfoList[i]=lInfoList[clbInfoIndexName].get();
	  }
  }

  /**
	 * @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));
    	_paramOutput->getDataList().push_back(*(_calibrationInfoList[(int)floor(_paramInput.getDataList()[index])]));
    }
  }

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;
};

} /* namespace GetClbInfoByIndex */
} /* namespace AMDA */
#endif /* GetClbInfoByIndex_HH_ */