ProcessSumIntoTableRange.cc
5.52 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* 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 {
ProcessSumIntoTableRange::ProcessSumIntoTableRange(Parameter ¶meter) : MultiParamProcess_CRTP(parameter), _dim1Table(NULL), _dim2Table (NULL), _outputParamTable(NULL), _mainParamId(""), _tablesInit(false) {
}
ProcessSumIntoTableRange::ProcessSumIntoTableRange(const ProcessSumIntoTableRange& pProcess, Parameter ¶meter)
: MultiParamProcess_CRTP(pProcess,parameter), _dim1Table(pProcess._dim1Table), _dim2Table (pProcess._dim2Table), _outputParamTable(pProcess._outputParamTable), _mainParamId(pProcess._mainParamId), _tablesInit(pProcess._tablesInit) {
}
ProcessSumIntoTableRange::~ProcessSumIntoTableRange() {
}
void ProcessSumIntoTableRange::establishConnection() {
ParameterCreatorFromExpression creator(_parameter.getParameterManager());
ParameterSPtr lParameter = creator.getOneParameterFromExpression(_parameter,_expression, isUserProcess());
_mainParamId = lParameter->getId();
_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) {
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) {
_paramNameList[it->second].first = _parameter.getParameterManager().getParameter(it->second);
}
}
}
if (_dim2Table != NULL) {
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) {
_paramNameList[it->second].first = _parameter.getParameterManager().getParameter(it->second);
}
}
}
_tablesInit = true;
}
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'")));
}
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;
}
}
int relatedDim = atoi(_attributList[0].c_str());
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;
}
AMDA::Info::ParamTable* table1Ptr = NULL;
AMDA::Info::ParamTable* table2Ptr = NULL;
switch (relatedDim) {
case 0:
table1Ptr = _dim1Table;
if (twoRanges)
table2Ptr = _dim2Table;
else
_outputParamTable = _dim2Table;
break;
case 1:
table1Ptr = _dim2Table;
if (twoRanges)
table2Ptr = _dim1Table;
else
_outputParamTable = _dim1Table;
break;
default:
table1Ptr = NULL;
table2Ptr = NULL;
}
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)) {
BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSumIntoTableRange::init Cannot retrieve related table")));
}
ParamData* lmainParamInput = _paramNameList[_mainParamId].first->getParamData(this).get();
SumIntoTableRangeCreator lSumIntoTableRangeCreator(*this, *lmainParamInput, minRange1, maxRange1, table1Ptr, relatedDim, minRange2, maxRange2, table2Ptr);
_operation = lSumIntoTableRangeCreator.getOperation();
_paramData = ParamDataSPtr(_operation->getParamOutput());
_paramData->setMinSampling(lmainParamInput->getMinSampling());
return timeStamp;
}
} /* namespace Parameters */
} /* namespace AMDA */