SourceXtractorPlusPlus  0.10
Please provide a description of the project.
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  for (const auto& name : m_property_to_names_map.at(property)) {
54  auto& col_info = m_name_to_col_info_map.at(name);
55  info_list.emplace_back(name, m_name_to_converter_map.at(name).first,
56  col_info.unit, col_info.description);
57  cell_values.emplace_back(m_name_to_converter_map.at(name).second(source));
58  }
59  }
60  if (info_list.empty()) {
61  throw Elements::Exception() << "The given configuration would not generate any output";
62  }
63  return Row {std::move(cell_values), std::make_shared<ColumnInfo>(move(info_list))};
64  };
65 }
66 
67 void OutputRegistry::printPropertyColumnMap(const std::vector<std::string>& properties) {
68  std::set<std::string> properties_set {properties.begin(), properties.end()};
69  for (auto& prop : m_output_properties) {
70  if (!properties.empty() && properties_set.find(prop.first) == properties_set.end()) {
71  continue;
72  }
73  std::cout << prop.first << ":\n";
74  for (auto& col : m_property_to_names_map.at(prop.second)) {
75  std::cout << " - " << col;
76  auto& info = m_name_to_col_info_map.at(col);
77  if (info.description != "") {
78  std::cout << " : " << info.description;
79  }
80  if (info.unit != "") {
81  std::cout << " " << info.unit << ""; // place here braces "()" around the units, if desired
82  }
83  std::cout << '\n';
84  }
85  }
86 }
87 
88 
89 }
std::move
T move(T... args)
std::vector< std::string >
std::find
T find(T... args)
std::function< Euclid::Table::Row(const SourceInterface &)>
SourceXtractor
Definition: Aperture.h:30
std::vector::at
T at(T... args)
std::cout
Exception.h
Elements::Exception
Euclid::Table
std::vector::begin
T begin(T... args)
OutputRegistry.h
std::vector::empty
T empty(T... args)
Euclid::Table::Row
std::vector::end
T end(T... args)
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition: SourceInterface.h:46
std::set
STL class.