Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
Manager.cc
Go to the documentation of this file.
1
9#include "Managers/Manager.h"
10
11#include "Pandora/Algorithm.h"
12
13namespace pandora
14{
15
16template<typename T>
17Manager<T>::Manager(const Pandora *const pPandora) :
18 m_nullListName("NullList"),
19 m_pPandora(pPandora),
20 m_currentListName(m_nullListName)
21{
22}
23
24//------------------------------------------------------------------------------------------------------------------------------------------
25
26template<typename T>
30
31//------------------------------------------------------------------------------------------------------------------------------------------
32
33template<typename T>
34StatusCode Manager<T>::GetList(const std::string &listName, const ObjectList *&pObjectList) const
35{
36 typename NameToListMap::const_iterator iter = m_nameToListMap.find(listName);
37
38 if (m_nameToListMap.end() == iter)
39 return STATUS_CODE_NOT_INITIALIZED;
40
41 pObjectList = iter->second;
42 return STATUS_CODE_SUCCESS;
43}
44
45//------------------------------------------------------------------------------------------------------------------------------------------
46
47template<typename T>
48StatusCode Manager<T>::GetCurrentList(const ObjectList *&pObjectList, std::string &listName) const
49{
50 listName = m_currentListName;
51 return this->GetList(listName, pObjectList);
52}
53
54//------------------------------------------------------------------------------------------------------------------------------------------
55
56template<typename T>
57inline StatusCode Manager<T>::GetCurrentListName(std::string &listName) const
59 if (m_currentListName.empty())
60 return STATUS_CODE_NOT_INITIALIZED;
61
62 listName = m_currentListName;
63 return STATUS_CODE_SUCCESS;
64}
66//------------------------------------------------------------------------------------------------------------------------------------------
67
68template<typename T>
69StatusCode Manager<T>::GetAlgorithmInputList(const Algorithm *const pAlgorithm, const ObjectList *&pObjectList, std::string &listName) const
70{
71 typename AlgorithmInfoMap::const_iterator iter = m_algorithmInfoMap.find(pAlgorithm);
72
73 if (m_algorithmInfoMap.end() != iter)
74 {
75 listName = iter->second.m_parentListName;
76 }
77 else
78 {
79 listName = m_currentListName;
80 }
81
82 return this->GetList(listName, pObjectList);
83}
84
85//------------------------------------------------------------------------------------------------------------------------------------------
86
87template<typename T>
88inline StatusCode Manager<T>::GetAlgorithmInputListName(const Algorithm *const pAlgorithm, std::string &listName) const
90 typename AlgorithmInfoMap::const_iterator iter = m_algorithmInfoMap.find(pAlgorithm);
91
92 if (m_algorithmInfoMap.end() == iter)
93 return this->GetCurrentListName(listName);
94
95 listName = iter->second.m_parentListName;
96 return STATUS_CODE_SUCCESS;
98
99//------------------------------------------------------------------------------------------------------------------------------------------
100
101template<typename T>
103{
104 return this->GetAlgorithmInputListName(pAlgorithm, m_currentListName);
105}
106
107//------------------------------------------------------------------------------------------------------------------------------------------
108
109template<typename T>
110StatusCode Manager<T>::ReplaceCurrentAndAlgorithmInputLists(const Algorithm *const pAlgorithm, const std::string &listName)
111{
112 if (m_nameToListMap.end() == m_nameToListMap.find(listName))
113 return STATUS_CODE_NOT_FOUND;
114
115 if (m_savedLists.end() == m_savedLists.find(listName))
116 return STATUS_CODE_NOT_ALLOWED;
117
118 if (m_algorithmInfoMap.end() == m_algorithmInfoMap.find(pAlgorithm))
119 return STATUS_CODE_FAILURE;
121 m_currentListName = listName;
122
123 for (typename AlgorithmInfoMap::value_type &mapEntry : m_algorithmInfoMap)
124 {
125 mapEntry.second.m_parentListName = listName;
126 }
128 return STATUS_CODE_SUCCESS;
129}
130
131//------------------------------------------------------------------------------------------------------------------------------------------
132
133template<typename T>
136 return this->ReplaceCurrentAndAlgorithmInputLists(pAlgorithm, m_nullListName);
137}
138
139//------------------------------------------------------------------------------------------------------------------------------------------
141template<typename T>
142StatusCode Manager<T>::RenameList(const std::string &oldListName, const std::string &newListName)
143{
144 if ((oldListName == newListName) || newListName.empty())
145 return STATUS_CODE_INVALID_PARAMETER;
146
147 if (m_nameToListMap.end() == m_nameToListMap.find(oldListName))
148 return STATUS_CODE_NOT_FOUND;
149
150 if ((oldListName == m_nullListName) || (m_savedLists.end() == m_savedLists.find(oldListName)))
151 return STATUS_CODE_NOT_ALLOWED;
152
153 if (m_savedLists.end() != m_savedLists.find(newListName))
154 return STATUS_CODE_ALREADY_PRESENT;
155
156 m_nameToListMap[newListName] = m_nameToListMap.at(oldListName);
157 m_nameToListMap.erase(oldListName);
158
159 m_savedLists.insert(newListName);
160 m_savedLists.erase(oldListName);
161
162 if (oldListName == m_currentListName)
163 m_currentListName = newListName;
164
165 for (typename AlgorithmInfoMap::value_type &mapEntry : m_algorithmInfoMap)
166 {
167 if (oldListName == mapEntry.second.m_parentListName)
168 mapEntry.second.m_parentListName = newListName;
169 }
170
171 return STATUS_CODE_SUCCESS;
172}
173
174//------------------------------------------------------------------------------------------------------------------------------------------
175
176template<typename T>
177StatusCode Manager<T>::CreateTemporaryListAndSetCurrent(const Algorithm *const pAlgorithm, std::string &temporaryListName)
178{
179 typename AlgorithmInfoMap::iterator iter = m_algorithmInfoMap.find(pAlgorithm);
180
181 if (m_algorithmInfoMap.end() == iter)
182 return STATUS_CODE_NOT_FOUND;
183
184 temporaryListName = pAlgorithm->GetInstanceName() + "_" + TypeToString(iter->second.m_numberOfListsCreated++);
185
186 if (!iter->second.m_temporaryListNames.insert(temporaryListName).second)
187 return STATUS_CODE_ALREADY_PRESENT;
188
189 m_nameToListMap[temporaryListName] = new ObjectList;
190 m_currentListName = temporaryListName;
191
192 return STATUS_CODE_SUCCESS;
193}
194
195//------------------------------------------------------------------------------------------------------------------------------------------
196
197template<typename T>
199{
200 if (m_algorithmInfoMap.end() != m_algorithmInfoMap.find(pAlgorithm))
201 return STATUS_CODE_ALREADY_PRESENT;
202
203 AlgorithmInfo algorithmInfo;
204 algorithmInfo.m_parentListName = m_currentListName;
205 algorithmInfo.m_numberOfListsCreated = 0;
206
207 if (!m_algorithmInfoMap.insert(typename AlgorithmInfoMap::value_type(pAlgorithm, algorithmInfo)).second)
208 return STATUS_CODE_ALREADY_PRESENT;
209
210 return STATUS_CODE_SUCCESS;
211}
212
213//------------------------------------------------------------------------------------------------------------------------------------------
214
215template<typename T>
216StatusCode Manager<T>::ResetAlgorithmInfo(const Algorithm *const pAlgorithm, bool isAlgorithmFinished)
217{
218 typename AlgorithmInfoMap::iterator algorithmIter = m_algorithmInfoMap.find(pAlgorithm);
219
220 if (m_algorithmInfoMap.end() == algorithmIter)
221 return STATUS_CODE_NOT_FOUND;
222
223 for (const std::string &temporaryListName : algorithmIter->second.m_temporaryListNames)
224 {
225 typename NameToListMap::iterator iter = m_nameToListMap.find(temporaryListName);
226
227 if (m_nameToListMap.end() == iter)
228 return STATUS_CODE_FAILURE;
229
230 ObjectList *const pObjectList(iter->second);
231 iter = m_nameToListMap.erase(iter);
232 delete pObjectList;
233 }
234
235 algorithmIter->second.m_temporaryListNames.clear();
236 m_currentListName = algorithmIter->second.m_parentListName;
237
238 if (isAlgorithmFinished)
239 algorithmIter = m_algorithmInfoMap.erase(algorithmIter);
240
241 return STATUS_CODE_SUCCESS;
242}
243
244//------------------------------------------------------------------------------------------------------------------------------------------
245
246template<typename T>
248{
249 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->EraseAllContent());
250 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->CreateInitialLists());
251
252 return STATUS_CODE_SUCCESS;
253}
254
255//------------------------------------------------------------------------------------------------------------------------------------------
256
257template<typename T>
259{
260 for (const typename NameToListMap::value_type &mapEntry : m_nameToListMap)
261 delete mapEntry.second;
262
263 m_currentListName = m_nullListName;
264 m_nameToListMap.clear();
265 m_savedLists.clear();
266 m_algorithmInfoMap.clear();
267
268 return STATUS_CODE_SUCCESS;
269}
270
271//------------------------------------------------------------------------------------------------------------------------------------------
272
273template<typename T>
275{
276 if (!m_nameToListMap.empty() || !m_savedLists.empty())
277 return STATUS_CODE_NOT_ALLOWED;
278
279 m_nameToListMap[m_nullListName] = new ObjectList;
280 m_savedLists.insert(m_nullListName);
281
282 return STATUS_CODE_SUCCESS;
283}
284
285//------------------------------------------------------------------------------------------------------------------------------------------
286
287template<typename T>
288T *Manager<T>::Modifiable(const T *const pT) const
289{
290 // Consider alternatives here. Idea: expose algorithms only to pointers to const objects, non-const functions accessible only via APIs.
291 return const_cast<T*>(pT);
292}
293
294//------------------------------------------------------------------------------------------------------------------------------------------
295//------------------------------------------------------------------------------------------------------------------------------------------
296
297template class Manager<CaloHit>;
298template class Manager<Cluster>;
299template class Manager<MCParticle>;
300template class Manager<ParticleFlowObject>;
301template class Manager<Track>;
302template class Manager<Vertex>;
303
304} // namespace pandora
Header file for the algorithm class.
Header file for the manager class.
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Algorithm class. Algorithm addresses are held only by the algorithm manager. They have a fully define...
Definition Algorithm.h:21
Manager class.
Definition Manager.h:27
unsigned int m_numberOfListsCreated
The number of lists created by the algorithm.
Definition Manager.h:169
virtual StatusCode ResetCurrentListToAlgorithmInputList(const Algorithm *const pAlgorithm)
Reset the current list to the algorithm input list.
Definition Manager.cc:102
virtual T * Modifiable(const T *const pT) const
Access a modifiable object, when provided with address to const object.
Definition Manager.cc:288
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
MANAGED_CONTAINER< const T * > ObjectList
Definition Manager.h:42
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 ~Manager()
Destructor.
Definition Manager.cc:27
std::string m_parentListName
The current list when algorithm was initialized.
Definition Manager.h:167
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 GetCurrentList(const ObjectList *&pObjectList, std::string &listName) const
Get the current list.
Definition Manager.cc:48
virtual StatusCode GetCurrentListName(std::string &listName) const
Get the current list name.
Definition Manager.cc:57
virtual StatusCode GetAlgorithmInputListName(const Algorithm *const pAlgorithm, std::string &listName) const
Get the algorithm track list name.
Definition Manager.cc:88
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 RegisterAlgorithm(const Algorithm *const pAlgorithm)
Register an algorithm with the manager.
Definition Manager.cc:198
virtual StatusCode CreateTemporaryListAndSetCurrent(const Algorithm *const pAlgorithm, std::string &temporaryListName)
Create a temporary list associated with a particular algorithm.
Definition Manager.cc:177
virtual StatusCode ResetForNextEvent()
Reset the manager.
Definition Manager.cc:247
Manager(const Pandora *const pPandora)
Constructor.
Definition Manager.cc:17
virtual StatusCode GetList(const std::string &listName, const ObjectList *&pObjectList) const
Get a list.
Definition Manager.cc:34
virtual StatusCode GetAlgorithmInputList(const Algorithm *const pAlgorithm, const ObjectList *&pObjectList, std::string &listName) const
Get the algorithm input list.
Definition Manager.cc:69
virtual StatusCode CreateInitialLists()
Create initial lists.
Definition Manager.cc:274
AlgorithmInfo class.
Definition Manager.h:165
Pandora class.
Definition Pandora.h:40
const std::string & GetInstanceName() const
Get the instance name.
Definition Process.h:109
std::string TypeToString(const T &t)
StatusCode
The StatusCode enum.