Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
genie::GSimFiles Class Reference

#include <GSimFiles.h>

Public Member Functions

 GSimFiles (bool chain=true, const int nmaxmodels=10)
 
 ~GSimFiles (void)
 
int NModels (void) const
 
int FindModelID (string tag) const
 
string ModelTag (int imodel) const
 
TFile * XSecFile (int imodel) const
 
string XSecFileName (int imodel) const
 
TChain * EvtChain (int imodel) const
 
vector< string > & EvtFileNames (int imodel) const
 
const stringPathToXMLFile (void) const
 
void Print (ostream &stream) const
 
bool LoadFromFile (string xmlfile)
 

Private Member Functions

void Init (const int nmaxmodels)
 
void CleanUp (void)
 

Private Attributes

bool fDoChain
 
int fNModels
 
vector< string > * fModelTag
 
vector< TFile * > * fXSecFile
 
vector< string > * fXSecFileName
 
vector< TChain * > * fEvtChain
 
vector< vector< string > > * fEvtFileNames
 
string fPath2XMLFile
 

Friends

ostream & operator<< (ostream &stream, const GSimFiles &gsimf)
 

Detailed Description

Definition at line 64 of file GSimFiles.h.

Constructor & Destructor Documentation

GSimFiles::GSimFiles ( bool  chain = true,
const int  nmaxmodels = 10 
)

Definition at line 34 of file GSimFiles.cxx.

35 {
36  fDoChain = chain;
37  this->Init(nmaxmodels);
38 }
void Init(const int nmaxmodels)
Definition: GSimFiles.cxx:254
GSimFiles::~GSimFiles ( void  )

Definition at line 40 of file GSimFiles.cxx.

41 {
42  this->CleanUp();
43 }
void CleanUp(void)
Definition: GSimFiles.cxx:273

Member Function Documentation

void GSimFiles::CleanUp ( void  )
private

Definition at line 273 of file GSimFiles.cxx.

274 {
275 
276  fPath2XMLFile = "";
277 
278 }
string fPath2XMLFile
Definition: GSimFiles.h:95
TChain * GSimFiles::EvtChain ( int  imodel) const

Definition at line 76 of file GSimFiles.cxx.

77 {
78  return (*fEvtChain)[imodel];
79 }
vector< TChain * > * fEvtChain
Definition: GSimFiles.h:93
vector< string > & GSimFiles::EvtFileNames ( int  imodel) const

Definition at line 81 of file GSimFiles.cxx.

82 {
83  return (*fEvtFileNames)[imodel];
84 }
vector< vector< string > > * fEvtFileNames
Definition: GSimFiles.h:94
int GSimFiles::FindModelID ( string  tag) const

Definition at line 50 of file GSimFiles.cxx.

51 {
52  int imodel = 0;
54  for( ; it != fModelTag->end(); ++it) {
55  if(*it == tag) return imodel;
56  imodel++;
57  }
58  return -1;
59 }
vector< string > * fModelTag
Definition: GSimFiles.h:90
intermediate_table::const_iterator const_iterator
void GSimFiles::Init ( const int  nmaxmodels)
private

Definition at line 254 of file GSimFiles.cxx.

255 {
256  fNModels = 0;
257  fModelTag = new vector<string> (nmaxmodels);
258  fXSecFile = new vector<TFile*> (nmaxmodels);
259  fXSecFileName = new vector<string> (nmaxmodels);
260  fEvtChain = new vector<TChain*> (nmaxmodels);
261  fEvtFileNames = new vector<vector<string> > (nmaxmodels);
262 
263  for(int i=0; i<nmaxmodels; i++) {
264  (*fModelTag) [i] = "";
265  (*fXSecFile) [i] = 0;
266  (*fEvtChain) [i] = 0;
267  }
268 
269  fPath2XMLFile = "";
270 
271 }
vector< TFile * > * fXSecFile
Definition: GSimFiles.h:91
vector< TChain * > * fEvtChain
Definition: GSimFiles.h:93
vector< string > * fModelTag
Definition: GSimFiles.h:90
string fPath2XMLFile
Definition: GSimFiles.h:95
vector< vector< string > > * fEvtFileNames
Definition: GSimFiles.h:94
vector< string > * fXSecFileName
Definition: GSimFiles.h:92
bool GSimFiles::LoadFromFile ( string  xmlfile)

Definition at line 91 of file GSimFiles.cxx.

