Blame view

src/ExternLib/ttcat_to_param/ProcessTTCatToParam.cc 2.68 KB
40f1fe40   Benjamin Renard   Define a simple p...
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
/*
 * ProcessTTCatToParam.cc
 *
 *  Created on: Jan 31, 2019
 *      Author: AKKA
 */
#include <stdlib.h>
#include <string>

#include "DicError.hh"
#include "AMDA_exception.hh"

#include "Operation.hh"
#include "ParameterManager.hh"
#include "ProcessTTCatToParam.hh"
#include "TTCatToParam.hh"
#include "TimeTableCatalogFactory.hh"
#include "Catalog.hh"

using namespace std;
using namespace boost;
using namespace log4cxx;

namespace AMDA {
namespace Parameters {

  ProcessTTCatToParam::ProcessTTCatToParam(Parameter &parameter)
  : SingleParamProcess_CRTP(parameter) {
  }

  ProcessTTCatToParam::ProcessTTCatToParam(const ProcessTTCatToParam& pProcess, Parameter &parameter)
    : SingleParamProcess_CRTP(pProcess,parameter) {
  }

  ProcessTTCatToParam::~ProcessTTCatToParam() {
  }

TimeStamp ProcessTTCatToParam::init() {
	if (_attributList.size() < 1) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessTTCatToParam::init required at least one attribute to define TimeTable or Catalog location'")));
	}

	std::string ttOrCatPath = _attributList[0];

	// Load TT or Catalog
	std::string lReaderType = TimeTableCatalog::TimeTableCatalogFactory::getInstance().getReaderType(ttOrCatPath);
	if(lReaderType.empty()){
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessTTCatToParam::init Unknown TimeTable or Catalog format") + ttOrCatPath));
	}
	TimeTableCatalog::Catalog inputTTOrCat;
	inputTTOrCat.read(ttOrCatPath, lReaderType);

	std::string paramName = "";
	int paramComp = 0;
	if (_attributList.size() > 1) {
		paramName = _attributList[1];
		std::size_t foundComp = paramName.find("[");
		if (foundComp != std::string::npos) {
			std::string compPart = paramName.substr(foundComp + 1);
			std::size_t endCompFound = compPart.find("]");
			if (endCompFound != std::string::npos) {
				compPart = compPart.substr(0,endCompFound);
			}
			try
			{
				paramComp = boost::lexical_cast<int>(compPart);
			}
			catch (const boost::bad_lexical_cast &e)
			{
				paramComp = 0;
			}
			paramName = paramName.substr(0,foundComp);
		}
	}
	
	TimeStamp timeStamp = _parameterInput->init( this, _timeIntervalList);
	Parameter::InfoList lInfoList = _parameterInput->getInfoList();
	_parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end());
	_paramInput = _parameterInput->getParamData(this).get();

	_operation = new TTCatToParam(*this,*_paramInput, inputTTOrCat.getIntervals(), paramName, paramComp);
	_paramData = ParamDataSPtr(_operation->getParamOutput());
	_paramData->setMinSampling(_paramInput->getMinSampling());
	return timeStamp;
}



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