GENIEGenerator
Loading...
Searching...
No Matches
gSplineAdd.cxx
Go to the documentation of this file.
1//____________________________________________________________________________
2/*!
3
4\program gspladd
5
6\brief Merges XML files containing GENIE cross section splines
7
8 Syntax :
9 gspladd -f file_list -d directory_list -o output.xml
10 [--message-thresholds xml_file]
11
12 Options :
13 -f
14 A list of input xml cross-section files. If more than one then
15 separate using commas.
16 -d
17 A list of input directories where to look for xml cross section
18 files. If more than one then separate using commas.
19 -o
20 output xml file
21 --message-thresholds
22 Allows users to customize the message stream thresholds.
23 The thresholds are specified using an XML file.
24 See $GENIE/config/Messenger.xml for the XML schema.
25
26 Notes :
27 There must be at least 2 files for the merges to work
28
29 Examples :
30
31 1) shell% gspladd -f xsec_Fe56.xml,xsec_O16.xml -o xsec.xml
32
33 will merge xsec_Fe56.xml and xsec_O16.xml into a single file
34 named xsec_all.xml
35
36 2) shell% gspladd -f xsec_Fe56.xml -d /path,/other_path -o xsec.xml
37
38 will merge xsec_Fe56.xml with all the xml cross-section files that
39 can be found in the /path and /other_path directories and write-out
40 a single file named xsec_all.xml
41
42\author Costas Andreopoulos <c.andreopoulos \at cern.ch>
43 Rutherford Appleton Laboratory
44
45\created July 05, 2007
46
47\cpright Copyright (c) 2003-2025, The GENIE Collaboration
48 For the full text of the license visit http://copyright.genie-mc.org
49
50*/
51//____________________________________________________________________________
52
53#include <cassert>
54#include <sstream>
55#include <string>
56#include <vector>
57
58#include <TSystem.h>
59
69
70using std::string;
71using std::vector;
72using std::ostringstream;
73
74using namespace genie;
75
76vector<string> GetAllInputFiles (void);
77void GetCommandLineArgs (int argc, char ** argv);
78void PrintSyntax (void);
79
80//User-specified options:
81string gOutFile; ///< output XML file
82vector<string> gInpFiles; ///< list of input XML files
83vector<string> gInpDirs; ///< list of input dirs (to look for XML files)
84vector<string> gAllFiles; ///< list of all input files
85
86//____________________________________________________________________________
87int main(int argc, char ** argv)
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}
111//____________________________________________________________________________
112vector<string> GetAllInputFiles(void)
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}
142//____________________________________________________________________________
143void GetCommandLineArgs(int argc, char ** argv)
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}
194//____________________________________________________________________________
195void PrintSyntax(void)
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}
203//____________________________________________________________________________
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
#define pFATAL
Definition Messenger.h:56
#define pDEBUG
Definition Messenger.h:63
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
int main()
Command line argument parser.
string ArgAsString(char opt)
bool OptionExists(char opt)
was option set?
void ReadFromCommandLine(int argc, char **argv)
Definition RunOpt.cxx:99
static RunOpt * Instance(void)
Definition RunOpt.cxx:54
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()
vector< string > gAllFiles
list of all input files
vector< string > gInpFiles
list of input XML files
vector< string > gInpDirs
list of input dirs (to look for XML files)
void GetCommandLineArgs(int argc, char **argv)
vector< string > GetAllInputFiles(void)
void PrintSyntax(void)
string gOutFile
output XML file
void MesgThresholds(string inpfile)
Definition AppInit.cxx:99
vector< string > Split(string input, string delim)
vector< string > GetAllFilesInPath(string path, string extension="")
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
enum genie::EXmlParseStatus XmlParserStatus_t