Blame view

src/Parameters/Parameter.cc 4.77 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
/**
 * Parameter.cc
 *
 *  Created on: 16 oct. 2012
 *      Author: AKKA IS
 */


#include "Parameter.hh"

#include "ParamGet.hh"
#include "ParamOutput.hh"
#include "ParamData.hh"
#include "Process.hh"
#include "ParamInterval.hh"
#include "CalibrationInfoWriter.hh"

#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "InstrumentMgr.hh"
#include "MissionMgr.hh"

using namespace std;

using namespace AMDA::Info;

namespace AMDA {
namespace Parameters {

  Parameter::Parameter(ParameterManager& pParamMng, string nameParam) :
		  _id(nameParam),
		  _parameterManager(pParamMng),
		  _clientInitCall(0),
		  _timeResolution(0) ,
		  _gapThreshold(pParamMng.getDefaultGapThreshold()) ,
deefda79   Benjamin Renard   Addapt resampling...
36
		  _referenceParameter(""),
193183ca   Benjamin Renard   Give the possibil...
37
		  _timeRestriction(NAN),
fbe3c2bb   Benjamin Renard   First commit
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
		  establishConnectionToDo(true){
  }

  Parameter::~Parameter() {
	  	  IntervalList::iterator it = _intervalList.begin();
	  if (it != _intervalList.end()) {
		  (*it)->setDataWriter(NULL);
	  }
	  for(auto x : _intervalList) { delete x; }
	  for(auto x : _calibrationInfoWriterList) { delete x;}

  }

  /**
   * Update client list.
   */
  void Parameter::openConnection(DataClient *pDataClient) {
	DataClientList::iterator it =  _dataClientList.find(pDataClient);
	if ( it ==  _dataClientList.end()) {
		_dataClientList.insert( make_pair( pDataClient,static_cast<ParamInterval*>(NULL)));
	}

	//To call once time
	if ( establishConnectionToDo ) {
		Process* process = dynamic_cast<Process*>(_dataWriter.get());
		if ( process )  {
			process->establishConnection();
		}
		establishConnectionToDo=false;
	}
  }

  /**
   * Update client list.
   */
  void Parameter::closeConnection(DataClient *pDataClient) {
	DataClientList::iterator it =  _dataClientList.find(pDataClient);
	if ( it !=  _dataClientList.end()) {
		auto lInterval = it->second;
		if (lInterval) { lInterval->removeClient(pDataClient); }
	}
  }

  /**
   * Compute the biggest interval with all client init information.
   */
  TimeStamp  Parameter::init(DataClient *pDataClient, TimeIntervalListSPtr pTimeIntervalList) {

	  TimeStamp lTimeStamp;
	  DataClientList::iterator it =  _dataClientList.find(pDataClient);
	if ( it ==  _dataClientList.end()) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN));
	} else {
		if ( ! it->second ) {
			IntervalList::iterator interval = _intervalList.begin();
			if (interval == _intervalList.end()) {
				//Interval creation
				_intervalList.push_back(new ParamInterval(TimeIntervalListSPtr(pTimeIntervalList),_dataWriter.get()));
				interval = --_intervalList.end();
				TimeStamp lTimeStampInterval = (*interval)->init();
				if(lTimeStampInterval > lTimeStamp) {
					lTimeStamp = lTimeStampInterval;
				}

				/// When the first _dataWriter has initialized the Calibration processing are possible
				///
				for(auto x : _calibrationInfoWriterList) { (*x)(*this); }
			} else {
				for ( ; interval !=  _intervalList.end() && ! (*interval)->getIsEqual(pTimeIntervalList.get()); ++interval );
				if (interval == _intervalList.end()) {
					//Interval creation
					_intervalList.push_back(new ParamInterval(TimeIntervalListSPtr(pTimeIntervalList),_dataWriter->clone(*this)));
					interval = --_intervalList.end();
					TimeStamp lTimeStampInterval = (*interval)->init();
					if(lTimeStampInterval > lTimeStamp) {
						lTimeStamp = lTimeStampInterval;
					}
				}
			}
			(*interval)->addClient(pDataClient);
			it->second=(*interval);
			++_clientInitCall;
		}
	}

	if ( _clientInitCall == _dataClientList.size()) {
		IntervalList::iterator interval = _intervalList.begin();
		for ( ; interval !=  _intervalList.end(); ++interval ) {
			(*interval)->active();
		}
d8db8efb   Benjamin Renard   Fix bugs with tim...
128
//		_clientInitCall=0;
fbe3c2bb   Benjamin Renard   First commit
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
	}

	// Exemple lecture ParamInfo, DataSetInfo, InstrumentInfo, MissionInfo
#if 0
	ParamInfoSPtr paramInfo = ParamMgr::getInstance()->getParamInfoFromId(getInfoId());
	if (paramInfo) {
		DataSetInfoSPtr dataSetInfo = DataSetMgr::getInstance()->getDataSetInfoFromId(paramInfo->getDatasetId());
		if (dataSetInfo) {
			InstrumentInfoSPtr instrumentInfo	= InstrumentMgr::getInstance()->getInstrumentInfoFromId(dataSetInfo->getInstrumentId());
			if (instrumentInfo) {
				MissionInfoSPtr mission	= MissionMgr::getInstance()->getMissionInfoFromId(instrumentInfo->getMissionId());
			}
		}
	}
#endif

	return lTimeStamp;
  }

boost::shared_future<ParamDataIndexInfo> Parameter::getAsync(DataClient * pClient) {
	return _dataClientList[pClient]->getAsync(pClient);
}

ParamDataSPtr& Parameter::getParamData(DataClient* pClient) { return _dataClientList[pClient]->getParamData();}

	void Parameter::delegateOtherTaskTo(ParameterSPtr& pParam) {
		if ( pParam.get() != this) {
			pParam->_calibrationInfoWriterList.splice(pParam->_calibrationInfoWriterList.begin(),_calibrationInfoWriterList);
		}
	}
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
159
bool Parameter::_isTableIndexParam = false;
fbe3c2bb   Benjamin Renard   First commit
160
161
162

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