92 {
93  LOG("GSimFiles", pNOTICE) << "Loading: " << xmlfile;
94 
95  vector<string> & model_tag = *fModelTag;
96  vector<TFile*> & xsec_file = *fXSecFile;
97  vector<string> & xsec_filename = *fXSecFileName;
98  vector<TChain*> & evt_chain = *fEvtChain;
99  vector< vector<string> > & evt_filenames = *fEvtFileNames;
100 
101  xmlTextReaderPtr reader = xmlNewTextReaderFilename(xmlfile.c_str());
102  if(reader == NULL) {
103  return false;
104  }
105 
106  const int kNodeTypeStartElement = 1;
107  const int kNodeTypeEndElement = 15;
108 
109  int imodel = 0;
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;
116 
117  if (reader != NULL) {
118  int ret = xmlTextReaderRead(reader);
119  while (ret == 1) {
120  xmlChar * name = xmlTextReaderName (reader);
121  xmlChar * value = xmlTextReaderValue (reader);
122  int type = xmlTextReaderNodeType (reader);
123  int depth = xmlTextReaderDepth (reader);
124 
125  bool start_element = (type==kNodeTypeStartElement);
126  bool end_element = (type==kNodeTypeEndElement);
127 
128  if(depth==0 && start_element) {
129  LOG("GSimFiles", pDEBUG) << "Root element = " << name;
130  if(xmlStrcmp(name, (const xmlChar *) "genie_simulation_outputs")) {
131  LOG("GSimFiles", pERROR)
132  << "\nXML doc. has invalid root element! [filename: "
133  << xmlfile << "]";
134  return false;
135  }
136  }
137 
138  if( (!xmlStrcmp(name, (const xmlChar *) "model")) && start_element) {
139  xmlChar * xname = xmlTextReaderGetAttribute(reader,(const xmlChar*)"name");
140  string sname = utils::str::TrimSpaces((const char *)xname);
141  model_tag[imodel] = sname;
142  LOG("GSimFiles", pNOTICE)
143  << "Adding files for model ID: "
144  << imodel << " (" << model_tag[imodel] << ")";
145  xmlFree(xname);
146  }
147  if( (!xmlStrcmp(name, (const xmlChar *) "model")) && end_element) {
148  LOG("GSimFiles", pNOTICE)
149  << "Done adding files for model ID: " << imodel;
150  imodel++;
151  }
152  if( (!xmlStrcmp(name, (const xmlChar *) "xsec_file")) && start_element) {
153  is_xsec_file = true;
154  }
155  if( (!xmlStrcmp(name, (const xmlChar *) "xsec_file")) && end_element) {
156  is_xsec_file = false;
157  }
158  if( (!xmlStrcmp(name, (const xmlChar *) "evt_file")) && start_element) {
159  is_evt_file = true;
160  is_ghep_evt_file = false;
161  is_gst_evt_file = false;
162  xmlChar * xfmt = xmlTextReaderGetAttribute(reader,(const xmlChar*)"format");
163  string sfmt = utils::str::TrimSpaces((const char *)xfmt);
164  if (sfmt.find("gst") != string::npos)
165  {
166  is_gst_evt_file = true;
167  if(!have_gst_files) { have_gst_files = true; }
168  }
169  else
170  if (sfmt.find("ghep") != string::npos)
171  {
172  is_ghep_evt_file = true;
173  if(!have_ghep_files) { have_ghep_files = true; }
174  }
175  if(have_gst_files && have_ghep_files) {
176  LOG("GSimFiles", pFATAL)
177  << "Oops! You shouldn't mix GHEP and GST event files in GSimFiles";
178  LOG("GSimFiles", pFATAL)
179  << "Please correct XML file: " << xmlfile;
180  gAbortingInErr = true;;
181  exit(1);
182  }
183  xmlFree(xfmt);
184  }
185  if( (!xmlStrcmp(name, (const xmlChar *) "evt_file")) && end_element) {
186  is_evt_file = false;
187  }
188  if( (!xmlStrcmp(name, (const xmlChar *) "#text")) && depth==3) {
189  string filename = utils::str::TrimSpaces((const char *)value);
190  if(is_evt_file) {
191  LOG("GSimFiles", pNOTICE)
192  << " * Adding event file: " << filename;
193  // chain the event trees, if requested
194  if(fDoChain) {
195  if(!evt_chain[imodel] && is_gst_evt_file) {
196  evt_chain[imodel] = new TChain("gst");
197  } else
198  if(!evt_chain[imodel] && is_ghep_evt_file) {
199  evt_chain[imodel] = new TChain("gtree");
200  }
201  if(evt_chain[imodel]) {
202  evt_chain[imodel]->Add(filename.c_str());
203  }
204  }//chain?
205  evt_filenames[imodel].push_back(filename);
206  }
207  if(is_xsec_file) {
208  LOG("GSimFiles", pNOTICE)
209  << " * Adding cross section file: " << filename;
210  xsec_file [imodel] = new TFile(filename.c_str(), "read");
211  xsec_filename[imodel] = filename;
212  if(!xsec_file[imodel]) {
213  exit(1);
214  }
215  }
216  }
217 
218  xmlFree(name);
219  xmlFree(value);
220 
221  ret = xmlTextReaderRead(reader);
222 
223  }//ret==1
224 
225  xmlFreeTextReader(reader);
226 
227  }//reader!=null
228 
229  fNModels = imodel;
230 
231  fPath2XMLFile = xmlfile;
232 
233  return true;
234 }
vector< TFile * > * fXSecFile
Definition: GSimFiles.h:91
static QCString name
Definition: declinfo.cpp:673
#define pERROR
Definition: Messenger.h:59
vector< TChain * > * fEvtChain
Definition: GSimFiles.h:93
vector< string > * fModelTag
Definition: GSimFiles.h:90
#define pFATAL
Definition: Messenger.h:56
string filename
Definition: train.py:213
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string fPath2XMLFile
Definition: GSimFiles.h:95
vector< vector< string > > * fEvtFileNames
Definition: GSimFiles.h:94
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
#define pNOTICE
Definition: Messenger.h:61
vector< string > * fXSecFileName
Definition: GSimFiles.h:92
bool gAbortingInErr
Definition: Messenger.cxx:34
#define pDEBUG
Definition: Messenger.h:63
string GSimFiles::ModelTag ( int  imodel) const

