GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XmlParserUtils.h
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \ genie::utils::xml
5 
6 \brief XML utilities
7 
8 \author Costas Andreopoulos <c.andreopoulos \at cern.ch>
9  University of Liverpool
10 
11 \created May 04, 2004
12 
13 \cpright Copyright (c) 2003-2024, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15 
16 */
17 //____________________________________________________________________________
18 
19 #ifndef _XML_UTILS_H_
20 #define _XML_UTILS_H_
21 
22 #include <string>
23 #include <vector>
24 #include <cstdlib>
25 
26 
27 #if !defined(__CINT__) && !defined(__MAKECINT__)
28 #include "libxml/parser.h"
29 #include "libxml/xmlmemory.h"
30 #endif
31 
32 #include <TSystem.h>
33 #include <TVectorT.h>
34 
36 #include "Framework/Utils/RunOpt.h"
37 
38 
39 class TFile;
40 class TH1F;
41 class TH1D;
42 class TH2D;
43 class TSpline3;
44 
45 using std::string;
46 using std::vector;
47 
48 namespace genie {
49 namespace utils {
50 namespace xml {
51 
52 #if !defined(__CINT__) && !defined(__MAKECINT__)
53 
54  string TrimSpaces(xmlChar * xmls) ;
55  // trim the leading/trailing spaces from an parsed xml string like in:
56  //
57  // " I am a string with lots of spaces " ---->
58  // "I am a string with lots of spaces"
59  //
60  // In this method, "\n" is treated as 'empty space' so as to trim not only
61  // empty spaces in the line that contains the string but also all leading
62  // and trailing empty lines
63 
64  //_________________________________________________________________________
65 
66  string GetAttribute(xmlNodePtr xml_cur, string attr_name) ;
67 #endif
68 
69  //_________________________________________________________________________
70  string GetXMLPathList( bool add_tune = true ) ;
71  // Get a colon separated list of potential locations for xml files
72  // e.g. ".:$MYSITEXML:/path/to/exp/version:$GALGCONF:$GENIE/config"
73  // user additions should be in $GXMLPATH
74 
75  //_________________________________________________________________________
76  inline string GetXMLDefaultPath() { return "$GENIE/config" ; }
77  //standard path in case no env variable are set
78 
79  //_________________________________________________________________________
80  string GetXMLFilePath(string basename) ;
81  // return a full path to a real XML file
82  // e.g. passing in "GNuMIFlux.xml"
83  // will return "/blah/GENIE/HEAD/config/GNuMIFlux.xml"
84  // allow ::colon:: ::semicolon:: and ::comma:: as path item separators
85  //_________________________________________________________________________
86 
87 #if !defined(__CINT__) && !defined(__MAKECINT__)
88 
89  // Find a particular node witin the input XML document.
90  // The node is specified using the input path.
91  // For example, to retrieve node <superk_energy_scale_err>
92  // in XML doc below
93  // <t2k>
94  // <systematics>
95  // <superk_energy_scale_err>
96  // 0.015
97  // </superk_energy_scale_err>
98  // </systematics>
99  // </t2k>
100  // specify the path "t2k/systematics/superk_energy_scale_err"
101  //
102  xmlNodePtr FindNode(xmlDocPtr xml_doc, string node_path);
103 
104  //
105  // Retrieve XML file data in various formats.
106  // To retrieve a ROOT object from within a ROOT file, the following XML scheme is used
107  // <some_node>
108  // <another_node>
109  // <filename> blah </filename>
110  // <objname> blah </objname>
111  // <objtype> blah </objtype>
112  // </another_node>
113  // </some_node>
114  //
115  bool GetBool (xmlDocPtr xml_doc, string node_path);
116  int GetInt (xmlDocPtr xml_doc, string node_path);
117  vector<int> GetIntArray (xmlDocPtr xml_doc, string node_path); // comma-separated values in XML file
118  double GetDouble (xmlDocPtr xml_doc, string node_path);
119  vector<double> GetDoubleArray (xmlDocPtr xml_doc, string node_path); // comma-separated values in XML file
120  string GetString (xmlDocPtr xml_doc, string node_path);
121  string GetROOTFileName(xmlDocPtr xml_doc, string node_path);
122  string GetROOTObjName (xmlDocPtr xml_doc, string node_path);
123  string GetROOTObjType (xmlDocPtr xml_doc, string node_path);
124  TFile * GetTFile (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
125  TH1F * GetTH1F (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
126  TH1D * GetTH1D (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
127  TH2D * GetTH2D (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
128  TVectorD * GetTVectorD (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
129 /*
130  TMatrixDSym * GetTMatrixDSym (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
131  TMatrixD * GetTMatrixD (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
132  TSpline3 * GetTSpline3 (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
133 */
134 #endif
135 
136 } // xml namespace
137 } // utils namespace
138 } // genie namespace
139 
140 #endif // _XML_UTILS_H_
141 
string GetXMLPathList(bool add_tune=true)
string GetROOTObjName(xmlDocPtr xml_doc, string node_path)
string TrimSpaces(xmlChar *xmls)
xmlNodePtr FindNode(xmlDocPtr xml_doc, string node_path)
TH1D * GetTH1D(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
string GetROOTFileName(xmlDocPtr xml_doc, string node_path)
TH1F * GetTH1F(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
string GetXMLFilePath(string basename)
string GetROOTObjType(xmlDocPtr xml_doc, string node_path)
TFile * GetTFile(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
vector< double > GetDoubleArray(xmlDocPtr xml_doc, string node_path)
string GetString(xmlDocPtr xml_doc, string node_path)
int GetInt(xmlDocPtr xml_doc, string node_path)
vector< int > GetIntArray(xmlDocPtr xml_doc, string node_path)
string GetXMLDefaultPath()
bool GetBool(xmlDocPtr xml_doc, string node_path)
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
double GetDouble(xmlDocPtr xml_doc, string node_path)
TH2D * GetTH2D(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
TVectorD * GetTVectorD(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")