Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
StreamingAlgorithm.cc
Go to the documentation of this file.
1
10
12
15
17
18#include <algorithm>
19#include <numeric>
20
21using namespace pandora;
22
23namespace lar_content
24{
25
27{
28}
29
30//------------------------------------------------------------------------------------------------------------------------------------------
31
35
36//------------------------------------------------------------------------------------------------------------------------------------------
37
39{
40 unsigned int i{0};
41 for (std::string listName : m_inputListNames)
42 {
43 std::string algStreamName{"Algorithms" + listName};
44 const ClusterList *pClusterList{nullptr};
45 // Set the input list as current
47 StatusCode code{PandoraContentApi::GetCurrentList(*this, pClusterList)};
48 if (code == STATUS_CODE_SUCCESS)
49 {
50 for (const auto &alg : m_streamAlgorithmMap.at(algStreamName))
51 { // ATTN - The algorithms replace the current list as they go
52 PandoraContentApi::GetCurrentList(*this, pClusterList);
53 if (!pClusterList->empty())
54 {
55 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RunDaughterAlgorithm(*this, alg));
56 }
57 }
58 // Save the current list to the target output list
59 if (!m_outputListName.empty())
61 else
63 }
64 else if (code != STATUS_CODE_NOT_INITIALIZED)
65 {
66 return code;
67 }
68 ++i;
69 }
70
71 // If we have a single output list specified, set that list as the current list
72 if (!m_outputListName.empty())
74
75 return STATUS_CODE_SUCCESS;
76}
77
78//------------------------------------------------------------------------------------------------------------------------------------------
79
81{
82 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ListType", m_listType));
83 std::transform(m_listType.begin(), m_listType.end(), m_listType.begin(), ::tolower);
84 if (m_listType != "cluster")
85 {
86 std::cout << "StreamingAlgorithm::ReadSettings - Error: Only Cluster list type is supported at this time" << std::endl;
87 return STATUS_CODE_INVALID_PARAMETER;
88 }
89
90 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "InputListNames", m_inputListNames));
91 if (m_inputListNames.empty())
92 {
93 std::cout << "StreamingAlgorithm::ReadSettings - Error: No input lists found" << std::endl;
94 return STATUS_CODE_NOT_FOUND;
95 }
96
97 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "OutputListName", m_outputListName));
99 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "OutputListNames", m_outputListNames));
100 if ((m_outputListName.empty() && m_outputListNames.empty()) || (!m_outputListName.empty() && !m_outputListNames.empty()))
101 {
102 std::cout << "StreamingAlgorithm::ReadSettings - Error: You must provide either a single output list name OR a list of output list names"
103 << std::endl;
104 return STATUS_CODE_NOT_FOUND;
105 }
106 if (!m_outputListNames.empty() && m_inputListNames.size() != m_outputListNames.size())
107 {
108 std::cout << "StreamingAlgorithm::ReadSettings - Error: When providing a list of output lists, there should be a one-to-one "
109 << "correspondence with the list of input lists" << std::endl;
110 return STATUS_CODE_INVALID_PARAMETER;
111 }
112
113 for (std::string listName : m_inputListNames)
114 {
115 std::string algStreamName{"Algorithms" + listName};
116 if (m_streamAlgorithmMap.find(algStreamName) != m_streamAlgorithmMap.end())
117 {
118 std::cout << "StreamingAlgorithm::ReadSettings - Error: Duplicate stream name found" << std::endl;
119 return STATUS_CODE_INVALID_PARAMETER;
120 }
122 STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithmList(*this, xmlHandle, algStreamName, m_streamAlgorithmMap[algStreamName]));
123 if (m_streamAlgorithmMap.at(algStreamName).empty())
124 {
125 std::cout << "StreamingAlgorithm::ReadSettings - Error: Found no algorithms for \'" << algStreamName << "\'" << std::endl;
126 return STATUS_CODE_NOT_FOUND;
127 }
128 }
129
130 return STATUS_CODE_SUCCESS;
131}
132
133} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the lar calo hit class.
Header file for the lar monte carlo particle helper helper class.
Header file for the lar monitoring helper helper class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
static pandora::StatusCode ReplaceCurrentList(const pandora::Algorithm &algorithm, const std::string &newListName)
Replace the current list with a pre-saved list; use this new list as a permanent replacement for the ...
static pandora::StatusCode GetCurrentList(const pandora::Algorithm &algorithm, const T *&pT)
Get the current list.
static pandora::StatusCode RunDaughterAlgorithm(const pandora::Algorithm &algorithm, const std::string &daughterAlgorithmName)
Run an algorithm registered with pandora, from within a parent algorithm.
StreamingAlgorithm()
Default constructor.
pandora::StringVector m_inputListNames
The names of the input lists.
std::string m_outputListName
The name of the output list.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
std::string m_listType
The type of the input lists (currently only Cluster is supported)
pandora::StringVector m_outputListNames
Names of the output lists if not combining into a single list at the end.
pandora::StatusCode Run()
Run the algorithm.
StreamAlgorithmMap m_streamAlgorithmMap
A map from individual streams to the algorithms that stream should run.
static StatusCode ReadVectorOfValues(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, std::vector< T > &vector)
Read a vector of values from a (space separated) list in an xml element.
Definition XmlHelper.h:229
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
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
MANAGED_CONTAINER< const Cluster * > ClusterList
StatusCode
The StatusCode enum.