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"
61 std::cout <<
"Booking TMVA Reader with " << method <<
" and weight file: " << weightFile
66 std::cout <<
"Weight file is pure xml." << std::endl;
68 reader->BookMVA(method, weightFile);
71 std::cout <<
"Unzipping file." << std::endl;
77 char tmpFilename[] =
"/tmp/tmva.XXXXXX";
78 int fdToUselessFile = mkstemp(tmpFilename);
80 weight_file_name +=
".xml";
81 FILE *theActualFile = fopen(weight_file_name.c_str(),
"w");
83 fputs(c, theActualFile);
84 fputs(
"\n", theActualFile);
85 fclose(theActualFile);
86 close(fdToUselessFile);
89 reader->BookMVA(method, weight_file_name);
92 remove(weight_file_name.c_str());
98 std::cout <<
"Reader booked" << std::endl;
103 <<
"I don't understand the extension on the filename: "
104 << 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)
tuple size
Write out results.
void loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)