Skip to content

Commit

Permalink
Compiles with OwnVector, but need a proper copy constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
kdlong committed Aug 6, 2019
1 parent 23bee66 commit 0ba28e0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 37 deletions.
22 changes: 11 additions & 11 deletions GeneratorInterface/LHEInterface/interface/TestWeightInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ std::string parseId(std::string label) {
return std::string(matches.str(1));
}

gen::WeightGroupInfo* getExampleScaleWeights() {
gen::WeightGroupInfo* scaleInfo = new gen::WeightGroupInfo(
gen::WeightGroupInfo getExampleScaleWeights() {
gen::WeightGroupInfo scaleInfo = gen::WeightGroupInfo(
"<weightgroup combine=\"envelope\" name=\"Central scale variation\">",
"centralScaleVariations"
);
Expand All @@ -24,16 +24,16 @@ gen::WeightGroupInfo* getExampleScaleWeights() {
R"(<weight MUF="2" MUR="0.5" PDF="263400" id="8"> mur=0.5 muf=2 </weight>)",
R"(<weight MUF="0.5" MUR="0.5" PDF="263400" id="9"> mur=0.5 muf=0.5 </weight>)",
};
scaleInfo->setWeightType(gen::kScaleWeights);
scaleInfo.setWeightType(gen::kScaleWeights);

for (size_t i = 0; i < entries.size(); i++) {
scaleInfo->addContainedId(i, parseId(entries[i]), entries[i]);
scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]);
}
return scaleInfo;
}

gen::WeightGroupInfo* getExampleScaleWeightsOutOfOrder() {
gen::WeightGroupInfo* scaleInfo = new gen::WeightGroupInfo(
gen::WeightGroupInfo getExampleScaleWeightsOutOfOrder() {
gen::WeightGroupInfo scaleInfo = gen::WeightGroupInfo(
"<weightgroup combine=\"envelope\" name=\"Central scale variation\">",
"centralScaleVariations"
);
Expand All @@ -48,15 +48,15 @@ gen::WeightGroupInfo* getExampleScaleWeightsOutOfOrder() {
R"(<weight MUF="1" MUR="0.5" PDF="263400" id="7"> mur=0.5 muf=1 </weight>)",
R"(<weight MUF="0.5" MUR="0.5" PDF="263400" id="9"> mur=0.5 muf=0.5 </weight>)",
};
scaleInfo->setWeightType(gen::kScaleWeights);
scaleInfo.setWeightType(gen::kScaleWeights);

for (size_t i = 0; i < entries.size(); i++) {
scaleInfo->addContainedId(i, parseId(entries[i]), entries[i]);
scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]);
}
return scaleInfo;
}

