13 if (fullString.length() >= ending.length()) {
14 return (0 == fullString.compare(
15 fullString.length() - ending.length(), ending.length(), ending));
23 FILE *
f = fopen(weightFile.c_str(),
"r");
26 <<
"Failed to open MVA file = " << weightFile <<
" !!\n";
30 fread(&magic, 4, 1, f);
31 fseek(f, -4, SEEK_END);
32 fread(&size, 4, 1, f);
36 gzFile
file = gzopen (weightFile.c_str(),
"r");
39 char *buffer = (
char*)malloc(size);
40 bytes_read = gzread (file, buffer, size - 1);
41 buffer[bytes_read] =
'\0';
44 const char * error_string;
45 error_string = gzerror (file, & err);
49 <<
"Error while reading gzipped file = " << weightFile <<
" !!\n" 60 TMVA::IMethod* ptr =
nullptr;
64 std::cout <<
"Booking TMVA Reader with " << method <<
" and weight file: " << weightFile
69 std::cout <<
"Weight file is pure xml." << std::endl;
71 ptr = reader->BookMVA(method, weightFile);
74 std::cout <<
"Unzipping file." << std::endl;
80 char tmpFilename[] =
"/tmp/tmva.XXXXXX";
81 int fdToUselessFile = mkstemp(tmpFilename);
83 weight_file_name +=
".xml";
84 FILE *theActualFile = fopen(weight_file_name.c_str(),
"w");
86 fputs(c, theActualFile);
87 fputs(
"\n", theActualFile);
88 fclose(theActualFile);
89 close(fdToUselessFile);
92 ptr = reader->BookMVA(method, weight_file_name);
95 remove(weight_file_name.c_str());
101 std::cout <<
"Reader booked" << std::endl;
106 <<
"I don't understand the extension on the filename: " 107 << weightFile <<
", it should be .xml, .gz, or .gzip" << std::endl;
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)