Skip to content

Commit de64a4f

Browse files
rpacholekknopers8
andauthored
QC check improvements (#286)
* Add parameter support in Check * Change CheckRunner name to a generated name from Check names * Clang format * Implement BSD checksum algorithm * follow the naming rules Co-authored-by: knopers8 <piotr.jan.konopka@cern.ch>
1 parent e49b31f commit de64a4f

6 files changed

Lines changed: 56 additions & 4 deletions

File tree

Framework/include/QualityControl/Check.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class Check
116116
std::string mModuleName;
117117
std::string mClassName;
118118
CheckInterface* mCheckInterface = nullptr;
119+
std::unordered_map<std::string, std::string> mCustomParameters;
119120

120121
// Policy
121122
std::string mPolicyType;

Framework/include/QualityControl/CheckInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class CheckInterface
8282
bool isObjectCheckable(const std::shared_ptr<MonitorObject> mo);
8383
bool isObjectCheckable(const MonitorObject* mo);
8484

85+
void setCustomParameters(const std::unordered_map<std::string, std::string>& parameters);
86+
87+
protected:
88+
std::unordered_map<std::string, std::string> mCustomParameters;
89+
8590
// private:
8691
// std::string mName;
8792

Framework/include/QualityControl/CheckRunner.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ class CheckRunner : public framework::Task
165165
*/
166166
void updateRevision();
167167

168+
/**
169+
* \brief BSD checksum algorithm.
170+
*
171+
* \param input_string String intended to be hashed
172+
*/
173+
static std::size_t hash(std::string input_string);
174+
168175
// General state
169176
std::string mDeviceName;
170177
std::vector<Check> mChecks;

Framework/src/Check.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ void Check::initConfig()
7171
std::vector<std::string> inputs;
7272
const auto& conf = config->getRecursive("qc.checks." + mName);
7373
// Params
74+
if (conf.count("checkParameters")) {
75+
mCustomParameters = config->getRecursiveMap("qc.checks." + mName + ".checkParameters");
76+
}
7477

7578
// Policy
7679
if (conf.count("policy")) {
@@ -254,6 +257,7 @@ void Check::loadLibrary()
254257
tempString += R"( because the class named ")";
255258
BOOST_THROW_EXCEPTION(FatalException() << errinfo_details(tempString));
256259
}
260+
mCheckInterface->setCustomParameters(mCustomParameters);
257261
mCheckInterface->configure(mName);
258262
}
259263

Framework/src/CheckInterface.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ bool CheckInterface::isObjectCheckable(const MonitorObject* mo)
2828
return encapsulated->IsA()->InheritsFrom(getAcceptedType().c_str());
2929
}
3030

31+
void CheckInterface::setCustomParameters(const std::unordered_map<std::string, std::string>& parameters)
32+
{
33+
mCustomParameters = parameters;
34+
}
35+
3136
} // namespace o2::quality_control::checker

Framework/src/CheckRunner.cxx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
#include <utility>
2323
#include <memory>
24-
#include <random>
24+
#include <functional>
25+
#include <algorithm>
2526
#include <set>
2627
// ROOT
2728
#include <TClass.h>
@@ -78,6 +79,21 @@ o2::framework::Inputs CheckRunner::createInputSpec(const std::string checkName,
7879
return inputs;
7980
}
8081

82+
std::size_t CheckRunner::hash(std::string inputString)
83+
{
84+
// BSD checksum
85+
const int mode = 16;
86+
std::size_t checksum = 0;
87+
88+
const std::size_t mask = (1 << (mode + 1)) - 1;
89+
for (char c : inputString) {
90+
// Rotate the sum
91+
checksum = (checksum >> 1) + ((checksum & 1) << (mode - 1));
92+
checksum = (checksum + (std::size_t)c) & mask;
93+
}
94+
return checksum;
95+
}
96+
8197
std::string CheckRunner::createCheckRunnerName(std::vector<Check> checks)
8298
{
8399
static const std::string alphanumeric =
@@ -91,11 +107,25 @@ std::string CheckRunner::createCheckRunnerName(std::vector<Check> checks)
91107
// If single check, use the check name
92108
name += checks[0].getName();
93109
} else {
94-
std::default_random_engine generator;
95-
std::uniform_int_distribution<int> distribution(0, alphanumeric.size());
110+
std::string hash_string = "";
111+
std::vector<std::string> names;
112+
// Fill vector with check names
113+
for (auto& c : checks) {
114+
names.push_back(c.getName());
115+
}
116+
// Be sure that after configuration shuffle, the name will be the same
117+
std::sort(names.begin(), names.end());
118+
119+
// Create a single string and hash it
120+
for (auto& n : names) {
121+
hash_string += n;
122+
}
123+
std::size_t num = hash(hash_string);
96124

125+
// Change numerical to alphanumeric hash representation
97126
for (int i = 0; i < NAME_LEN; ++i) {
98-
name += alphanumeric[distribution(generator)];
127+
name += alphanumeric[num % alphanumeric.size()];
128+
num = num / alphanumeric.size();
99129
}
100130
}
101131
return name;

0 commit comments

Comments
 (0)