File indexing completed on 2025-01-18 09:15:56
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
0012 #include <cstdlib>
0013 #include <filesystem>
0014 #include <iostream>
0015 #include <string>
0016
0017 #include "FileLoaderHelper.h"
0018
0019 using namespace dd4hep;
0020
0021 void usage(int argc, char** argv) {
0022 std::cerr
0023 << "Usage: -plugin <name> -arg [-arg] \n"
0024 " cache:<string> cache location (may be read-only) \n"
0025 " file:<string> file location \n"
0026 " url:<string> url location \n"
0027 " cmd:<string> download command with {0} for url, {1} for output \n"
0028 "\tArguments given: "
0029 << arguments(argc, argv) << std::endl;
0030 std::exit(EINVAL);
0031 }
0032
0033
0034 long load_file(Detector& , int argc, char** argv) {
0035
0036 std::string cache, file, url;
0037 for (int i = 0; i < argc && argv[i]; ++i) {
0038 if (0 == std::strncmp("cache:", argv[i], 6))
0039 cache = (argv[i] + 6);
0040 else if (0 == std::strncmp("file:", argv[i], 5))
0041 file = (argv[i] + 5);
0042 else if (0 == std::strncmp("url:", argv[i], 4))
0043 url = (argv[i] + 4);
0044 else {
0045 std::cerr << "Unexpected argument \"" << argv[i] << "\"" << std::endl;
0046 usage(argc, argv);
0047 }
0048 }
0049 printout(DEBUG, "FileLoader", "arg cache: " + cache);
0050 printout(DEBUG, "FileLoader", "arg file: " + file);
0051 printout(DEBUG, "FileLoader", "arg url: " + url);
0052
0053
0054 if (file.empty()) {
0055 printout(WARNING, "FileLoader", "no file specified");
0056 }
0057 if (url.empty()) {
0058 printout(WARNING, "FileLoader", "no url specified");
0059 }
0060
0061 EnsureFileFromURLExists(url, file, cache);
0062
0063 return 1;
0064 }
0065
0066 DECLARE_APPLY(epic_FileLoader, load_file)