Skip to content

Commit

Permalink
Command Line Options Rewrite, main branch (2024.04.09.) (#533)
Browse files Browse the repository at this point in the history
* Renamed traccc::Reals to traccc::opts::value_array.

* Re-organized the command line option code.

Making sure that there wouldn't be duplications between the classes,
and that they would be implemented in a slightly more pleasing way.

* Updated the applications for the CMDL option changes.

* Introduced a common base class for the program options.

* Introduced traccc::opts::program_options.

And with it, re-designed how the "option groups" would be used
by the executables exactly.

* Made the code use float constants.

At the same time tried to make it a bit clearer in the code that
"theta_range" is not configured directly, but rather comes from
"eta_range".

* Made value_array normalization easier.

At the same time made sure that traccc::opts::generation
would set/print all its values correctly.
  • Loading branch information
krasznaa authored Apr 10, 2024
1 parent 77a4f09 commit a813e18
Show file tree
Hide file tree
Showing 75 changed files with 2,608 additions and 2,323 deletions.
85 changes: 39 additions & 46 deletions examples/io/create_binaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,96 +12,89 @@
#include "traccc/io/read_measurements.hpp"
#include "traccc/io/read_spacepoints.hpp"
#include "traccc/io/write.hpp"
#include "traccc/options/common_options.hpp"
#include "traccc/options/handle_argument_errors.hpp"
#include "traccc/options/detector.hpp"
#include "traccc/options/input_data.hpp"
#include "traccc/options/output_data.hpp"
#include "traccc/options/program_options.hpp"

// VecMem include(s).
#include <vecmem/memory/host_memory_resource.hpp>

namespace po = boost::program_options;
// System include(s).
#include <cstdlib>

int create_binaries(const std::string& detector_file,
const std::string& digi_config_file,
const traccc::common_options& common_opts) {
int create_binaries(const traccc::opts::detector& detector_opts,
const traccc::opts::input_data& input_opts,
const traccc::opts::output_data& output_opts) {

// Read the surface transforms
auto [surface_transforms, _] = traccc::io::read_geometry(detector_file);
auto [surface_transforms, _] =
traccc::io::read_geometry(detector_opts.detector_file);

// Read the digitization configuration file
auto digi_cfg = traccc::io::read_digitization_config(digi_config_file);
auto digi_cfg =
traccc::io::read_digitization_config(detector_opts.digitization_file);

// Memory resource used by the EDM.
vecmem::host_memory_resource host_mr;

// Loop over events
for (unsigned int event = common_opts.skip;
event < common_opts.events + common_opts.skip; ++event) {
for (unsigned int event = input_opts.skip;
event < input_opts.events + input_opts.skip; ++event) {

// Read the cells from the relevant event file
traccc::io::cell_reader_output cells_csv(&host_mr);
traccc::io::read_cells(cells_csv, event, common_opts.input_directory,
common_opts.input_data_format,
&surface_transforms, &digi_cfg);
traccc::io::read_cells(cells_csv, event, input_opts.directory,
input_opts.format, &surface_transforms,
&digi_cfg);

// Write binary file
traccc::io::write(event, common_opts.input_directory,
traccc::io::write(event, output_opts.directory,
traccc::data_format::binary,
vecmem::get_data(cells_csv.cells),
vecmem::get_data(cells_csv.modules));

// Read the hits from the relevant event file
traccc::io::spacepoint_reader_output spacepoints_csv(&host_mr);
traccc::io::read_spacepoints(
spacepoints_csv, event, common_opts.input_directory,
surface_transforms, common_opts.input_data_format);
traccc::io::read_spacepoints(spacepoints_csv, event,
input_opts.directory, surface_transforms,
input_opts.format);

// Write binary file
traccc::io::write(event, common_opts.input_directory,
traccc::io::write(event, output_opts.directory,
traccc::data_format::binary,
vecmem::get_data(spacepoints_csv.spacepoints),
vecmem::get_data(spacepoints_csv.modules));

// Read the measurements from the relevant event file
traccc::io::measurement_reader_output measurements_csv(&host_mr);
traccc::io::read_measurements(measurements_csv, event,
common_opts.input_directory,
common_opts.input_data_format);
input_opts.directory, input_opts.format);

// Write binary file
traccc::io::write(event, common_opts.input_directory,
traccc::io::write(event, output_opts.directory,
traccc::data_format::binary,
vecmem::get_data(measurements_csv.measurements),
vecmem::get_data(measurements_csv.modules));
}

return 0;
return EXIT_SUCCESS;
}

// The main routine
//
int main(int argc, char* argv[]) {
// Set up the program options
po::options_description desc("Allowed options");

// Add options
desc.add_options()("help,h", "Give some help with the program's options");
desc.add_options()("detector_file", po::value<std::string>()->required(),
"specify detector file");
desc.add_options()("digitization_config_file",
po::value<std::string>()->required(),
"specify digitization configuration file");
traccc::common_options common_opts(desc);

po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);

// Check errors
traccc::handle_argument_errors(vm, desc);

// Read options
auto detector_file = vm["detector_file"].as<std::string>();
auto digi_config_file = vm["digitization_config_file"].as<std::string>();
common_opts.read(vm);

return create_binaries(detector_file, digi_config_file, common_opts);

// Program options.
traccc::opts::detector detector_opts;
traccc::opts::input_data input_opts;
traccc::opts::output_data output_opts;
traccc::opts::program_options program_opts{
"Binary File Creation",
{detector_opts, input_opts, output_opts},
argc,
argv};

// Run the application.
return create_binaries(detector_opts, input_opts, output_opts);
}
66 changes: 42 additions & 24 deletions examples/options/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,48 @@
# Set up the "build" of the traccc::option library.
traccc_add_library( traccc_options options TYPE SHARED
# header files
"include/traccc/options/common_options.hpp"
"include/traccc/options/detector_input_options.hpp"
"include/traccc/options/finding_input_options.hpp"
"include/traccc/options/full_tracking_input_options.hpp"
"include/traccc/options/details/interface.hpp"
"include/traccc/options/details/value_array.hpp"
"include/traccc/options/details/value_array.ipp"
"include/traccc/options/accelerator.hpp"
"include/traccc/options/clusterization.hpp"
"include/traccc/options/detector.hpp"
"include/traccc/options/generation.hpp"
"include/traccc/options/handle_argument_errors.hpp"
"include/traccc/options/mt_options.hpp"
"include/traccc/options/options.hpp"
"include/traccc/options/particle_gen_options.hpp"
"include/traccc/options/propagation_options.hpp"
"include/traccc/options/seeding_input_options.hpp"
"include/traccc/options/telescope_detector_options.hpp"
"include/traccc/options/throughput_options.hpp"
"include/traccc/options/input_data.hpp"
"include/traccc/options/output_data.hpp"
"include/traccc/options/performance.hpp"
"include/traccc/options/program_options.hpp"
"include/traccc/options/telescope_detector.hpp"
"include/traccc/options/threading.hpp"
"include/traccc/options/throughput.hpp"
"include/traccc/options/track_finding.hpp"
"include/traccc/options/track_propagation.hpp"
"include/traccc/options/track_resolution.hpp"
"include/traccc/options/track_seeding.hpp"
# source files
"src/options/common_options.cpp"
"src/options/detector_input_options.cpp"
"src/options/finding_input_options.cpp"
"src/options/full_tracking_input_options.cpp"
"src/options/handle_argument_errors.cpp"
"src/options/mt_options.cpp"
"src/options/particle_gen_options.cpp"
"src/options/propagation_options.cpp"
"src/options/seeding_input_options.cpp"
"src/options/telescope_detector_options.cpp"
"src/options/throughput_options.cpp"
"src/details/interface.cpp"
"src/accelerator.cpp"
"src/clusterization.cpp"
"src/detector.cpp"
"src/generation.cpp"
"src/handle_argument_errors.cpp"
"src/input_data.cpp"
"src/output_data.cpp"
"src/performance.cpp"
"src/program_options.cpp"
"src/telescope_detector.cpp"
"src/threading.cpp"
"src/throughput.cpp"
"src/track_finding.cpp"
"src/track_propagation.cpp"
"src/track_resolution.cpp"
"src/track_seeding.cpp"
)
target_link_libraries( traccc_options PUBLIC traccc::io
traccc::performance Boost::program_options)
target_link_libraries( traccc_options
PUBLIC
Boost::program_options
traccc::io
PRIVATE
traccc::performance
)
36 changes: 36 additions & 0 deletions examples/options/include/traccc/options/accelerator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Local include(s).
#include "traccc/options/details/interface.hpp"

namespace traccc::opts {

/// Option(s) for accelerator usage
class accelerator : public interface {

public:
/// @name Options
/// @{

/// Whether to compare the accelerator code's output with that of the CPU
bool compare_with_cpu = false;

/// @}

/// Constructor
accelerator();

private:
/// Print the specific options of this class
std::ostream& print_impl(std::ostream& out) const override;

}; // struct accelerator

} // namespace traccc::opts
36 changes: 36 additions & 0 deletions examples/options/include/traccc/options/clusterization.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Local include(s).
#include "traccc/options/details/interface.hpp"

namespace traccc::opts {

/// Options for the cell clusterization algorithm(s)
class clusterization : public interface {

public:
/// @name Options
/// @{

/// The number of cells to merge in a partition
unsigned short target_cells_per_partition = 1024;

/// @}

/// Constructor
clusterization();

private:
/// Print the specific options of this class
std::ostream& print_impl(std::ostream& out) const override;

}; // class clusterization

} // namespace traccc::opts
55 changes: 0 additions & 55 deletions examples/options/include/traccc/options/common_options.hpp

This file was deleted.

Loading

0 comments on commit a813e18

Please sign in to comment.