Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
XmlHelper.cc
Go to the documentation of this file.
1
10
11#include "Helpers/XmlHelper.h"
12
13namespace pandora
14{
15
16StatusCode XmlHelper::ProcessAlgorithm(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &description,
17 std::string &algorithmName)
18{
19 if ("algorithm" != xmlHandle.ToNode()->ValueStr())
20 return STATUS_CODE_NOT_ALLOWED;
21
22 for (TiXmlElement *pXmlElement = xmlHandle.FirstChild("algorithm").Element(); nullptr != pXmlElement;
23 pXmlElement = pXmlElement->NextSiblingElement("algorithm"))
24 {
25 if (description.empty())
26 return PandoraContentApi::CreateDaughterAlgorithm(algorithm, pXmlElement, algorithmName);
27
28 try
29 {
30 const char *const pAttribute(pXmlElement->Attribute("description"));
31
32 if (!pAttribute)
33 return STATUS_CODE_NOT_FOUND;
34
35 if (description == std::string(pAttribute))
36 return PandoraContentApi::CreateDaughterAlgorithm(algorithm, pXmlElement, algorithmName);
37 }
38 catch (...)
39 {
40 }
41 }
42
43 return STATUS_CODE_NOT_FOUND;
44}
45
46//------------------------------------------------------------------------------------------------------------------------------------------
47
48StatusCode XmlHelper::ProcessAlgorithmList(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &listName,
49 StringVector &algorithmNames)
50{
51 if ("algorithm" != xmlHandle.ToNode()->ValueStr())
52 return STATUS_CODE_NOT_ALLOWED;
53
54 const TiXmlHandle algorithmListHandle = TiXmlHandle(xmlHandle.FirstChild(listName).Element());
55
56 for (TiXmlElement *pXmlElement = algorithmListHandle.FirstChild("algorithm").Element(); nullptr != pXmlElement;
57 pXmlElement = pXmlElement->NextSiblingElement("algorithm"))
58 {
59 std::string algorithmName;
60 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateDaughterAlgorithm(algorithm, pXmlElement, algorithmName));
61 algorithmNames.push_back(algorithmName);
62 }
63
64 return STATUS_CODE_SUCCESS;
65}
66
67//------------------------------------------------------------------------------------------------------------------------------------------
68
69StatusCode XmlHelper::ProcessAlgorithmTool(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &description,
70 AlgorithmTool *&pAlgorithmTool)
71{
72 if ("algorithm" != xmlHandle.ToNode()->ValueStr())
73 return STATUS_CODE_NOT_ALLOWED;
74
75 for (TiXmlElement *pXmlElement = xmlHandle.FirstChild("tool").Element(); nullptr != pXmlElement;
76 pXmlElement = pXmlElement->NextSiblingElement("tool"))
77 {
78 if (description.empty())
79 return PandoraContentApi::CreateAlgorithmTool(algorithm, pXmlElement, pAlgorithmTool);
80
81 try
82 {
83 const char *const pAttribute(pXmlElement->Attribute("description"));
84
85 if (!pAttribute)
86 return STATUS_CODE_NOT_FOUND;
87
88 if (description == std::string(pAttribute))
89 return PandoraContentApi::CreateAlgorithmTool(algorithm, pXmlElement, pAlgorithmTool);
90 }
91 catch (...)
92 {
93 }
94 }
95
96 return STATUS_CODE_NOT_FOUND;
97}
98
99//------------------------------------------------------------------------------------------------------------------------------------------
100
101StatusCode XmlHelper::ProcessAlgorithmToolList(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &listName,
102 AlgorithmToolVector &algorithmToolVector)
103{
104 if ("algorithm" != xmlHandle.ToNode()->ValueStr())
105 return STATUS_CODE_NOT_ALLOWED;
106
107 const TiXmlHandle algorithmListHandle = TiXmlHandle(xmlHandle.FirstChild(listName).Element());
108
109 for (TiXmlElement *pXmlElement = algorithmListHandle.FirstChild("tool").Element(); nullptr != pXmlElement;
110 pXmlElement = pXmlElement->NextSiblingElement("tool"))
111 {
112 AlgorithmTool *pAlgorithmTool(nullptr);
113 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateAlgorithmTool(algorithm, pXmlElement, pAlgorithmTool));
114 algorithmToolVector.push_back(pAlgorithmTool);
115 }
116
117 return STATUS_CODE_SUCCESS;
118}
119
120//------------------------------------------------------------------------------------------------------------------------------------------
121
122void XmlHelper::TokenizeString(const std::string &inputString, StringVector &tokens, const std::string &delimiter)
123{
124 std::string::size_type lastPos = inputString.find_first_not_of(delimiter, 0);
125 std::string::size_type pos = inputString.find_first_of(delimiter, lastPos);
126
127 while ((std::string::npos != pos) || (std::string::npos != lastPos))
128 {
129 tokens.push_back(inputString.substr(lastPos, pos - lastPos));
130 lastPos = inputString.find_first_not_of(delimiter, pos);
131 pos = inputString.find_first_of(delimiter, lastPos);
132 }
133}
134
135} // namespace pandora
Header file for the pandora content api class.
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the xml helper class.
static pandora::StatusCode CreateDaughterAlgorithm(const pandora::Algorithm &algorithm, pandora::TiXmlElement *const pXmlElement, std::string &daughterAlgorithmName)
Create an algorithm instance, via one of the algorithm factories registered with pandora....
static pandora::StatusCode CreateAlgorithmTool(const pandora::Algorithm &algorithm, pandora::TiXmlElement *const pXmlElement, pandora::AlgorithmTool *&pAlgorithmTool)
Create an algorithm tool instance, via one of the algorithm tool factories registered with pandora....
Algorithm class. Algorithm addresses are held only by the algorithm manager. They have a fully define...
Definition Algorithm.h:21
AlgorithmTool class. Algorithm tools will tend to be tailored for specific parent algorithms,...
TiXmlElement * Element() const
Definition tinyxml.h:1710
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition tinyxml.cc:1635
TiXmlNode * ToNode() const
Definition tinyxml.h:1692
const std::string & ValueStr() const
Definition tinyxml.h:501
static StatusCode ProcessAlgorithm(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &description, std::string &algorithmName)
Process an algorithm described in an xml element with a matching "description = .....
Definition XmlHelper.cc:16
static void TokenizeString(const std::string &inputString, StringVector &tokens, const std::string &delimiter=" ")
Tokenize a string.
Definition XmlHelper.cc:122
static StatusCode ProcessAlgorithmToolList(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &listName, AlgorithmToolVector &algorithmToolVector)
Process a list of algorithms tools in an xml file.
Definition XmlHelper.cc:101
static StatusCode ProcessAlgorithmTool(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &description, AlgorithmTool *&pAlgorithmTool)
Process an algorithm tool described in an xml element with a matching "description = ....
Definition XmlHelper.cc:69
static StatusCode ProcessAlgorithmList(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &listName, StringVector &algorithmNames)
Process a list of daughter algorithms in an xml file.
Definition XmlHelper.cc:48
std::vector< std::string > StringVector
std::vector< AlgorithmTool * > AlgorithmToolVector
StatusCode
The StatusCode enum.