Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
AlgorithmObjectManager.cc
Go to the documentation of this file.
1
10
11#include "Objects/Cluster.h"
13#include "Objects/Vertex.h"
14
15#include <algorithm>
16
17namespace pandora
18{
19
20template<typename T>
22 Manager<T>(pPandora),
23 m_canMakeNewObjects(false)
24{
25}
26
27//------------------------------------------------------------------------------------------------------------------------------------------
29template<typename T>
34//------------------------------------------------------------------------------------------------------------------------------------------
35
36template<typename T>
37StatusCode AlgorithmObjectManager<T>::CreateTemporaryListAndSetCurrent(const Algorithm *const pAlgorithm, std::string &temporaryListName)
38{
39 m_canMakeNewObjects = true;
40 return Manager<T>::CreateTemporaryListAndSetCurrent(pAlgorithm, temporaryListName);
41}
42
43//------------------------------------------------------------------------------------------------------------------------------------------
45template<typename T>
46StatusCode AlgorithmObjectManager<T>::MoveObjectsToTemporaryListAndSetCurrent(const Algorithm *const pAlgorithm, const std::string &originalListName,
47 std::string &temporaryListName, const ObjectList &objectsToMove)
48{
49 if (objectsToMove.empty())
50 return STATUS_CODE_NOT_INITIALIZED;
51
52 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->CreateTemporaryListAndSetCurrent(pAlgorithm, temporaryListName));
53 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->MoveObjectsBetweenLists(temporaryListName, originalListName, &objectsToMove));
54
55 return STATUS_CODE_SUCCESS;
57
58//------------------------------------------------------------------------------------------------------------------------------------------
59
60template<typename T>
61StatusCode AlgorithmObjectManager<T>::SaveObjects(const std::string &targetListName, const std::string &sourceListName)
62{
63 typename Manager<T>::NameToListMap::iterator targetObjectListIter = Manager<T>::m_nameToListMap.find(targetListName);
64
65 if (Manager<T>::m_nameToListMap.end() == targetObjectListIter)
66 {
67 Manager<T>::m_nameToListMap[targetListName] = new ObjectList;
68 Manager<T>::m_savedLists.insert(targetListName);
69 }
70
71 return this->MoveObjectsBetweenLists(targetListName, sourceListName);
72}
73
74//------------------------------------------------------------------------------------------------------------------------------------------
75
76template<typename T>
77StatusCode AlgorithmObjectManager<T>::SaveObjects(const std::string &targetListName, const std::string &sourceListName, const ObjectList &objectsToSave)
78{
79 if (objectsToSave.empty())
80 return STATUS_CODE_NOT_INITIALIZED;
81
82 typename Manager<T>::NameToListMap::iterator targetObjectListIter = Manager<T>::m_nameToListMap.find(targetListName);
83
84 if (Manager<T>::m_nameToListMap.end() == targetObjectListIter)
85 {
86 Manager<T>::m_nameToListMap[targetListName] = new ObjectList;
87 Manager<T>::m_savedLists.insert(targetListName);
88 }
89
90 return this->MoveObjectsBetweenLists(targetListName, sourceListName, &objectsToSave);
91}
92
93//------------------------------------------------------------------------------------------------------------------------------------------
94
95template<typename T>
96StatusCode AlgorithmObjectManager<T>::MoveObjectsBetweenLists(const std::string &targetListName, const std::string &sourceListName,
97 const ObjectList *const pObjectSubset)
98{
99 if (Manager<T>::m_nullListName == targetListName)
100 return STATUS_CODE_NOT_ALLOWED;
101
102 typename Manager<T>::NameToListMap::iterator sourceListIter = Manager<T>::m_nameToListMap.find(sourceListName);
104 if (Manager<T>::m_nameToListMap.end() == sourceListIter)
105 return STATUS_CODE_NOT_FOUND;
106
107 if (sourceListIter->second->empty())
108 return STATUS_CODE_NOT_INITIALIZED;
109
110 typename Manager<T>::NameToListMap::iterator targetListIter = Manager<T>::m_nameToListMap.find(targetListName);
112 if (Manager<T>::m_nameToListMap.end() == targetListIter)
113 return STATUS_CODE_FAILURE;
114
115 if (!pObjectSubset)
116 {
117 for (const T *const pT : *sourceListIter->second)
118 {
119 if (targetListIter->second->end() != std::find(targetListIter->second->begin(), targetListIter->second->end(), pT))
120 return STATUS_CODE_ALREADY_PRESENT;
121
122 targetListIter->second->push_back(pT);
123 }
124
125 sourceListIter->second->clear();
126 }
127 else
128 {
129 if ((sourceListIter->second == pObjectSubset) || (targetListIter->second == pObjectSubset))
130 return STATUS_CODE_INVALID_PARAMETER;
131
132 for (const T *const pT : *pObjectSubset)
133 {
134 typename ObjectList::iterator objectIter = std::find(sourceListIter->second->begin(), sourceListIter->second->end(), pT);
135
136 if (sourceListIter->second->end() == objectIter)
137 return STATUS_CODE_NOT_FOUND;
138
139 if (targetListIter->second->end() != std::find(targetListIter->second->begin(), targetListIter->second->end(), pT))
140 return STATUS_CODE_ALREADY_PRESENT;
141
142 targetListIter->second->push_back(pT);
143 objectIter = sourceListIter->second->erase(objectIter);
144 }
145 }
146
147 m_canMakeNewObjects = false;
148 return STATUS_CODE_SUCCESS;
150
151//------------------------------------------------------------------------------------------------------------------------------------------
152
153template<typename T>
155{
157 return STATUS_CODE_NOT_FOUND;
158
159 m_canMakeNewObjects = false;
161 return STATUS_CODE_SUCCESS;
162}
163
164//------------------------------------------------------------------------------------------------------------------------------------------
166template<typename T>
167StatusCode AlgorithmObjectManager<T>::DeleteObject(const T *const pT, const std::string &listName)
168{
169 typename Manager<T>::NameToListMap::iterator listIter = Manager<T>::m_nameToListMap.find(listName);
171 if (Manager<T>::m_nameToListMap.end() == listIter)
172 return STATUS_CODE_NOT_FOUND;
173
174 typename ObjectList::iterator deletionIter = std::find(listIter->second->begin(), listIter->second->end(), pT);
175
176 if (listIter->second->end() == deletionIter)
177 return STATUS_CODE_NOT_FOUND;
178
179 deletionIter = listIter->second->erase(deletionIter);
180 delete pT;
181
182 return STATUS_CODE_SUCCESS;
183}
184
185//------------------------------------------------------------------------------------------------------------------------------------------
186
187template<typename T>
188StatusCode AlgorithmObjectManager<T>::DeleteObjects(const ObjectList &objectList, const std::string &listName)
189{
190 typename Manager<T>::NameToListMap::iterator listIter = Manager<T>::m_nameToListMap.find(listName);
191
192 if (Manager<T>::m_nameToListMap.end() == listIter)
193 return STATUS_CODE_NOT_FOUND;
194
195 if (listIter->second == &objectList)
196 return STATUS_CODE_INVALID_PARAMETER;
197
198 for (const T *const pT : objectList)
199 {
200 typename ObjectList::iterator deletionIter = std::find(listIter->second->begin(), listIter->second->end(), pT);
201
202 if (listIter->second->end() == deletionIter)
203 return STATUS_CODE_NOT_FOUND;
204
205 deletionIter = listIter->second->erase(deletionIter);
206 delete pT;
207 }
208
209 return STATUS_CODE_SUCCESS;
210}
211
212//------------------------------------------------------------------------------------------------------------------------------------------
213
214template<typename T>
215StatusCode AlgorithmObjectManager<T>::DeleteTemporaryObjects(const Algorithm *const pAlgorithm, const std::string &temporaryListName)
216{
217 if (Manager<T>::m_savedLists.end() != Manager<T>::m_savedLists.find(temporaryListName))
218 return STATUS_CODE_NOT_ALLOWED;
219
221
222 if (Manager<T>::m_algorithmInfoMap.end() == algorithmIter)
223 return STATUS_CODE_NOT_FOUND;
224
225 if (algorithmIter->second.m_temporaryListNames.end() == algorithmIter->second.m_temporaryListNames.find(temporaryListName))
226 return STATUS_CODE_NOT_ALLOWED;
227
228 typename Manager<T>::NameToListMap::iterator listIter = Manager<T>::m_nameToListMap.find(temporaryListName);
229
230 if (Manager<T>::m_nameToListMap.end() == listIter)
231 return STATUS_CODE_FAILURE;
232
233 for (const T *const pT : *listIter->second)
234 delete pT;
235
236 listIter->second->clear();
237 return STATUS_CODE_SUCCESS;
238}
239
240//------------------------------------------------------------------------------------------------------------------------------------------
241
242template<typename T>
244{
246
247 if (Manager<T>::m_algorithmInfoMap.end() == algorithmIter)
248 return STATUS_CODE_NOT_FOUND;
249
250 for (const std::string &temporaryListName : algorithmIter->second.m_temporaryListNames)
251 {
252 typename Manager<T>::NameToListMap::const_iterator listIter = Manager<T>::m_nameToListMap.find(temporaryListName);
253
254 if (Manager<T>::m_nameToListMap.end() == listIter)
255 return STATUS_CODE_FAILURE;
256
257 objectList.insert(objectList.end(), listIter->second->begin(), listIter->second->end());
258 }
259
260 return STATUS_CODE_SUCCESS;
261}
262
263//------------------------------------------------------------------------------------------------------------------------------------------
264
265template<typename T>
267{
268 m_canMakeNewObjects = false;
270}
271
272//------------------------------------------------------------------------------------------------------------------------------------------
273
274template<typename T>
276{
277 m_canMakeNewObjects = false;
278 return Manager<T>::ReplaceCurrentAndAlgorithmInputLists(pAlgorithm, listName);
279}
280
281//------------------------------------------------------------------------------------------------------------------------------------------
282
283template<typename T>
285{
286 m_canMakeNewObjects = false;
287 return Manager<T>::DropCurrentList(pAlgorithm);
288}
289
290//------------------------------------------------------------------------------------------------------------------------------------------
291
292template<typename T>
293StatusCode AlgorithmObjectManager<T>::RenameList(const std::string &oldListName, const std::string &newListName)
294{
295 if (m_canMakeNewObjects)
296 return STATUS_CODE_NOT_ALLOWED;
297
298 return Manager<T>::RenameList(oldListName, newListName);
299}
300
301//------------------------------------------------------------------------------------------------------------------------------------------
302
303template<typename T>
304StatusCode AlgorithmObjectManager<T>::ResetAlgorithmInfo(const Algorithm *const pAlgorithm, bool isAlgorithmFinished)
305{
306 ObjectList objectList;
307 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->GetResetDeletionObjects(pAlgorithm, objectList));
308
309 for (const T *const pT : objectList)
310 delete pT;
311
312 m_canMakeNewObjects = false;
313 return Manager<T>::ResetAlgorithmInfo(pAlgorithm, isAlgorithmFinished);
314}
315
316//------------------------------------------------------------------------------------------------------------------------------------------
317
318template<typename T>
320{
322 {
323 for (const T *const pT : *mapEntry.second)
324 delete pT;
325 }
326
327 m_canMakeNewObjects = false;
329}
330
331//------------------------------------------------------------------------------------------------------------------------------------------
332//------------------------------------------------------------------------------------------------------------------------------------------
333
336template class AlgorithmObjectManager<Vertex>;
337
338} // namespace pandora
Header file for the algorithm object manager class.
Header file for the cluster class.
Header file for the particle flow object class.
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the vertex class.
Algorithm class. Algorithm addresses are held only by the algorithm manager. They have a fully define...
Definition Algorithm.h:21
AlgorithmObjectManager class.
virtual StatusCode ResetCurrentListToAlgorithmInputList(const Algorithm *const pAlgorithm)
Reset the current list to the algorithm input list.
AlgorithmObjectManager(const Pandora *const pPandora)
Constructor.
virtual StatusCode GetResetDeletionObjects(const Algorithm *const pAlgorithm, ObjectList &objectList) const
Get the list of objects that will be deleted when the algorithm info is reset.
virtual StatusCode EraseAllContent()
Erase all manager content.
virtual StatusCode CreateTemporaryListAndSetCurrent(const Algorithm *const pAlgorithm, std::string &temporaryListName)
Make a temporary list and set it to be the current list.
virtual StatusCode SaveObjects(const std::string &targetListName, const std::string &sourceListName)
Save a list of objects.
virtual StatusCode DropCurrentList(const Algorithm *const pAlgorithm)
Drop the current list, returning the current list to its default empty/null state.
virtual StatusCode RenameList(const std::string &oldListName, const std::string &newListName)
Rename a saved list, altering its saved name from a specified old list name to a specified new list n...
virtual StatusCode DeleteObjects(const ObjectList &objectList, const std::string &listName)
Delete a list of objects from a specified list.
virtual StatusCode DeleteObject(const T *const pT, const std::string &listName)
Delete an object from a specified list.
virtual StatusCode TemporarilyReplaceCurrentList(const std::string &listName)
Temporarily replace the current list with another list, which may only be a temporary list....
virtual StatusCode ResetAlgorithmInfo(const Algorithm *const pAlgorithm, bool isAlgorithmFinished)
Remove temporary lists and reset the current cluster list to that when algorithm was initialized.
virtual StatusCode MoveObjectsToTemporaryListAndSetCurrent(const Algorithm *const pAlgorithm, const std::string &originalListName, std::string &temporaryListName, const ObjectList &objectsToMove)
Move objects to a new temporary object list and set it to be the current object list.
virtual StatusCode DeleteTemporaryObjects(const Algorithm *const pAlgorithm, const std::string &temporaryListName)
Delete the contents of a temporary list.
virtual StatusCode MoveObjectsBetweenLists(const std::string &targetListName, const std::string &sourceListName, const ObjectList *pObjectSubset=nullptr)
Move (a subset of) objects between two lists.
virtual StatusCode ReplaceCurrentAndAlgorithmInputLists(const Algorithm *const pAlgorithm, const std::string &listName)
Replace the current and algorithm input lists with a pre-existing list.
Manager class.
Definition Manager.h:27
virtual StatusCode ResetCurrentListToAlgorithmInputList(const Algorithm *const pAlgorithm)
Reset the current list to the algorithm input list.
Definition Manager.cc:102
virtual StatusCode RenameList(const std::string &oldListName, const std::string &newListName)
Rename a saved list, altering its saved name from a specified old list name to a specified new list n...
Definition Manager.cc:142
virtual StatusCode EraseAllContent()
Erase all manager content.
Definition Manager.cc:258
virtual StatusCode ResetAlgorithmInfo(const Algorithm *const pAlgorithm, bool isAlgorithmFinished)
Remove temporary lists and reset the current list to that when algorithm was initialized.
Definition Manager.cc:216
virtual StatusCode DropCurrentList(const Algorithm *const pAlgorithm)
Drop the current list, returning the current list to its default empty/null state.
Definition Manager.cc:134
virtual StatusCode ReplaceCurrentAndAlgorithmInputLists(const Algorithm *const pAlgorithm, const std::string &listName)
Replace the current and algorithm input lists with a pre-existing list.
Definition Manager.cc:110
virtual StatusCode CreateTemporaryListAndSetCurrent(const Algorithm *const pAlgorithm, std::string &temporaryListName)
Create a temporary list associated with a particular algorithm.
Definition Manager.cc:177
Pandora class.
Definition Pandora.h:40
StatusCode
The StatusCode enum.