ProcessNode.cc
4.39 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
/*
* ProcessNode.cc
*
* Created on: Oct 31, 2012
* Author: f.casimir
*/
#include <sstream>
#include <algorithm>
#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() {
}
std::string injectResamplingIntoProcess(const double& pTimeresolution, const double& pGapThreshold, const std::string& pExpression) {
std::stringstream lBuffer;
bool isAParam = false;
unsigned int length = pExpression.size();
std::string part;
for ( unsigned int i = 0; i < length; ++i) {
switch(pExpression[i]) {
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
lBuffer << "#sampling_classic(#sum_into_table_range($";
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;
lBuffer << ");" << pTimeresolution << ";" << pGapThreshold << ")";
}
else {
lBuffer << pExpression[i];
}
break;
case '$':
isAParam = true;
lBuffer << "#sampling_classic($";
break;
default:
if( isAParam && ! (isalnum(pExpression[i]) || (pExpression[i]=='_'))) {
lBuffer << ";" << pTimeresolution << ";" << pGapThreshold << ")";
isAParam=false;
}
lBuffer << pExpression[i];
break;
}
}
if (isAParam) {
lBuffer << ";" << pTimeresolution << ";" << pGapThreshold << ")";
}
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();
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);
}
//user process
xmlChar *lUserProcess = xmlGetProp(pNode, (const xmlChar *) "userProcess");
if (lUserProcess != NULL)
{
lProcess->setIsUserProcess(strcasecmp ((const char*)lUserProcess, "true") == 0);
xmlFree(lUserProcess);
}
DataWriterSPtr lDataWriter( lProcess);
std::string* xmlFileName = pContext.get<std::string*>();
lDataWriter->setSignatureTrigger(*xmlFileName);
lParameter->setDataWriter(lDataWriter);
if (pNode->children && pNode->children->content && pNode->children->content[0] != '\0') {
std::string expression = std::string((char*)pNode->children->content);
// Remove all aspaces
expression.erase(std::remove(expression.begin(), expression.end(), ' '), expression.end());
if ( lTimeResolution != 0 ) {
// Inject Resampling
expression = injectResamplingIntoProcess(lTimeResolution, lGapThreshold, expression.c_str());
lProcess->setExpression(expression);
} else {
lProcess->setExpression(expression.c_str());
}
} else {
if ( lParameter->getParameterList().size() == 1 ) {
// Inject Resampling
if ( lTimeResolution != 0 ) {
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 */