ParamInfo.hh 9.26 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 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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
/*
 * ParamInfo.hh
 *
 *  Created on: Oct 6, 2014
 *      Author: m.mazel
 */

#ifndef PARAMINFO_HH_
#define PARAMINFO_HH_

#include <iostream>
#include <sstream>
#include <set>
#include <boost/shared_ptr.hpp>
#include <algorithm>

#include "InfoLogger.hh"
#include "ParamTable.hh"
#include "StatusInfo.hh"
#include "ParameterIndexesTool.hh"


namespace AMDA {
namespace Info {

//Info keys for params
#define PARAMETER_ID           "PARAMETER_ID"
#define PARAMETER_NAME         "PARAMETER_NAME"
#define PARAMETER_SHORT_NAME   "PARAMETER_SHORT_NAME"
#define PARAMETER_COMPONENTS   "PARAMETER_COMPONENTS"
#define PARAMETER_UNITS        "PARAMETER_UNITS"
#define PARAMETER_COORDSYS     "PARAMETER_COORDINATE_SYSTEM"
#define PARAMETER_TENSOR       "PARAMETER_TENSOR_ORDER"
#define PARAMETER_SICONV       "PARAMETER_SI_CONVERSION"
#define PARAMETER_FILLVALUE    "PARAMETER_FILL_VALUE"
#define PARAMETER_UCD          "PARAMETER_UCD"
#define PARAMETER_STATUS_NAME  "PARAMETER_STATUS_NAME"
#define PARAMETER_STATUS_MIN   "PARAMETER_STATUS_MIN"
#define PARAMETER_STATUS_MAX   "PARAMETER_STATUS_NAX"
#define PARAMETER_PROCESS_INFO "PARAMETER_PROCESS_INFO"
#define PARAMETER_PROCESS_DESC "PARAMETER_PROCESS_DESC"
#define PARAMETER_LINKED_PARAM "PARAMETER_LINKED_PARAMS"
#define PARAMETER_INFO "PARAMETER_INFO"

/**
 * @class ParamInfo
 * @brief Information about a parameter.
 * @details
 */
class ParamInfo {
public:
	ParamInfo () :
		_id(""),
		_name(""),
		_short_name(""),
		_components(""),
		_units(""),
		_coordinates_system(""),
		_tensor_order(0),
		_si_conversion(""),
		_fill_value(NAN),
		_ucd(""),
		_statusDef(),
		_processInfo(""),
		_processDesc(""),
		_linkedParamList(),
		_dataset_id(""),
		_instrument_id("")
	{}

	ParamInfo(const ParamInfo& info) : _id(info._id), _name(info._name),
		_short_name(info._short_name), _components(info._components),
		_units(info._units), _coordinates_system(info._coordinates_system),
		_tensor_order(info._tensor_order), _si_conversion(info._si_conversion),
		_tables(info._tables), _fill_value(info._fill_value), _ucd(info._ucd), _statusDef(info._statusDef),
		_processInfo(info._processInfo), _processDesc(info._processDesc), _linkedParamList(info._linkedParamList),
		_dataset_id(info._dataset_id), _instrument_id(info._instrument_id)
	{}

	friend std::ostream& operator<<(std::ostream& out_, const ParamInfo& dsi);

	/*
	 * @brief Get parameter Id
	 */
	const std::string& getId() const {
		return _id;
	}

	/*
	 * @brief Set parameter Id
	 */
	void setId(const std::string& id) {
		_id = id;
	}

	/*
	 * @brief Get parameter name
	 */
	const std::string& getName() const {
		return _name;
	}

	/*
	 * @brief Set parameter name
	 */
	void setName(const std::string& name) {
		_name = name;
	}

	/*
	 * @brief Get parameter short name
	 */
	const std::string& getShortName() const {
		return _short_name;
	}

	/*
	 * @brief Set parameter short name
	 */
	void setShortName(const std::string& shortName) {
		_short_name = shortName;
	}

	/*
	 * @brief Get parameter components
	 */
	std::string getComponents(AMDA::Common::ParameterIndexComponent componentIndex=AMDA::Common::ParameterIndexComponent(-1,-1)) {
		if ((componentIndex.getDim1Index() == -1) && (componentIndex.getDim2Index() == -1)) {
			return _components;
		}
		else {
			if (_components.empty() == false) {
				// Extract values separated by a comma
				std::stringstream sStream(_components);
				std::vector<std::string> componentList;
				std::string element;

				if (componentIndex.getDim2Index() == -1)
				{
					while (std::getline(sStream, element, ',')) {
						componentList.push_back(element);
					}

					// Return the componenet associated with the index
					if (((int) componentList.size()) > componentIndex.getDim1Index()) {
						return componentList.at (componentIndex.getDim1Index());
					} else {
						return std::string();
					}
				}
				else
				{
					while (std::getline(sStream, element, ';')) {
						componentList.push_back(element);
					}

					if ((componentIndex.getDim1Index() < 0) ||
						(componentIndex.getDim1Index() > (int) componentList.size()))
						return componentList.at (componentIndex.getDim1Index());

					sStream.str(componentList.at(componentIndex.getDim1Index()));
					componentList.clear();

					while (std::getline(sStream, element, ',')) {
						componentList.push_back(element);
					}

					// Return the componenet associated with the index
					if (((int) componentList.size()) > componentIndex.getDim2Index()) {
						return componentList.at (componentIndex.getDim2Index());
					} else {
						return std::string();
					}
				}
			} else {
				return std::string();
			}
		}
	}

