Alexandria
2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
SourceCatalog
src
lib
CatalogFromTable.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2012-2022 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
25
#include "
SourceCatalog/CatalogFromTable.h
"
26
#include "
ElementsKernel/Exception.h
"
27
#include "
SourceCatalog/PhotometryParsingException.h
"
28
#include "
SourceCatalog/SourceAttributes/Photometry.h
"
29
#include "
Table/CastVisitor.h
"
30
#include "
Table/ColumnInfo.h
"
31
#include <vector>
32
33
namespace
Euclid
{
34
namespace
SourceCatalog {
35
36
CatalogFromTable::CatalogFromTable
(
std::shared_ptr<Euclid::Table::ColumnInfo>
column_info_ptr
,
37
const
std::string
&
source_id_column_name
,
38
std::vector
<
std::shared_ptr<AttributeFromRow>
>
attribute_from_row_ptr_vector
) {
39
40
std::unique_ptr<size_t>
source_id_index_ptr
=
column_info_ptr
->find(
source_id_column_name
);
41
if
(
source_id_index_ptr
==
nullptr
) {
42
throw
Elements::Exception
() <<
"Column info does not have the column "
<<
source_id_column_name
;
43
}
44
m_source_id_index
= *
source_id_index_ptr
;
45
46
m_attribute_from_row_ptr_vector
=
std::move
(
attribute_from_row_ptr_vector
);
47
}
48
49
CatalogFromTable::~CatalogFromTable
() =
default
;
50
51
Euclid::SourceCatalog::Catalog
CatalogFromTable::createCatalog
(
const
Euclid::Table::Table
&
input_table
) {
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
(
const
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
(
m_attribute_from_row_ptr_vector
.size());
64
try
{
65
std::transform
(
m_attribute_from_row_ptr_vector
.begin(),
m_attribute_from_row_ptr_vector
.end(),
66
attribute_ptr_vector
.begin(),
67
[&
row
](
const
std::shared_ptr<AttributeFromRow>
&
attr
) { return attr->createAttribute(row); });
68
}
catch
(
const
PhotometryParsingException
&
parsing_exception
) {
69
throw
Elements::Exception
() <<
"Parsing error while parsing the source with Id = "
<<
source_id
<<
" : "
70
<<
parsing_exception
.what();
71
}
catch
(
const
std::exception
& e) {
72
throw
Elements::Exception
() <<
"Error while parsing the source with Id = "
<<
source_id
<<
" : "
<< e.what();
73
}
catch
(...) {
74
throw
Elements::Exception
() <<
"Error while parsing the source with Id = "
<<
source_id
;
75
}
76
77
source_vector
.emplace_back(
source_id
,
std::move
(
attribute_ptr_vector
));
78
}
79
80
return
Catalog
{
source_vector
};
81
}
82
83
}
// namespace SourceCatalog
84
}
// end of namespace Euclid
CastVisitor.h
CatalogFromTable.h
ColumnInfo.h
Exception.h
PhotometryParsingException.h
Photometry.h
std::string
Elements::Exception
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
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
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:36
Euclid::SourceCatalog::CatalogFromTable::createCatalog
Euclid::SourceCatalog::Catalog createCatalog(const Euclid::Table::Table &input_table)
Definition
CatalogFromTable.cpp:51
Euclid::SourceCatalog::CatalogFromTable::m_source_id_index
size_t m_source_id_index
Definition
CatalogFromTable.h:51
Euclid::SourceCatalog::CatalogFromTable::~CatalogFromTable
virtual ~CatalogFromTable()
Euclid::SourceCatalog::Catalog
Catalog contains a container of sources.
Definition
Catalog.h:47
Euclid::SourceCatalog::Coordinates
Store the Right Ascension (Ra) and Delination (Dec) of a source in decimal degrees,...
Definition
Coordinates.h:41
Euclid::SourceCatalog::PhotometryParsingException
Definition
PhotometryParsingException.h:34
Euclid::Table::Table
Represents a table.
Definition
Table.h:49
std::exception
std::move
T move(T... args)
Euclid
Definition
index_sequence.h:27
std::shared_ptr
std::transform
T transform(T... args)
std::unique_ptr
std::vector
Generated by
1.9.8