Definition at line 61 of file GSimFiles.cxx.

62 {
63  return (*fModelTag)[imodel];
64 }
vector< string > * fModelTag
Definition: GSimFiles.h:90
int GSimFiles::NModels ( void  ) const

Definition at line 45 of file GSimFiles.cxx.

46 {
47  return fNModels;
48 }
const string & GSimFiles::PathToXMLFile ( void  ) const

Definition at line 86 of file GSimFiles.cxx.

87 {
88  return fPath2XMLFile;
89 }
string fPath2XMLFile
Definition: GSimFiles.h:95
void GSimFiles::Print ( ostream &  stream) const

Definition at line 236 of file GSimFiles.cxx.

237 {
238  stream << endl;
239  stream << "loaded from path: " << fPath2XMLFile << endl;
240  for(int imodel=0; imodel < this->NModels(); imodel++) {
241  stream << "model tag: [" << this->ModelTag(imodel) << "]" << endl;
242  if(this->XSecFile(imodel)) {
243  stream << " xsec file : " << this->XSecFileName(imodel) << endl;
244  }
245  const vector<string> & filenames = this->EvtFileNames(imodel);
246  vector<string>::const_iterator iter = filenames.begin();
247  for( ; iter != filenames.end(); ++iter) {
248  string filename = *iter;
249  stream << " event file : " << filename << endl;
250  }
251  }
252 }
string ModelTag(int imodel) const
Definition: GSimFiles.cxx:61
vector< string > & EvtFileNames(int imodel) const
Definition: GSimFiles.cxx:81
int NModels(void) const
Definition: GSimFiles.cxx:45
intermediate_table::const_iterator const_iterator
string filename
Definition: train.py:213
string XSecFileName(int imodel) const
Definition: GSimFiles.cxx:71
string fPath2XMLFile
Definition: GSimFiles.h:95
TFile * XSecFile(int imodel) const
Definition: GSimFiles.cxx:66
QTextStream & endl(QTextStream &s)
TFile * GSimFiles::XSecFile ( int  imodel) const

Definition at line 66 of file GSimFiles.cxx.

67 {
68  return (*fXSecFile)[imodel];
69 }
vector< TFile * > * fXSecFile
Definition: GSimFiles.h:91
string GSimFiles::XSecFileName ( int  imodel) const

Definition at line 71 of file GSimFiles.cxx.

72 {
73  return (*fXSecFileName)[imodel];
74 }
vector< string > * fXSecFileName
Definition: GSimFiles.h:92

Friends And Related Function Documentation

ostream& operator<< ( ostream &  stream,
const GSimFiles gsimf 
)
friend

Definition at line 27 of file GSimFiles.cxx.

28  {
29  f.Print(stream);
30  return stream;
31  }

Member Data Documentation

bool genie::GSimFiles::fDoChain
private

Definition at line 88 of file GSimFiles.h.

vector<TChain*>* genie::GSimFiles::fEvtChain
private

Definition at line 93 of file GSimFiles.h.

vector<vector<string> >* genie::GSimFiles::fEvtFileNames
private

Definition at line 94 of file GSimFiles.h.

vector<string>* genie::GSimFiles::fModelTag
private

Definition at line 90 of file GSimFiles.h.

int genie::GSimFiles::fNModels
private

Definition at line 89 of file GSimFiles.h.

string genie::GSimFiles::fPath2XMLFile
private

Definition at line 95 of file GSimFiles.h.

vector<TFile*>* genie::GSimFiles::fXSecFile
private

Definition at line 91 of file GSimFiles.h.

vector<string>* genie::GSimFiles::fXSecFileName
private

Definition at line 92 of file GSimFiles.h.


The documentation for this class was generated from the following files: