Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
OrderedCaloHitList.cc
Go to the documentation of this file.
1
9#include "Objects/CaloHit.h"
11
12#include <algorithm>
13
14namespace pandora
15{
16
20
21//------------------------------------------------------------------------------------------------------------------------------------------
22
24{
25 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->Add(rhs));
26}
27
28//------------------------------------------------------------------------------------------------------------------------------------------
29
31{
32 for (const value_type &entry : m_theList)
33 delete entry.second;
34}
35
36//------------------------------------------------------------------------------------------------------------------------------------------
37
39{
40 for (const value_type &rhsEntry : rhs)
41 {
42 for (const CaloHit *const pCaloHit : *rhsEntry.second)
43 {
44 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->Add(pCaloHit, rhsEntry.first));
45 }
46 }
47
48 return STATUS_CODE_SUCCESS;
49}
50
51//------------------------------------------------------------------------------------------------------------------------------------------
52
54{
55 for (const value_type &rhsEntry : rhs)
56 {
57 for (const CaloHit *const pCaloHit : *rhsEntry.second)
58 {
59 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, this->Remove(pCaloHit, rhsEntry.first));
60 }
61 }
62
63 return STATUS_CODE_SUCCESS;
64}
65
66//------------------------------------------------------------------------------------------------------------------------------------------
67
69{
70 for (const CaloHit *const pCaloHit : caloHitList)
71 {
72 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, this->Add(pCaloHit, pCaloHit->GetPseudoLayer()));
73 }
74
75 return STATUS_CODE_SUCCESS;
76}
77
78//------------------------------------------------------------------------------------------------------------------------------------------
79
81{
82 for (const CaloHit *const pCaloHit : caloHitList)
83 {
84 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, this->Remove(pCaloHit, pCaloHit->GetPseudoLayer()));
85 }
86
87 return STATUS_CODE_SUCCESS;
88}
89
90//------------------------------------------------------------------------------------------------------------------------------------------
91
92StatusCode OrderedCaloHitList::GetCaloHitsInPseudoLayer(const unsigned int pseudoLayer, CaloHitList *&pCaloHitList) const
93{
94 OrderedCaloHitList::const_iterator iter = this->find(pseudoLayer);
95
96 if (this->end() == iter)
97 return STATUS_CODE_NOT_FOUND;
98
99 pCaloHitList = iter->second;
100
101 return STATUS_CODE_SUCCESS;
102}
103
104//------------------------------------------------------------------------------------------------------------------------------------------
105
106unsigned int OrderedCaloHitList::GetNCaloHitsInPseudoLayer(const unsigned int pseudoLayer) const
107{
108 OrderedCaloHitList::const_iterator iter = this->find(pseudoLayer);
109
110 if (this->end() == iter)
111 return 0;
112
113 return iter->second->size();
114}
115
116//------------------------------------------------------------------------------------------------------------------------------------------
117
119{
120 for (const value_type &entry : m_theList)
121 delete entry.second;
122
123 this->clear();
124
125 if (!this->empty())
126 throw StatusCodeException(STATUS_CODE_FAILURE);
127}
128
129//------------------------------------------------------------------------------------------------------------------------------------------
130
132{
133 for (const value_type &entry : m_theList)
134 {
135 caloHitList.insert(caloHitList.end(), entry.second->begin(), entry.second->end());
136 }
137}
138
139//------------------------------------------------------------------------------------------------------------------------------------------
140
142{
143 if (this == &rhs)
144 return true;
145
146 if (!this->empty())
147 this->Reset();
148
149 return (STATUS_CODE_SUCCESS == this->Add(rhs));
150}
151
152//------------------------------------------------------------------------------------------------------------------------------------------
153
154StatusCode OrderedCaloHitList::Add(const CaloHit *const pCaloHit, const unsigned int pseudoLayer)
155{
156 TheList::iterator iter = m_theList.find(pseudoLayer);
157
158 if (m_theList.end() == iter)
159 {
160 CaloHitList *const pCaloHitList = new CaloHitList;
161 pCaloHitList->push_back(pCaloHit);
162
163 if (!(m_theList.insert(TheList::value_type(pseudoLayer, pCaloHitList)).second))
164 {
165 delete pCaloHitList;
166 return STATUS_CODE_FAILURE;
167 }
168 }
169 else
170 {
171 if (iter->second->end() != std::find(iter->second->begin(), iter->second->end(), pCaloHit))
172 return STATUS_CODE_ALREADY_PRESENT;
173
174 iter->second->push_back(pCaloHit);
175 }
176
177 return STATUS_CODE_SUCCESS;
178}
179
180//------------------------------------------------------------------------------------------------------------------------------------------
181
182StatusCode OrderedCaloHitList::Remove(const CaloHit *const pCaloHit, const unsigned int pseudoLayer)
183{
184 TheList::iterator listIter = m_theList.find(pseudoLayer);
185
186 if (m_theList.end() == listIter)
187 return STATUS_CODE_NOT_FOUND;
188
189 CaloHitList::iterator caloHitIter = std::find(listIter->second->begin(), listIter->second->end(), pCaloHit);
190
191 if (listIter->second->end() == caloHitIter)
192 return STATUS_CODE_NOT_FOUND;
193
194 caloHitIter = listIter->second->erase(caloHitIter);
195
196 if (listIter->second->empty())
197 {
198 delete listIter->second;
199 listIter = m_theList.erase(listIter);
200 }
201
202 return STATUS_CODE_SUCCESS;
203}
204
205} // namespace pandora
Header file for the calo hit class.
Header file for the ordered calo hit list class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:43
#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
CaloHit class.
Definition CaloHit.h:26
Calo hit lists arranged by pseudo layer.
const_iterator end() const
Returns a const iterator referring to the past-the-end element in the ordered calo hit list.
void clear()
Clear the ordered calo hit list.
OrderedCaloHitList()
Default constructor.
void Reset()
Reset the ordered calo hit list, emptying its contents.
TheList m_theList
The ordered calo hit list.
bool operator=(const OrderedCaloHitList &rhs)
Assignment operator.
StatusCode Remove(const OrderedCaloHitList &rhs)
Remove the hits in a second ordered calo hit list from this list.
unsigned int GetNCaloHitsInPseudoLayer(const unsigned int pseudoLayer) const
Get the number of calo hits in a specified pseudo layer.
TheList::const_iterator const_iterator
StatusCode GetCaloHitsInPseudoLayer(const unsigned int pseudoLayer, CaloHitList *&pCaloHitList) const
Get calo hits in specified pseudo layer.
StatusCode Add(const OrderedCaloHitList &rhs)
Add the hits from a second ordered calo hit list to this list.
bool empty() const
Returns whether the map container is empty (i.e. whether its size is 0)
const_iterator find(const unsigned int index) const
Searches the container for an element with specified layer and returns an iterator to it if found,...
void FillCaloHitList(CaloHitList &caloHitList) const
Fill a provided calo hit list with all the calo hits in the ordered calo hit list.
StatusCodeException class.
MANAGED_CONTAINER< const CaloHit * > CaloHitList
StatusCode
The StatusCode enum.