musrfit 1.10.0
PUserFcnBase.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 PUserFcnBase.cpp
4
5 Author: Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8***************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2007-2026 by Andreas Suter *
12 * andreas.suter@psi.ch *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28 ***************************************************************************/
29
30#include <vector>
31#include <fstream>
32
33#include "PUserFcnBase.h"
34
36
37//--------------------------------------------------------------------------
90Int_t parseXmlFile(TSAXParser *saxParser, const char *startup_path_name)
91{
92 Int_t status;
93 std::fstream xmlFile;
94 UInt_t xmlSize = 0;
95 Char_t *xmlBuffer = nullptr;
96
97 xmlFile.open(startup_path_name, std::ios::in | std::ios::ate); // open file for reading and go to the end of the file
98 if (xmlFile.is_open()) { // check if file has been opened successfully
99 xmlSize = xmlFile.tellg(); // get the position within the stream == size of the file (since we are at the end)
100 xmlFile.seekg(0, std::ios::beg); // go back to the beginning of the stream
101 xmlBuffer = new Char_t[xmlSize]; // allocate buffer memory for the whole XML file
102 xmlFile.read(xmlBuffer, xmlSize); // read in the whole XML file into the buffer
103 xmlFile.close(); // close the XML file
104 }
105 if (!xmlBuffer) { // file has not been read into the buffer
106 status = 1;
107 } else {
108 status = saxParser->ParseBuffer(xmlBuffer, xmlSize); // parse buffer
109 delete[] xmlBuffer; // free the buffer memory
110 xmlBuffer = nullptr;
111 }
112
113 return status;
114}
115
116//--------------------------------------------------------------------------
155std::vector<void *> gGlobalUserFcn;
const char * startup_path_name
char * xmlBuffer
std::fstream xmlFile
if(xmlFile.is_open())
return status
unsigned int xmlSize
int parseXmlFile(TSAXParser *, const char *)
Replacement function for TSAXParser::ParseFile().
std::vector< void * > gGlobalUserFcn
Global storage for user function objects requiring persistent state.
ClassImp(PUserFcnBase) Int_t parseXmlFile(TSAXParser *saxParser
Parses an XML file using buffer-based parsing for better compatibility.
Abstract base class for user-defined theory functions in musrfit.