std::vector<gen::WeightGroupInfo*> getExamplePdfWeights() {
edm::OwnVector<gen::WeightGroupInfo> getExamplePdfWeights() {
std::vector<std::string> entries = {
R"(<weightgroup combine="hessian" name="NNPDF31_nnlo_hessian_pdfas">)",
R"(<weight MUF="1" MUR="1" PDF="306000" id="10"> Member 0 of sets NNPDF31_nnlo_hessian_pdfas</weight>)",
Expand Down Expand Up @@ -987,7 +987,7 @@ std::vector<gen::WeightGroupInfo*> getExamplePdfWeights() {
R"(</weightgroup>)",
};

std::vector<gen::WeightGroupInfo*> pdfWeights;
edm::OwnVector<gen::WeightGroupInfo> pdfWeights;

//Don't forget about the scale weights
int counter = 8;
Expand All @@ -998,7 +998,7 @@ std::vector<gen::WeightGroupInfo*> getExamplePdfWeights() {
else if (entry.find("</weightgroup") == std::string::npos) {
std::cout << "Adding! " << entry << " ID " << parseId(entry) << std::endl;
auto currentSet = pdfWeights.back();
currentSet->addContainedId(counter, parseId(entry), entry);
currentSet.addContainedId(counter, parseId(entry), entry);
}
counter++;
}
Expand Down
18 changes: 8 additions & 10 deletions GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ExternalLHEProducer : public edm::one::EDProducer<edm::BeginRunProducer,
std::shared_ptr<lhef::LHEEvent> partonLevel;
boost::ptr_deque<LHERunInfoProduct> runInfoProducts;
bool wasMerged;
std::vector<gen::WeightGroupInfo*> weightGroups_;
edm::OwnVector<gen::WeightGroupInfo> weightGroups_;

class FileCloseSentry : private boost::noncopyable {
public:
Expand Down Expand Up @@ -213,10 +213,8 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
int weightNum = 0;
for (const auto& weight : partonLevel->weights()) {
weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex);
auto group = weightGroups_.at(weightGroupIndex);
if (!group)
throw std::out_of_range("Invalid index " + weightGroupIndex);
int entry = group->weightVectorEntry(weight.id, weightNum);
auto group = weightGroups_[weightGroupIndex];
int entry = group.weightVectorEntry(weight.id, weightNum);
weightProduct->addWeight(weight.wgt, weightGroupIndex, entry);
weightNum++;
}
Expand Down Expand Up @@ -350,9 +348,9 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es)
reader_ = std::make_unique<lhef::LHEReader>(infiles, skip);

std::unique_ptr<LHEWeightInfoProduct> weightInfoProduct(new LHEWeightInfoProduct);
gen::WeightGroupInfo* scaleInfo = getExampleScaleWeights();
gen::WeightGroupInfo scaleInfo = getExampleScaleWeights();
//gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder();
std::vector<gen::WeightGroupInfo*> pdfSets = getExamplePdfWeights();
edm::OwnVector<gen::WeightGroupInfo> pdfSets = getExamplePdfWeights();

weightInfoProduct->addWeightGroupInfo(scaleInfo);
for (auto pdfSet : pdfSets)
Expand Down Expand Up @@ -537,16 +535,16 @@ int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int
// Start search at previous index, under expectation of ordered weights
for (int index = previousGroupIndex;
index < std::min(index+1, static_cast<int>(weightGroups_.size())); index++) {
gen::WeightGroupInfo* weightGroup = weightGroups_.at(previousGroupIndex);
gen::WeightGroupInfo& weightGroup = weightGroups_[previousGroupIndex];
// Fast search assuming order is not perturbed outside of weight group
if (weightGroup->indexInRange(weightIndex) && weightGroup->containsWeight(wgtId, weightIndex))
if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex))
return static_cast<int>(index);
}

// Fall back to unordered search
int counter = 0;
for (auto weightGroup : weightGroups_) {
if (weightGroup->containsWeight(wgtId, weightIndex))
if (weightGroup.containsWeight(wgtId, weightIndex))
return counter;
counter++;
}
Expand Down
4 changes: 2 additions & 2 deletions GeneratorInterface/LHEInterface/plugins/LHESource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) {
);
cenPdfInfo.setWeightType(gen::kPdfWeights);

product->addWeightGroupInfo(&scaleInfo);
product->addWeightGroupInfo(&cenPdfInfo);
product->addWeightGroupInfo(scaleInfo);
product->addWeightGroupInfo(cenPdfInfo);
std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHEWeightInfoProduct>(std::move(product)));
iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@

//#include <hepml.hpp>

#include "DataFormats/Common/interface/OwnVector.h"
#include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h"

