Alexandria  2.18
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PdfFromRow.h
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 
19 /*
20  * Copyright (C) 2012-2021 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 
49 #include "Table/CastVisitor.h"
50 #include <map>
51 #include <string>
52 #include <vector>
53 
54 namespace Euclid {
55 namespace SourceCatalog {
56 
57 template <typename T>
58 class PdfFromRow : public AttributeFromRow {
59 
60 public:
62  : m_keys(std::move(keys)), m_column_names(std::move(column_names)) {}
63 
64  virtual ~PdfFromRow() = default;
65 
68 
69  for (auto& pair : m_keys) {
70  // Use the key values to create the axis of the PDF
71  GridContainer::GridAxis<T> axis{pair.first, pair.second};
72  // Create a PDF with zero values
73  typename Pdf<T>::PdfType pdf{axis};
74 
75  // Get the PDF data from the row
76  auto& col_name = m_column_names.at(pair.first);
77  auto data = boost::apply_visitor(Table::CastVisitor<std::vector<double>>{}, row[col_name]);
78  if (data.size() != pdf.size()) {
79  throw Elements::Exception() << "Incompatible PDF size";
80  }
81 
82  // Copy the data in the PDF
83  std::copy(data.begin(), data.end(), pdf.begin());
84 
85  // Put the PDF in the map
86  pdf_map.emplace(pair.first, std::move(pdf));
87  }
88 
89  return make_unique<Pdf<T>>(std::move(pdf_map));
90  }
91 
92 private:
95 };
96 
97 } // namespace SourceCatalog
98 } // namespace Euclid
99 
100 #endif /* SOURCECATALOG_PDFFROMROW_H */
T copy(T...args)
Representation of a multi-dimensional grid which contains axis information.
Definition: GridContainer.h:97
std::map< std::string, std::string > m_column_names
Definition: PdfFromRow.h:94
PdfFromRow(std::map< std::string, std::vector< T >> keys, std::map< std::string, std::string > column_names)
Definition: PdfFromRow.h:61
STL class.
STL class.
T at(T...args)
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
std::map< std::string, std::vector< T > > m_keys
Definition: PdfFromRow.h:93
Interface for building a source Attribute from a table Row.
T move(T...args)
Represents one row of a Table.
Definition: Row.h:64
STL class.
STL class.
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:66