Skip to content

Commit

Permalink
Merge pull request cms-sw#15 from dteague/from-CMSSW_11_1_0_pre2
Browse files Browse the repository at this point in the history
Fix Orphan weight stuff
  • Loading branch information
kdlong committed Jul 29, 2020
2 parents 808d586 + 31043ca commit baeb16f
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,17 @@ namespace gen {
void WeightGroupInfo::addContainedId(int weightEntry, std::string id, std::string label = "") {
if (firstId_ == -1 || weightEntry < firstId_) {
firstId_ = weightEntry;
// Reset to reflect that indices will be shifted
for (auto& entry : idsContained_)
for (auto& entry : idsContained_) // Reset if indices need to be shifted
entry.localIndex = entry.globalIndex - firstId_;
}
if (weightEntry > lastId_)
lastId_ = weightEntry;

WeightMetaInfo info;
info.globalIndex = weightEntry;
info.localIndex = weightEntry - firstId_;
info.id = id;
info.label = label;

if (idsContained_.size() < info.localIndex) {
idsContained_.resize(info.localIndex);
idsContained_.insert(idsContained_.begin() + info.localIndex, info);
} else if (idsContained_.size() == info.localIndex) {
idsContained_.push_back(info);
} else {
idsContained_.resize(info.localIndex + 1);
idsContained_[info.localIndex] = info;
}
size_t localIndex = weightEntry - firstId_;
WeightMetaInfo info = {static_cast<size_t>(weightEntry), localIndex, id, label};
// logic to insert for all cases e.g. inserting in the middle of the vector
idsContained_.resize(lastId_ - firstId_);
idsContained_.insert(idsContained_.begin() + localIndex, info);
}

std::vector<WeightMetaInfo> WeightGroupInfo::containedIds() const { return idsContained_; }
Expand Down

0 comments on commit baeb16f

Please sign in to comment.