GENIEGenerator
Loading...
Searching...
No Matches
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-2025, 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
37
38
39class TFile;
40class TH1F;
41class TH1D;
42class TH2D;
43class TSpline3;
44
45using std::string;
46using std::vector;
47
48namespace genie {
49namespace utils {
50namespace xml {
51
52#if !defined(__CINT__) && !defined(__MAKECINT__)
53
54 string TrimSpaces(xmlChar * xmls) ;
55 string TrimSpacesClean(xmlChar * xmls) ;
56 // trim the leading/trailing spaces from an parsed xml string like in:
57 //
58 // " I am a string with lots of spaces " ---->
59 // "I am a string with lots of spaces"
60 //
61 // In this method, "\n" is treated as 'empty space' so as to trim not only
62 // empty spaces in the line that contains the string but also all leading
63 // and trailing empty lines
64
65 //_________________________________________________________________________
66
67 string GetAttribute(xmlNodePtr xml_cur, string attr_name) ;
68#endif
69
70 //_________________________________________________________________________
71 string GetXMLPathList( bool add_tune = true ) ;
72 // Get a colon separated list of potential locations for xml files
73 // e.g. ".:$MYSITEXML:/path/to/exp/version:$GALGCONF:$GENIE/config"
74 // user additions should be in $GXMLPATH
75
76 //_________________________________________________________________________
77 inline string GetXMLDefaultPath() { return "$GENIE/config" ; }
78 //standard path in case no env variable are set
79
80 //_________________________________________________________________________
81 string GetXMLFilePath(string basename) ;
82 // return a full path to a real XML file
83 // e.g. passing in "GNuMIFlux.xml"
84 // will return "/blah/GENIE/HEAD/config/GNuMIFlux.xml"
85 // allow ::colon:: ::semicolon:: and ::comma:: as path item separators
86 //_________________________________________________________________________
87
88#if !defined(__CINT__) && !defined(__MAKECINT__)
89
90 // Find a particular node witin the input XML document.
91 // The node is specified using the input path.
92 // For example, to retrieve node <superk_energy_scale_err>
93 // in XML doc below
94 // <t2k>
95 // <systematics>
96 // <superk_energy_scale_err>
97 // 0.015
98 // </superk_energy_scale_err>
99 // </systematics>
100 // </t2k>
101 // specify the path "t2k/systematics/superk_energy_scale_err"
102 //
103 xmlNodePtr FindNode(xmlDocPtr xml_doc, string node_path);
104
105 //
106 // Retrieve XML file data in various formats.
107 // To retrieve a ROOT object from within a ROOT file, the following XML scheme is used
108 // <some_node>
109 // <another_node>
110 // <filename> blah </filename>
111 // <objname> blah </objname>
112 // <objtype> blah </objtype>
113 // </another_node>
114 // </some_node>
115 //
116 bool GetBool (xmlDocPtr xml_doc, string node_path);
117 int GetInt (xmlDocPtr xml_doc, string node_path);
118 vector<int> GetIntArray (xmlDocPtr xml_doc, string node_path); // comma-separated values in XML file
119 double GetDouble (xmlDocPtr xml_doc, string node_path);
120 vector<double> GetDoubleArray (xmlDocPtr xml_doc, string node_path); // comma-separated values in XML file
121 string GetString (xmlDocPtr xml_doc, string node_path);
122 string GetROOTFileName(xmlDocPtr xml_doc, string node_path);
123 string GetROOTObjName (xmlDocPtr xml_doc, string node_path);
124 string GetROOTObjType (xmlDocPtr xml_doc, string node_path);
125 TFile * GetTFile (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
126 TH1F * GetTH1F (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
127 TH1D * GetTH1D (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
128 TH2D * GetTH2D (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
129 TVectorD * GetTVectorD (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
130/*
131 TMatrixDSym * GetTMatrixDSym (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
132 TMatrixD * GetTMatrixD (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
133 TSpline3 * GetTSpline3 (xmlDocPtr xml_doc, string node_path, string base_dir = "<env>");
134*/
135#endif
136
137} // xml namespace
138} // utils namespace
139} // genie namespace
140
141#endif // _XML_UTILS_H_
142
TVectorD * GetTVectorD(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
TH2D * GetTH2D(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
vector< double > GetDoubleArray(xmlDocPtr xml_doc, string node_path)
string GetXMLPathList(bool add_tune=true)
double GetDouble(xmlDocPtr xml_doc, string node_path)
string TrimSpaces(xmlChar *xmls)
string GetString(xmlDocPtr xml_doc, string node_path)
bool GetBool(xmlDocPtr xml_doc, string node_path)
xmlNodePtr FindNode(xmlDocPtr xml_doc, string node_path)
string GetROOTObjName(xmlDocPtr xml_doc, string node_path)
int GetInt(xmlDocPtr xml_doc, string node_path)
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
string TrimSpacesClean(xmlChar *xmls)
vector< int > GetIntArray(xmlDocPtr xml_doc, string node_path)
string GetROOTFileName(xmlDocPtr xml_doc, string node_path)
string GetROOTObjType(xmlDocPtr xml_doc, string node_path)
string GetXMLDefaultPath()
string GetXMLFilePath(string basename)
TH1F * GetTH1F(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
TH1D * GetTH1D(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
TFile * GetTFile(xmlDocPtr xml_doc, string node_path, string base_dir="<env>")
Root of GENIE utility namespaces.
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25