Skip to content

Commit 81e8eed

Browse files
authored
Merge pull request #822 from stephenswat/feat/structured_config
Add structured configuration printing
2 parents 2b3b3cf + 528bbf7 commit 81e8eed

36 files changed

+610
-184
lines changed

examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Project include(s).
88
include( traccc-compiler-options-cpp )
99

10+
add_subdirectory(utils)
1011
add_subdirectory(options)
1112
add_subdirectory(run)
1213
add_subdirectory(io)

examples/options/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ target_link_libraries( traccc_options
4848
Boost::program_options
4949
traccc::io
5050
traccc::performance
51+
traccc::utils
5152
)

examples/options/include/traccc/options/accelerator.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ class accelerator : public interface {
2727
/// Constructor
2828
accelerator();
2929

30-
private:
31-
/// Print the specific options of this class
32-
std::ostream& print_impl(std::ostream& out) const override;
33-
30+
std::unique_ptr<configuration_printable> as_printable() const override;
3431
}; // struct accelerator
3532

3633
} // namespace traccc::opts

examples/options/include/traccc/options/clusterization.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class clusterization
2929
operator clustering_config() const override;
3030
operator host::clusterization_algorithm::config_type() const override;
3131

32+
std::unique_ptr<configuration_printable> as_printable() const override;
33+
3234
private:
3335
/// @name Options
3436
/// @{
@@ -38,10 +40,6 @@ class clusterization
3840
unsigned int target_cells_per_thread;
3941
unsigned int backup_size_multiplier;
4042
/// @}
41-
42-
/// Print the specific options of this class
43-
std::ostream& print_impl(std::ostream& out) const override;
44-
4543
}; // class clusterization
4644

4745
} // namespace traccc::opts

examples/options/include/traccc/options/details/interface.hpp

+5-13
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
#pragma once
99

10+
#include "traccc/examples/utils/printable.hpp"
11+
1012
// Boost include(s).
1113
#include <boost/program_options.hpp>
1214

1315
// System include(s).
1416
#include <iosfwd>
17+
#include <memory>
1518
#include <string>
1619
#include <string_view>
1720

@@ -35,20 +38,13 @@ class interface {
3538
///
3639
virtual void read(const boost::program_options::variables_map& vm);
3740

38-
/// Helper for printing the options to an output stream
39-
///
40-
/// @param out The output stream to print to
41-
/// @return The output stream
42-
///
43-
std::ostream& print(std::ostream& out) const;
41+
/// Helper for turning an interface into a printable set of options.
42+
virtual std::unique_ptr<configuration_printable> as_printable() const = 0;
4443

4544
/// Get the description of this program option group
4645
const boost::program_options::options_description& options() const;
4746

4847
protected:
49-
/// Print the specific options of the derived class
50-
virtual std::ostream& print_impl(std::ostream& out) const;
51-
5248
/// (Boost) Description of this program option group
5349
boost::program_options::options_description m_desc;
5450

@@ -57,8 +53,4 @@ class interface {
5753
std::string m_description;
5854

5955
}; // class interface
60-
61-
/// Printout helper for @c traccc::opts::interface and types derived from it
62-
std::ostream& operator<<(std::ostream& out, const interface& opt);
63-
6456
} // namespace traccc::opts

examples/options/include/traccc/options/detector.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ class detector : public interface {
4040
/// Constructor
4141
detector();
4242

43-
private:
44-
/// Print the specific options of this class
45-
std::ostream& print_impl(std::ostream& out) const override;
46-
43+
std::unique_ptr<configuration_printable> as_printable() const override;
4744
}; // struct detector
4845

4946
} // namespace traccc::opts

examples/options/include/traccc/options/generation.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ class generation : public interface {
6969
///
7070
void read(const boost::program_options::variables_map& vm) override;
7171

72-
private:
73-
/// Print the specific options of this class
74-
std::ostream& print_impl(std::ostream& out) const override;
75-
72+
std::unique_ptr<configuration_printable> as_printable() const override;
7673
}; // struct generation
7774

7875
} // namespace traccc::opts

examples/options/include/traccc/options/input_data.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ class input_data : public interface {
4646
///
4747
void read(const boost::program_options::variables_map& vm) override;
4848

49-
private:
50-
/// Print the specific options of this class
51-
std::ostream& print_impl(std::ostream& out) const override;
52-
49+
std::unique_ptr<configuration_printable> as_printable() const override;
5350
}; // class input_data
5451

5552
} // namespace traccc::opts

examples/options/include/traccc/options/output_data.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ class output_data : public interface {
4545
///
4646
void read(const boost::program_options::variables_map& vm) override;
4747

48-
private:
49-
/// Print the specific options of this class
50-
std::ostream& print_impl(std::ostream& out) const override;
51-
48+
std::unique_ptr<configuration_printable> as_printable() const override;
5249
}; // class output_data
5350

5451
} // namespace traccc::opts

examples/options/include/traccc/options/performance.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ class performance : public interface {
2727
/// Constructor
2828
performance();
2929

30-
private:
31-
/// Print the specific options of this class
32-
std::ostream& print_impl(std::ostream& out) const override;
33-
30+
std::unique_ptr<configuration_printable> as_printable() const override;
3431
}; // struct performance
3532

3633
} // namespace traccc::opts

examples/options/include/traccc/options/telescope_detector.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ class telescope_detector : public interface {
4646
///
4747
void read(const boost::program_options::variables_map& vm) override;
4848

49-
private:
50-
/// Print the specific options of this class
51-
std::ostream& print_impl(std::ostream& out) const override;
52-
49+
std::unique_ptr<configuration_printable> as_printable() const override;
5350
}; // ckass telescope_detector
5451

5552
} // namespace traccc::opts

examples/options/include/traccc/options/threading.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ class threading : public interface {
3636
///
3737
void read(const boost::program_options::variables_map& vm) override;
3838

39-
private:
40-
/// Print the specific options of this class
41-
std::ostream& print_impl(std::ostream& out) const override;
42-
39+
std::unique_ptr<configuration_printable> as_printable() const override;
4340
}; // struct threading
4441

4542
} // namespace traccc::opts

examples/options/include/traccc/options/throughput.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ class throughput : public interface {
3737
/// Constructor
3838
throughput();
3939

40-
private:
41-
/// Print the specific options of this class
42-
std::ostream& print_impl(std::ostream& out) const override;
43-
40+
std::unique_ptr<configuration_printable> as_printable() const override;
4441
}; // class throughput
4542

4643
} // namespace traccc::opts

examples/options/include/traccc/options/track_finding.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class track_finding : public interface, public config_provider<finding_config> {
3131
/// Configuration conversion operators
3232
operator finding_config() const override;
3333

34+
std::unique_ptr<configuration_printable> as_printable() const override;
35+
3436
private:
3537
/// @name Options
3638
/// @{
@@ -55,10 +57,6 @@ class track_finding : public interface, public config_provider<finding_config> {
5557
/// PDG number for particle hypothesis (Default: muon)
5658
int pdg_number = 13;
5759
/// @}
58-
59-
/// Print the specific options of this class
60-
std::ostream& print_impl(std::ostream& out) const override;
61-
6260
}; // class track_finding
6361

6462
} // namespace traccc::opts

examples/options/include/traccc/options/track_propagation.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ class track_propagation : public interface,
3434
/// Configuration provider
3535
operator detray::propagation::config() const override;
3636

37+
std::unique_ptr<configuration_printable> as_printable() const override;
38+
3739
private:
3840
/// @name Options
3941
/// @{
4042
/// Propagation configuration object
4143
detray::propagation::config config;
4244
/// @}
4345

44-
/// Print the specific options of this class
45-
std::ostream& print_impl(std::ostream& out) const override;
46-
4746
/// Search window (helper variable)
4847
value_array<unsigned int, 2> m_search_window = {0u, 0u};
4948

examples/options/include/traccc/options/track_resolution.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ class track_resolution : public interface {
2727
/// Constructor
2828
track_resolution();
2929

30-
private:
31-
/// Print the specific options of this class
32-
std::ostream& print_impl(std::ostream& out) const override;
33-
30+
std::unique_ptr<configuration_printable> as_printable() const override;
3431
}; // class track_resolution
3532

3633
} // namespace traccc::opts

examples/options/include/traccc/options/track_seeding.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class track_seeding : public interface {
3333
/// Constructor
3434
track_seeding();
3535

36+
std::unique_ptr<configuration_printable> as_printable() const override;
3637
}; // struct track_seeding
3738

3839
} // namespace traccc::opts

examples/options/src/accelerator.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// Local include(s).
99
#include "traccc/options/accelerator.hpp"
1010

11+
#include "traccc/examples/utils/printable.hpp"
12+
1113
// System include(s).
1214
#include <iostream>
1315

@@ -20,10 +22,15 @@ accelerator::accelerator() : interface("Accelerator Options") {
2022
"Compare accelerator output with that of the CPU");
2123
}
2224

23-
std::ostream& accelerator::print_impl(std::ostream& out) const {
25+
std::unique_ptr<configuration_printable> accelerator::as_printable() const {
26+
std::unique_ptr<configuration_printable> cat =
27+
std::make_unique<configuration_category>("Accelerator options");
28+
29+
dynamic_cast<configuration_category &>(*cat).add_child(
30+
std::make_unique<configuration_kv_pair>(
31+
"Compare with CPU output", compare_with_cpu ? "yes" : "no"));
2432

25-
out << " Compare with CPU results: " << (compare_with_cpu ? "yes" : "no");
26-
return out;
33+
return cat;
2734
}
2835

2936
} // namespace traccc::opts

