EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
xclient.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file xclient.cc
1 #include <algorithm>
2 #include <cstdint>
3 #include <iostream>
4 #include <string>
5 #include <vector>
6 
7 #include <xpload/xpload.h>
8 
9 using namespace std;
10 
11 class ArgParser
12 {
13  public:
14  ArgParser(int &argc, char **argv);
15  string get_value(const string &option) const;
16  private:
17  vector<string> args;
18 };
19 
20 
21 int main(int argc, char **argv)
22 {
23  ArgParser arg_parser(argc, argv);
24 
25  string cfg = arg_parser.get_value("-c");
26  string tag = arg_parser.get_value("-t");
27  string domain = arg_parser.get_value("-d");
28  uint64_t timestamp = std::stoul(arg_parser.get_value("-s"));
29 
30  xpload::Configurator config(cfg);
31 
32  xpload::Result result = xpload::fetch(tag, domain, timestamp, config);
33 
34  if (result.paths.empty())
35  {
36  cout << "No paths found\n";
37  }
38  else
39  {
40  cout << "Found paths:\n";
41 
42  for (const string& path : result.paths)
43  cout << path << '\n';
44  }
45 
46  return EXIT_SUCCESS;
47 }
48 
49 
50 ArgParser::ArgParser(int &argc, char **argv)
51 {
52  for (int i=1; i < argc; ++i)
53  args.push_back( string(argv[i]) );
54 }
55 
56 string ArgParser::get_value(const string &option) const
57 {
58  auto itr = find(args.begin(), args.end(), option);
59 
60  string value{""};
61 
62  if (itr != args.end() && ++itr != args.end()) {
63  value = *itr;
64  }
65 
66  // Default values
67  if (value.empty() && option == "-c") return "test";
68  if (value.empty() && option == "-t") return "example_tag_1";
69  if (value.empty() && option == "-d") return "CEMC";
70  if (value.empty() && option == "-s") return std::to_string(UINT64_MAX);
71 
72  return value;
73 }