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 fread(&magic, 4, 1, f);
27 fseek(f, -4, SEEK_END);
28 fread(&size, 4, 1, f);
32 gzFile
file = gzopen (weightFile.c_str(),
"r");
35 char *buffer = (
char*)malloc(size);
36 bytes_read = gzread (file, buffer, size - 1);
37 buffer[bytes_read] =
'\0';
40 const char * error_string;
41 error_string = gzerror (file, & err);
43 cout<<
"Error while reading gzipped file: "<<error_string;
51 const std::string& weightFile,
bool verbose) {
54 std::cout <<
"Booking TMVA Reader with " << method <<
" and weight file: " << weightFile
59 std::cout <<
"Weight file is pure xml." << std::endl;
61 reader->BookMVA(method, weightFile);
64 std::cout <<
"Unzipping file." << std::endl;
70 char tmpFilename[] =
"/tmp/tmva.XXXXXX";
71 int fdToUselessFile = mkstemp(tmpFilename);
72 std::string weight_file_name(tmpFilename);
73 weight_file_name +=
".xml";
74 FILE *theActualFile = fopen(weight_file_name.c_str(),
"w");
76 fputs(c, theActualFile);
77 fputs(
"\n", theActualFile);
78 fclose(theActualFile);
79 close(fdToUselessFile);
82 reader->BookMVA(method, weight_file_name);
85 remove(weight_file_name.c_str());
91 std::cout <<
"Reader booked" << std::endl;
96 <<
"I don't understand the extension on the filename: "
97 << 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)