	/*
	 * @brief Set parameter components
	 */
	void setComponents(const std::string& components) {
		_components = components;
	}

	/*
	 * @brief Get parameter units
	 */
	const std::string& getUnits() const {
		return _units;
	}

	/*
	 * @brief Set parameter units
	 */
	void setUnits(const std::string& units) {
		_units = units;
	}

	/*
	 * @brief Get parameter cordinate system
	 */
	const std::string& getCoordinatesSystem() const {
		return _coordinates_system;
	}

	/*
	 * @brief Set parameter coordinate system
	 */
	void setCoordinatesSystem(const std::string& coordinatesSystem) {
		_coordinates_system = coordinatesSystem;
	}

	/*
	 * @brief Get parameter tensor order
	 */
	int getTensorOrder() const {
		return _tensor_order;
	}

	/*
	 * @brief Set parameter tensor order
	 */
	void setTensorOrder(int tensorOrder) {
		_tensor_order = tensorOrder;
	}

	/*
	 * @brief Get parameter SI conversion
	 */
	const std::string& getSiConversion() const {
		return _si_conversion;
	}

	/*
	 * @brief Set parameter SI conversion
	 */
	void setSiConversion(const std::string& siConversion) {
		_si_conversion = siConversion;
	}

	/*
	 * @brief Get parameter table from dimension
	 */
	boost::shared_ptr<ParamTable> getTable(int dim) {
		return _tables[dim];
	}

	/*
	 * @brief Add a table to the parameter for a given dimension
	 */
	void addTable(int dim, boost::shared_ptr<ParamTable>& tableSPtr) {
	                   _tables[dim] = tableSPtr;
	}

	/*
	 * @brief Get all parameter tables
	 */
	std::map<int, boost::shared_ptr<ParamTable>>& getTables() {
		return _tables;
	}

	/*
	 * @brief Get parameter fill value
	 */
	double getFillValue() const {
		return _fill_value;
	}

	/*
	 * @brief Set parameter fill value
	 */
	void setFillValue(double fillValue) {
		_fill_value = fillValue;
	}

	/*
	 * @brief Get parameter UCD
	 */
	const std::string& getUcd() const {
		return _ucd;
	}

	/*
	 * @brief Set parameter UCD
	 */
	void setUcd(const std::string& ucd) {
		_ucd = ucd;
	}

	/*
	 * @brief Add parameter status for a given min/max values
	 */
	void addStatus(double minVal, double maxVal, std::string name, std::string color = "") {
		StatusInfo info;
		info.setRange(minVal,maxVal);
		info.setName(name);
		info.setColor(color);
		_statusDef.push_back(info);
	}

	/*
	 * @brief Get list of parameter status
	 */
	const std::vector<StatusInfo>& getStatusDef() const {
		return _statusDef;
	}

	/*
	 * @brief Set information about parameter process
	 */
	void setProcessInfo(const std::string& processInfo) {
		_processInfo = processInfo;
	}

	/*
	 * @brief Get information about parameter process
	 */
	const std::string& getProcessInfo() const {
		return _processInfo;
	}

	/*
	 * @brief Set a description of the parameter process
	 */
	void setProcessDescription(const std::string& processDesc) {
		_processDesc = processDesc;
	}

	/*
	 * @brief Get the description of the parameter process
	 */
	const std::string& getProcessDescription() const {
		return _processDesc;
	}

	/*
	 * @brief Get a list of linked parameters to this parameter
	 */
	const std::vector<std::string>& getLinkedParamList() const {
		return _linkedParamList;
	}

	/*
	 * @brief Add a parameter id to the linked parameter list
	 */
	void addLinkedParamId(const std::string& paramId)
	{
		_linkedParamList.push_back(paramId);
	}

	/*
	 * @brief Get the associated dataset id
	 */
	const std::string& getDatasetId() const {
		return _dataset_id;
	}

	/*
	 * @brief Set the associated dataset id
	 */
	void setDatasetId(const std::string& datasetId) {
		_dataset_id = datasetId;
	}

	/*
 	 * @brief Get the associated instrument id (for informational purposes, can be used to write in a legend for example)
 	 */
	const std::string& getInstrumentId() const {
		return _instrument_id;
	}

	/*
 	 * @brief Set the associated instrument id (for informational purposes, can be used to write in a legend for example)
 	 */
	void setInstrumentId(const std::string& instrumentId) {
		_instrument_id = instrumentId;
	}

	/*
	 * @brief Get a map with parameter info
	 */
	std::vector<std::pair<std::string,std::string>> getInfoMap(ParameterManager *parameterManager);

protected:
	std::string _id;
	std::string _name;
	std::string _short_name;
	std::string _components;
	std::string _units;
	std::string _coordinates_system;
	int			_tensor_order;
	std::string _si_conversion;
	std::map<int, boost::shared_ptr<ParamTable>> _tables;
	double		_fill_value;
	std::string _ucd;
	std::vector<StatusInfo> _statusDef;
	std::string _processInfo;
	std::string _processDesc;
	std::vector<std::string> _linkedParamList;
	std::string _dataset_id;
	std::string _instrument_id;
};

typedef boost::shared_ptr<ParamInfo> ParamInfoSPtr;
typedef std::map<std::string,ParamInfoSPtr> ParamInfoMap;

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


#endif /* PARAMINFO_HH_ */