Blame view

src/InternLib/SingleParamProcess.cc 6.17 KB
1eac3ad2   brenard   Fix tests used to...
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
/*
 * 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 &parameter) : Process(parameter), _paramInput(NULL), _treatTerminated(false), _expressionParsed(false)
		{
		}

		SingleParamProcess::SingleParamProcess(const SingleParamProcess &pProcess, Parameter &parameter) :
				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());
854a7fcf   Benjamin Renard   First implementat...
34
				_parameterInput = creator.getOneParameterFromExpression(_parameter,_expression, isUserProcess());
1eac3ad2   brenard   Fix tests used to...
35
36
37
38
39
40
41
42
43
44
45
		}


		void SingleParamProcess::establishConnection() {
			if (!_expressionParsed)
				parse();
			_expressionParsed = true;
			_parameterInput->openConnection(this);
		}

		unsigned int SingleParamProcess::write() {
1eac3ad2   brenard   Fix tests used to...
46
47
48
49
50
51
52
			int ret = 0;
			unsigned int nbDataBeforeCallProcess = _paramData->getDataNumber();
			ParamDataIndexInfo lParamDataIndexInfo;

			this->_treatTerminated = false;

			lParamDataIndexInfo =_parameterInput->getAsync(this).get();
1eac3ad2   brenard   Fix tests used to...
53
			_operation->write(lParamDataIndexInfo);
c2fa3b5d   Benjamin Renard   Rework of legend ...
54

1eac3ad2   brenard   Fix tests used to...
55
			ret = _paramData->getDataNumber() - nbDataBeforeCallProcess;
bb672c4c   Benjamin Renard   Fix side effect i...
56
                        bool updateDims = (nbDataBeforeCallProcess == 0) && (ret > 0);
1eac3ad2   brenard   Fix tests used to...
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

			// 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());
72d1e9e7   Hacene SI HADJ MOHAND   moitie de l'us
112
113
114
115
116
117
                        
                                                            // adding tableParams into linked params 
                                                            std::map<int, boost::shared_ptr<AMDA::Info::ParamTable>> tables =paramInfo->getTables();

                                                            if(! tables.empty()){
                                                                 for(auto table : tables){
5d98ad1c   Hacene SI HADJ MOHAND   us ok tests ok
118
                                                                     if (table.second != nullptr){
f49cb7a4   Benjamin Renard   Fix bug in base p...
119
120
                                                                            if(table.second->isVariable(&parameter.getParameterManager())){
                                                                            std::map<std::string, std::string> tableParams = table.second->getTableParams(&parameter.getParameterManager());
5d98ad1c   Hacene SI HADJ MOHAND   us ok tests ok
121
122
123
124
125
126
                                                                            if(! tableParams.empty())
                                                                                for(auto tableParam : tableParams){
                                                                                    paramInfo->addLinkedParamId(tableParam.second);
                                                                                }
                                                                     
                                                                           }
72d1e9e7   Hacene SI HADJ MOHAND   moitie de l'us
127
                                                                     }
72d1e9e7   Hacene SI HADJ MOHAND   moitie de l'us
128
129
                                                               }
                                                            }
1eac3ad2   brenard   Fix tests used to...
130
131
132
133
134
135
136
137
138
139
140
141
142
143

			paramInfo->setProcessInfo(processInfo);
		}

		/*
		 * @brief Get min sampling
		 */
		double SingleParamProcess::getMinSampling()
		{
			if (!_expressionParsed)
				parse();
			_expressionParsed = true;
			if (_parameterInput == nullptr)
				return 0;
deefda79   Benjamin Renard   Addapt resampling...
144
145
146
147
148
149
			if (!_parameterInput->getReferenceParameter().empty()) {
				std::string paramRefId = _parameterInput->getReferenceParameter();
				ParameterSPtr refParam = _parameterInput->getParameterManager().getParameter(paramRefId);
				return refParam->getDataWriterTemplate()->getMinSampling();
			}
			else if (_parameterInput->getTimeResolution() > 0)
1eac3ad2   brenard   Fix tests used to...
150
151
152
153
154
155
156
				return _parameterInput->getTimeResolution();
			if (_parameterInput->getDataWriterTemplate() == nullptr)
				return 0;
			return _parameterInput->getDataWriterTemplate()->getMinSampling();
		}
	} /* namespace Parameters */
} /* namespace AMDA */