Blame view

src/Info/ParamInfo.cc 8.41 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/*
 * ParamInfo.cc
 *
 *  Created on: Oct 8, 2014
 *      Author: m.mazel
 */

#include "ParamInfo.hh"
a11fb6d3   Hacene SI HADJ MOHAND   lol
9
#include "Parameter.hh"
dc01b853   Hacene SI HADJ MOHAND   il reste get cali...
10
#include "Process.hh"
a11fb6d3   Hacene SI HADJ MOHAND   lol
11
12
13
14
15
16
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <iostream>
fbe3c2bb   Benjamin Renard   First commit
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

namespace AMDA {
namespace Info {

std::ostream& operator<<(std::ostream& out, const ParamInfo& pi){

	out << "[ParamInfo]" << std::endl;
	out << "{"<<std::endl;
	out << "  _id                 = " << pi._id << std::endl;
	out << "  _name               = " << pi._name << std::endl;
	out << "  _short_name         = " << pi._short_name << std::endl;
	out << "  _components         = " << pi._components << std::endl;
	out << "  _units              = " << pi._units << std::endl;
	out << "  _coordinates_system = " << pi._coordinates_system << std::endl;
	out << "  _tensor_order       = " << pi._tensor_order << std::endl;
	out << "  _si_conversion      = " << pi._si_conversion << std::endl;
	out << "  _fill_value         = " << pi._fill_value << std::endl;
	out << "  _ucd                = " << pi._ucd << std::endl;
	out << "  _statusDef          = ";
	for (auto status : pi._statusDef)
		out  << "[" << status.getMinValue() <<
		", " << status.getMaxValue() <<
		", " << status.getName() << "]," << std::endl;
	out << "  _processInfo        = " << pi._processInfo << std::endl;
	out << "  _processDesc        = " << pi._processDesc << std::endl;
	out << "  _linkedParamList    = ";
	for (auto linkedParam : pi._linkedParamList)
		out << linkedParam << ", ";
	out << std::endl;
	out << "  _dataset_id         = " << pi._dataset_id << std::endl;
8c8ac7bf   Benjamin Renard   Write mission/ins...
47
	out << "  _instrument_id         = " << pi._dataset_id << std::endl;
fbe3c2bb   Benjamin Renard   First commit
48
49
50
51
52
53
	out << "}" << std::endl;
	return out;
}

#define PUSHINFO(infoMap, key, value) if(!value.empty())infoMap.push_back(std::pair<std::string,std::string>(key,value))

a11fb6d3   Hacene SI HADJ MOHAND   lol
54
std::vector<std::pair<std::string,std::string>> ParamInfo::getInfoMap(ParameterManager * parameterManager)
fbe3c2bb   Benjamin Renard   First commit
55
56
57
58
59
60
61
{
	std::vector<std::pair<std::string,std::string>> infoMap;

	PUSHINFO(infoMap, PARAMETER_ID, getId());
	PUSHINFO(infoMap, PARAMETER_NAME,getName());
	PUSHINFO(infoMap, PARAMETER_SHORT_NAME,getShortName());

0051287c   Hacene SI HADJ MOHAND   starting us
62
	if (getProcessInfo().empty() )
fbe3c2bb   Benjamin Renard   First commit
63
64
65
66
67
68
69
70
71
72
	{
		//not a processed param
		PUSHINFO(infoMap, PARAMETER_COMPONENTS, getComponents());
		PUSHINFO(infoMap, PARAMETER_UNITS, getUnits());
		PUSHINFO(infoMap, PARAMETER_COORDSYS, getCoordinatesSystem());
		std::stringstream tensorOrder;
		tensorOrder << getTensorOrder();
		PUSHINFO(infoMap, PARAMETER_TENSOR, tensorOrder.str());
		PUSHINFO(infoMap, PARAMETER_SICONV, getSiConversion());

fbe3c2bb   Benjamin Renard   First commit
73

fbe3c2bb   Benjamin Renard   First commit
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
		std::stringstream fillVal;
		fillVal << getFillValue();
		PUSHINFO(infoMap, PARAMETER_FILLVALUE, fillVal.str());
		PUSHINFO(infoMap, PARAMETER_UCD, getUcd());

		//push status if defined
		if (!_statusDef.empty())
		{
			for (int i = 0; i < (int)_statusDef.size(); ++i)
			{
				std::stringstream statusIndex;
				statusIndex << i;

				std::stringstream crtVal;

				std::stringstream infoKey;
				infoKey.str("");
				infoKey << PARAMETER_STATUS_NAME << "[" << statusIndex.str() << "]";
				PUSHINFO(infoMap, infoKey.str(),_statusDef[i].getName());
				infoKey.str("");
				infoKey << PARAMETER_STATUS_MIN << "[" << statusIndex.str() << "]";
				crtVal.str("");
				crtVal << _statusDef[i].getMinValue();
				PUSHINFO(infoMap, infoKey.str(),crtVal.str());
				infoKey.str("");
				infoKey << PARAMETER_STATUS_MAX << "[" << statusIndex.str() << "]";
				crtVal.str("");
				crtVal << _statusDef[i].getMaxValue();
				PUSHINFO(infoMap, infoKey.str(),crtVal.str());
			}
		}
dc01b853   Hacene SI HADJ MOHAND   il reste get cali...
105
106
107
108
109
110
111
112
113
114
115
                
                       		if (_tables.empty())
		{
			//no table defined
			//PUSHINFO(infoMap, PARAMETER_TABLE, std::string("None"));
		}
		else
		{
			//push tables definition
			for (auto table : _tables)
			{
5d98ad1c   Hacene SI HADJ MOHAND   us ok tests ok
116
117
                                                                 if(table.second != nullptr)
                                                                      table.second->addTableInfo(parameterManager, table.first, infoMap);
dc01b853   Hacene SI HADJ MOHAND   il reste get cali...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
                                                            }
		}
                                        //adjout des info de tables 
                                        ParameterSPtr param = parameterManager->getParameter(getId());
                                        std::map<std::string, boost::shared_ptr<std::vector<double>>> infoList =param->getInfoList();
                                                if(! infoList.empty()){
                                                    for (auto inf : infoList){
                                                        if(! inf.second->empty()){
                                                             std::ostringstream values;

                                                             // Convert all but the last element to avoid a trailing ","
                                                             std::copy(inf.second->begin(), inf.second->end()-1,
                                                              std::ostream_iterator<double>(values, ","));

                                                           // Now add the last element with no delimiter
                                                           values<< inf.second->back();
                                                           std::stringstream infoKey;
                                                infoKey.str("");
                                                infoKey << PARAMETER_INFO<< "[" << inf.first  << "]";
                                                PUSHINFO(infoMap ,  infoKey.str()  , values.str());
                                                }
                                            }
                                        }
                
fbe3c2bb   Benjamin Renard   First commit
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
	}
	else
	{
		//processed parameter
		PUSHINFO(infoMap, PARAMETER_PROCESS_INFO, getProcessInfo());
		PUSHINFO(infoMap, PARAMETER_PROCESS_DESC, getProcessDescription());

		std::stringstream linkedParam;
		bool isFirst = true;
		for (auto param : _linkedParamList)
		{
			if (!isFirst)
				linkedParam << ",";
			isFirst = false;
			linkedParam << param;
		}
0051287c   Hacene SI HADJ MOHAND   starting us
158
		
dc01b853   Hacene SI HADJ MOHAND   il reste get cali...
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
                                         PUSHINFO(infoMap, PARAMETER_LINKED_PARAM, linkedParam.str());
	
                                        ParameterSPtr pParam = parameterManager->getParameter(getId());
                                        Process* lProcess = dynamic_cast<Process*>(pParam->getDataWriterTemplate().get());
                                        if( lProcess  != NULL){
                                            std::list<std::string>clbList=  lProcess->getUsedClbInfo();
                                            if(! clbList.empty()){
                                               std::map<std::string, boost::shared_ptr<std::vector<double>>> infoList =pParam->getInfoList();
                                                 if(! infoList.empty()){
                                                    for (auto inf : infoList){
                                                        if(! inf.second->empty() && (std::find(clbList.begin(), clbList.end(), inf.first) != clbList.end())) {
                                                             std::ostringstream values;
                                                             // Convert all but the last element to avoid a trailing ","
                                                             std::copy(inf.second->begin(), inf.second->end()-1,
                                                              std::ostream_iterator<double>(values, ","));

                                                           // Now add the last element with no delimiter
                                                           values<< inf.second->back();
                                                           std::stringstream infoKey;
                                                infoKey.str("");
                                                infoKey << PARAMETER_INFO<< "[" << inf.first  << "]";
                                                PUSHINFO(infoMap ,  infoKey.str()  , values.str());
                                                }
                                            }
                                        }
                                            
                                        }
                                        }
                                        //Process* lProcess = ServicesServer::getInstance()->getProcess("sampling_classic", &param);
                    }

fbe3c2bb   Benjamin Renard   First commit
190
191
192
193
194
	return infoMap;
}

} /* namespace Info */
} /* namespace AMDA */