Blame view

src/ParamGetImpl/DDServerInterface/ParamGetDDBase.cc 10 KB
fbe3c2bb   Benjamin Renard   First commit
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
/*
 * ParamGetDDBase.cc
 *
 *  Created on: 15 oct. 2012
 *      Author: casimir
 */

#include "DDServerInterfaceConfig.hh"
#include "VirtualInstrumentManager.hh"
#include "VirtualInstrument.hh"
#include "VirtualInstrumentInterval.hh"
#include "Packet.hh"
#include "ParamGetDDBase.hh"

#include <stdlib.h>

#include "Parameter.hh"
#include "ParamData.hh"
#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "DicError.hh"
#include "TimeUtil.hh"
#include "Helper.hh"


using namespace AMDA::DDServerInterface;
using namespace VI;

namespace AMDA {

	namespace DDServerInterface {
		class VirtualInstrumentInterval;
	} // DDServerInterface

	namespace Parameters {

		ParamGetDDBase::ParamGetDDBase(Parameter &parameter) :
6edc9ff8   Hacene SI HADJ MOHAND   rm_6463
38
				ParamGet_CRTP<ParamGetDDBase>(parameter), _parName(""), _viName(""), _maxDim1Size(-1), _maxDim2Size(-1), _maxDim3Size(-1), _dim3Num(-1), _dim3CutIndex(-1), _minSumIndex(-1), _maxSumIndex(-1), _pusher(NULL), _timeStamp(0) {
fbe3c2bb   Benjamin Renard   First commit
39
40
41
42
		}

		ParamGetDDBase::ParamGetDDBase(const ParamGetDDBase &pParamGetDDBase, Parameter &parameter) :
				ParamGet_CRTP<ParamGetDDBase>(pParamGetDDBase, parameter), _parName(pParamGetDDBase._parName), _viName(pParamGetDDBase._viName)
0dfc4085   Benjamin Renard   Give the possibil...
43
								, _maxDim1Size(pParamGetDDBase._maxDim1Size), _maxDim2Size(pParamGetDDBase._maxDim2Size), _maxDim3Size(pParamGetDDBase._maxDim3Size)
ff482c31   Benjamin Renard   Give the possibil...
44
								, _dim3Num(pParamGetDDBase._dim3Num), _dim3CutIndex(pParamGetDDBase._dim3CutIndex)
6edc9ff8   Hacene SI HADJ MOHAND   rm_6463
45
                                                                                                                                                                , _minSumIndex(pParamGetDDBase._minSumIndex), _maxSumIndex(pParamGetDDBase._maxSumIndex)
fbe3c2bb   Benjamin Renard   First commit
46
47
48
49
50
51
52
53
54
								, _pusher(pParamGetDDBase._pusher), _infoRequestList(pParamGetDDBase._infoRequestList), _timeStamp(pParamGetDDBase._timeStamp) {
		}

		ParamGetDDBase::~ParamGetDDBase() {
			/*---------- Close VI and return -----------------------*/
			delete _pusher;
		}

