* Define a function for the XML-reading workaround in order to clean up a bit.
For the moment we keep to copies of it -- one for the use within the various musrfit programs, one that can be used in user functions. * musrt0 is now again activated in musrgui/musredit by default.
This commit is contained in:
@@ -415,35 +415,19 @@ int PMsr2Data::SetRunNumbers(const string &runListFile)
|
||||
*
|
||||
* <p><b>return:</b>
|
||||
* - 0 if everything went fine
|
||||
* - return value of the ParseFile-method otherwise
|
||||
* - return value of the parseXmlFile function otherwise
|
||||
*/
|
||||
int PMsr2Data::ParseXmlStartupFile()
|
||||
{
|
||||
fstream xmlFile;
|
||||
unsigned int xmlSize = 0;
|
||||
char *xmlBuffer = 0;
|
||||
int status;
|
||||
fSaxParser = new TSAXParser();
|
||||
fStartupHandler = new PStartupHandler();
|
||||
string startup_path_name(fStartupHandler->GetStartupFilePath().Data());
|
||||
fSaxParser->ConnectToHandler("PStartupHandler", fStartupHandler);
|
||||
//status = fSaxParser->ParseFile(startup_path_name.c_str());
|
||||
// parsing the file as above seems to lead to problems in certain environments; try working around through a buffer as follows
|
||||
xmlFile.open(startup_path_name.c_str(), ios::in | ios::ate); // open file for reading and go to the end of the file
|
||||
if (xmlFile.is_open()) { // check if file has been opened successfully
|
||||
xmlSize = xmlFile.tellg(); // get the position within the stream == size of the file (since we are at the end)
|
||||
xmlFile.seekg(0, ios::beg); // go back to the beginning of the stream
|
||||
xmlBuffer = new char[xmlSize]; // allocate buffer memory for the whole XML file
|
||||
xmlFile.read(xmlBuffer, xmlSize); // read in the whole XML file into the buffer
|
||||
xmlFile.close(); // close the XML file
|
||||
}
|
||||
if (!xmlBuffer) { // file has not been read into the buffer
|
||||
status = 1;
|
||||
} else {
|
||||
status = fSaxParser->ParseBuffer(xmlBuffer, xmlSize); // parse buffer
|
||||
delete[] xmlBuffer; // free the buffer memory
|
||||
xmlBuffer = 0;
|
||||
}
|
||||
// parsing the file as above seems to lead to problems in certain environments;
|
||||
// use the parseXmlFile function instead (see PStartupHandler.cpp for the definition)
|
||||
status = parseXmlFile(fSaxParser, startup_path_name.c_str());
|
||||
// check for parse errors
|
||||
if (status) { // error
|
||||
cerr << endl << ">> msr2data: **WARNING** Reading/parsing musrfit_startup.xml failed." << endl;
|
||||
|
||||
Reference in New Issue
Block a user