File indexing completed on 2026-09-14 08:26:03
0001
0002
0003
0004 #include <DD4hep/DetFactoryHelper.h>
0005 #include <DD4hep/Factories.h>
0006 #include <DD4hep/Primitives.h>
0007 #include <DD4hep/Printout.h>
0008 #include <XML/Utilities.h>
0009
0010 #include <fmt/core.h>
0011 #include <fmt/format.h>
0012
0013 #include <cstdlib>
0014 #include <filesystem>
0015 #include <iostream>
0016 #include <string>
0017
0018 #include "FileLoaderHelper.h"
0019
0020 using namespace dd4hep;
0021
0022 void usage(int argc, char** argv) {
0023 std::cerr
0024 << "Usage: -plugin <name> -arg [-arg] \n"
0025 " cache:<string> cache location (may be read-only) \n"
0026 " file:<string> file location \n"
0027 " url:<string> url location \n"
0028 " cmd:<string> download command with {0} for url, {1} for output \n"
0029 "\tArguments given: "
0030 << arguments(argc, argv) << std::endl;
0031 std::exit(EINVAL);
0032 }
0033
0034
0035 long load_file(Detector& , int argc, char** argv) {
0036
0037 std::string cache, file, url;
0038 for (int i = 0; i < argc && argv[i]; ++i) {
0039 if (0 == std::strncmp("cache:", argv[i], 6))
0040 cache = (argv[i] + 6);
0041 else if (0 == std::strncmp("file:", argv[i], 5))
0042 file = (argv[i] + 5);
0043 else if (0 == std::strncmp("url:", argv[i], 4))
0044 url = (argv[i] + 4);
0045 else {
0046 std::cerr << "Unexpected argument \"" << argv[i] << "\"" << std::endl;
0047 usage(argc, argv);
0048 }
0049 }
0050 printout(DEBUG, "FileLoader", "arg cache: " + cache);
0051 printout(DEBUG, "FileLoader", "arg file: " + file);
0052 printout(DEBUG, "FileLoader", "arg url: " + url);
0053
0054
0055 if (file.empty()) {
0056 printout(WARNING, "FileLoader", "no file specified");
0057 }
0058 if (url.empty()) {
0059 printout(WARNING, "FileLoader", "no url specified");
0060 }
0061
0062 EnsureFileFromURLExists(url, file, cache);
0063
0064 return 1;
0065 }
0066
0067 DECLARE_APPLY(epic_FileLoader, load_file)