GENIEGenerator
Loading...
Searching...
No Matches
gSplineAdd.cxx File Reference
#include <cassert>
#include <sstream>
#include <string>
#include <vector>
#include <TSystem.h>
#include "Framework/EventGen/XSecAlgorithmI.h"
#include "Framework/Conventions/XmlParserStatus.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/Utils/RunOpt.h"
#include "Framework/Utils/AppInit.h"
#include "Framework/Utils/XSecSplineList.h"
#include "Framework/Utils/StringUtils.h"
#include "Framework/Utils/SystemUtils.h"
#include "Framework/Utils/CmdLnArgParser.h"
Include dependency graph for gSplineAdd.cxx:

Go to the source code of this file.

Functions

vector< string > GetAllInputFiles (void)
void GetCommandLineArgs (int argc, char **argv)
void PrintSyntax (void)
int main (int argc, char **argv)

Variables

string gOutFile
 output XML file
vector< string > gInpFiles
 list of input XML files
vector< string > gInpDirs
 list of input dirs (to look for XML files)
vector< string > gAllFiles
 list of all input files

Function Documentation

◆ GetAllInputFiles()

vector< string > GetAllInputFiles ( void )

Definition at line 112 of file gSplineAdd.cxx.

113{
114 vector<string> files;
115
116 vector<string>::const_iterator file_iter;
117 vector<string>::const_iterator dir_iter;
118
119 // add all files that were input explictly
120 file_iter = gInpFiles.begin();
121 for( ; file_iter != gInpFiles.end(); ++file_iter) {
122 string filename = *file_iter;
123 files.push_back(filename);
124 } // file_iter
125
126 // loop over input directories
127 dir_iter = gInpDirs.begin();
128 for( ; dir_iter != gInpDirs.end(); ++dir_iter) {
129 string path = *dir_iter;
130 // get all XML files in this dir
131 vector<string> path_files = utils::system::GetAllFilesInPath(path,"xml");
132 // add these files too
133 file_iter = path_files.begin();
134 for( ; file_iter != path_files.end(); ++file_iter) {
135 string filename = *file_iter;
136 files.push_back(filename);
137 }//file_iter
138 }//dir_iter
139
140 return files;
141}
vector< string > gInpFiles
list of input XML files
vector< string > gInpDirs
list of input dirs (to look for XML files)
vector< string > GetAllFilesInPath(string path, string extension="")

References genie::utils::system::GetAllFilesInPath(), gInpDirs, and gInpFiles.

Referenced by GetCommandLineArgs().

◆ GetCommandLineArgs()

void GetCommandLineArgs ( int argc,
char ** argv )

Definition at line 143 of file gSplineAdd.cxx.

144{
145 LOG("gspladd", pNOTICE) << "Parsing command line arguments";
146
147 // Common run options.
149
150 // Parse run options for this app
151
152 CmdLnArgParser parser(argc,argv);
153
154 if( parser.OptionExists('f') ) {
155 LOG("gspladd", pINFO) << "Reading input files";
156 string inpfiles = parser.ArgAsString('f');
157 if(inpfiles.find(",") != string::npos) {
158 // split the comma separated list
159 gInpFiles = utils::str::Split(inpfiles, ",");
160 } else {
161 // there is just one file
162 gInpFiles.push_back(inpfiles);
163 }
164 }
165
166 if( parser.OptionExists('d') ) {
167 LOG("gspladd", pINFO) << "Reading input directories";
168 string inpdirs = parser.ArgAsString('d');
169 if(inpdirs.find(",") != string::npos) {
170 // split the comma separated list
171 gInpDirs = utils::str::Split(inpdirs, ",");
172 } else {
173 // there is just one directory
174 gInpDirs.push_back(inpdirs);
175 }
176 }
177
178 if( parser.OptionExists('o') ) {
179 LOG("gspladd", pINFO) << "Reading output file name";
180 gOutFile = parser.ArgAsString('o');
181 } else {
182 LOG("gspladd", pFATAL) << "You must specify an output file name";
183 PrintSyntax();
184 exit(1);
185 }
186
188 if(gAllFiles.size() <= 1) {
189 LOG("gspladd", pFATAL) << "There must be at least 2 input files";
190 PrintSyntax();
191 exit(1);
192 }
193}
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
#define pFATAL
Definition Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
Command line argument parser.
void ReadFromCommandLine(int argc, char **argv)
Definition RunOpt.cxx:99
static RunOpt * Instance(void)
Definition RunOpt.cxx:54
vector< string > gAllFiles
list of all input files
vector< string > GetAllInputFiles(void)
void PrintSyntax(void)
string gOutFile
output XML file
vector< string > Split(string input, string delim)

