Skip to content

Commit

Permalink
fixing readerhelper problems
Browse files Browse the repository at this point in the history
  • Loading branch information
dteague committed Aug 15, 2019
1 parent 071c069 commit 6bfea57
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>
#include <map>
#include <regex>
#include <fstream>

#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h"
Expand All @@ -13,7 +14,7 @@

class LHEWeightGroupReaderHelper {
public:
LHEWeightGroupReaderHelper() : curGroup(gen::kUnknownWeights) {}
LHEWeightGroupReaderHelper() : curWeight(gen::kUnknownWeights) {}

//// possibly add more versions of this functions for different inputs
void parseLHEFile(std::string filename);
Expand All @@ -31,18 +32,17 @@ class LHEWeightGroupReaderHelper {
gen::WeightType curWeight;
gen::WeightGroupInfo* scaleInfo;
edm::OwnVector<gen::WeightGroupInfo> pdfVector;
std::regex weightStart(".*<weightgroup.+>.*");
std::regex weightEnd(".*</weightgroup>.*");
std::regex weightContent("<weight.*>\\s*(.+)</weight>");
std::regex weightStart = std::regex(".*<weightgroup.+>.*");
std::regex weightEnd = std::regex(".*</weightgroup>.*");
std::regex weightContent = std::regex("<weight.*>\\s*(.+)</weight>");

};

void
LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) {
ifstream file;
std::ifstream file;
file.open(filename);


//// may put in constructor, can have flag to specify these values
//// To make this class a little more flexible
std::vector<std::string> weightGroup = {"name|type", "combine"};
Expand All @@ -52,36 +52,41 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) {
std::regex infoTags = createRegexSearch(weightInfo);
/// end that comment


std::string line;
std::smatch m;
int index = 0;
while(getline(file, line)) {
if(std::regex_match(line, weightStart)) {
std::string groupLine = line;
std::string name = getTagsMap(line, groupTags)["name"];

if(name == "Central scale variation")
curWeight = gen::kScaleWeights;
else
curWeight = gen::kPdfWeights;
curWeight = gen::kScaleWeights;
else
curWeight = gen::kPdfWeights;

/// file weights

while(getline(file, line) && !std::regex_match(line, weightEnd)) {
auto tmp = getTagsMap(line, infoTags);
std::regex_search(line, m, weightContent);
std::string content = m[1].str();

gen::WeightGroupInfo* tmpWeight = nullptr;
if(curWeight == gen::kScaleWeights)
if(curWeight == gen::kScaleWeights) {
tmpWeight = new gen::ScaleWeightGroupInfo(groupLine);
else if(curWeight == gen::kPdfWeights)
scaleInfo = tmpWeight;
}
else if(curWeight == gen::kPdfWeights) {
tmpWeight = new gen::PdfWeightGroupInfo(groupLine);

tmpWeight->setWeightType(curWeight);
// pdfVector.push_back(tmpWeight);
}
tmpWeight->addContainedId(index, tmp["id"], line);
index++;

if(curWeight == gen::kPdfWeights) //hate hate hate
pdfVector.push_back(tmpWeight);
index++;

}
curWeight = gen::kUnknownWeights;
}
Expand Down Expand Up @@ -113,7 +118,7 @@ std::regex
LHEWeightGroupReaderHelper::createRegexSearch(std::vector<std::string> names) {
std::string s = "(?:";
size_t numNames = names.size();
for(int i=0; i < numNames; ++i) {
for(size_t i=0; i < numNames; ++i) {
s += "\\s*(" + names[i] + ")=\"([^\"]+)\"";
if(i != numNames - 1) {
s += "|";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,11 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es)
//gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder();

// setup file reader
string LHEfilename ="cmsgrid_final.lhe";
std::string LHEfilename ="cmsgrid_final.lhe";
LHEWeightGroupReaderHelper reader;
reader.parseLHEFile(LHEfilename);
scaleInfo = *reader.getScaleInfo();
pdfSet = reader.getPdfVector();


pdfSets = reader.getPdfVector();

weightInfoProduct->addWeightGroupInfo(scaleInfo);
for (auto pdfSet : pdfSets)
Expand Down

0 comments on commit 6bfea57

Please sign in to comment.