Alexandria  2.14.1
Please provide a description of the project.
PdfFromRow.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 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 
19  /*
20  * Copyright (C) 2012-2020 Euclid Science Ground Segment
21  *
22  * This library is free software; you can redistribute it and/or modify it under
23  * the terms of the GNU Lesser General Public License as published by the Free
24  * Software Foundation; either version 3.0 of the License, or (at your option)
25  * any later version.
26  *
27  * This library is distributed in the hope that it will be useful, but WITHOUT
28  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
29  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
30  * details.
31  *
32  * You should have received a copy of the GNU Lesser General Public License
33  * along with this library; if not, write to the Free Software Foundation, Inc.,
34  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35  */
36 
37 /*
38  * @file PdfFromRow.h
39  * @author nikoapos
40  */
41 
42 #ifndef SOURCECATALOG_PDFFROMROW_H
43 #define SOURCECATALOG_PDFFROMROW_H
44 
45 #include <map>
46 #include <string>
47 #include <vector>
50 #include "Table/CastVisitor.h"
53 
54 namespace Euclid {
55 namespace SourceCatalog {
56 
57 template <typename T>
58 class PdfFromRow : public AttributeFromRow {
59 
60 public:
61 
64  : m_keys(std::move(keys)), m_column_names(std::move(column_names)) {
65  }
66 
67  virtual ~PdfFromRow() = default;
68 
71 
72  for (auto& pair : m_keys) {
73  // Use the key values to create the axis of the PDF
74  GridContainer::GridAxis<T> axis {pair.first, pair.second};
75  // Create a PDF with zero values
76  typename Pdf<T>::PdfType pdf {axis};
77 
78  // Get the PDF data from the row
79  auto& col_name = m_column_names.at(pair.first);
80  auto data = boost::apply_visitor(Table::CastVisitor<std::vector<double>>{}, row[col_name]);
81  if (data.size() != pdf.size()) {
82  throw Elements::Exception() << "Incompatible PDF size";
83  }
84 
85  // Copy the data in the PDF
86  std::copy(data.begin(), data.end(), pdf.begin());
87 
88  // Put the PDF in the map
89  pdf_map.emplace(pair.first, std::move(pdf));
90  }
91 
92  return make_unique<Pdf<T>>(std::move(pdf_map));
93  }
94 
95 private:
96 
99 
100 };
101 
102 }
103 }
104 
105 #endif /* SOURCECATALOG_PDFFROMROW_H */
106 
Euclid::GridContainer::GridAxis
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
std::string
STL class.
Euclid::GridContainer::GridContainer
Representation of a multi-dimensional grid which contains axis information.
Definition: GridContainer.h:97
std::move
T move(T... args)
std::vector
STL class.
Euclid::Table::CastVisitor
Definition: CastVisitor.h:41
Euclid::SourceCatalog::PdfFromRow::m_keys
std::map< std::string, std::vector< T > > m_keys
Definition: PdfFromRow.h:97
Euclid::SourceCatalog::PdfFromRow::PdfFromRow
PdfFromRow(std::map< std::string, std::vector< T >> keys, std::map< std::string, std::string > column_names)
Definition: PdfFromRow.h:62
CastVisitor.h
AttributeFromRow.h
Exception.h
std::map::at
T at(T... args)
std::copy
T copy(T... args)
Elements::Exception
std::map
STL class.
Euclid::SourceCatalog::AttributeFromRow
Interface for building a source Attribute from a table Row.
Definition: AttributeFromRow.h:45
Pdf.h
Euclid::SourceCatalog::PdfFromRow
Definition: PdfFromRow.h:58
std
STL namespace.
Euclid::SourceCatalog::PdfFromRow::m_column_names
std::map< std::string, std::string > m_column_names
Definition: PdfFromRow.h:98
Euclid::Table::Row
Represents one row of a Table.
Definition: Row.h:64
Euclid::SourceCatalog::PdfFromRow::createAttribute
std::unique_ptr< Attribute > createAttribute(const Euclid::Table::Row &row) override
The createAttribute method for creating an Attribute from a Table row.
Definition: PdfFromRow.h:69
memory_tools.h
std::unique_ptr
STL class.
Euclid
Definition: InstOrRefHolder.h:29
Euclid::SourceCatalog::PdfFromRow::~PdfFromRow
virtual ~PdfFromRow()=default