References genie::CmdLnArgParser::ArgAsString(), gAllFiles, GetAllInputFiles(), gInpDirs, gInpFiles, gOutFile, genie::RunOpt::Instance(), LOG, genie::CmdLnArgParser::OptionExists(), pFATAL, pINFO, pNOTICE, PrintSyntax(), genie::RunOpt::ReadFromCommandLine(), and genie::utils::str::Split().

Referenced by main().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 87 of file gSplineAdd.cxx.

88{
89 GetCommandLineArgs(argc,argv);
90
92
94
95 vector<string>::const_iterator file_iter = gAllFiles.begin();
96 for( ; file_iter != gAllFiles.end(); ++file_iter) {
97 string filename = *file_iter;
98 LOG("gspladd", pNOTICE) << " ---- >> Loading file : " << filename;
99 XmlParserStatus_t ist = xspl->LoadFromXml(filename, true);
100 assert(ist==kXmlOK);
101 }
102
103 LOG("gspladd",pDEBUG) << *xspl ;
104
105 LOG("gspladd", pNOTICE)
106 << " ****** Saving all loaded splines into : " << gOutFile;
107 xspl->SaveAsXml(gOutFile);
108
109 return 0;
110}
#define pDEBUG
Definition Messenger.h:63
List of cross section vs energy splines.
void SaveAsXml(const string &filename, bool save_init=true) const
XmlParserStatus_t LoadFromXml(const string &filename, bool keep=false)
static XSecSplineList * Instance()
void GetCommandLineArgs(int argc, char **argv)
void MesgThresholds(string inpfile)
Definition AppInit.cxx:99
enum genie::EXmlParseStatus XmlParserStatus_t

References gAllFiles, GetCommandLineArgs(), gOutFile, genie::RunOpt::Instance(), genie::XSecSplineList::Instance(), genie::kXmlOK, genie::XSecSplineList::LoadFromXml(), LOG, genie::utils::app_init::MesgThresholds(), pDEBUG, pNOTICE, and genie::XSecSplineList::SaveAsXml().

◆ PrintSyntax()

void PrintSyntax ( void )

Definition at line 195 of file gSplineAdd.cxx.

196{
197 LOG("gspladd", pNOTICE)
198 << "\n\n" << "Syntax:" << "\n"
199 << " gspladd -f file_list -d directory_list -o output.xml\n"
200 << " [--message-thresholds xml_file]\n";
201
202}

References LOG, and pNOTICE.

Referenced by GetCommandLineArgs().

Variable Documentation

◆ gAllFiles

vector<string> gAllFiles

list of all input files

Definition at line 84 of file gSplineAdd.cxx.

Referenced by GetCommandLineArgs(), and main().

◆ gInpDirs

vector<string> gInpDirs

list of input dirs (to look for XML files)

Definition at line 83 of file gSplineAdd.cxx.

Referenced by GetAllInputFiles(), and GetCommandLineArgs().

◆ gInpFiles

vector<string> gInpFiles

list of input XML files

Definition at line 82 of file gSplineAdd.cxx.

Referenced by GetAllInputFiles(), and GetCommandLineArgs().

◆ gOutFile

string gOutFile

output XML file

Definition at line 81 of file gSplineAdd.cxx.

Referenced by Close(), GetCommandLineArgs(), and main().