Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:26

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 // Project include(s)
0010 #include "detray/core/detector.hpp"
0011 #include "detray/navigation/volume_graph.hpp"
0012 #include "detray/utils/logging.hpp"
0013 
0014 // Detray IO include(s)
0015 #include "detray/io/frontend/detector_reader.hpp"
0016 #include "detray/io/utils/file_handle.hpp"
0017 
0018 // Example linear algebra plugin: std::array
0019 #include "detray/tutorial/types.hpp"
0020 
0021 // Vecmem include(s)
0022 #include <vecmem/memory/host_memory_resource.hpp>
0023 
0024 // System include(s)
0025 #include <ios>
0026 #include <iostream>
0027 #include <stdexcept>
0028 #include <string>
0029 
0030 /// Read a detector from file and transform its volumes and navigation links to
0031 /// a graph in dot format
0032 int main(int argc, char** argv) {
0033   std::clog << "Detector Graph Tutorial\n=======================\n";
0034 
0035   // Input data file
0036   auto reader_cfg = detray::io::detector_reader_config{};
0037   if (argc == 2) {
0038     reader_cfg.add_file(argv[1]);
0039   } else {
0040     throw std::runtime_error("Please specify an input file name!");
0041   }
0042 
0043   std::clog << reader_cfg << std::endl;
0044 
0045   // Read a toy detector
0046   using metadata_t = detray::tutorial::toy_metadata;
0047   using detector_t = detray::detector<metadata_t>;
0048 
0049   // Create an empty detector to be filled
0050   vecmem::host_memory_resource host_mr;
0051 
0052   // Read the detector in
0053   const auto [det, names] =
0054       detray::io::read_detector<detector_t>(host_mr, reader_cfg);
0055 
0056   // Display the detector volume graph
0057   detray::volume_graph graph(det);
0058 
0059   const std::string file_stem{det.name(names) + "_dot"};
0060   const std::ios_base::openmode io_mode{std::ios::out | std::ios::trunc};
0061   detray::io::file_handle out_file{file_stem, ".txt", io_mode};
0062 
0063   *out_file << graph.to_dot_string() << std::endl;
0064 
0065   DETRAY_INFO_HOST("Wrote file: " << file_stem + ".txt");
0066 }