Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <DD4hep/DetFactoryHelper.h>
#include <DD4hep/Factories.h>
#include <DD4hep/Printout.h>
#include <XML/Utilities.h>
#include <filesystem>
#include <iostream>
#include <string>
namespace fs = std::filesystem;
using namespace dd4hep;
void usage(int argc, char** argv) {
std::cout <<
"Usage: -plugin <name> -arg [-arg] \n"
" name: factory name FileLoader \n"
" file:<string> file location \n"
" url:<string> url location \n"
"\tArguments given: " << arguments(argc,argv) << std::endl;
std::exit(EINVAL);
}
// Plugin to download files
long load_file(
Detector& /* desc */,
int argc,
char** argv
) {
std::string file, url;
for (int i = 0; i < argc && argv[i]; ++i) {
if (0 == std::strncmp("file:",argv[i], 5)) file = (argv[i] + 5);
else if (0 == std::strncmp("url:", argv[i], 4)) url = (argv[i] + 4);
else usage(argc, argv);
}
std::cout << "Loading " << file << " from " << url << std::endl;
if (!fs::exists(fs::path(file))) {
std::string parent_path = fs::path(file).parent_path();
auto ret = std::system(("mkdir -p " + parent_path + " && "
"curl --retry 5 -f " + url + " -o " + file).c_str());