26 using std::ostringstream;
39 string str = string( (
const char *) xmls );
45 xmlChar * xmls = xmlGetProp(xml_cur, (
const xmlChar *) attr_name.c_str());
61 std::string p0 = RunOpt::Instance()->XMLPath();
62 if ( p0.size() ) { pathlist += std::string(p0) +
":" ; }
63 const char* p1 = std::getenv(
"GXMLPATH" );
64 if ( p1 ) { pathlist += std::string(p1) +
":" ; }
65 const char* p2 = std::getenv(
"GXMLPATHS" );
66 if ( p2 ) { pathlist += std::string(p2) +
":" ; }
69 const char* p3 = std::getenv(
"GALGCONF" );
70 if ( p3 ) { pathlist += std::string(p3) +
":" ; }
72 if ( add_tune && RunOpt::Instance() -> Tune() ) {
74 if ( RunOpt::Instance() -> Tune() -> IsConfigured() ) {
76 if ( ! RunOpt::Instance() -> Tune() -> IsValidated() ) {
77 LOG(
"XmlParser",
pFATAL) <<
"Tune not validated" ;
81 if ( ! RunOpt::Instance() -> Tune() -> OnlyConfiguration() )
82 pathlist += RunOpt::Instance() -> Tune() -> TuneDirectory() +
":" ;
84 pathlist += RunOpt::Instance() -> Tune() -> CMCDirectory() +
':' ;
90 auto GENIE_REWEIGHT = std::getenv(
"GENIE_REWEIGHT");
92 pathlist +=
":" + (std::string(GENIE_REWEIGHT) +
"/config");
93 pathlist +=
":$GENIE/src/Tools/Flux/GNuMINtuple";
107 if ( basename ==
"" )
return basename;
112 size_t np = paths.size();
113 for (
size_t i=0; i< np; ++i ) {
114 const char* tmppath = paths[i].c_str();
115 std::string onepath = gSystem->ExpandPathName(tmppath);
118 bool noAccess = gSystem->AccessPathName(onepath.c_str());
132 xmlNodePtr root_node = xmlDocGetRootElement(xml_doc);
133 if(root_node==NULL) {
134 LOG(
"XML",
pERROR) <<
"Null root XML node";
140 unsigned int ndepth = node_path_vec.size();
141 unsigned int idepth = 0;
143 xmlNodePtr curr_node = root_node;
145 while (curr_node != NULL) {
147 curr_node->name, (
const xmlChar *) node_path_vec[idepth].c_str())) )
150 if(idepth == ndepth) {
153 curr_node = curr_node->xmlChildrenNode;
156 curr_node = curr_node->next;
170 xmlNodeListGetString(xml_doc, node->xmlChildrenNode, 1) );
172 if(content ==
"true" ||
179 content ==
"I")
return true;
181 if(content ==
"false" ||
182 content ==
"FALSE" ||
183 content ==
"False" ||
188 content ==
"O")
return false;
191 <<
"Could not interpret content (" << content
192 <<
") found at node_path: " << node_path <<
" as a boolean!";
203 xmlNodeListGetString(xml_doc, node->xmlChildrenNode, 1) );
204 int value = atoi(content.c_str());
218 xmlNodeListGetString(xml_doc, node->xmlChildrenNode, 1) );
221 vector<string>::const_iterator str_tokens_iter = str_tokens.begin();
222 for( ; str_tokens_iter != str_tokens.end(); ++str_tokens_iter) {
224 if (not token.size() )
continue;
225 array.push_back( atoi(token.c_str()) );
237 xmlNodeListGetString(xml_doc, node->xmlChildrenNode, 1) );
238 double value = atof(content.c_str());
245 vector<double> array;
253 xmlNodeListGetString(xml_doc, node->xmlChildrenNode, 1) );
256 vector<string>::const_iterator str_tokens_iter = str_tokens.begin();
257 for( ; str_tokens_iter != str_tokens.end(); ++str_tokens_iter) {
259 if (not token.size() )
continue;
260 array.push_back( atof(token.c_str()) );
272 xmlNodeListGetString(xml_doc, node->xmlChildrenNode, 1) );
292 xmlDocPtr xml_doc,
string node_path,
string base_dir)
294 LOG(
"XML",
pINFO) <<
"Reading info at XML node node_path: " << node_path;
298 string used_base_dir = base_dir;
299 if(base_dir.find(
"<env>") != string::npos) {
300 used_base_dir = gSystem->Getenv(
"GENIE");
303 const char * full_filename =
304 Form(
"%s/%s", used_base_dir.c_str(), filename.c_str());
305 TFile * file =
new TFile(full_filename,
"read");
307 LOG(
"XML",
pERROR) <<
"No file: " << full_filename <<
" found";
310 if(file->IsZombie()) {
311 LOG(
"XML",
pERROR) <<
"File is a zombie: " << full_filename;
319 xmlDocPtr xml_doc,
string node_path,
string base_dir)
325 TH1F * h = (TH1F*)file->Get(objname.c_str());
333 TH1F * hcopy =
new TH1F(*h);
334 hcopy->SetDirectory(0);
342 xmlDocPtr xml_doc,
string node_path,
string base_dir)
348 TH1D * h = (TH1D*)file->Get(objname.c_str());
356 TH1D * hcopy =
new TH1D(*h);
357 hcopy->SetDirectory(0);
365 xmlDocPtr xml_doc,
string node_path,
string base_dir)
371 TH2D * h = (TH2D*)file->Get(objname.c_str());
379 TH2D * hcopy =
new TH2D(*h);
380 hcopy->SetDirectory(0);
388 xmlDocPtr xml_doc,
string node_path,
string base_dir)
394 TVectorD * vec = (TVectorD*)file->Get(objname.c_str());
402 TVectorD * veccopy =
new TVectorD(*vec);
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)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
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 TrimSpaces(string input)
vector< string > Split(string input, string delim)
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>")