Skip to content

Commit e6152d7

Browse files
jackal1-66sawenzel
authored andcommitted
Created group labels for randomisation + added protection on non-integer fractions
1 parent 9caae96 commit e6152d7

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

Generators/src/GeneratorHybrid.cxx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ Bool_t GeneratorHybrid::Init()
245245
}
246246
count++;
247247
}
248+
// Label for groups: concatenation of the names of the generators in the group, separated by '+'.
249+
// Currently used only if randomisation is enabled
250+
auto groupLabel = [this](int k) {
251+
std::string label;
252+
for (auto subIndex : mGroups[k]) {
253+
if (!label.empty()) {
254+
label += "+";
255+
}
256+
label += (mConfigs[subIndex] == "" ? mGens[subIndex] : mConfigs[subIndex]);
257+
}
258+
return label;
259+
};
248260
if (mRandomize) {
249261
if (std::all_of(mFractions.begin(), mFractions.end(), [](int i) { return i == 1; })) {
250262
LOG(info) << "Full randomisation of generators order";
@@ -261,12 +273,12 @@ Bool_t GeneratorHybrid::Init()
261273
if (mFractions[k] == 0) {
262274
// Generator will not be used if fraction is 0
263275
mRngFractions.push_back(-1);
264-
LOG(info) << "Generator " << mGens[k] << " will not be used";
276+
LOG(info) << "Generator " << groupLabel(k) << " will not be used";
265277
} else {
266278
chance = static_cast<float>(mFractions[k]) / allfracs;
267279
sum += chance;
268280
mRngFractions.push_back(sum);
269-
LOG(info) << "Generator " << (mConfigs[k] == "" ? mGens[k] : mConfigs[k]) << " has a " << chance * 100 << "% chance of being used";
281+
LOG(info) << "Generator " << groupLabel(k) << " has a " << chance * 100 << "% chance of being used";
270282
}
271283
}
272284
}
@@ -707,6 +719,10 @@ Bool_t GeneratorHybrid::parseJSON(const std::string& path)
707719
if (doc.HasMember("fractions")) {
708720
const auto& fractions = doc["fractions"];
709721
for (const auto& frac : fractions.GetArray()) {
722+
if (!frac.IsInt()) {
723+
LOG(fatal) << "Fractions must be integers. Wrong type found in JSON";
724+
return false;
725+
}
710726
mFractions.push_back(frac.GetInt());
711727
}
712728
} else {

0 commit comments

Comments
 (0)