LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArOverlapMatrix.h
Go to the documentation of this file.
1 
8 #ifndef LAR_OVERLAP_MATRIX_H
9 #define LAR_OVERLAP_MATRIX_H 1
10 
11 #include "Pandora/PandoraInternal.h"
12 
13 #include <unordered_map>
14 #include <vector>
15 
16 namespace lar_content
17 {
18 
22 template <typename T>
24 {
25 public:
26  typedef T OverlapResult;
27 
31  class Element
32  {
33  public:
41  Element(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const OverlapResult &overlapResult);
42 
48  const pandora::Cluster *GetCluster1() const;
49 
55  const pandora::Cluster *GetCluster2() const;
56 
62  const OverlapResult &GetOverlapResult() const;
63 
69  bool operator<(const Element &rhs) const;
70 
71  private:
72  const pandora::Cluster *m_pCluster1;
73  const pandora::Cluster *m_pCluster2;
74  OverlapResult m_overlapResult;
75  };
76 
77  typedef std::vector<Element> ElementList;
78 
85  void GetUnambiguousElements(const bool ignoreUnavailable, ElementList &elementList) const;
86 
97  bool DefaultAmbiguityFunction(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2,
98  const pandora::Cluster *&pCluster1, const pandora::Cluster *&pCluster2) const;
99 
108  void GetNConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, unsigned int &n1, unsigned int &n2) const;
109 
117  void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const;
118 
128  void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList,
129  unsigned int &n1, unsigned int &n2) const;
130 
131  typedef std::unordered_map<const pandora::Cluster *, pandora::ClusterList> ClusterNavigationMap;
132  typedef std::unordered_map<const pandora::Cluster *, OverlapResult> OverlapList;
133  typedef std::unordered_map<const pandora::Cluster *, OverlapList> TheMatrix;
134 
136 
140  const_iterator begin() const;
141 
145  const_iterator end() const;
146 
152  void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const;
153 
162  const OverlapResult &GetOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2) const;
163 
171  const OverlapList &GetOverlapList(const pandora::Cluster *const pCluster1) const;
172 
178  const ClusterNavigationMap &GetClusterNavigationMap12() const;
179 
185  const ClusterNavigationMap &GetClusterNavigationMap21() const;
186 
194  void SetOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const OverlapResult &overlapResult);
195 
203  void ReplaceOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const OverlapResult &overlapResult);
204 
210  void RemoveCluster(const pandora::Cluster *const pCluster);
211 
215  void Clear();
216 
217 private:
226  void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList,
227  pandora::ClusterList &clusterList1, pandora::ClusterList &clusterList2) const;
228 
236  void ExploreConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, pandora::ClusterList &clusterList1,
237  pandora::ClusterList &clusterList2) const;
238 
239  TheMatrix m_overlapMatrix;
240  ClusterNavigationMap m_clusterNavigationMap12;
241  ClusterNavigationMap m_clusterNavigationMap21;
242 };
243 
244 //------------------------------------------------------------------------------------------------------------------------------------------
245 
246 template <typename T>
247 inline void OverlapMatrix<T>::GetNConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, unsigned int &n1, unsigned int &n2) const
248 {
249  ElementList elementList;
250  this->GetConnectedElements(pCluster, ignoreUnavailable, elementList, n1, n2);
251 }
252 
253 //------------------------------------------------------------------------------------------------------------------------------------------
254 
255 template <typename T>
256 inline void OverlapMatrix<T>::GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
257 {
258  unsigned int n1(0), n2(0);
259  this->GetConnectedElements(pCluster, ignoreUnavailable, elementList, n1, n2);
260 }
261 
262 //------------------------------------------------------------------------------------------------------------------------------------------
263 
264 template <typename T>
266 {
267  return m_overlapMatrix.begin();
268 }
269 
270 //------------------------------------------------------------------------------------------------------------------------------------------
271 
272 template <typename T>
274 {
275  return m_overlapMatrix.end();
276 }
277 
278 //------------------------------------------------------------------------------------------------------------------------------------------
279 
280 template <typename T>
282  const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2) const
283 {
284  const OverlapList &overlapList(this->GetOverlapList(pCluster1));
285  typename OverlapList::const_iterator iter = overlapList.find(pCluster2);
286 
287  if (overlapList.end() == iter)
288  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
289 
290  return iter->second;
291 }
292 
293 //------------------------------------------------------------------------------------------------------------------------------------------
294 
295 template <typename T>
296 inline const typename OverlapMatrix<T>::OverlapList &OverlapMatrix<T>::GetOverlapList(const pandora::Cluster *const pCluster1) const
297 {
298  typename TheMatrix::const_iterator iter = m_overlapMatrix.find(pCluster1);
299 
300  if (m_overlapMatrix.end() == iter)
301  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
302 
303  return iter->second;
304 }
305 
306 //------------------------------------------------------------------------------------------------------------------------------------------
307 
308 template <typename T>
310 {
312 }
313 
314 //------------------------------------------------------------------------------------------------------------------------------------------
315 
316 template <typename T>
318 {
320 }
321 
322 //------------------------------------------------------------------------------------------------------------------------------------------
323 
324 template <typename T>
326 {
327  m_overlapMatrix.clear();
328  m_clusterNavigationMap12.clear();
329  m_clusterNavigationMap21.clear();
330 }
331 
332 //------------------------------------------------------------------------------------------------------------------------------------------
333 //------------------------------------------------------------------------------------------------------------------------------------------
334 
335 template <typename T>
337  const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const OverlapResult &overlapResult) :
338  m_pCluster1(pCluster1),
339  m_pCluster2(pCluster2),
340  m_overlapResult(overlapResult)
341 {
342 }
343 
344 //------------------------------------------------------------------------------------------------------------------------------------------
345 
346 template <typename T>
347 inline const pandora::Cluster *OverlapMatrix<T>::Element::GetCluster1() const
348 {
349  return m_pCluster1;
350 }
351 
352 //------------------------------------------------------------------------------------------------------------------------------------------
353 
354 template <typename T>
355 inline const pandora::Cluster *OverlapMatrix<T>::Element::GetCluster2() const
356 {
357  return m_pCluster2;
358 }
359 
360 //------------------------------------------------------------------------------------------------------------------------------------------
361 
362 template <typename T>
364 {
365  return m_overlapResult;
366 }
367 
368 //------------------------------------------------------------------------------------------------------------------------------------------
369 
370 template <typename T>
372 {
373  if (this == &rhs)
374  return false;
375 
376  return (this->GetOverlapResult() < rhs.GetOverlapResult());
377 }
378 
379 } // namespace lar_content
380 
381 #endif // #ifndef LAR_OVERLAP_MATRIX_H
OverlapResult m_overlapResult
The overlap result.
const pandora::Cluster * m_pCluster1
The address of cluster 1.
void Clear()
Clear overlap matrix.
void RemoveCluster(const pandora::Cluster *const pCluster)
Remove entries from matrix corresponding to specified cluster.
Element(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const OverlapResult &overlapResult)
Constructor.
bool DefaultAmbiguityFunction(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2, const pandora::Cluster *&pCluster1, const pandora::Cluster *&pCluster2) const
Default ambiguity function, checking that only one cluster from view 1 and view 2 is found...
const OverlapResult & GetOverlapResult() const
Get the overlap result.
const ClusterNavigationMap & GetClusterNavigationMap12() const
Get the cluster navigation map 1->2.
intermediate_table::const_iterator const_iterator
std::vector< Element > ElementList
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (view 1 clusters with current implementation) ...
const OverlapResult & GetOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2) const
Get the overlap result for a specified pair of clusters.
ClusterNavigationMap m_clusterNavigationMap12
The cluster navigation map 1->2.
const OverlapList & GetOverlapList(const pandora::Cluster *const pCluster1) const
Get the overlap list for a specified cluster.
bool operator<(const Element &rhs) const
Element less than operator.
const ClusterNavigationMap & GetClusterNavigationMap21() const
Get the cluster navigation map 2->1.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterNavigationMap
const_iterator begin() const
Returns an iterator referring to the first element in the overlap matrix.
TheMatrix::const_iterator const_iterator
std::unordered_map< const pandora::Cluster *, OverlapResult > OverlapList
void GetUnambiguousElements(const bool ignoreUnavailable, ElementList &elementList) const
Get unambiguous elements.
void SetOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const OverlapResult &overlapResult)
Set overlap result.
TheMatrix m_overlapMatrix
The overlap matrix.
void ExploreConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, pandora::ClusterList &clusterList1, pandora::ClusterList &clusterList2) const
Explore connections associated with a given cluster.
const pandora::Cluster * GetCluster2() const
Get the address of cluster 2.
const_iterator end() const
Returns an iterator referring to the past-the-end element in the overlap matrix.
std::unordered_map< const pandora::Cluster *, OverlapList > TheMatrix
const pandora::Cluster * m_pCluster2
The address of cluster 2.
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void ReplaceOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const OverlapResult &overlapResult)
SetReplace an existing overlap result.
OverlapMatrix class.
ClusterNavigationMap m_clusterNavigationMap21
The cluster navigation map 2->1.
const pandora::Cluster * GetCluster1() const
Get the address of cluster 1.
void GetNConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, unsigned int &n1, unsigned int &n2) const
Get the number of connections for a specified cluster.