musrfit  1.9.2
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-2023 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 //--------------------------------------------------------------------------
38 // This function is a replacement for the ParseFile method of TSAXParser.
39 // It is needed because in certain environments ParseFile does not work but ParseBuffer does.
40 //--------------------------------------------------------------------------
53 Int_t parseXmlFile(TSAXParser *saxParser, const char *startup_path_name)
54 {
55  Int_t status;
56  std::fstream xmlFile;
57  UInt_t xmlSize = 0;
58  Char_t *xmlBuffer = nullptr;
59 
60  xmlFile.open(startup_path_name, std::ios::in | std::ios::ate); // open file for reading and go to the end of the file
61  if (xmlFile.is_open()) { // check if file has been opened successfully
62  xmlSize = xmlFile.tellg(); // get the position within the stream == size of the file (since we are at the end)
63  xmlFile.seekg(0, std::ios::beg); // go back to the beginning of the stream
64  xmlBuffer = new Char_t[xmlSize]; // allocate buffer memory for the whole XML file
65  xmlFile.read(xmlBuffer, xmlSize); // read in the whole XML file into the buffer
66  xmlFile.close(); // close the XML file
67  }
68  if (!xmlBuffer) { // file has not been read into the buffer
69  status = 1;
70  } else {
71  status = saxParser->ParseBuffer(xmlBuffer, xmlSize); // parse buffer
72  delete[] xmlBuffer; // free the buffer memory
73  xmlBuffer = nullptr;
74  }
75 
76  return status;
77 }
78 
79 // place a void pointer vector for global user function objects which might be needed
80 std::vector<void *> gGlobalUserFcn;
ClassImp(PUserFcnBase) Int_t parseXmlFile(TSAXParser *saxParser
int parseXmlFile(TSAXParser *, const char *)
const char * startup_path_name
std::fstream xmlFile
std::vector< void * > gGlobalUserFcn
Char_t * xmlBuffer
return status
UInt_t xmlSize