examples/options/src/clusterization.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "traccc/options/clusterization.hpp"
1010

1111
#include "traccc/clusterization/clusterization_algorithm.hpp"
12+
#include "traccc/examples/utils/printable.hpp"
1213

1314
// System include(s).
1415
#include <iostream>
@@ -50,12 +51,25 @@ clusterization::operator host::clusterization_algorithm::config_type() const {
5051
return {};
5152
}
5253

53-
std::ostream& clusterization::print_impl(std::ostream& out) const {
54-
out << " Threads per partition: " << threads_per_partition << "\n";
55-
out << " Target cells per thread: " << target_cells_per_thread << "\n";
56-
out << " Max cells per thread: " << max_cells_per_thread << "\n";
57-
out << " Scratch space size mult.: " << backup_size_multiplier;
58-
return out;
59-
}
54+
std::unique_ptr<configuration_printable> clusterization::as_printable() const {
55+
std::unique_ptr<configuration_printable> cat =
56+
std::make_unique<configuration_category>("Clustering options");
57+
58+
dynamic_cast<configuration_category &>(*cat).add_child(
59+
std::make_unique<configuration_kv_pair>(
60+
"Threads per partition", std::to_string(threads_per_partition)));
61+
dynamic_cast<configuration_category &>(*cat).add_child(
62+
std::make_unique<configuration_kv_pair>(
63+
"Target cells per thread",
64+
std::to_string(target_cells_per_thread)));
65+
dynamic_cast<configuration_category &>(*cat).add_child(
66+
std::make_unique<configuration_kv_pair>(
67+
"Max cells per thread", std::to_string(max_cells_per_thread)));
68+
dynamic_cast<configuration_category &>(*cat).add_child(
69+
std::make_unique<configuration_kv_pair>(
70+
"Scratch space multiplier",
71+
std::to_string(backup_size_multiplier)));
6072

73+
return cat;
74+
}
6175
} // namespace traccc::opts

examples/options/src/details/interface.cpp

-17
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,8 @@ interface::interface(std::string_view group_desc)
1515

1616
void interface::read(const boost::program_options::variables_map&) {}
1717

18-
std::ostream& interface::print(std::ostream& out) const {
19-
20-
out << ">>> " << m_description << " <<<\n";
21-
return print_impl(out);
22-
}
23-
2418
const boost::program_options::options_description& interface::options() const {
2519

2620
return m_desc;
2721
}
28-
29-
std::ostream& interface::print_impl(std::ostream& out) const {
30-
31-
return (out << " None");
32-
}
33-
34-
std::ostream& operator<<(std::ostream& out, const interface& opt) {
35-
36-
return opt.print(out);
37-
}
38-
3922
} // namespace traccc::opts

examples/options/src/detector.cpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// Project include(s).
99
#include "traccc/options/detector.hpp"
1010

11+
#include "traccc/examples/utils/printable.hpp"
12+
1113
// System include(s).
1214
#include <iostream>
1315

@@ -37,15 +39,27 @@ detector::detector() : interface("Detector Options") {
3739
"Digitization file");
3840
}
3941

40-
std::ostream& detector::print_impl(std::ostream& out) const {
42+
std::unique_ptr<configuration_printable> detector::as_printable() const {
43+
std::unique_ptr<configuration_printable> cat =
44+
std::make_unique<configuration_category>("Detector options");
45+
46+
dynamic_cast<configuration_category &>(*cat).add_child(
47+
std::make_unique<configuration_kv_pair>("Detector file",
48+
detector_file));
49+
dynamic_cast<configuration_category &>(*cat).add_child(
50+
std::make_unique<configuration_kv_pair>("Material file",
51+
material_file));
52+
dynamic_cast<configuration_category &>(*cat).add_child(
53+
std::make_unique<configuration_kv_pair>("Surface grid file",
54+
grid_file));
55+
dynamic_cast<configuration_category &>(*cat).add_child(
56+
std::make_unique<configuration_kv_pair>(
57+
"Use detray detector", use_detray_detector ? "yes" : "no"));
58+
dynamic_cast<configuration_category &>(*cat).add_child(
59+
std::make_unique<configuration_kv_pair>("Digitization file",
60+
digitization_file));
4161

42-
out << " Detector file : " << detector_file << "\n"
43-
<< " Material file : " << material_file << "\n"
44-
<< " Surface grid file : " << grid_file << "\n"
45-
<< " Use detray::detector: " << (use_detray_detector ? "yes" : "no")
46-
<< "\n"
47-
<< " Digitization file : " << digitization_file;
48-
return out;
62+
return cat;
4963
}
5064

5165
} // namespace traccc::opts

0 commit comments

Comments
 (0)