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);
42 unsigned int NVar = 0;
43 unsigned int NSpec = 0;
45 std::vector<float> dumbVars;
46 std::vector<float> dumbSpecs;
49 std::vector<std::string> specNames;
69 std::stringstream is(tmpstr);
75 if (gzipped) isend = !std::getline(is, line);
76 else isend = !std::getline(f, line);
81 if (line.find(
"<Weights ") != std::string::npos)
break;
84 else if (line.find(
"<MethodSetup Method=") != std::string::npos) {
85 method = get_quoted_substring(line, 1, 2);
89 else if (line.find(
"<Variables NVar=") != std::string::npos) {
90 NVar = std::atoi(get_quoted_substring(line, 1, 2).c_str());
94 else if (line.find(
"<Spectators NSpec=") != std::string::npos) {
95 NSpec = std::atoi(get_quoted_substring(line, 1, 2).c_str());
99 else if (line.find(
"<Variable ") != std::string::npos) {
100 unsigned int pos = line.find(
"Expression=");
101 varNames.push_back(get_quoted_substring(line.substr(pos, line.length() - pos), 1, 2));
102 dumbVars.push_back(0);
106 else if (line.find(
"Spectator ") != std::string::npos) {
107 unsigned int pos = line.find(
"Expression=");
108 specNames.push_back(get_quoted_substring(line.substr(pos, line.length() - pos), 1, 2));
109 dumbSpecs.push_back(0);
116 TMVA::Reader* mvaReader =
new TMVA::Reader(
"!Color:Silent:!Error");
122 for(
size_t i = 0;
i < NVar; ++
i){
123 mvaReader->AddVariable(varNames[
i], &dumbVars[i]);
126 for(
size_t i = 0;
i < NSpec; ++
i){
127 mvaReader->AddSpectator(specNames[
i], &dumbSpecs[i]);
136 TMVA::MethodBDT* bdt =
dynamic_cast<TMVA::MethodBDT*
>( mvaReader->FindMVA(method) );
137 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