ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
detector_writer.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/io/frontend/detail/detector_components_writer.hpp"
13#include "detray/io/frontend/detector_writer_config.hpp"
14#include "detray/io/frontend/impl/json_writers.hpp"
15#include "detray/io/utils/create_path.hpp"
16#include "detray/utils/logging.hpp"
17
18// System include(s)
19#include <filesystem>
20#include <ios>
21
22namespace detray::io {
23
31template <class detector_t>
32void write_detector(detector_t& det, const typename detector_t::name_map& names,
34 // How to open the file
35 const std::ios_base::openmode out_mode{std::ios_base::out |
36 std::ios_base::binary};
37 auto mode =
38 cfg.replace_files() ? (out_mode | std::ios_base::trunc) : out_mode;
39
40 const auto file_path = detray::io::create_path(cfg.path());
41
42 if (det.material_store().all_empty()) {
43 cfg.write_material(false);
44 }
45
46 // Get the writer
47 io::detail::detector_components_writer<detector_t> writer{};
48 if (cfg.format() == io::format::json) {
49 detail::add_json_writers(writer, cfg);
50 }
51
52 if (cfg.compactify_json()) {
53 DETRAY_ERROR_HOST("Compactifying json files is not yet implemented");
54 }
55
56 writer.write(det, names, mode, file_path);
57}
58
59} // namespace detray::io
The following enums are global for all detectors.
Definition concepts.hpp:18
void write_detector(detector_t &det, const typename detector_t::name_map &names, detector_writer_config &cfg)
Writer function for detray detectors.
Definition detector_writer.hpp:32
auto create_path(const std::string &outdir)
Check if a given file path exists and generate it if not.
Definition create_path.hpp:79
config struct for detector writing.
Definition detector_writer_config.hpp:21
bool write_material() const
Return whether material data is written.
Definition detector_writer_config.hpp:51
detray::io::format format() const
Return the selected output format.
Definition detector_writer_config.hpp:42
bool compactify_json() const
Return whether JSON output is compacted.
Definition detector_writer_config.hpp:48
bool replace_files() const
Return whether existing output files are replaced.
Definition detector_writer_config.hpp:45
const std::string & path() const
GettersReturn the output directory used for detector files.
Definition detector_writer_config.hpp:39