Blame view

src/XMLParameterConfigurator/ProcessNode.cc 5.08 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/*
 * ProcessNode.cc
 *
 *  Created on: Oct 31, 2012
 *      Author: f.casimir
 */

#include <sstream>
e85676de   Benjamin Renard   Fix #6325
9
#include <algorithm>
fbe3c2bb   Benjamin Renard   First commit
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

#include "ProcessNode.hh"


#include <boost/shared_ptr.hpp>

#include <Parameter.hh>
#include <Process.hh>
#include <Parameter.hh>
#include <FileConfigurator.hh>
#include <ServicesServer.hh>

#include "Config.hh"

using namespace AMDA::Parameters;
using namespace boost;

namespace AMDA {
namespace XMLParameterConfigurator {

ProcessNode::ProcessNode() : NodeCfg() {
}

ProcessNode::~ProcessNode() {
}

deefda79   Benjamin Renard   Addapt resampling...
36
std::string injectResamplingIntoProcess(const std::string& pProcessName, const std::string& pProcessParams, const std::string& pExpression) {
fbe3c2bb   Benjamin Renard   First commit
37
38
39
	std::stringstream lBuffer;
	bool isAParam = false;

e85676de   Benjamin Renard   Fix #6325
40
41
	unsigned int length = pExpression.size();
	std::string part;
fbe3c2bb   Benjamin Renard   First commit
42
43
	for ( unsigned int i = 0; i < length; ++i) {
		switch(pExpression[i]) {
e85676de   Benjamin Renard   Fix #6325
44
45
46
47
48
49
		case '#':
			part = pExpression.substr(i);
			if (part.find("#sum_into_table_range($") == 0) {
				int patternSize = std::string("#sum_into_table_range($").size();
				i += patternSize;
				//special case with sum_into_table_range
deefda79   Benjamin Renard   Addapt resampling...
50
				lBuffer << "#" << pProcessName << "(#sum_into_table_range($";
e85676de   Benjamin Renard   Fix #6325
51
52
53
54
55
56
57
58
				part = part.substr(patternSize);
				std::size_t pos = part.find(";");
				lBuffer << part.substr(0, pos);
				i += pos;
				part = part.substr(pos);
				pos = part.find(")");
				lBuffer << part.substr(0, pos);
				i += pos;
deefda79   Benjamin Renard   Addapt resampling...
59
				lBuffer << ");" << pProcessParams << ")";
e85676de   Benjamin Renard   Fix #6325
60
61
62
63
64
			}
			else {
				lBuffer << pExpression[i];
			}
			break;
fbe3c2bb   Benjamin Renard   First commit
65
66
		case '$':
			isAParam = true;
deefda79   Benjamin Renard   Addapt resampling...
67
			lBuffer << "#" << pProcessName << "($";
fbe3c2bb   Benjamin Renard   First commit
68
69
70
			break;
		default:
			if( isAParam && ! (isalnum(pExpression[i]) || (pExpression[i]=='_'))) {
deefda79   Benjamin Renard   Addapt resampling...
71
				lBuffer << ";" << pProcessParams << ")";
fbe3c2bb   Benjamin Renard   First commit
72
73
74
75
76
77
78
				isAParam=false;
			}
			lBuffer << pExpression[i];
			break;
		}
	}
	if (isAParam) {
deefda79   Benjamin Renard   Addapt resampling...
79
		lBuffer << ";" << pProcessParams << ")";
fbe3c2bb   Benjamin Renard   First commit
80
81
82
83
84
85
86
87
88
89
90
	}

	return std::string(lBuffer.str());
}

void ProcessNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
	LOG4CXX_DEBUG(gLogger, "ProcessNode::proceed");
	Parameter* lParameter = pContext.get<Parameter*>();

	double lTimeResolution = lParameter->getTimeResolution();
	double lGapThreshold = lParameter->getGapThreshold();
deefda79   Benjamin Renard   Addapt resampling...
91
	std::string lReferenceParam = lParameter->getReferenceParameter();
fbe3c2bb   Benjamin Renard   First commit
92
93
94
95
96
97
98
99
100
101
	Process *lProcess = ServicesServer::getInstance()->getProcess("standard", *lParameter);

	//process description
	xmlChar *lProcessDesc = xmlGetProp(pNode, (const xmlChar *) "description");
	if (lProcessDesc != NULL)
	{
		lProcess->setDescription(std::string((const char *)lProcessDesc));
		xmlFree(lProcessDesc);
	}

854a7fcf   Benjamin Renard   First implementat...
102
103
104
105
106
107
108
109
	//user process
	xmlChar *lUserProcess = xmlGetProp(pNode, (const xmlChar *) "userProcess");
	if (lUserProcess != NULL)
	{
		lProcess->setIsUserProcess(strcasecmp ((const char*)lUserProcess, "true") == 0);
		xmlFree(lUserProcess);
	}

fbe3c2bb   Benjamin Renard   First commit
110
111
112
113
114
	DataWriterSPtr lDataWriter( lProcess);
	std::string* xmlFileName = pContext.get<std::string*>();
	lDataWriter->setSignatureTrigger(*xmlFileName);

	lParameter->setDataWriter(lDataWriter);
236880a3   Benjamin Renard   Fix expression pa...
115
	if (pNode->children && pNode->children->content && pNode->children->content[0] != '\0') {
e85676de   Benjamin Renard   Fix #6325
116
117
118
		std::string expression = std::string((char*)pNode->children->content);
		// Remove all aspaces
		expression.erase(std::remove(expression.begin(), expression.end(), ' '), expression.end());
deefda79   Benjamin Renard   Addapt resampling...
119
120
121
122
123
		if (!lReferenceParam.empty()) {
			// Inject Resampling with reference param
			expression = injectResamplingIntoProcess("sampling_under_refparam", lReferenceParam, expression.c_str());
		}
		else if ( lTimeResolution != 0 ) {
fbe3c2bb   Benjamin Renard   First commit
124
			// Inject Resampling
deefda79   Benjamin Renard   Addapt resampling...
125
			std::stringstream lProcessParams;
46ee40b3   Benjamin Renard   Fix reference fil...
126
			lProcessParams << lTimeResolution << ";" << lGapThreshold;
deefda79   Benjamin Renard   Addapt resampling...
127
			expression = injectResamplingIntoProcess("sampling_classic", lProcessParams.str(), expression.c_str());
fbe3c2bb   Benjamin Renard   First commit
128
		}
deefda79   Benjamin Renard   Addapt resampling...
129
		lProcess->setExpression(expression);
fbe3c2bb   Benjamin Renard   First commit
130
131
132
	} else {
		if ( lParameter->getParameterList().size() == 1 ) {
			// Inject Resampling
deefda79   Benjamin Renard   Addapt resampling...
133
134
135
136
137
138
139
140
141
142
			if (!lReferenceParam.empty()) {
				lProcess = ServicesServer::getInstance()->getProcess("sampling_under_refparam",*lParameter);
				std::stringstream lBuffer;
				lProcess->getAttributList().push_back(lReferenceParam);
				lBuffer.str(""); lBuffer << "$" << (*lParameter->getParameterList().begin())->getId();
				lProcess->setExpression(lBuffer.str());
				lDataWriter.reset( lProcess);
				lParameter->setDataWriter(lDataWriter);
			}
			else if ( lTimeResolution != 0 ) {
fbe3c2bb   Benjamin Renard   First commit
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
				lProcess = ServicesServer::getInstance()->getProcess("sampling_classic",*lParameter);
				std::stringstream lBuffer;
				lBuffer.str(""); lBuffer << lTimeResolution;
				lProcess->getAttributList().push_back(lBuffer.str());
				lBuffer.str(""); lBuffer << lGapThreshold;
				lProcess->getAttributList().push_back(lBuffer.str());
				lBuffer.str(""); lBuffer << "$" << (*lParameter->getParameterList().begin())->getId();
				lProcess->setExpression(lBuffer.str());
				lDataWriter.reset( lProcess);
				lParameter->setDataWriter(lDataWriter);
			}
			else
				//only one parameter + no process => use the same info
				(*lParameter->getParameterList().begin())->setInfoId(lParameter->getInfoId());
		} else {
			ERROR_EXCEPTION( "Too many ParamGet with no process");
		}
	}
}

} /* namespace XMLParameterConfigurator */
} /* namespace AMDA */