9 int strpos(
const std::string &haystack,
char needle,
unsigned int nth)
12 for (
unsigned int i=0 ;
i<nth ; ++
i) {
13 std::size_t
pos = haystack.find(needle, found);
14 if (pos == std::string::npos)
return -1;
23 int pos = strpos(str,
'"', n1);
24 int count = strpos(str,
'"', n2) - pos;
25 return str.substr(pos, count - 1);
40 unsigned int NVar = 0;
41 unsigned int NSpec = 0;
43 std::vector<float> dumbVars;
44 std::vector<float> dumbSpecs;
47 std::vector<std::string> specNames;
65 std::stringstream is(tmpstr);
71 if (gzipped) isend = !std::getline(is, line);
72 else isend = !std::getline(f, line);
77 if (line.find(
"<Weights ") != std::string::npos)
break;
80 else if (line.find(
"<MethodSetup Method=") != std::string::npos) {
81 method = get_quoted_substring(line, 1, 2);
85 else if (line.find(
"<Variables NVar=") != std::string::npos) {
86 NVar = std::atoi(get_quoted_substring(line, 1, 2).c_str());
90 else if (line.find(
"<Spectators NSpec=") != std::string::npos) {
91 NSpec = std::atoi(get_quoted_substring(line, 1, 2).c_str());
95 else if (line.find(
"<Variable ") != std::string::npos) {
96 unsigned int pos = line.find(
"Expression=");
97 varNames.push_back(get_quoted_substring(line.substr(pos, line.length() - pos), 1, 2));
98 dumbVars.push_back(0);
102 else if (line.find(
"Spectator ") != std::string::npos) {
103 unsigned int pos = line.find(
"Expression=");
104 specNames.push_back(get_quoted_substring(line.substr(pos, line.length() - pos), 1, 2));
105 dumbSpecs.push_back(0);
112 TMVA::Reader* mvaReader =
new TMVA::Reader(
"!Color:Silent:!Error");
118 for(
size_t i = 0;
i < NVar; ++
i){
119 mvaReader->AddVariable(varNames[
i], &dumbVars[i]);
122 for(
size_t i = 0;
i < NSpec; ++
i){
123 mvaReader->AddSpectator(specNames[
i], &dumbSpecs[i]);
132 TMVA::MethodBDT* bdt =
dynamic_cast<TMVA::MethodBDT*
>( mvaReader->FindMVA(method) );
133 std::unique_ptr<const GBRForest> gbrForest = std::make_unique<const GBRForest>(
GBRForest(bdt));
bool hasEnding(std::string const &fullString, std::string const &ending)
char * readGzipFile(const std::string &weightFile)
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
std::string fullPath() const