Blame view

src/ParamOutputImpl/IntervalTrue/ParamOutputIntervalTrueFile.cc 3.67 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
38
39
40
/**
 * ParamOutputIntervalTrueFile.cc
 *
 *  Created on: 18 oct. 2012
 *      Author: AKKA IS
 */

#include <string>
#include <iostream>

#include <iomanip>
#include <string.h>

#include "PrintIntervalTrue.hh"
#include "ParamOutputIntervalTrueFile.hh"

#include "DicError.hh"

#include "ParameterManager.hh"
#include "Parameter.hh"
#include "ParamData.hh"
#include "TimeUtil.hh"
#include "Helper.hh"

// Download module include
#include "Config.hh"
#include "DD_time.hh"

#include "TimeInterval.hh"

using namespace AMDA::Parameters;

namespace AMDA {
	namespace ParamOutputImpl {
		namespace Download {

		 log4cxx::LoggerPtr gLogger = log4cxx::Logger::getLogger("AMDA-Kernel.XMLConfigurator");

			ParamOutputIntervalTrueFile::ParamOutputIntervalTrueFile(ParameterManager& pParameterManager) :
					ParamOutput(pParameterManager),
e8595a44   Hacene SI HADJ MOHAND   J'ai corrigĂ© les ...
41
					_typeFormatTime(FORMAT_OUTPUT_TIME_DOYTIME),
fbe3c2bb   Benjamin Renard   First commit
42
43
44
45
46
47
48
49
					_firstVisit(true){
				_lFileName.str("");
			}

			ParamOutputIntervalTrueFile::~ParamOutputIntervalTrueFile() {
			}

			void ParamOutputIntervalTrueFile::establishConnection() {
854a7fcf   Benjamin Renard   First implementat...
50
				_parameter = _parameterManager.getSampledParameter(_paramName, _samplingMode, _samplingValue, _gapThreshold, true);
fbe3c2bb   Benjamin Renard   First commit
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
				if(_parameter == NULL)  {
					LOG4CXX_ERROR(_logger,"ParamOutput::init parameter : \""<< _paramName <<"\" Not Exist" );
					BOOST_THROW_EXCEPTION( ParamOutput_exception());
				}
				getParameter()->openConnection(this);
			}

			void ParamOutputIntervalTrueFile::init() {
				getParameter()->init(this, _timeIntervalList);
			}

			void ParamOutputIntervalTrueFile::apply() {


				_paramDataIndexInfo = _parameter->getAsync(this).get();

				initOutput();
				_printIntervalTrue->setParamDataIndexInfo(_paramDataIndexInfo);

fa4b7852   Benjamin Renard   Fix bug around ti...
70
				while ((!_paramDataIndexInfo._noMoreTimeInt && !_paramDataIndexInfo._timeIntToProcessChanged) || (_paramDataIndexInfo._nbDataToProcess > 0)) {
fbe3c2bb   Benjamin Renard   First commit
71
72
					try {
						_parameter->getParamData(this)->accept(*_printIntervalTrue);
fa4b7852   Benjamin Renard   Fix bug around ti...
73
74
						if (_paramDataIndexInfo._timeIntToProcessChanged || _paramDataIndexInfo._noMoreTimeInt)
							break;
fbe3c2bb   Benjamin Renard   First commit
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
						_paramDataIndexInfo = _parameter->getAsync(this).get();
						_printIntervalTrue->setParamDataIndexInfo(_paramDataIndexInfo);
					} catch(AMDA::AMDA_exception & e) {
						e << AMDA::errno_code(AMDA_PARAM_OUTPUT_ERR);
						throw;
					}
				}
				endOutput();
			}



			void ParamOutputIntervalTrueFile::initOutput() {

				LOG4CXX_DEBUG(_logger, "ParamOutput init  ASCII file creation");
				createCurrentfile();
				_printIntervalTrue = PrintIntervalTrueSPtr(new PrintIntervalTrue(_paramDataIndexInfo, _currentfile));
			}

			void ParamOutputIntervalTrueFile::endOutput() {
				_currentfile << std::endl;
				_currentfile.close();
				LOG4CXX_INFO(_logger, "file " << _lFileName.str() << " is created");
			}

			void ParamOutputIntervalTrueFile::createCurrentfile() {
				char buffer[TIMELENGTH];
				Double2DD_Time(buffer, _timeIntervalList->front()._startTime);

				_lFileName << "outputInt-" << _paramName;
				if (!_indexList.empty()) {
					for (unsigned int i = 0; i < _indexList.size(); ++i) {
						_lFileName << "_" << _indexList[i];
					}
				}
				int ret = AMDA::Helpers::Helper::mkdir(_workPath.c_str());
				if(ret) {
					const size_t buflen = 250;
					char buf[250];
					LOG4CXX_ERROR(_logger, "Create working directory error : " << strerror_r(ret, buf,  buflen));
					BOOST_THROW_EXCEPTION( ParamOutput_exception());
				}
				_lFileName << "_" << buffer << ".txt";
				std::string lComputedFileName = _workPath + "/" +_lFileName.str();
				LOG4CXX_INFO(_logger, "Create outputInt-paramid_starttime.txt file: " << lComputedFileName);
				_currentfile.open(lComputedFileName.c_str());
			}

		} // namespace Download
	} // namespace ParamOutputImpl
} /* namespace AMDA */