Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Catalog.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2021 Euclid Science Ground Segment
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
28
30
31namespace Euclid {
32namespace SourceCatalog {
33
34//-----------------------------------------------------------------------------
35// Constructor
37 // Set the m_indices_map map
38 for (size_t index = 0; index < m_source_vector.size(); ++index) {
39 auto it = m_source_index_map.emplace(m_source_vector[index].getId(), index);
40 // Make sure the element does not already exist
41 if (!it.second) {
42 throw Elements::Exception() << "Euclid::SourceCatalog::Catalog: Source object already exist "
43 << "in the map for source ID : " << m_source_vector[index].getId()
44 << ", index: " << index;
45 }
46 }
47} // Eof Euclid::SourceCatalog::Catalog
48
49//-----------------------------------------------------------------------------
50// find source in the map
51// return source otherwise null pointer
53 std::shared_ptr<Source> ptr(nullptr);
55 if (it != m_source_index_map.end()) {
56 ptr = std::make_shared<Source>(m_source_vector[it->second]);
57 }
58
59 return ptr;
60
61} // Eof Catalog::find
62
63//-----------------------------------------------------------------------------
64
65} /* namespace SourceCatalog */
66} // end of namespace Euclid
std::map< Source::id_type, size_t > m_source_index_map
Definition Catalog.h:122
Catalog(const std::vector< Source > &source_vector)
Build a catalog of Source objects.
Definition Catalog.cpp:36
std::shared_ptr< Source > find(const Source::id_type &source_id) const
Find the Source object from its identification number.
Definition Catalog.cpp:52
std::vector< Source > m_source_vector
Definition Catalog.h:119
Store the Right Ascension (Ra) and Delination (Dec) of a source in decimal degrees,...
Definition Coordinates.h:41
boost::variant< int64_t, std::string > id_type
Definition Source.h:51
T emplace(T... args)
T end(T... args)
T find(T... args)