17#if defined(MUON_SUBSYSTEM_MCH)
19#elif defined(MUON_SUBSYSTEM_MID)
22#include <boost/program_options.hpp>
29#include <unordered_map>
37using DPMAP = std::unordered_map<DPID, std::vector<DPVAL>>;
45 converter.raw_data =
v.payload_pt1;
46 return s + converter.value;
62 uint64_t minTime{std::numeric_limits<uint64_t>::max()};
76 return std::make_pair(dmin, dmax);
81 std::cout <<
"size of " << what <<
" map = " <<
m.size() << std::endl;
86 auto mean = std::accumulate(
v.begin(),
v.end(), 0.0,
sum);
91 auto last = std::unique(vv.begin(), vv.end());
92 vv.erase(last, vv.end());
94 std::cout << fmt::format(
"{:64s} {:4d} ({:4d} unique) values of mean {:7.2f} : ",
i.first.get_alias(),
v.size(), vv.size(), mean);
98 std::cout << fmt::format(
" {:7.2f} ",
sum(0., dp)) << dp <<
"\n";
101 std::cout <<
"timeRange=" << timeRange.first <<
" " << timeRange.second <<
"\n";
108 std::cout <<
"Reading from file " << fileName <<
"\n";
109 std::unique_ptr<TFile> fin(TFile::Open(fileName.c_str()));
110 if (fin->IsZombie()) {
113 TClass* cl = TClass::GetClass(
typeid(
DPMAP));
115 DPMAP*
m =
static_cast<DPMAP*
>(fin->GetObjectChecked(
"ccdb_object", cl));
117 std::cerr <<
"Could not read ccdb_object from file " << fileName <<
"\n";
125 std::vector<std::string> what;
135 for (
auto w : what) {
136 std::map<std::string, std::string> metadata;
143 const std::string dpConfName)
147 using DPCONF = std::unordered_map<DPID, std::string>;
148 std::map<std::string, std::string> metadata;
150 std::cout <<
"size of dpconf map = " <<
m->size() << std::endl;
153 std::cout <<
i.second <<
" " <<
i.first <<
"\n";
160 std::unordered_map<DPID, std::string> dpid2DataDesc;
161#if defined(MUON_SUBSYSTEM_MCH)
163#elif defined(MUON_SUBSYSTEM_MID)
168 for (
const auto&
a : aliases) {
169 DPID::FILL(dpidtmp,
a, o2::dcs::DeliveryType::DPVAL_DOUBLE);
170 dpid2DataDesc[dpidtmp] = fmt::format(
"{}DATAPOINTS", o2::muon ::subsysname());
175 std::map<std::string, std::string> md;
176 std::cout <<
"storing config of " << dpid2DataDesc.size() <<
" "
186 uint64_t timestamp_seconds = timestamp / 1000;
187 uint64_t timestamp_ms = timestamp % 1000;
190#if defined(MUON_SUBSYSTEM_MCH)
192 std::array<double, 2> defaultValues{1650., 0.1};
193 for (
size_t itype = 0; itype < 2; ++itype) {
195 for (
const auto& alias : aliases) {
197 dpMap[obj.id].emplace_back(obj.data);
200#elif defined(MUON_SUBSYSTEM_MID)
202 std::array<double, 2> defaultValues{9600., 5};
203 for (
size_t itype = 0; itype < 2; ++itype) {
204 std::vector<o2::mid::dcs::MeasurementType> typeVec{
types[itype]};
206 for (
auto& alias : aliases) {
208 dpMap[obj.id].emplace_back(obj.data);
210 dpMap[obj.id].emplace_back(obj.data);
217 std::map<std::string, std::string> md;
218 md[
"default"] =
"true";
219 std::cout <<
"storing default values of " <<
o2::muon::subsysname() <<
" data points to " << ccdb <<
"\n";
221#if defined(MUON_SUBSYSTEM_MCH)
224#elif defined(MUON_SUBSYSTEM_MID)
229bool match(
const std::vector<std::string>& queries,
const char*
pattern)
231 return std::find_if(queries.begin(), queries.end(), [
pattern](std::string s) { return std::regex_match(s, std::regex(pattern, std::regex::extended | std::regex::icase)); }) != queries.end();
236 po::variables_map vm;
237 po::options_description
usage(
"Usage");
240 std::string dpConfName;
247 std::string fileName;
249 uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
253 (
"help,h",
"produce help message")
254 (
"ccdb,c",po::value<std::string>(&
ccdbUrl)->default_value(
"http://localhost:6464"),
"ccdb url")
255 (
"query,q",po::value<std::vector<std::string>>(),
"what to query (if anything)")
256 (
"timestamp,t",po::value<uint64_t>(×tamp)->default_value(now),
"timestamp for query or put (in ms)")
257 (
"put-datapoint-config,p",po::bool_switch(&put),
"upload datapoint configuration")
258 (
"verbose,v",po::value<int>(&
verboseLevel)->default_value(0),
"verbose level")
259 (
"datapoint-conf-name",po::value<std::string>(&dpConfName)->default_value(
CcdbDpConfName()),
"dp conf name (only if not from mch or mid)")
260 (
"file,f",po::value<std::string>(&fileName)->default_value(
""),
"read from file instead of from ccdb")
261 (
"upload-default-values,u",po::bool_switch(&upload_default),
"upload default values")
265 po::options_description cmdline;
268 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
270 if (vm.count(
"help")) {
271 std::cout <<
"This program printout summary information from "
273 std::cout <<
usage <<
"\n";
279 }
catch (boost::program_options::error& e) {
280 std::cout <<
"Error: " << e.what() <<
"\n";
284 if (fileName.size() > 0) {
288 if (vm.count(
"query")) {
289 auto query = vm[
"query"].as<std::vector<std::string>>();
291 hv =
match(query,
".*(hv)");
292#if defined(MUON_SUBSYSTEM_MCH)
293 lv =
match(query,
".*(lv)");
297 dpconf =
match(query,
".*(dpconf)");
299 if (!hv && !lv && !dpconf) {
300 std::cout <<
"Must specify at least one of dpconf,hv";
301#if defined(MUON_SUBSYSTEM_MCH)
304 std::cout <<
" parameter to --query option\n";
322 if (upload_default) {
int storeAsTFileAny(const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const
void init(std::string const &hosts)
std::enable_if<!std::is_base_of< o2::conf::ConfigurableParam, T >::value, T * >::type retrieveFromTFileAny(std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1, std::map< std::string, std::string > *headers=nullptr, std::string const &etag="", const std::string &createdNotAfter="", const std::string &createdNotBefore="") const
static constexpr long INFINITE_TIMESTAMP
static void FILL(const DataPointIdentifier &dpid, const std::string &alias, const DeliveryType type) noexcept
void doQueryHVLV(const std::string fileName)
std::unordered_map< DPID, std::vector< DPVAL > > DPMAP
float sum(float s, o2::dcs::DataPointValue v)
bool match(const std::vector< std::string > &queries, const char *pattern)
void makeCCDBEntryForDCS(const std::string ccdbUrl, uint64_t timestamp)
void dump(const std::string what, DPMAP m, int verbose)
void makeDefaultCCDBEntry(const std::string ccdbUrl, uint64_t timestamp)
std::pair< DPVAL, DPVAL > computeTimeRange(const std::vector< DPVAL > &dps)
void doQueryDataPointConfig(const std::string ccdbUrl, uint64_t timestamp, const std::string dpConfName)
std::string CcdbDpConfName()
GLsizei GLenum GLenum * types
GLsizei const GLfloat * value
GLboolean GLboolean GLboolean GLboolean a
GLubyte GLubyte GLubyte GLubyte w
GLsizeiptr const void GLenum usage
o2::dcs::DataPointCompositeObject createDataPointCompositeObject(const std::string &alias, T val, uint32_t seconds, uint16_t msec, uint16_t flags=0)
std::vector< std::string > aliases(std::vector< MeasurementType > types={ MeasurementType::HV_V, MeasurementType::HV_I, MeasurementType::LV_V_FEE_ANALOG, MeasurementType::LV_V_FEE_DIGITAL, MeasurementType::LV_V_SOLAR})
std::vector< std::string > aliases(std::vector< MeasurementType > types={ MeasurementType::HV_V, MeasurementType::HV_I})
const char * subsysname()
uint64_t get_epoch_time() const noexcept
std::array< uint16_t, 5 > pattern