SourceXtractorPlusPlus  0.15
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
27 
29 
30 #include <iostream>
31 
32 using namespace Euclid::Table;
33 
34 namespace SourceXtractor {
35 
36 auto OutputRegistry::getSourceToRowConverter(const std::vector<std::string>& enabled_properties) -> SourceToRowConverter {
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 
70 void OutputRegistry::printPropertyColumnMap(const std::vector<std::string>& properties) {
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 empty(T...args)
T end(T...args)
T move(T...args)
T find(T...args)
STL class.
T begin(T...args)
The SourceInterface is an abstract &quot;source&quot; that has properties attached to it.