class LHEWeightInfoProduct {
public:
LHEWeightInfoProduct() {}
LHEWeightInfoProduct(std::vector<gen::WeightGroupInfo*>& weightGroups);
LHEWeightInfoProduct(edm::OwnVector<gen::WeightGroupInfo>& weightGroups);
LHEWeightInfoProduct(const LHEWeightInfoProduct& other);
LHEWeightInfoProduct(LHEWeightInfoProduct&& other);
~LHEWeightInfoProduct() {}
LHEWeightInfoProduct& operator=(const LHEWeightInfoProduct &other);
LHEWeightInfoProduct& operator=(LHEWeightInfoProduct &&other);

const std::vector<gen::WeightGroupInfo*>& allWeightGroupsInfo() const;
const gen::WeightGroupInfo* containingWeightGroupInfo(int index) const;
const gen::WeightGroupInfo* orderedWeightGroupInfo(int index) const;
void addWeightGroupInfo(gen::WeightGroupInfo* info);
const edm::OwnVector<gen::WeightGroupInfo>& allWeightGroupsInfo() const;
const gen::WeightGroupInfo& containingWeightGroupInfo(int index) const;
const gen::WeightGroupInfo& orderedWeightGroupInfo(int index) const;
void addWeightGroupInfo(gen::WeightGroupInfo& info);

private:
std::vector<gen::WeightGroupInfo*> weightGroupsInfo_;
edm::OwnVector<gen::WeightGroupInfo> weightGroupsInfo_;


};
Expand Down
24 changes: 24 additions & 0 deletions SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ namespace gen {
WeightGroupInfo(std::string header):
headerEntry_(header), name_(header), firstId_(-1), lastId_(-1) {}

//WeightGroupInfo& operator=(const WeightGroupInfo &other) {
// headerEntry_ = other.headerEntry_;
// name_ = other.name_;
// weightType_ = other.weightType_;
// idsContained_ = other.idsContained_;
// firstId_ = other.firstId_;
// lastId_ = other.lastId_;
// return * this;
//}

//WeightGroupInfo& operator=(WeightGroupInfo &&other) {
// headerEntry_ = std::move(other.headerEntry_);
// name_ = std::move(other.name_);
// weightType_ = std::move(other.weightType_);
// idsContained_ = std::move(other.idsContained_);
// firstId_ = std::move(other.firstId_);
// lastId_ = std::move(other.lastId_);
// return *this;
//}

WeightGroupInfo* clone() const {
return new WeightGroupInfo(*this);
}

WeightMetaInfo weightMetaInfo(int weightEntry) {
return idsContained_.at(weightEntry);
}
Expand Down
18 changes: 10 additions & 8 deletions SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h"

LHEWeightInfoProduct::LHEWeightInfoProduct(std::vector<gen::WeightGroupInfo*>& weightGroups) {
LHEWeightInfoProduct::LHEWeightInfoProduct(edm::OwnVector<gen::WeightGroupInfo>& weightGroups) {
weightGroupsInfo_ = weightGroups;
}

Expand All @@ -17,22 +17,24 @@ LHEWeightInfoProduct& LHEWeightInfoProduct::operator=(LHEWeightInfoProduct &&oth
return *this;
}

const std::vector<gen::WeightGroupInfo*>& LHEWeightInfoProduct::allWeightGroupsInfo() const {
const edm::OwnVector<gen::WeightGroupInfo>& LHEWeightInfoProduct::allWeightGroupsInfo() const {
return weightGroupsInfo_;
}

const gen::WeightGroupInfo* LHEWeightInfoProduct::containingWeightGroupInfo(int index) const {
for (const auto weightGroup : weightGroupsInfo_) {
if (weightGroup->indexInRange(index))
const gen::WeightGroupInfo& LHEWeightInfoProduct::containingWeightGroupInfo(int index) const {
for (const auto& weightGroup : weightGroupsInfo_) {
if (weightGroup.indexInRange(index))
return weightGroup;
}
throw std::domain_error("Failed to find containing weight group");
}

const gen::WeightGroupInfo* LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const {
return weightGroupsInfo_.at(weightGroupIndex);
const gen::WeightGroupInfo& LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const {
if (weightGroupIndex >= static_cast<int>(weightGroupsInfo_.size()))
throw std::range_error("Weight index out of range!");
return weightGroupsInfo_[weightGroupIndex];
}

void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo* info) {
void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo& info) {
weightGroupsInfo_.push_back(info);
}
1 change: 1 addition & 0 deletions SimDataFormats/GeneratorProducts/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
<class name="std::vector<gen::WeightGroupInfo>"/>
<class name="std::vector<gen::WeightGroupInfo*>"/>
<class name="edm::OwnVector<gen::WeightGroupInfo>"/>
<class name="edm::Wrapper<gen::WeightGroupInfo>"/>
<class name="edm::Wrapper&lt;LHERunInfoProduct&gt;"/>
<class name="edm::Wrapper&lt;LHEWeightInfoProduct&gt;"/>
<class name="edm::Wrapper&lt;LHEWeightProduct&gt;"/>
Expand Down

0 comments on commit 0ba28e0

Please sign in to comment.