Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2024 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Local include(s).
0009 #include "read_conditions_config.hpp"
0010 
0011 // Acts include(s).
0012 #if __has_include(<ActsPlugins/Json/ActsJson.hpp>)
0013 #include <ActsPlugins/Json/ActsJson.hpp>
0014 #include <ActsPlugins/Json/GeometryHierarchyMapJsonConverter.hpp>
0015 #include <ActsPlugins/Json/UtilitiesJsonConverter.hpp>
0016 #else
0017 #include <Acts/Plugins/Json/ActsJson.hpp>
0018 #include <Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp>
0019 #include <Acts/Plugins/Json/UtilitiesJsonConverter.hpp>
0020 #endif
0021 
0022 // System include(s).
0023 #include <fstream>
0024 
0025 namespace traccc {
0026 
0027 /// Function allowing the read of @c traccc::module_conditions_config objects
0028 ///
0029 /// Note that this function must be declared in the same namespace as
0030 /// @c traccc::module_conditions_config for nlohmann_json to work correctly.
0031 ///
0032 traccc::conditions_config read_conditions_config(const nlohmann::json& json) {
0033   traccc::conditions_config result;
0034 
0035   static const char* entries_key = "entries";
0036   static const char* binningdata_key = "binningdata";
0037   static const char* geometric = "geometric";
0038   static const char* segmentation = "segmentation";
0039 
0040   std::vector<traccc::conditions_config::InputElement> elements;
0041 
0042   for (const auto& entry : json[entries_key]) {
0043     Acts::GeometryIdentifier geoId;
0044     Acts::GeometryIdentifier::Value null(0u);
0045     geoId = geoId.withVolume(entry.value("volume", null))
0046                 .withLayer(entry.value("layer", null))
0047                 .withSensitive(entry.value("sensitive", null));
0048 
0049     const auto& json_val = entry["value"];
0050     const auto& json_geom = json_val[geometric];
0051     const auto& json_segm = json_geom[segmentation];
0052     const auto& json_binning = json_segm[binningdata_key];
0053     vector2 shift = {0.f, 0.f};
0054 
0055     if (json_binning.contains("shift")) {
0056       shift[0] = json_binning["shift"][0].get<float>();
0057       shift[1] = json_binning["shift"][1].get<float>();
0058     }
0059 
0060     elements.push_back({geoId, {shift}});
0061   }
0062 
0063   return traccc::conditions_config(std::move(elements));
0064 }
0065 
0066 namespace io::json {
0067 
0068 conditions_config read_conditions_config(std::string_view filename) {
0069   conditions_config result;
0070 
0071   // Open the input file. Relying on exceptions for the error handling.
0072   std::ifstream infile(filename.data(), std::ifstream::binary);
0073   infile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
0074 
0075   // Read the contents of the file into a JSON object.
0076   nlohmann::json json;
0077   infile >> json;
0078 
0079   // Construct the object from the JSON configuration.
0080   return traccc::read_conditions_config(json);
0081 }
0082 
0083 }  // namespace io::json
0084 }  // namespace traccc