Blame view

src/ExternLib/sum_into_table_range/ProcessSumIntoTableRange.cc 5.52 KB
bd34e02d   Benjamin Renard   Add sum in table ...
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
/*
 * ProcessSumIntoTableRange.cc
 *
 *  Created on: Oct 6, 2016
 *      Author: AKKA IS
 */
#include <stdlib.h>
#include <string>

#include <boost/lexical_cast.hpp>

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

#include "Operation.hh"
#include "ParameterManager.hh"
#include "ProcessSumIntoTableRange.hh"
#include "SumIntoTableRangeCreator.hh"
#include "ParamMgr.hh"
#include "ParameterCreatorFromExpression.hh"

using namespace std;
using namespace boost;
using namespace log4cxx;

namespace AMDA {
namespace Parameters {

f1326d28   Benjamin Renard   Some fixes
29
  ProcessSumIntoTableRange::ProcessSumIntoTableRange(Parameter &parameter) : MultiParamProcess_CRTP(parameter), _dim1Table(NULL), _dim2Table (NULL), _outputParamTable(NULL), _mainParamId(""), _tablesInit(false) {
bd34e02d   Benjamin Renard   Add sum in table ...
30
31
32
  }

  ProcessSumIntoTableRange::ProcessSumIntoTableRange(const ProcessSumIntoTableRange& pProcess, Parameter &parameter)
f1326d28   Benjamin Renard   Some fixes
33
    : MultiParamProcess_CRTP(pProcess,parameter), _dim1Table(pProcess._dim1Table), _dim2Table (pProcess._dim2Table), _outputParamTable(pProcess._outputParamTable), _mainParamId(pProcess._mainParamId), _tablesInit(pProcess._tablesInit) {
bd34e02d   Benjamin Renard   Add sum in table ...
34
35
36
37
38
39
40
  }

  ProcessSumIntoTableRange::~ProcessSumIntoTableRange() {
  }

  void ProcessSumIntoTableRange::establishConnection() {
	  ParameterCreatorFromExpression creator(_parameter.getParameterManager());
854a7fcf   Benjamin Renard   First implementat...
41
	  ParameterSPtr lParameter = creator.getOneParameterFromExpression(_parameter,_expression, isUserProcess());
966af096   Benjamin Renard   Fix 'sum in range...
42
	  _mainParamId = lParameter->getId();
bd34e02d   Benjamin Renard   Add sum in table ...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
	  _paramNameList[lParameter->getId()].first = lParameter;

	  AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(lParameter->getInfoId());

	  if (paramInfo != nullptr)
	  {
		  std::map<int, boost::shared_ptr<AMDA::Info::ParamTable>>& paramTables = paramInfo->getTables();
		  if (paramTables.find(0) != paramTables.end())
			  _dim1Table = paramInfo->getTable(0).get();
		  else
			  _dim1Table = NULL;
		  if (paramTables.find(1) != paramTables.end())
			  _dim2Table = paramInfo->getTable(1).get();
		  else
			  _dim2Table = NULL;

		  if (_dim1Table != NULL) {
e7ea756d   Benjamin Renard   Implements tables...
60
61
			  if (_dim1Table->isVariable(&_parameter.getParameterManager())) {
				  for (std::map<std::string, std::string>::iterator it = _dim1Table->getTableParams(&_parameter.getParameterManager()).begin(); it != _dim1Table->getTableParams(&_parameter.getParameterManager()).end(); ++it) {
bd34e02d   Benjamin Renard   Add sum in table ...
62
63
64
65
66
67
					  _paramNameList[it->second].first = _parameter.getParameterManager().getParameter(it->second);
				  }
			  }
		  }

		  if (_dim2Table != NULL) {
e7ea756d   Benjamin Renard   Implements tables...
68
69
			  if (_dim2Table->isVariable(&_parameter.getParameterManager())) {
				  for (std::map<std::string, std::string>::iterator it = _dim2Table->getTableParams(&_parameter.getParameterManager()).begin(); it != _dim2Table->getTableParams(&_parameter.getParameterManager()).end(); ++it) {
bd34e02d   Benjamin Renard   Add sum in table ...
70
71
72
73
					  _paramNameList[it->second].first = _parameter.getParameterManager().getParameter(it->second);
				  }
			  }
		  }
f1326d28   Benjamin Renard   Some fixes
74
                  _tablesInit = true;
bd34e02d   Benjamin Renard   Add sum in table ...
75
76
77
78
79
80
81
82
83
84
	  }

	  MultiParamProcess::establishConnection();
  }

