LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MultiPandoraApiImpl.cc
Go to the documentation of this file.
1 
9 #include "Pandora/Pandora.h"
10 #include "Pandora/StatusCodes.h"
11 
13 
15 {
17 }
18 
19 //------------------------------------------------------------------------------------------------------------------------------------------
20 
21 const pandora::Pandora *MultiPandoraApiImpl::GetPandoraInstance(const pandora::Pandora *const pPrimaryPandora, const unsigned int volumeId) const
22 {
23  PandoraInstanceList instanceList(this->GetDaughterPandoraInstanceList(pPrimaryPandora));
24  instanceList.push_back(pPrimaryPandora);
25 
26  for (const pandora::Pandora *const pPandora : instanceList)
27  {
28  try
29  {
30  if (volumeId == this->GetVolumeId(pPandora))
31  return pPandora;
32  }
33  catch (const pandora::StatusCodeException &) {}
34  }
35 
36  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
37 }
38 
39 //------------------------------------------------------------------------------------------------------------------------------------------
40 
41 const PandoraInstanceList &MultiPandoraApiImpl::GetDaughterPandoraInstanceList(const pandora::Pandora *const pPrimaryPandora) const
42 {
44 
45  if (m_primaryToDaughtersMap.end() == iter)
46  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
47 
48  return iter->second;
49 }
50 
51 //------------------------------------------------------------------------------------------------------------------------------------------
52 
53 const pandora::Pandora *MultiPandoraApiImpl::GetPrimaryPandoraInstance(const pandora::Pandora *const pDaughterPandora) const
54 {
55  PandoraRelationMap::const_iterator iter = m_daughterToPrimaryMap.find(pDaughterPandora);
56 
57  if (m_daughterToPrimaryMap.end() == iter)
58  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
59 
60  return iter->second;
61 }
62 
63 //------------------------------------------------------------------------------------------------------------------------------------------
64 
65 unsigned int MultiPandoraApiImpl::GetVolumeId(const pandora::Pandora *const pPandora) const
66 {
68 
69  if (m_pandoraToVolumeIdMap.end() == iter)
70  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
71 
72  return iter->second;
73 }
74 
75 //------------------------------------------------------------------------------------------------------------------------------------------
76 
77 void MultiPandoraApiImpl::SetVolumeId(const pandora::Pandora *const pPandora, const unsigned int volumeId)
78 {
79  if (m_pandoraToVolumeIdMap.count(pPandora))
80  throw pandora::StatusCodeException(pandora::STATUS_CODE_ALREADY_PRESENT);
81 
82  if (!m_pandoraToVolumeIdMap.insert(PandoraToVolumeIdMap::value_type(pPandora, volumeId)).second)
83  throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
84 }
85 
86 //------------------------------------------------------------------------------------------------------------------------------------------
87 
89 {
90 }
91 
92 //------------------------------------------------------------------------------------------------------------------------------------------
93 
95 {
96  // ATTN This is a copy of the input map, which will be modified by calls to delete pandora instances
97  PandoraInstanceMap pandoraInstanceMap(m_primaryToDaughtersMap);
98 
99  for (const auto &mapElement : pandoraInstanceMap)
100  this->DeletePandoraInstances(mapElement.first);
101 }
102 
103 //------------------------------------------------------------------------------------------------------------------------------------------
104 
105 void MultiPandoraApiImpl::AddPrimaryPandoraInstance(const pandora::Pandora *const pPrimaryPandora)
106 {
107  if (!m_primaryToDaughtersMap.insert(PandoraInstanceMap::value_type(pPrimaryPandora, PandoraInstanceList())).second)
108  throw pandora::StatusCodeException(pandora::STATUS_CODE_ALREADY_PRESENT);
109 }
110 
111 //------------------------------------------------------------------------------------------------------------------------------------------
112 
113 void MultiPandoraApiImpl::AddDaughterPandoraInstance(const pandora::Pandora *const pPrimaryPandora, const pandora::Pandora *const pDaughterPandora)
114 {
115  PandoraInstanceMap::iterator iter = m_primaryToDaughtersMap.find(pPrimaryPandora);
116 
117  if (m_primaryToDaughtersMap.end() == iter)
118  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_FOUND);
119 
120  iter->second.push_back(pDaughterPandora);
121 
122  if (!m_daughterToPrimaryMap.insert(PandoraRelationMap::value_type(pDaughterPandora, pPrimaryPandora)).second)
123  throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
124 }
125 
126 //------------------------------------------------------------------------------------------------------------------------------------------
127 
128 void MultiPandoraApiImpl::DeletePandoraInstances(const pandora::Pandora *const pPrimaryPandora)
129 {
130  PandoraInstanceList pandoraInstanceList;
131 
132  try
133  {
134  pandoraInstanceList = this->GetDaughterPandoraInstanceList(pPrimaryPandora);
135  }
136  catch (const pandora::StatusCodeException &)
137  {
138  std::cout << "MultiPandoraApiImpl::DeletePandoraInstances - unable to find daughter instances associated with primary " << pPrimaryPandora << std::endl;
139  }
140 
141  pandoraInstanceList.push_back(pPrimaryPandora);
142  m_primaryToDaughtersMap.erase(pPrimaryPandora);
143 
144  for (const pandora::Pandora *const pPandora : pandoraInstanceList)
145  {
146  m_pandoraToVolumeIdMap.erase(pPandora);
147  m_daughterToPrimaryMap.erase(pPandora);
148  delete pPandora;
149  }
150 }
PandoraToVolumeIdMap m_pandoraToVolumeIdMap
The map from pandora instance to volume id.
intermediate_table::iterator iterator
~MultiPandoraApiImpl()
Destructor;.
void AddDaughterPandoraInstance(const pandora::Pandora *const pPrimaryPandora, const pandora::Pandora *const pDaughterPandora)
Add a pandora daughter instance, associated to a primary pandora instance.
void DeletePandoraInstances(const pandora::Pandora *const pPrimaryPandora)
Delete all pandora instances associated with (and including) a specified primary pandora instance...
void AddPrimaryPandoraInstance(const pandora::Pandora *const pPrimaryPandora)
Declare a new primary pandora instance.
const pandora::Pandora * GetPrimaryPandoraInstance(const pandora::Pandora *const pDaughterPandora) const
Get the address of the primary pandora instance associated with a given daughter pandora instance...
std::vector< const pandora::Pandora * > PandoraInstanceList
intermediate_table::const_iterator const_iterator
Header file for the MultiPandoraApiImpl class.
std::unordered_map< const pandora::Pandora *, PandoraInstanceList > PandoraInstanceMap
void SetVolumeId(const pandora::Pandora *const pPandora, const unsigned int volumeId)
Set the volume id associated with a given pandora instance.
PandoraRelationMap m_daughterToPrimaryMap
The map from daughter pandora instance to primary pandora instance.
const PandoraInstanceMap & GetPandoraInstanceMap() const
Get the pandora instance map.
MultiPandoraApiImpl()
Default constructor;.
const PandoraInstanceList & GetDaughterPandoraInstanceList(const pandora::Pandora *const pPrimaryPandora) const
Get the list of daughter pandora instances associated with a given primary pandora instance...
PandoraInstanceMap m_primaryToDaughtersMap
The map from primary pandora instance to list of daughter pandora instances.
unsigned int GetVolumeId(const pandora::Pandora *const pPandora) const
Get the volume id associated with a given pandora instance.
const pandora::Pandora * GetPandoraInstance(const pandora::Pandora *const pPrimaryPandora, const unsigned int volumeId) const
Get the address of the pandora instance associated with a given primary pandora instance and volume i...