Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:27

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2024 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Project include(s).
0009 #include "traccc/io/read_digitization_config.hpp"
0010 #include "traccc/io/utils.hpp"
0011 #include "traccc/io/write.hpp"
0012 
0013 // GTest include(s).
0014 #include <gtest/gtest.h>
0015 
0016 // System include(s).
0017 #include <cstdio>
0018 #include <filesystem>
0019 #include <fstream>
0020 
0021 TEST(io_json, digitization_config) {
0022   // Read in the ODD digitization configuration.
0023   const traccc::digitization_config orig = traccc::io::read_digitization_config(
0024       traccc::io::get_absolute_path(
0025           (std::filesystem::path("geometries") / std::filesystem::path("odd") /
0026            std::filesystem::path("odd-digi-geometric-config.json"))
0027               .native()),
0028       traccc::data_format::json);
0029 
0030   // Write the digitization configuration to a temporary file.
0031   const std::string tempfile =
0032       (std::filesystem::temp_directory_path() /
0033        std::filesystem::path("traccc-odd-digi-config-io-test.json"))
0034           .native();
0035   traccc::io::write(tempfile, traccc::data_format::json, orig);
0036 
0037   // Read in the digitization configuration from the temporary file.
0038   const traccc::digitization_config copy =
0039       traccc::io::read_digitization_config(tempfile, traccc::data_format::json);
0040 
0041   // Remove the temporary file.
0042   std::remove(tempfile.c_str());
0043 
0044   // Check that the two configurations are the same.
0045   ASSERT_EQ(orig.size(), copy.size());
0046   auto orig_it = orig.begin();
0047   auto copy_it = copy.begin();
0048   for (; orig_it != orig.end(); ++orig_it, ++copy_it) {
0049     EXPECT_EQ(orig_it->dimensions, copy_it->dimensions);
0050     EXPECT_EQ(orig_it->bin_edges.size(), copy_it->bin_edges.size());
0051   }
0052 }