13 #include "libxml/parser.h" 14 #include "libxml/xmlmemory.h" 15 #include "libxml/xmlreader.h" 23 using namespace genie;
37 this->
Init(nmaxmodels);
55 if(*it == tag)
return imodel;
93 LOG(
"GSimFiles",
pNOTICE) <<
"Loading: " << xmlfile;
101 xmlTextReaderPtr reader = xmlNewTextReaderFilename(xmlfile.c_str());
106 const int kNodeTypeStartElement = 1;
107 const int kNodeTypeEndElement = 15;
110 bool is_xsec_file =
false;
111 bool is_evt_file =
false;
112 bool is_ghep_evt_file =
false;
113 bool is_gst_evt_file =
false;
114 bool have_ghep_files =
false;
115 bool have_gst_files =
false;
117 if (reader != NULL) {
118 int ret = xmlTextReaderRead(reader);
120 xmlChar *
name = xmlTextReaderName (reader);
121 xmlChar *
value = xmlTextReaderValue (reader);
122 int type = xmlTextReaderNodeType (reader);
123 int depth = xmlTextReaderDepth (reader);
125 bool start_element = (type==kNodeTypeStartElement);
126 bool end_element = (type==kNodeTypeEndElement);
128 if(depth==0 && start_element) {
130 if(xmlStrcmp(name, (
const xmlChar *)
"genie_simulation_outputs")) {
132 <<
"\nXML doc. has invalid root element! [filename: " 138 if( (!xmlStrcmp(name, (
const xmlChar *)
"model")) && start_element) {
139 xmlChar * xname = xmlTextReaderGetAttribute(reader,(
const xmlChar*)
"name");
141 model_tag[imodel] = sname;
143 <<
"Adding files for model ID: " 144 << imodel <<
" (" << model_tag[imodel] <<
")";
147 if( (!xmlStrcmp(name, (
const xmlChar *)
"model")) && end_element) {
149 <<
"Done adding files for model ID: " << imodel;
152 if( (!xmlStrcmp(name, (
const xmlChar *)
"xsec_file")) && start_element) {
155 if( (!xmlStrcmp(name, (
const xmlChar *)
"xsec_file")) && end_element) {
156 is_xsec_file =
false;
158 if( (!xmlStrcmp(name, (
const xmlChar *)
"evt_file")) && start_element) {
160 is_ghep_evt_file =
false;
161 is_gst_evt_file =
false;
162 xmlChar * xfmt = xmlTextReaderGetAttribute(reader,(
const xmlChar*)
"format");
164 if (sfmt.find(
"gst") != string::npos)
166 is_gst_evt_file =
true;
167 if(!have_gst_files) { have_gst_files =
true; }
170 if (sfmt.find(
"ghep") != string::npos)
172 is_ghep_evt_file =
true;
173 if(!have_ghep_files) { have_ghep_files =
true; }
175 if(have_gst_files && have_ghep_files) {
177 <<
"Oops! You shouldn't mix GHEP and GST event files in GSimFiles";
179 <<
"Please correct XML file: " << xmlfile;
185 if( (!xmlStrcmp(name, (
const xmlChar *)
"evt_file")) && end_element) {
188 if( (!xmlStrcmp(name, (
const xmlChar *)
"#text")) && depth==3) {
192 <<
" * Adding event file: " <<
filename;
195 if(!evt_chain[imodel] && is_gst_evt_file) {
196 evt_chain[imodel] =
new TChain(
"gst");
198 if(!evt_chain[imodel] && is_ghep_evt_file) {
199 evt_chain[imodel] =
new TChain(
"gtree");
201 if(evt_chain[imodel]) {
202 evt_chain[imodel]->Add(filename.c_str());
205 evt_filenames[imodel].push_back(filename);
209 <<
" * Adding cross section file: " <<
filename;
210 xsec_file [imodel] =
new TFile(filename.c_str(),
"read");
212 if(!xsec_file[imodel]) {
221 ret = xmlTextReaderRead(reader);
225 xmlFreeTextReader(reader);
240 for(
int imodel=0; imodel < this->
NModels(); imodel++) {
241 stream <<
"model tag: [" << this->
ModelTag(imodel) <<
"]" <<
endl;
245 const vector<string> & filenames = this->
EvtFileNames(imodel);
247 for( ; iter != filenames.end(); ++iter) {
249 stream <<
" event file : " << filename <<
endl;
257 fModelTag =
new vector<string> (nmaxmodels);
258 fXSecFile =
new vector<TFile*> (nmaxmodels);
260 fEvtChain =
new vector<TChain*> (nmaxmodels);
263 for(
int i=0; i<nmaxmodels; i++) {
264 (*fModelTag) [i] =
"";
265 (*fXSecFile) [i] = 0;
266 (*fEvtChain) [i] = 0;
vector< TFile * > * fXSecFile
THE MAIN GENIE PROJECT NAMESPACE
string ModelTag(int imodel) const
vector< TChain * > * fEvtChain
void Init(const int nmaxmodels)
vector< string > * fModelTag
vector< string > & EvtFileNames(int imodel) const
TChain * EvtChain(int imodel) const
const string & PathToXMLFile(void) const
string XSecFileName(int imodel) const
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
bool LoadFromFile(string xmlfile)
void Print(ostream &stream) const
int FindModelID(string tag) const
vector< vector< string > > * fEvtFileNames
string TrimSpaces(string input)
GSimFiles(bool chain=true, const int nmaxmodels=10)
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
TFile * XSecFile(int imodel) const
vector< string > * fXSecFileName
QTextStream & endl(QTextStream &s)