		TimeStamp ParamGetDDBase::init() {
2f05d991   RENARD Benjamin   Generate param in...
55
                        /// Create ParamData
fbe3c2bb   Benjamin Renard   First commit
56
57
			_vi = VirtualInstrumentManager::getInstance()->getVirtualInstrument(
					_viName);
193183ca   Benjamin Renard   Give the possibil...
58
			_pusher = _vi->getParamPusher(_parName, _maxDim1Size, _maxDim2Size, _maxDim3Size, _dim3Num, _dim3CutIndex, _minSumIndex, _maxSumIndex, _parameter.getTimeRestriction());
65c661e8   Benjamin Renard   Table definition ...
59
60
			//Param info
			AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(_parameter.getInfoId(),true);
6d3dba6e   Benjamin Renard   Fix bug with fill...
61
			if ((paramInfo != nullptr) && (isnan(_pusher->getFillValue())) && (!isnan(paramInfo->getOriginalFillValue())))
65c661e8   Benjamin Renard   Table definition ...
62
			{
6d3dba6e   Benjamin Renard   Fix bug with fill...
63
				_pusher->setFillValue(paramInfo->getOriginalFillValue());
65c661e8   Benjamin Renard   Table definition ...
64
			}
fbe3c2bb   Benjamin Renard   First commit
65
66
67
			_paramData = ParamDataSPtr(_pusher->_paramData);
			_paramData->setMinSampling(_vi->getMinSampling());

2f05d991   RENARD Benjamin   Generate param in...
68
                        getDDInfo();
fbe3c2bb   Benjamin Renard   First commit
69
70
71
			// Get ParamFlow instance only if there is at least one TimeInterval to process
			// and if delta is not equal to 0.
			if (_timeIntervalList->size() != 0 && !(_timeIntervalList->size() == 1 && (_timeIntervalList->front()._stopTime - _timeIntervalList->front()._startTime) == 0) ) {
2f05d991   RENARD Benjamin   Generate param in...
72
                            _paramFlow = _vi->getParamFlow(_parName, _timeIntervalList);
fbe3c2bb   Benjamin Renard   First commit
73
74
75
76
77
78
79
80
81
82
			} else if (_timeIntervalList->size() == 0) {
				LOG4CXX_WARN(gLogger, "ParamGetDDBase::init => List of time interval is empty");
			} else {
				// Nothing to do
			}
			if (_timeStamp == 0 && _signatureTrigger != "") {
				// _signatureTrigger must be a name of xml parameter file
				_timeStamp = AMDA::Helpers::Helper::dateOfFile(
						_signatureTrigger.c_str());
			}
2f05d991   RENARD Benjamin   Generate param in...
83
84
85
                        
                        setGlobalStart(_vi->getGlobalStartTime());
                        setGlobalStop(_vi->getGlobalStopTime());
fbe3c2bb   Benjamin Renard   First commit
86
87
88
89
90
91
92
93
94
95
96
97

			return _timeStamp;
		}

		unsigned int ParamGetDDBase::write() {
			unsigned int result = 0;

			if (_paramFlow.get() == nullptr) {
				BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::ex_msg("Param flow not yet initialized for parameter '" + _parName));
			} else {
				// Nothing to do
			}
a6490f4d   Benjamin Renard   Do not throw an e...
98

fbe3c2bb   Benjamin Renard   First commit
99
100
			PacketPtr lPacket = _paramFlow->get();
			if (lPacket) {
a6490f4d   Benjamin Renard   Do not throw an e...
101
102
103
104
105
106
107
108
				if (lPacket->nodata) {
					LOG4CXX_DEBUG(gLogger, "ParamGetDDBase::write => no data packet");
					//Add NaN value at interval start and stop times
					_paramData->getTimeList().push_back(lPacket->startTime);
					_pusher->putNaN();
					_paramData->getTimeList().push_back(lPacket->stopTime);
					_pusher->putNaN();
					_paramData->getIndexInfo()._timeIntToProcessChanged = _paramFlow->isTimeIntToProcessChanged();
fa4b7852   Benjamin Renard   Fix bug around ti...
109
					_paramData->getIndexInfo()._noMoreTimeInt = _paramFlow->isNoMoreTimeInt();
a6490f4d   Benjamin Renard   Do not throw an e...
110
111
					_paramData->getIndexInfo()._nbDataToProcess = 2;
					result += 2;
fbe3c2bb   Benjamin Renard   First commit
112
					delete lPacket;
a6490f4d   Benjamin Renard   Do not throw an e...
113
114
115
116
				}
				else {
					do {
						result += lPacket->data->VarNumber;
193183ca   Benjamin Renard   Give the possibil...
117
118
						LOG4CXX_DEBUG(gLogger, "put data " << lPacket->data->VarNumber);
						_pusher->put(lPacket->data.get(), lPacket->time.get());
a6490f4d   Benjamin Renard   Do not throw an e...
119
120
121
122
123
						delete lPacket;
					} while( ( lPacket = _paramFlow->tryGet()));

					// Push up the information if all time interval was processed.
					_paramData->getIndexInfo()._timeIntToProcessChanged = _paramFlow->isTimeIntToProcessChanged();
fa4b7852   Benjamin Renard   Fix bug around ti...
124
					_paramData->getIndexInfo()._noMoreTimeInt = _paramFlow->isNoMoreTimeInt();
a6490f4d   Benjamin Renard   Do not throw an e...
125
126
127
128
129
				}
			}
			else {
				// Push up the information if all time interval was processed.
				_paramData->getIndexInfo()._timeIntToProcessChanged = _paramFlow->isTimeIntToProcessChanged();
fa4b7852   Benjamin Renard   Fix bug around ti...
130
				_paramData->getIndexInfo()._noMoreTimeInt = _paramFlow->isNoMoreTimeInt();
fbe3c2bb   Benjamin Renard   First commit
131
132
			}

a6490f4d   Benjamin Renard   Do not throw an e...
133

fbe3c2bb   Benjamin Renard   First commit
134
135

