/* * GetClbInfo.hh * * Created on: Dec 3, 2012 * Author: f.casimir */ #ifndef GetClbInfo_HH_ #define GetClbInfo_HH_ #include "vector" #include #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 GetClbInfo : public Base::GetClbInfo { public: typedef typename TParamData::ElementType ElementType; /** * @brief Constructor. * @details Create the ParamData type of the input ParamData. */ GetClbInfo(Process& pProcess, TParamData& paramInput) : Base::GetClbInfo(pProcess), _paramInput(paramInput), _paramOutput(new ParamDataTab1DDouble()), _maxSize(0) { _paramDataOutput=_paramOutput; } /** * * @overload Base::GetClbInfo::init() */ void init(Parameter& pInput, Process::AttributeList& pAttribute) { Parameter::InfoList& lInfoList = pInput.getInfoList(); std::vector 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(); _maxSize = std::max(_maxSize, (int)_calibrationInfoList[atoi(fields[0].c_str())]->size()); } } /** * @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)); ElementType value = _paramInput.getDataList()[index]; std::vector calib; calib.resize(_maxSize, std::nan("")); 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::iterator it = info->begin(); it != info->end(); ++it) { calib[i] = (*it); ++i; } } } _paramOutput->getDataList().push_back(calib); } } 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 _calibrationInfoList; int _maxSize; }; } /* namespace GetClbInfo */ } /* namespace AMDA */ #endif /* GetClbInfo_HH_ */