Histogram2DNode.hh
3.59 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
/*
* Histogram2DNode.hh
*
* Created on: Jan 27, 2023
* Author: AKKODIS
*/
#ifndef HISTOGRAM2DNODENODE_HH_
#define HISTOGRAM2DNODENODE_HH_
#include <libxml/globals.h>
#include <libxml/tree.h>
#include <libxml/xmlstring.h>
#include <iosfwd>
#include "FileConfigurator.hh"
#include "DrawingPropertiesNode.hh"
#include "PlotLogger.hh"
#include "NodeCfg.hh"
#include "Histogram2DSeriesProperties.hh"
namespace plot {
/**
* Class that handle a <histogram2d> xml node.
* Template class that should be instanciated for each subclass of PanelOutputPanel.
*/
template<class PlotType>
class Histogram2DSeriesNode: public plot::DrawingPropertiesNode<PlotType> {
public:
Histogram2DSeriesNode() :
DrawingPropertiesNode<PlotType>() {
DrawingPropertiesNode<PlotType>::getChildList()["bins"] = AMDA::XMLConfigurator::NodeCfgSPtr(new BinsNode());
DrawingPropertiesNode<PlotType>::getChildList()["histotype"] = AMDA::XMLConfigurator::NodeCfgSPtr(new HistotypeNode());
}
virtual ~Histogram2DSeriesNode() {
}
void proceed(xmlNodePtr pNode_,
const AMDA::Parameters::CfgContext& pContext_) {
LOG4CXX_DEBUG(gLogger, "Histogram2DSeriesNode::proceed");
PlotType* plotOutput = pContext_.get<PlotType*>();
xmlChar* name = pContext_.get<xmlChar*>();
// initialize series with default properties
DrawingProperties defaultProps = plotOutput->getParameter(
(const char*) name).getDefaultProperties();
std::shared_ptr<Histogram2DSeriesProperties> histogramPropsPtr =
std::shared_ptr<Histogram2DSeriesProperties>(new Histogram2DSeriesProperties(defaultProps));
// parse attributes...
parseAttributes(pNode_, *histogramPropsPtr.get());
// add series definition to parameter
histogramPropsPtr->setParamId((const char*)name);
plotOutput->getParameter((const char*) name).addHistogram2DSeriesProperties(histogramPropsPtr);
//parse children nodes
AMDA::Parameters::CfgContext context;
context.push<xmlChar*>(name);
context.push<Histogram2DSeriesProperties*>(histogramPropsPtr.get());
context.push<DrawingProperties*>(histogramPropsPtr.get());
AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode_, context);
}
protected:
void parseAttributes(xmlNodePtr pNode_, DrawingProperties& props_) {
// read parent attributes
DrawingPropertiesNode<PlotType>::parseAttributes(pNode_, props_);
// specific series node attributes :
xmlChar * value = NULL;
value = xmlGetProp(pNode_, (const xmlChar*) "index");
if (value) {
AMDA::Common::ParameterIndexComponentList indexList;
if (!AMDA::Common::ParameterIndexesTool::parse((const char*) value, -1, -1, indexList) || indexList.empty())
{
LOG4CXX_ERROR(gLogger, "Histogram2DSeriesNode::parseAttributes - Bad index definition " << (const char*) value);
xmlFree(value);
BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("Bad Histogram2Dserie index definition"));
}
((Histogram2DSeriesProperties&) props_).setIndex(indexList.front());
xmlFree(value);
} else {
((Histogram2DSeriesProperties&) props_).setIndex(AMDA::Common::ParameterIndexComponent(-1,-1)); // default case: if no index attribute, we use default index value -1 which means for all series.
}
value = xmlGetProp(pNode_, (const xmlChar*) "id");
if (value) {
((Histogram2DSeriesProperties&) props_).setId(atoi((const char*) value));
xmlFree(value);
}
// -- associated x serie id
value = xmlGetProp(pNode_, (const xmlChar*) "xId");
if (value) {
((Histogram2DSeriesProperties&) props_).setXId(atoi((const char*) value));
xmlFree(value);
}
}
};
}
/* namespace plot */
#endif /* HISTOGRAM2DNODENODE_HH_ */