16 #define COUT std::cout
18 #define COUT LogDebug("ExpressionEvaluator")
21 using namespace reco::exprEvalDetails;
35 rm += sfile +
' ' + ofile;
45 : m_name(
"VI_" + generateName()) {
47 pch +=
"/src/precompile.h";
55 std::string ofile = baseDir +
"/tmp/" + m_name +
".so";
62 std::ifstream
ss(file.c_str());
63 COUT <<
"local file: " << file << std::endl;
65 std::getline(
ss, cxxf);
66 incDir = baseDir + incDir;
69 std::string file = relDir + incDir + pch +
".cxxflags";
70 COUT <<
"file in release area: " << file << std::endl;
71 std::ifstream
ss(file.c_str());
73 std::getline(
ss, cxxf);
74 incDir = relDir + incDir;
79 throw cms::Exception(
"ExpressionEvaluator",
"error in opening patch area for " + baseDir);
80 std::string file = paDir + incDir + pch +
".cxxflags";
81 COUT <<
"file in base release area: " << file << std::endl;
82 std::ifstream
ss(file.c_str());
85 "ExpressionEvaluator",
86 pch +
" file not found neither in " + baseDir +
" nor in " + relDir +
" nor in " + paDir);
87 std::getline(
ss, cxxf);
88 incDir = paDir + incDir;
93 std::regex rq(
"-I[^ ]+");
94 cxxf = std::regex_replace(cxxf, rq,
std::string(
""));
98 cxxf = std::regex_replace(cxxf, rq,
std::string(
"='\""));
101 std::regex rq(
"\" ");
102 cxxf = std::regex_replace(cxxf, rq,
std::string(
"\"' "));
104 COUT <<
'|' << cxxf <<
"|\n" << std::endl;
107 std::string cpp =
"c++ -H -Wall -shared -Winvalid-pch ";
109 cpp +=
" -I" + incDir;
110 cpp +=
" -o " + ofile +
' ' + sfile +
" 2>&1\n";
112 COUT << cpp << std::endl;
118 source +=
"struct " + m_name +
" final : public " + iname +
"{\n";
122 source +=
"extern " + quote +
'C' + quote +
' ' +
std::string(iname) +
"* " + factory +
"() {\n";
123 source +=
"static " + m_name +
" local;\n";
124 source +=
"return &local;\n}\n";
126 COUT << source << std::endl;
129 std::ofstream
tmp(sfile.c_str());
130 tmp << source << std::endl;
137 void* dl = dlopen(ofile.c_str(), RTLD_LAZY);
139 remove(
m_name, baseDir +
"/tmp");
141 std::string(
"compilation/linking failed\n") + cpp +
ss +
"dlerror " + dlerror());
145 m_expr = dlsym(dl, factory.c_str());
146 remove(
m_name, baseDir +
"/tmp");
std::string execSysCommand(const std::string &cmdline)
ExpressionEvaluator(const char *pkg, const char *iname, const std::string &iexpr)
static std::string const source
std::string getEnvironmentVariable(std::string const &name, std::string const &defaultValue=std::string())