LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
LArOverlapTensor.h
Go to the documentation of this file.
1 
8 #ifndef LAR_OVERLAP_TENSOR_H
9 #define LAR_OVERLAP_TENSOR_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:
42  Element(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, const OverlapResult &overlapResult);
43 
49  const pandora::Cluster *GetClusterU() const;
50 
56  const pandora::Cluster *GetClusterV() const;
57 
63  const pandora::Cluster *GetClusterW() const;
64 
70  const OverlapResult &GetOverlapResult() const;
71 
77  bool operator<(const Element &rhs) const;
78 
79  private:
80  const pandora::Cluster *m_pClusterU;
81  const pandora::Cluster *m_pClusterV;
82  const pandora::Cluster *m_pClusterW;
83  OverlapResult m_overlapResult;
84  };
85 
86  typedef std::vector<Element> ElementList;
87 
94  void GetUnambiguousElements(const bool ignoreUnavailable, ElementList &elementList) const;
95 
108  bool DefaultAmbiguityFunction(const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV, const pandora::ClusterList &clusterListW,
109  const pandora::Cluster *&pClusterU, const pandora::Cluster *&pClusterV, const pandora::Cluster *&pClusterW) const;
110 
120  void GetNConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, unsigned int &nU, unsigned int &nV, unsigned int &nW) const;
121 
129  void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const;
130 
141  void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList, unsigned int &nU,
142  unsigned int &nV, unsigned int &nW) const;
143 
144  typedef std::unordered_map<const pandora::Cluster*, pandora::ClusterList> ClusterNavigationMap;
145  typedef std::unordered_map<const pandora::Cluster*, OverlapResult> OverlapList;
146  typedef std::unordered_map<const pandora::Cluster*, OverlapList> OverlapMatrix;
147  typedef std::unordered_map<const pandora::Cluster*, OverlapMatrix> TheTensor;
148 
150 
154  const_iterator begin() const;
155 
159  const_iterator end() const;
160 
166  void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const;
167 
177  const OverlapResult &GetOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW) const;
178 
187  const OverlapList &GetOverlapList(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV) const;
188 
196  const OverlapMatrix &GetOverlapMatrix(const pandora::Cluster *const pClusterU) const;
197 
203  const ClusterNavigationMap &GetClusterNavigationMapUV() const;
204 
210  const ClusterNavigationMap &GetClusterNavigationMapVW() const;
211 
217  const ClusterNavigationMap &GetClusterNavigationMapWU() const;
218 
227  void SetOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, const OverlapResult &overlapResult);
228 
237  void ReplaceOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, const OverlapResult &overlapResult);
238 
244  void RemoveCluster(const pandora::Cluster *const pCluster);
245 
249  void Clear();
250 
251 private:
261  void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList,
262  pandora::ClusterList &clusterListU, pandora::ClusterList &clusterListV, pandora::ClusterList &clusterListW) const;
263 
272  void ExploreConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, pandora::ClusterList &clusterListU,
273  pandora::ClusterList &clusterListV, pandora::ClusterList &clusterListW) const;
274 
275  TheTensor m_overlapTensor;
276  ClusterNavigationMap m_clusterNavigationMapUV;
277  ClusterNavigationMap m_clusterNavigationMapVW;
278  ClusterNavigationMap m_clusterNavigationMapWU;
279 };
280 
281 //------------------------------------------------------------------------------------------------------------------------------------------
282 
283 template <typename T>
284 inline void OverlapTensor<T>::GetNConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, unsigned int &nU, unsigned int &nV,
285  unsigned int &nW) const
286 {
287  ElementList elementList;
288  this->GetConnectedElements(pCluster, ignoreUnavailable, elementList, nU, nV, nW);
289 }
290 
291 //------------------------------------------------------------------------------------------------------------------------------------------
292 
293 template <typename T>
294 inline void OverlapTensor<T>::GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
295 {
296  unsigned int nU(0), nV(0), nW(0);
297  this->GetConnectedElements(pCluster, ignoreUnavailable, elementList, nU, nV, nW);
298 }
299 
300 //------------------------------------------------------------------------------------------------------------------------------------------
301 
302 template <typename T>
304 {
305  return m_overlapTensor.begin();
306 }
307 
308 //------------------------------------------------------------------------------------------------------------------------------------------
309 
310 template <typename T>
312 {
313  return m_overlapTensor.end();
314 }
315 
316 //------------------------------------------------------------------------------------------------------------------------------------------
317 
318 template <typename T>
320  const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW) const
321 {
322  const OverlapList &overlapList(this->GetOverlapList(pClusterU, pClusterV));
323  typename OverlapList::const_iterator iter = overlapList.find(pClusterW);
324 
325  if (overlapList.end() == iter)
326  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
327 
328  return iter->second;
329 }
330 
331 //------------------------------------------------------------------------------------------------------------------------------------------
332 
333 template <typename T>
335  const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV) const
336 {
337  const OverlapMatrix &overlapMatrix(this->GetOverlapMatrix(pClusterU));
338  typename OverlapMatrix::const_iterator iter = overlapMatrix.find(pClusterV);
339 
340  if (overlapMatrix.end() == iter)
341  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
342 
343  return iter->second;
344 }
345 
346 //------------------------------------------------------------------------------------------------------------------------------------------
347 
348 template <typename T>
350  const pandora::Cluster *const pClusterU) const
351 {
352  typename TheTensor::const_iterator iter = m_overlapTensor.find(pClusterU);
353 
354  if (m_overlapTensor.end() == iter)
355  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
356 
357  return iter->second;
358 }
359 
360 //------------------------------------------------------------------------------------------------------------------------------------------
361 
362 template <typename T>
364 {
366 }
367 
368 //------------------------------------------------------------------------------------------------------------------------------------------
369 
370 template <typename T>
372 {
374 }
375 
376 //------------------------------------------------------------------------------------------------------------------------------------------
377 
378 template <typename T>
380 {
382 }
383 
384 //------------------------------------------------------------------------------------------------------------------------------------------
385 
386 template <typename T>
388 {
389  m_overlapTensor.clear();
390  m_clusterNavigationMapUV.clear();
391  m_clusterNavigationMapVW.clear();
392  m_clusterNavigationMapWU.clear();
393 }
394 
395 //------------------------------------------------------------------------------------------------------------------------------------------
396 //------------------------------------------------------------------------------------------------------------------------------------------
397 
398 template <typename T>
399 inline OverlapTensor<T>::Element::Element(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW,
400  const OverlapResult &overlapResult) :
401  m_pClusterU(pClusterU),
402  m_pClusterV(pClusterV),
403  m_pClusterW(pClusterW),
404  m_overlapResult(overlapResult)
405 {
406 }
407 
408 //------------------------------------------------------------------------------------------------------------------------------------------
409 
410 template <typename T>
411 inline const pandora::Cluster *OverlapTensor<T>::Element::GetClusterU() const
412 {
413  return m_pClusterU;
414 }
415 
416 //------------------------------------------------------------------------------------------------------------------------------------------
417 
418 template <typename T>
419 inline const pandora::Cluster *OverlapTensor<T>::Element::GetClusterV() const
420 {
421  return m_pClusterV;
422 }
423 
424 //------------------------------------------------------------------------------------------------------------------------------------------
425 
426 template <typename T>
427 inline const pandora::Cluster *OverlapTensor<T>::Element::GetClusterW() const
428 {
429  return m_pClusterW;
430 }
431 
432 //------------------------------------------------------------------------------------------------------------------------------------------
433 
434 template <typename T>
436 {
437  return m_overlapResult;
438 }
439 
440 //------------------------------------------------------------------------------------------------------------------------------------------
441 
442 template <typename T>
444 {
445  if (this == &rhs)
446  return false;
447 
448  return (this->GetOverlapResult() < rhs.GetOverlapResult());
449 }
450 
451 } // namespace lar_content
452 
453 #endif // #ifndef LAR_OVERLAP_TENSOR_H
OverlapResult m_overlapResult
The overlap result.
OverlapTensor class.
ClusterNavigationMap m_clusterNavigationMapVW
The cluster navigation map V->W.
const ClusterNavigationMap & GetClusterNavigationMapVW() const
Get the cluster navigation map V->W.
ClusterNavigationMap m_clusterNavigationMapUV
The cluster navigation map U->V.
const pandora::Cluster * GetClusterW() const
Get the address of the w cluster.
const_iterator begin() const
Returns an iterator referring to the first element in the overlap tensor.
void GetNConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, unsigned int &nU, unsigned int &nV, unsigned int &nW) const
Get the number of connections for a specified cluster.
const pandora::Cluster * m_pClusterW
The address of the w cluster.
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
const ClusterNavigationMap & GetClusterNavigationMapUV() const
Get the cluster navigation map U->V.
std::unordered_map< const pandora::Cluster *, OverlapList > OverlapMatrix
void ExploreConnections(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, pandora::ClusterList &clusterListU, pandora::ClusterList &clusterListV, pandora::ClusterList &clusterListW) const
Explore connections associated with a given cluster.
void ReplaceOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, const OverlapResult &overlapResult)
SetReplace an existing overlap result.
const pandora::Cluster * GetClusterU() const
Get the address of the u cluster.
TheTensor m_overlapTensor
The overlap tensor.
std::unordered_map< const pandora::Cluster *, OverlapResult > OverlapList
const OverlapList & GetOverlapList(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV) const
Get the overlap list for a specified pair of clusters.
const_iterator end() const
Returns an iterator referring to the past-the-end element in the overlap tensor.
void SetOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, const OverlapResult &overlapResult)
Set overlap result.
void Clear()
Clear overlap tensor.
std::vector< Element > ElementList
intermediate_table::const_iterator const_iterator
void GetUnambiguousElements(const bool ignoreUnavailable, ElementList &elementList) const
Get unambiguous elements.
const OverlapMatrix & GetOverlapMatrix(const pandora::Cluster *const pClusterU) const
Get the cluster overlap matrix for a specified cluster.
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (U clusters with current implementation)
Element(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, const OverlapResult &overlapResult)
Constructor.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
const pandora::Cluster * m_pClusterU
The address of the u cluster.
ClusterNavigationMap m_clusterNavigationMapWU
The cluster navigation map W->U.
const OverlapResult & GetOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW) const
Get the overlap result for a specified trio of clusters.
bool operator<(const Element &rhs) const
Element less than operator.
const OverlapResult & GetOverlapResult() const
Get the overlap result.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterNavigationMap
const pandora::Cluster * m_pClusterV
The address of the v cluster.
std::unordered_map< const pandora::Cluster *, OverlapMatrix > TheTensor
const pandora::Cluster * GetClusterV() const
Get the address of the v cluster.
void RemoveCluster(const pandora::Cluster *const pCluster)
Remove entries from tensor corresponding to specified cluster.
bool DefaultAmbiguityFunction(const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV, const pandora::ClusterList &clusterListW, const pandora::Cluster *&pClusterU, const pandora::Cluster *&pClusterV, const pandora::Cluster *&pClusterW) const
Default ambiguity function, checking that only one U, V and W cluster is found.
const ClusterNavigationMap & GetClusterNavigationMapWU() const
Get the cluster navigation map W->U.
TheTensor::const_iterator const_iterator