Alexandria  2.18
Please provide a description of the project.
CatalogFromTable.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 
27 #include "Table/CastVisitor.h"
28 #include "Table/ColumnInfo.h"
29 #include <vector>
30 
31 namespace Euclid {
32 namespace SourceCatalog {
33 
35  const std::string& source_id_column_name,
36  std::vector<std::shared_ptr<AttributeFromRow>> attribute_from_row_ptr_vector) {
37 
38  std::unique_ptr<size_t> source_id_index_ptr = column_info_ptr->find(source_id_column_name);
39  if (source_id_index_ptr == nullptr) {
40  throw Elements::Exception() << "Column info does not have the column " << source_id_column_name;
41  }
42  m_source_id_index = *(source_id_index_ptr);
43 
44  m_attribute_from_row_ptr_vector = std::move(attribute_from_row_ptr_vector);
45 }
46 
48  // @todo Auto-generated destructor stub
49 }
50 
52 
53  std::vector<Source> source_vector;
54 
55  // Figure out the type of the first row, and then assume all following
56  // must be of the same
57  CastSourceIdVisitor castVisitor;
58 
59  for (auto row : input_table) {
60 
61  auto source_id = boost::apply_visitor(castVisitor, row[m_source_id_index]);
62 
63  std::vector<std::shared_ptr<Attribute>> attribute_ptr_vector;
64 
65  for (auto& attribute_from_table_ptr : m_attribute_from_row_ptr_vector) {
66  attribute_ptr_vector.push_back(attribute_from_table_ptr->createAttribute(row));
67  }
68 
69  source_vector.push_back(Source{source_id, move(attribute_ptr_vector)});
70  }
71 
72  return Catalog{source_vector};
73 }
74 
75 } // namespace SourceCatalog
76 } // end of namespace Euclid
std::string
STL class.
std::shared_ptr< Euclid::Table::ColumnInfo >
Euclid::SourceCatalog::CatalogFromTable::~CatalogFromTable
virtual ~CatalogFromTable()
Definition: CatalogFromTable.cpp:47
std::move
T move(T... args)
std::vector
STL class.
Photometry.h
CastVisitor.h
Euclid::SourceCatalog::Catalog
Catalog contains a container of sources.
Definition: Catalog.h:47
std::vector::push_back
T push_back(T... args)
CatalogFromTable.h
Euclid::SourceCatalog::CatalogFromTable::CatalogFromTable
CatalogFromTable(std::shared_ptr< Euclid::Table::ColumnInfo > column_info_ptr, const std::string &source_id_column_name, std::vector< std::shared_ptr< AttributeFromRow >> attribute_from_row_ptr_vector)
Definition: CatalogFromTable.cpp:34
Euclid::SourceCatalog::CatalogFromTable::m_source_id_index
size_t m_source_id_index
Definition: CatalogFromTable.h:51
Elements::Exception
Euclid::SourceCatalog::Source
The Source class includes all information related to a sky source.
Definition: Source.h:48
Euclid::SourceCatalog::CatalogFromTable::createCatalog
Euclid::SourceCatalog::Catalog createCatalog(const Euclid::Table::Table &input_table)
Definition: CatalogFromTable.cpp:51
Euclid::Table::Table
Represents a table.
Definition: Table.h:49
Euclid::SourceCatalog::CastSourceIdVisitor
This type can be used together with boost::apply_visitor to cast boost::variant with an unknown under...
Definition: Source.h:105
ColumnInfo.h
Euclid::Table::ColumnInfo::find
std::unique_ptr< std::size_t > find(const std::string &name) const
Returns the index of a column, given the name of it, or nullptr if there is no column with this name.
Definition: ColumnInfo.cpp:76
std::unique_ptr
STL class.
Euclid
Definition: InstOrRefHolder.h:29
Euclid::SourceCatalog::CatalogFromTable::m_attribute_from_row_ptr_vector
std::vector< std::shared_ptr< AttributeFromRow > > m_attribute_from_row_ptr_vector
Definition: CatalogFromTable.h:53