forked from AliceO2Group/QualityControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelperCommon.h
More file actions
125 lines (112 loc) · 4.28 KB
/
Copy pathHelperCommon.h
File metadata and controls
125 lines (112 loc) · 4.28 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file HelperHist.h
/// \author Artur Furs afurs@cern.ch
/// \brief Histogram helper
#ifndef QC_MODULE_FIT_HELPERCOMMON_H
#define QC_MODULE_FIT_HELPERCOMMON_H
#include <map>
#include <vector>
#include <string>
#include <tuple>
#include <utility>
#include <memory>
#include <type_traits>
#include <regex>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/property_tree/ptree.hpp>
#include "QualityControl/QcInfoLogger.h"
namespace o2::quality_control_modules::fit
{
namespace helper
{
template <typename ValueType>
inline ValueType getConfigFromPropertyTree(const boost::property_tree::ptree& config, const char* fieldName, ValueType value = {})
{
const auto& node = config.get_child_optional(fieldName);
if (node) {
value = node.get_ptr()->get_child("").get_value<ValueType>();
ILOG(Debug, Support) << fieldName << ": " << value << "\"" << ENDM;
} else {
ILOG(Debug, Support) << "Default " << fieldName << ": " << value << ENDM;
}
return value;
}
template <typename Param_t,
typename = typename std::enable_if<std::is_floating_point<Param_t>::value ||
std::is_same<std::string, Param_t>::value ||
std::is_integral<Param_t>::value>>
inline auto parseParameters(const std::string& param, const std::string& del)
{
std::regex reg(del);
std::sregex_token_iterator first{ param.begin(), param.end(), reg, -1 }, last;
std::vector<Param_t> vecResult;
for (auto it = first; it != last; it++) {
if constexpr (std::is_integral<Param_t>::value && !std::is_same<bool, Param_t>::value) {
if (!boost::algorithm::trim_copy<std::string>(*it).empty()) {
vecResult.push_back(std::stoi(*it));
}
} else if constexpr (std::is_floating_point<Param_t>::value) {
if (!boost::algorithm::trim_copy<std::string>(*it).empty()) {
vecResult.push_back(std::stof(*it));
}
} else if constexpr (std::is_same<std::string, Param_t>::value) {
vecResult.push_back(*it);
} else if constexpr (std::is_same<bool, Param_t>::value) {
std::string trimmed = boost::algorithm::trim_copy<std::string>(*it);
vecResult.push_back(boost::algorithm::to_lower_copy(trimmed) == "true" || trimmed == "1");
}
}
return vecResult;
}
// first entry - start BC, second - number of BCs in row
template <typename BitSetBC>
inline std::vector<std::pair<int, int>> getMapBCtrains(const BitSetBC& bitsetBC)
{
std::vector<std::pair<int, int>> vecTrains{};
int nBCs{ 0 };
int firstBC{ -1 };
for (int iBC = 0; iBC < bitsetBC.size(); iBC++) {
if (bitsetBC.test(iBC)) {
// BC in train
nBCs++;
if (firstBC == -1) {
// first BC in train
firstBC = iBC;
}
} else if (nBCs > 0) {
// Next after end of train BC
vecTrains.push_back({ firstBC, nBCs });
firstBC = -1;
nBCs = 0;
}
}
if (nBCs > 0) { // last iteration
vecTrains.push_back({ firstBC, nBCs });
}
return vecTrains;
}
std::map<unsigned int, std::string> multiplyMaps(const std::vector<std::tuple<std::string, std::map<unsigned int, std::string>, std::string>>& vecPreffixMapSuffix, bool useMapSizeAsMultFactor = true);
template <typename R, typename... Args, std::size_t... IArgs>
auto funcWithArgsAsTupleBase(std::function<R(Args...)> func, const std::tuple<Args...>& tupleArgs, std::index_sequence<IArgs...>)
{
return func(std::get<IArgs>(tupleArgs)...);
}
template <typename R, typename... Args>
auto funcWithArgsAsTuple(std::function<R(Args...)> func, const std::tuple<Args...>& tupleArgs)
{
return funcWithArgsAsTupleBase(func, tupleArgs, std::make_index_sequence<sizeof...(Args)>{});
}
} // namespace helper
} // namespace o2::quality_control_modules::fit
#endif