ListPruningAlgorithm.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArUtility/ListPruningAlgorithm.cc
3  *
4  * @brief Implementation of the list pruning algorithm class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 ListPruningAlgorithm::ListPruningAlgorithm() : m_warnIfObjectsUnavailable(true)
19 {
20 }
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
25 {
26  for (const std::string &listName : m_pfoListNames)
27  {
28  try
29  {
30  const PfoList *pPfoList(nullptr);
31  const StatusCode statusCode(PandoraContentApi::GetList(*this, listName, pPfoList));
32 
33  if (STATUS_CODE_SUCCESS != statusCode)
34  throw StatusCodeException(statusCode);
35 
36  const PfoList pfoList(*pPfoList);
37 
38  for (const ParticleFlowObject *const pPfo : pfoList)
39  {
40  if (STATUS_CODE_SUCCESS != PandoraContentApi::Delete(*this, pPfo, listName))
41  std::cout << "ListPruningAlgorithm: Could not delete Pfo." << std::endl;
42  }
43  }
44  catch (StatusCodeException &)
45  {
46  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
47  std::cout << "ListPruningAlgorithm: pfo list " << listName << " unavailable." << std::endl;
48  }
49  }
50 
51  for (const std::string &listName : m_clusterListNames)
52  {
53  try
54  {
55  const ClusterList *pClusterList(nullptr);
56  const StatusCode statusCode(PandoraContentApi::GetList(*this, listName, pClusterList));
57 
58  if (STATUS_CODE_SUCCESS != statusCode)
59  throw StatusCodeException(statusCode);
60 
61  const ClusterList clusterList(*pClusterList);
62 
63  for (const Cluster *const pCluster : clusterList)
64  {
65  if (!m_warnIfObjectsUnavailable && !pCluster->IsAvailable())
66  continue;
67 
68  if (STATUS_CODE_SUCCESS != PandoraContentApi::Delete(*this, pCluster, listName) && m_warnIfObjectsUnavailable)
69  std::cout << "ListPruningAlgorithm: Could not delete Cluster." << std::endl;
70  }
71  }
72  catch (StatusCodeException &)
73  {
74  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
75  std::cout << "ListPruningAlgorithm: cluster list " << listName << " unavailable." << std::endl;
76  }
77  }
78 
79  for (const std::string &listName : m_vertexListNames)
80  {
81  try
82  {
83  const VertexList *pVertexList(nullptr);
84  const StatusCode statusCode(PandoraContentApi::GetList(*this, listName, pVertexList));
85 
86  if (STATUS_CODE_SUCCESS != statusCode)
87  throw StatusCodeException(statusCode);
88 
89  const VertexList vertexList(*pVertexList);
90 
91  for (const Vertex *const pVertex : vertexList)
92  {
93  if (!m_warnIfObjectsUnavailable && !pVertex->IsAvailable())
94  continue;
95 
96  if (STATUS_CODE_SUCCESS != PandoraContentApi::Delete(*this, pVertex, listName) && m_warnIfObjectsUnavailable)
97  std::cout << "ListPruningAlgorithm: Could not delete Vertex." << std::endl;
98  }
99  }
100  catch (StatusCodeException &)
101  {
102  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
103  std::cout << "ListPruningAlgorithm: vertex list " << listName << " unavailable." << std::endl;
104  }
105  }
106 
107  return STATUS_CODE_SUCCESS;
108 }
109 
110 //------------------------------------------------------------------------------------------------------------------------------------------
111 
112 StatusCode ListPruningAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
113 {
114  PANDORA_RETURN_RESULT_IF_AND_IF(
115  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "PfoListNames", m_pfoListNames));
116 
117  PANDORA_RETURN_RESULT_IF_AND_IF(
118  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "ClusterListNames", m_clusterListNames));
119 
120  PANDORA_RETURN_RESULT_IF_AND_IF(
121  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "VertexListNames", m_vertexListNames));
122 
123  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
124  XmlHelper::ReadValue(xmlHandle, "WarnIfObjectsUnavailable", m_warnIfObjectsUnavailable));
125 
126  return STATUS_CODE_SUCCESS;
127 }
128 
129 } // namespace lar_content
std::string string
Definition: nybbler.cc:12
pandora::StringVector m_clusterListNames
The cluster list names.
pandora::StringVector m_pfoListNames
The pfo list names.
Header file for the list pruning algorithm class.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
bool m_warnIfObjectsUnavailable
Whether to print warning if attempt made to delete unavailable objects.
std::list< Vertex > VertexList
Definition: DCEL.h:182
pandora::StringVector m_vertexListNames
The vertex list names.
QTextStream & endl(QTextStream &s)