SingleParamProcess.cc
6.17 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
/*
* SingleParamProcess.cc
*
* Created on: Feb 6, 2013
* Author: f.casimir
*/
#include "Operation.hh"
#include "ParamData.hh"
#include "SingleParamProcess.hh"
#include "ParameterCreatorFromExpression.hh"
#include "ParamMgr.hh"
namespace AMDA {
namespace Parameters {
SingleParamProcess::SingleParamProcess(Parameter ¶meter) : Process(parameter), _paramInput(NULL), _treatTerminated(false), _expressionParsed(false)
{
}
SingleParamProcess::SingleParamProcess(const SingleParamProcess &pProcess, Parameter ¶meter) :
Process(pProcess,parameter),
_parameterInput(pProcess._parameterInput),
_paramInput(NULL), _treatTerminated(false), _expressionParsed(false) {
//Establish Connection Without Parse
_parameterInput->openConnection(this);
}
SingleParamProcess::~SingleParamProcess() {
}
void SingleParamProcess::parse() {
ParameterCreatorFromExpression creator(_parameter.getParameterManager());
_parameterInput = creator.getOneParameterFromExpression(_parameter,_expression, isUserProcess());
}
void SingleParamProcess::establishConnection() {
if (!_expressionParsed)
parse();
_expressionParsed = true;
_parameterInput->openConnection(this);
}
unsigned int SingleParamProcess::write() {
int ret = 0;
unsigned int nbDataBeforeCallProcess = _paramData->getDataNumber();
ParamDataIndexInfo lParamDataIndexInfo;
this->_treatTerminated = false;
lParamDataIndexInfo =_parameterInput->getAsync(this).get();
_operation->write(lParamDataIndexInfo);
ret = _paramData->getDataNumber() - nbDataBeforeCallProcess;
bool updateDims = (nbDataBeforeCallProcess == 0) && (ret > 0);
// Reset operation to prepare static data for the next TimeInterval.
if (lParamDataIndexInfo._timeIntToProcessChanged) {
_paramData->getIndexInfo()._endTimeIntIndexList.push_back(_paramData->getDataNumber());
_operation->reset();
}
// There is no more time interval to process
else if (lParamDataIndexInfo._noMoreTimeInt) {
_paramData->getIndexInfo()._endTimeIntIndexList.push_back(_paramData->getDataNumber());
} else {
// Nothing to do.
}
// Pull up information on which time interval changed.
_paramData->getIndexInfo()._timeIntToProcessChanged = lParamDataIndexInfo._timeIntToProcessChanged;
_paramData->getIndexInfo()._noMoreTimeInt = lParamDataIndexInfo._noMoreTimeInt;
if (updateDims)
_paramData->updateDims();
return ret;
}
/*
* @brief @ to know the resampling strategy to use. If it's true, the nearest value will be use
*/
bool SingleParamProcess::useNearestValue()
{
return _parameterInput->getDataWriterTemplate()->useNearestValue();
}
/**
* @brief update parameter info in relation to the process
*/
void SingleParamProcess::updateInfo(Parameter & parameter)
{
LOG4CXX_DEBUG(_logger, "SingleParamProcess::updateInfo - " << parameter.getId());
if (parameter.getInfoId().empty())
parameter.setInfoId(parameter.getId());
//just clone param info from input parameter to processed parameter
AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->cloneParamInfoFromId(_parameterInput->getInfoId(), parameter.getInfoId());
if (paramInfo == nullptr)
return;
//Derived parameter => no comes from a dataset
paramInfo->setDatasetId("");
std::string processInfo = "Single param process from '";
processInfo += _parameterInput->getId();
processInfo += "'";
paramInfo->addLinkedParamId(_parameterInput->getId());
// adding tableParams into linked params
std::map<int, boost::shared_ptr<AMDA::Info::ParamTable>> tables =paramInfo->getTables();
if(! tables.empty()){
for(auto table : tables){
if (table.second != nullptr){
if(table.second->isVariable(¶meter.getParameterManager())){
std::map<std::string, std::string> tableParams = table.second->getTableParams(¶meter.getParameterManager());
if(! tableParams.empty())
for(auto tableParam : tableParams){
paramInfo->addLinkedParamId(tableParam.second);
}
}
}
}
}
paramInfo->setProcessInfo(processInfo);
}
/*
* @brief Get min sampling
*/
double SingleParamProcess::getMinSampling()
{
if (!_expressionParsed)
parse();
_expressionParsed = true;
if (_parameterInput == nullptr)
return 0;
if (!_parameterInput->getReferenceParameter().empty()) {
std::string paramRefId = _parameterInput->getReferenceParameter();
ParameterSPtr refParam = _parameterInput->getParameterManager().getParameter(paramRefId);
return refParam->getDataWriterTemplate()->getMinSampling();
}
else if (_parameterInput->getTimeResolution() > 0)
return _parameterInput->getTimeResolution();
if (_parameterInput->getDataWriterTemplate() == nullptr)
return 0;
return _parameterInput->getDataWriterTemplate()->getMinSampling();
}
} /* namespace Parameters */
} /* namespace AMDA */