12#include "Persistency/EventReadingAlgorithm.h"
13#include "Persistency/EventWritingAlgorithm.h"
38 delete mapEntry.second;
41 delete mapEntry.second;
44 delete pAlgorithmTool;
47 delete mapEntry.second;
59 if (!
m_algorithmFactoryMap.insert(AlgorithmFactoryMap::value_type(algorithmType, pAlgorithmFactory)).second)
60 return STATUS_CODE_ALREADY_PRESENT;
62 return STATUS_CODE_SUCCESS;
69 if (!
m_algorithmToolFactoryMap.insert(AlgorithmToolFactoryMap::value_type(algorithmToolType, pAlgorithmToolFactory)).second)
70 return STATUS_CODE_ALREADY_PRESENT;
72 return STATUS_CODE_SUCCESS;
80 pXmlElement = pXmlElement->NextSiblingElement(
"algorithm"))
82 std::string algorithmName;
87 return STATUS_CODE_SUCCESS;
94 const char *
const pAttribute(pXmlElement->
Attribute(
"type"));
98 std::cout <<
"Algorithm encountered in xml without defined type." << std::endl;
99 return STATUS_CODE_NOT_FOUND;
102 std::string xmlInstanceLabel;
105 if (STATUS_CODE_NOT_FOUND != instanceStatusCode)
106 return instanceStatusCode;
112 std::cout <<
"Algorithm type '" << pXmlElement->
Attribute(
"type") <<
"' not registered with pandora algorithm manager." << std::endl;
113 return STATUS_CODE_NOT_FOUND;
116 Algorithm *
const pLocalAlgorithm = iter->second->CreateAlgorithm();
120 std::stringstream ss;
121 ss << std::setw(4) << std::setfill(
'0') << (1 +
m_algorithmMap.size());
122 algorithmName =
"Alg" + ss.str();
126 if (!
m_algorithmMap.insert(AlgorithmMap::value_type(algorithmName, pLocalAlgorithm)).second)
129 if (!xmlInstanceLabel.empty() && !
m_specificAlgorithmInstanceMap.insert(SpecificAlgorithmInstanceMap::value_type(xmlInstanceLabel, algorithmName)).second)
131 std::cout <<
"Failure attempting to reuse algorithm with xml instance label " << xmlInstanceLabel << std::endl;
141 delete pLocalAlgorithm;
142 throw statusCodeException;
145 return STATUS_CODE_SUCCESS;
152 const char *
const pAttribute(pXmlElement->
Attribute(
"type"));
156 std::cout <<
"Algorithm tool encountered in xml without defined type." << std::endl;
157 return STATUS_CODE_NOT_FOUND;
164 std::cout <<
"Algorithm tool type '" << pXmlElement->
Attribute(
"type") <<
"' not registered with pandora algorithm manager." << std::endl;
165 return STATUS_CODE_NOT_FOUND;
168 AlgorithmTool *
const pLocalAlgorithmTool = iter->second->CreateAlgorithmTool();
172 std::stringstream ss;
174 const std::string toolInstanceName(
"Tool" + ss.str());
181 pAlgorithmTool = pLocalAlgorithmTool;
185 delete pLocalAlgorithmTool;
186 throw statusCodeException;
189 return STATUS_CODE_SUCCESS;
198 const char *
const pAttribute(pXmlElement->
Attribute(
"instance"));
201 return STATUS_CODE_NOT_FOUND;
203 xmlInstanceLabel = std::string(pAttribute);
207 return STATUS_CODE_NOT_FOUND;
209 algorithmName = iter->second;
210 AlgorithmMap::const_iterator targetIter =
m_algorithmMap.find(algorithmName);
212 if ((
m_algorithmMap.end() == targetIter) || (targetIter->second->GetType() != std::string(pXmlElement->
Attribute(
"type"))))
213 return STATUS_CODE_FAILURE;
215 return STATUS_CODE_SUCCESS;
219 return STATUS_CODE_NOT_FOUND;
233 return STATUS_CODE_SUCCESS;
Header file for the algorithm class.
Header file for the algorithm manager class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Factory class for instantiating algorithm.
Factory class for instantiating algorithm.
Factory class for instantiating algorithms.
Algorithm class. Algorithm addresses are held only by the algorithm manager. They have a fully define...
StatusCode CreateAlgorithmTool(TiXmlElement *const pXmlElement, AlgorithmTool *&pAlgorithmTool)
Create an algorithm tool, via one of the algorithm tool factories registered with pandora.
StatusCode RegisterAlgorithmToolFactory(const std::string &algorithmToolType, AlgorithmToolFactory *const pAlgorithmToolFactory)
Register an algorithm tool factory.
const Pandora *const m_pPandora
The pandora instance that will run the algorithms.
StatusCode InitializeAlgorithms(const TiXmlHandle *const pXmlHandle)
Initialize algorithms.
AlgorithmToolVector m_algorithmToolVector
The algorithm tool vector.
StatusCode ResetForNextEvent()
Call the reset callback in all managed algorithms and algorithm tools.
StatusCode RegisterAlgorithmFactory(const std::string &algorithmType, AlgorithmFactory *const pAlgorithmFactory)
Register an algorithm factory.
SpecificAlgorithmInstanceMap m_specificAlgorithmInstanceMap
The specific algorithm instance map.
AlgorithmMap m_algorithmMap
The algorithm map.
AlgorithmManager(const Pandora *const pPandora)
Constructor.
StatusCode FindSpecificAlgorithmInstance(TiXmlElement *const pXmlElement, std::string &algorithmName, std::string &xmlInstanceLabel) const
Find the name of a specific algorithm instance, so that it can be re-used.
~AlgorithmManager()
Destructor.
StatusCode CreateAlgorithm(TiXmlElement *const pXmlElement, std::string &algorithmName)
Create an algorithm, via one of the algorithm factories registered with pandora.
AlgorithmFactoryMap m_algorithmFactoryMap
The algorithm factory map.
AlgorithmToolFactoryMap m_algorithmToolFactoryMap
The algorithm tool factory map.
StringVector m_pandoraAlgorithms
The ordered list of names of top-level algorithms, to be run by pandora.
virtual StatusCode Initialize()
Perform any operations that must occur after reading settings, but before running the process.
virtual StatusCode ReadSettings(const TiXmlHandle xmlHandle)=0
Read the algorithm settings.
StatusCode RegisterDetails(const Pandora *const pPandora, const std::string &type, const std::string &instanceName)
Register i) the pandora instance that will run the process and ii) the process type.
StatusCodeException class.
const char * Attribute(const char *name) const
TiXmlElement * Element() const
TiXmlHandle FirstChild() const
Return a handle to the first child node.
StatusCode
The StatusCode enum.