SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
OutputRegistry.cpp
Go to the documentation of this file.
1
17/*
18 * File: OutputRegistry.cpp
19 * Author: nikoapos
20 *
21 * Created on July 28, 2016, 7:12 PM
22 */
23
24#include <algorithm>
25
26#include "ElementsKernel/Exception.h"
27
29
30#include <iostream>
31
32using namespace Euclid::Table;
33
34namespace SourceXtractor {
35
37 std::vector<std::type_index> out_prop_list {};
38 for (auto& prop : enabled_properties) {
39 if (m_output_properties.count(prop) == 0) {
40 throw Elements::Exception() << "Unknown output property " << prop;
41 }
42 auto matching_properties = m_output_properties.equal_range(prop);
43 for (auto i = matching_properties.first; i != matching_properties.second; ++i) {
44 if (std::find(out_prop_list.begin(), out_prop_list.end(), i->second) == out_prop_list.end()) {
45 out_prop_list.emplace_back(i->second);
46 }
47 }
48 }
49 return [this, out_prop_list](const SourceInterface& source) {
51 std::vector<Row::cell_type> cell_values {};
52 for (const auto& property : out_prop_list) {
53 if (m_property_to_names_map.count(property) == 0) {
54 throw Elements::Exception() << "Missing column generator for " << property.name();
55 }
56 for (const auto& name : m_property_to_names_map.at(property)) {
57 auto& col_info = m_name_to_col_info_map.at(name);
58 info_list.emplace_back(name, m_name_to_converter_map.at(name).first,
59 col_info.unit, col_info.description);
60 cell_values.emplace_back(m_name_to_converter_map.at(name).second(source));
61 }
62 }
63 if (info_list.empty()) {
64 throw Elements::Exception() << "The given configuration would not generate any output";
65 }
66 return Row {std::move(cell_values), std::make_shared<ColumnInfo>(move(info_list))};
67 };
68}
69
71 std::set<std::string> properties_set {properties.begin(), properties.end()};
72 for (auto& prop : m_output_properties) {
73 if (!properties.empty() && properties_set.find(prop.first) == properties_set.end()) {
74 continue;
75 }
76 std::cout << prop.first << ":\n";
77 for (auto& col : m_property_to_names_map.at(prop.second)) {
78 std::cout << " - " << col;
79 auto& info = m_name_to_col_info_map.at(col);
80 if (info.description != "") {
81 std::cout << " : " << info.description;
82 }
83 if (info.unit != "") {
84 std::cout << " " << info.unit << ""; // place here braces "()" around the units, if desired
85 }
86 std::cout << '\n';
87 }
88 }
89}
90
91
92}
T begin(T... args)
std::map< std::string, ColInfo > m_name_to_col_info_map
SourceToRowConverter getSourceToRowConverter(const std::vector< std::string > &enabled_optional)
std::multimap< std::string, std::type_index > m_output_properties
std::function< Euclid::Table::Row(const SourceInterface &)> SourceToRowConverter
std::map< std::string, std::pair< std::type_index, ColumnFromSource > > m_name_to_converter_map
std::map< std::type_index, std::vector< std::string > > m_property_to_names_map
void printPropertyColumnMap(const std::vector< std::string > &properties={})
The SourceInterface is an abstract "source" that has properties attached to it.
T emplace_back(T... args)
T empty(T... args)
T end(T... args)
T find(T... args)
T make_shared(T... args)
T move(T... args)