  TimeStamp ProcessSumIntoTableRange::init() {
	if (_attributList.size() < 3) {
	  BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSumIntoTableRange::init required at least 3 attributes'")));
	}

f1326d28   Benjamin Renard   Some fixes
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	TimeStamp timeStamp = MultiParamProcess::init();

	if (!_tablesInit) {
		AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(_paramNameList[_mainParamId].first->getInfoId());
		if (paramInfo != nullptr)
		{
			std::map<int, boost::shared_ptr<AMDA::Info::ParamTable>>& paramTables = paramInfo->getTables();
			if (paramTables.find(0) != paramTables.end())
				_dim1Table = paramInfo->getTable(0).get();
			else
				_dim1Table = NULL;
			if (paramTables.find(1) != paramTables.end())
				_dim2Table = paramInfo->getTable(1).get();
			else
				_dim2Table = NULL;
			_tablesInit = true;
			
		}
	}

bd34e02d   Benjamin Renard   Add sum in table ...
105
	int    relatedDim = atoi(_attributList[0].c_str());
8da18331   Benjamin Renard   sum_into_table_ra...
106
107
108
109
110
111
112
113
114
115
116
	double minRange1  = atof(_attributList[1].c_str());
	double maxRange1  = atof(_attributList[2].c_str());

	double minRange2 = -1;
	double maxRange2 = -1;
	bool twoRanges = false; 
	if (_attributList.size() == 5) {
		minRange2 = atof(_attributList[3].c_str());
		maxRange2 = atof(_attributList[4].c_str());
		twoRanges = true;
	}
bd34e02d   Benjamin Renard   Add sum in table ...
117

8da18331   Benjamin Renard   sum_into_table_ra...
118
119
	AMDA::Info::ParamTable* table1Ptr = NULL;
	AMDA::Info::ParamTable* table2Ptr = NULL;
bd34e02d   Benjamin Renard   Add sum in table ...
120
121
	switch (relatedDim) {
	case 0:
8da18331   Benjamin Renard   sum_into_table_ra...
122
123
124
125
126
		table1Ptr = _dim1Table;
		if (twoRanges)
			table2Ptr = _dim2Table;
		else
			_outputParamTable = _dim2Table;
bd34e02d   Benjamin Renard   Add sum in table ...
127
128
		break;
	case 1:
8da18331   Benjamin Renard   sum_into_table_ra...
129
130
131
132
133
		table1Ptr = _dim2Table;
		if (twoRanges)
			table2Ptr = _dim1Table;
		else
			_outputParamTable = _dim1Table;
bd34e02d   Benjamin Renard   Add sum in table ...
134
135
		break;
	default:
8da18331   Benjamin Renard   sum_into_table_ra...
136
137
		table1Ptr = NULL;
		table2Ptr = NULL;
bd34e02d   Benjamin Renard   Add sum in table ...
138
139
	}

8da18331   Benjamin Renard   sum_into_table_ra...
140
141
142
143
	if (table1Ptr == NULL) {
	  BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSumIntoTableRange::init Cannot retrieve related table")));
	}
	if (twoRanges && (table2Ptr == NULL)) {
bd34e02d   Benjamin Renard   Add sum in table ...
144
145
146
	  BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSumIntoTableRange::init Cannot retrieve related table")));
	}

966af096   Benjamin Renard   Fix 'sum in range...
147
	ParamData* lmainParamInput = _paramNameList[_mainParamId].first->getParamData(this).get();
bd34e02d   Benjamin Renard   Add sum in table ...
148

8da18331   Benjamin Renard   sum_into_table_ra...
149
	SumIntoTableRangeCreator lSumIntoTableRangeCreator(*this, *lmainParamInput, minRange1, maxRange1, table1Ptr, relatedDim, minRange2, maxRange2, table2Ptr);
bd34e02d   Benjamin Renard   Add sum in table ...
150
151
152
153
154
155
156
157
158
	_operation = lSumIntoTableRangeCreator.getOperation();
	_paramData = ParamDataSPtr(_operation->getParamOutput());
	_paramData->setMinSampling(lmainParamInput->getMinSampling());

	return timeStamp;
}

} /* namespace Parameters */
} /* namespace AMDA */