			// if time interval changed store index which delimit the end of the time interval.
fa4b7852   Benjamin Renard   Fix bug around ti...
136
			if (_paramData->getIndexInfo()._timeIntToProcessChanged || _paramData->getIndexInfo()._noMoreTimeInt) {
fbe3c2bb   Benjamin Renard   First commit
137
138
139
140
141
142
143
144
145
146
				unsigned int lEndTimeIntIndex = _paramData->getIndexInfo()._nbDataToProcess;
				_paramData->getIndexInfo()._endTimeIntIndexList.push_back(lEndTimeIntIndex);
			}
			else {
				// Nothing to do.
			}

			return result;
		}

fbe3c2bb   Benjamin Renard   First commit
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
		void ParamGetDDBase::getDDInfo() {
			for (InfoRequestList::iterator lIt = _infoRequestList.begin();
					lIt != _infoRequestList.end(); ++lIt) {
				auto lInfoName = *lIt;
				if (_parameter.getInfoList().find(lInfoName)
						== _parameter.getInfoList().end()) {
					LOG4CXX_INFO( gLogger,
							"ParamGetDDBase:getInfoDD( " << lInfoName << "')");
					const InfoList& lList = _vi->getDDInfo(lIt->c_str());
					for (auto lIt : lList) {
						_parameter.setInfoValues(lIt.first.c_str(), lIt.second);
					}
				}
			}
		}

		/*
		 * @brief Get min sampling
		 */
		double ParamGetDDBase::getMinSampling()
		{
			_vi = VirtualInstrumentManager::getInstance()->getVirtualInstrument(
				_viName);
			return _vi->getMinSampling();
		}

		/**
		 * @brief update parameter info in relation to the ParamGet
		 */
		void ParamGetDDBase::updateInfo(Parameter & parameter)
		{
			LOG4CXX_DEBUG(gLogger, "ParamGetDDBase::updateInfo - " << parameter.getId());
			if (parameter.getInfoId().empty())
				parameter.setInfoId(parameter.getId());

			//Param info
			AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(parameter.getInfoId(),true);

			if (paramInfo == nullptr)
				return;

			//fill value automatically replace by nan
			paramInfo->setFillValue(NAN);

			//Add parameter info id as parameter name if no exist
			if (paramInfo->getName().empty())
				paramInfo->setName(parameter.getInfoId());

			//Add parameter info id as parameter short name if no exist
			if (paramInfo->getShortName().empty())
				paramInfo->setShortName(parameter.getInfoId());

			std::string datasetId = paramInfo->getDatasetId();
			if (datasetId.empty())
				//get vi ID as dataset id if no dataset info defined
				datasetId = _vi->getViName();

			//link dataset info to param info
			paramInfo->setDatasetId(datasetId);

			//Dataset info
			AMDA::Info::DataSetInfoSPtr datasetInfo = AMDA::Info::DataSetMgr::getInstance()->getDataSetInfoFromId(datasetId,true);

31f7feac   Hacene SI HADJ MOHAND   ajout autre info
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
 										                                                            // 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(&parameter.getParameterManager())){
                                                                            std::map<std::string, std::string> tableParams = table.second->getTableParams(&parameter.getParameterManager());
                                                                            if(! tableParams.empty())
                                                                                for(auto tableParam : tableParams){
                                                                                    paramInfo->addLinkedParamId(tableParam.second);
                                                                                }
                                                                     
                                                                           }
                                                                     }
                                                               }
                                                            }
                        
fbe3c2bb   Benjamin Renard   First commit
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
			if (datasetInfo == nullptr)
				return;

			//Add dataset id as dataset name if no exist
			if (datasetInfo->getName().empty())
				datasetInfo->setName(_vi->getViName());

			//Set sampling values
			datasetInfo->setMinSampling((int)_vi->getMinSampling());
			datasetInfo->setMaxSampling((int)_vi->getMaxSampling());

			//Set global start time
			std::stringstream isoTime;
			TimeUtil::formatTimeDateInIso(_vi->getGlobalStartTime(), isoTime);
			datasetInfo->setGlobalStart(isoTime.str());

			//Set global stop time
			isoTime.str("");
			TimeUtil::formatTimeDateInIso(_vi->getGlobalStopTime(), isoTime);
			datasetInfo->setGlobalStop(isoTime.str());

			//Set source
			datasetInfo->setSource("CDPP/DDServer");
		}

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