Project
Loading...
Searching...
No Matches
DownloadCCDBFile.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include "CCDB/CcdbApi.h"
13#include "CCDB/CCDBQuery.h"
15#include <map>
16#include "TFile.h"
17#include <iostream>
18#include <boost/program_options.hpp>
19
20namespace bpo = boost::program_options;
21
22bool initOptionsAndParse(bpo::options_description& options, int argc, char* argv[], bpo::variables_map& vm)
23{
24 options.add_options()(
25 "host", bpo::value<std::string>()->default_value("alice-ccdb.cern.ch"), "CCDB server")(
26 "path,p", bpo::value<std::vector<std::string>>()->multitoken(), "CCDB path (identifies the object) [or space separated list of paths for batch processing]")(
27 "dest,d", bpo::value<std::string>()->default_value("./"), "destination path")(
28 "no-preserve-path", "Do not preserve path structure. If not set, the full path structure -- reflecting the '--path' argument will be put.")(
29 "outfile,o", bpo::value<std::string>()->default_value("snapshot.root"), "Name of output file. If set to \"\", the name will be determined from the uploaded content. (Will be the same in case of batch downloading multiple paths.)")(
30 "timestamp,t", bpo::value<long>()->default_value(-1), "timestamp in ms - default -1 = now")(
31 "created-not-before", bpo::value<long>()->default_value(0), "CCDB created-not-before time (Time Machine)")(
32 "created-not-after", bpo::value<long>()->default_value(3385078236000), "CCDB created-not-after time (Time Machine)")(
33 "help,h", "Produce help message.");
34
35 try {
36 bpo::store(parse_command_line(argc, argv, options), vm);
37
38 // help
39 if (vm.count("help")) {
40 std::cout << options << std::endl;
41 return false;
42 }
43
44 bpo::notify(vm);
45 } catch (const bpo::error& e) {
46 std::cerr << e.what() << "\n\n";
47 std::cerr << "Error parsing command line arguments; Available options:\n";
48
49 std::cerr << options << std::endl;
50 return false;
51 }
52 return true;
53}
54
55// a simple tool to download the CCDB blob and store in a ROOT file
56int main(int argc, char* argv[])
57{
58 bpo::options_description options("Allowed options");
59 bpo::variables_map vm;
60 if (!initOptionsAndParse(options, argc, argv, vm)) {
61 return 1;
62 }
63
65 auto host = vm["host"].as<std::string>();
66 api.init(host);
67
68 std::map<std::string, std::string> filter;
69 long timestamp = vm["timestamp"].as<long>();
70 if (timestamp == -1) {
72 }
73 auto paths = vm["path"].as<std::vector<std::string>>();
74 auto dest = vm["dest"].as<std::string>();
75 if (paths.size() == 0) {
76 std::cerr << "No path given";
77 return 1;
78 }
79
80 std::cout << "Querying host " << host << " for path(s) " << paths[0] << " ... and timestamp " << timestamp << "\n";
81 bool no_preserve_path = vm.count("no-preserve-path") == 0;
82 auto filename = vm["outfile"].as<std::string>();
83 auto notBefore = vm["created-not-before"].as<long>();
84 auto notAfter = vm["created-not-after"].as<long>();
85
86 bool success = true;
87 for (auto& p : paths) {
88 // could even multi-thread this
89 success |= api.retrieveBlob(p, dest, filter, timestamp, no_preserve_path, filename, std::to_string(notAfter), std::to_string(notBefore));
90 }
91 return success ? 0 : 1;
92}
bool initOptionsAndParse(bpo::options_description &options, int argc, char *argv[], bpo::variables_map &vm)
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
void init(std::string const &hosts)
Definition CcdbApi.cxx:240
bool retrieveBlob(std::string const &path, std::string const &targetdir, std::map< std::string, std::string > const &metadata, long timestamp, bool preservePathStructure=true, std::string const &localFileName="snapshot.root", std::string const &createdNotAfter="", std::string const &createdNotBefore="", std::map< std::string, std::string > *headers=nullptr) const
Definition CcdbApi.cxx:922
GLsizei const GLuint * paths
Definition glcorearb.h:5475
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
#define main