|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +#include "CCDB/CcdbApi.h" |
| 12 | +#include "DetectorsDCS/DataPointIdentifier.h" |
| 13 | +#include "DetectorsDCS/DataPointValue.h" |
| 14 | +#include <boost/program_options.hpp> |
| 15 | +#include <ctime> |
| 16 | +#include <iostream> |
| 17 | +#include <numeric> |
| 18 | +#include <string> |
| 19 | +#include <unordered_map> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +namespace po = boost::program_options; |
| 23 | +using DPID = o2::dcs::DataPointIdentifier; |
| 24 | +using DPVAL = o2::dcs::DataPointValue; |
| 25 | +using DPMAP = std::unordered_map<DPID, std::vector<DPVAL>>; |
| 26 | + |
| 27 | +int main(int argc, char** argv) |
| 28 | +{ |
| 29 | + po::variables_map vm; |
| 30 | + po::options_description usage("Usage"); |
| 31 | + |
| 32 | + std::string ccdbUrl; |
| 33 | + uint64_t timestamp; |
| 34 | + bool lv; |
| 35 | + bool hv; |
| 36 | + bool verbose; |
| 37 | + |
| 38 | + std::time_t now = std::time(nullptr); |
| 39 | + |
| 40 | + // clang-format off |
| 41 | + usage.add_options() |
| 42 | + ("help,h", "produce help message") |
| 43 | + ("ccdb",po::value<std::string>(&ccdbUrl)->default_value("http://localhost:6464"),"ccdb url") |
| 44 | + ("timestamp,t",po::value<uint64_t>(×tamp)->default_value(now),"timestamp to query") |
| 45 | + ("hv",po::bool_switch(&hv),"query HV") |
| 46 | + ("lv",po::bool_switch(&lv),"query LV") |
| 47 | + ("verbose,v",po::bool_switch(&verbose),"verbose output") |
| 48 | + ; |
| 49 | + // clang-format on |
| 50 | + |
| 51 | + po::options_description cmdline; |
| 52 | + cmdline.add(usage); |
| 53 | + |
| 54 | + po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm); |
| 55 | + |
| 56 | + if (vm.count("help")) { |
| 57 | + std::cout << "This program printout summary information from MCH DCS entries.\n"; |
| 58 | + std::cout << usage << "\n"; |
| 59 | + return 2; |
| 60 | + } |
| 61 | + |
| 62 | + try { |
| 63 | + po::notify(vm); |
| 64 | + } catch (boost::program_options::error& e) { |
| 65 | + std::cout << "Error: " << e.what() << "\n"; |
| 66 | + exit(1); |
| 67 | + } |
| 68 | + |
| 69 | + if (!hv && !lv) { |
| 70 | + std::cout << "Must specify at least one of --hv or --lv\n"; |
| 71 | + std::cout << usage << "\n"; |
| 72 | + return 3; |
| 73 | + } |
| 74 | + |
| 75 | + std::vector<std::string> what; |
| 76 | + if (hv) { |
| 77 | + what.emplace_back("MCH/HV"); |
| 78 | + } |
| 79 | + if (lv) { |
| 80 | + what.emplace_back("MCH/LV"); |
| 81 | + } |
| 82 | + |
| 83 | + // union Converter { |
| 84 | + // uint64_t raw_data; |
| 85 | + // T t_value; |
| 86 | + // }; |
| 87 | + // if (dpcom.id.get_type() != dt) { |
| 88 | + // throw std::runtime_error("DPCOM is of unexpected type " + o2::dcs::show(dt)); |
| 89 | + // } |
| 90 | + // Converter converter; |
| 91 | + // converter.raw_data = dpcom.data.payload_pt1; |
| 92 | + |
| 93 | + auto sum = |
| 94 | + [](float s, o2::dcs::DataPointValue v) { |
| 95 | + union Converter { |
| 96 | + uint64_t raw_data; |
| 97 | + double value; |
| 98 | + } converter; |
| 99 | + converter.raw_data = v.payload_pt1; |
| 100 | + return s + converter.value; |
| 101 | + }; |
| 102 | + |
| 103 | + o2::ccdb::CcdbApi api; |
| 104 | + api.init(ccdbUrl); |
| 105 | + for (auto w : what) { |
| 106 | + std::map<std::string, std::string> metadata; |
| 107 | + auto* m = api.retrieveFromTFileAny<DPMAP>(w, metadata, timestamp); |
| 108 | + std::cout << "size of " << w << " map = " << m->size() << std::endl; |
| 109 | + if (verbose) { |
| 110 | + for (auto& i : *m) { |
| 111 | + auto v = i.second; |
| 112 | + auto mean = std::accumulate(v.begin(), v.end(), 0.0, sum); |
| 113 | + if (v.size()) { |
| 114 | + mean /= v.size(); |
| 115 | + } |
| 116 | + std::cout << fmt::format("{:64s} {:4d} values of mean {:7.2f}\n", i.first.get_alias(), v.size(), |
| 117 | + mean); |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + return 0; |
| 122 | +} |
0 commit comments