Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix expression evaluator unit test #27723

Merged
merged 3 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions CommonTools/Utils/src/ExpressionEvaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace {
return n1;
}

void remove(std::string const& name) {
std::string sfile = "/tmp/" + name + ".cc";
std::string ofile = "/tmp/" + name + ".so";
void remove(std::string const& name, std::string const& tmpDir = "/tmp") {
std::string sfile = tmpDir + "/" + name + ".cc";
std::string ofile = tmpDir + "/" + name + ".so";

std::string rm = "rm -f ";
rm += sfile + ' ' + ofile;
Expand All @@ -55,13 +55,13 @@ namespace reco {
pch += "/src/precompile.h";
std::string quote("\"");

std::string sfile = "/tmp/" + m_name + ".cc";
std::string ofile = "/tmp/" + m_name + ".so";

auto arch = edm::getEnvironmentVariable("SCRAM_ARCH");
auto baseDir = edm::getEnvironmentVariable("CMSSW_BASE");
auto relDir = edm::getEnvironmentVariable("CMSSW_RELEASE_BASE");

std::string sfile = baseDir + "/tmp/" + m_name + ".cc";
std::string ofile = baseDir + "/tmp/" + m_name + ".so";

std::string incDir = "/include/" + arch + "/";
std::string cxxf;
{
Expand Down Expand Up @@ -144,16 +144,16 @@ namespace reco {

void* dl = dlopen(ofile.c_str(), RTLD_LAZY);
if (!dl) {
remove(m_name);
remove(m_name, baseDir + "/tmp");
throw cms::Exception("ExpressionEvaluator",
std::string("compilation/linking failed\n") + cpp + ss + "dlerror " + dlerror());
return;
}

m_expr = dlsym(dl, factory.c_str());
remove(m_name);
remove(m_name, baseDir + "/tmp");
}

ExpressionEvaluator::~ExpressionEvaluator() { remove(m_name); }
ExpressionEvaluator::~ExpressionEvaluator() { remove(m_name, edm::getEnvironmentVariable("CMSSW_BASE") + "/tmp"); }

} // namespace reco
2 changes: 1 addition & 1 deletion CommonTools/Utils/test/ExpressionEvaluatorUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main() {
}

try {
std::string cut = "bool operator()(int i, int j) override { return i<10&& j<5; }";
std::string cut = "bool operator()(int i, int j) const override { return i<10&& j<5; }";
auto const& mcut =
*reco_expressionEvaluator("CommonTools/Utils", SINGLE_ARG(reco::genericExpression<bool, int, int>), cut);
std::cout << mcut(2, 7) << ' ' << mcut(3, 4) << std::endl;
Expand Down