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) 2021-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 "traccc/io/utils.hpp"
0010 
0011 // System include(s).
0012 #include <cstdlib>
0013 #include <filesystem>
0014 #include <iomanip>
0015 #include <sstream>
0016 
0017 namespace traccc::io {
0018 
0019 const std::string& data_directory() {
0020   // Establish the directory name only once for the application.
0021   static const std::string data_dir = [] {
0022     // Look for an environment variable specifying the directory name.
0023     const char* env_dir = std::getenv("TRACCC_TEST_DATA_DIR");
0024     if (env_dir == nullptr) {
0025       // If an environment variable is not set, rely on the definition
0026       // coming from the build system.
0027       return std::string(TRACCC_TEST_DATA_DIR) + "/";
0028     }
0029     // Initialise the directory name using the environment variable.
0030     return std::string(env_dir) + "/";
0031   }();
0032 
0033   // Return the previously initialised variable.
0034   return data_dir;
0035 }
0036 
0037 std::string get_event_filename(std::size_t event, std::string_view suffix) {
0038   std::ostringstream stream;
0039   stream << "event" << std::setfill('0') << std::setw(9) << event << suffix;
0040   return stream.str();
0041 }
0042 
0043 std::string get_absolute_path(std::string_view path) {
0044   // Check if the path is already absolute.
0045   if (std::filesystem::path(path).is_absolute()) {
0046     return std::string{path};
0047   }
0048 
0049   // Otherwise, prepend the data directory to the path.
0050   return std::filesystem::path(data_directory()) / std::filesystem::path(path);
0051 }
0052 
0053 }  // namespace traccc::io