All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Static Public Member Functions | Static Public Attributes | List of all members
ConfigurationParser Struct Reference

Classes

struct  opt
 

Public Types

enum  error {
  Success, InvalidNumber, InvalidOption, LogicError,
  ExtraArguments, MissingArgument
}
 

Static Public Member Functions

static error parse (ConfigurationParameters &params, unsigned int argc, char **argv)
 
static void printHelp (int exitCode=0, const char *progName="simplifyGDML")
 

Static Public Attributes

static const unsigned int DefaultDebugLevel = 1
 

Detailed Description

Definition at line 90 of file simplifyGDML.cc.

Member Enumeration Documentation

Member Function Documentation

ConfigurationParser::error ConfigurationParser::parse ( ConfigurationParameters params,
unsigned int  argc,
char **  argv 
)
static

Definition at line 175 of file simplifyGDML.cc.

176 {
177  static const option longopts[] = {
178  { "validate", no_argument, NULL, opt::Validate },
179  { "schema", required_argument, NULL, opt::Schema },
180  { "setup", required_argument, NULL, opt::Setup },
181  { "overwrite", no_argument, NULL, opt::Overwrite },
182  { "nowrite", no_argument, NULL, opt::NoWrite },
183  { "debug", optional_argument, NULL, opt::Debug },
184  { "help", no_argument, NULL, opt::Help },
185 // { "one", no_argument, &value, 1 },
186 // { "two", no_argument, &value, 2 },
187  { NULL, 0, NULL, 0 }
188  }; // longopts
189 
190  // automatically build the short option string from the long one
191  std::string shortopts = ":"; // this means no error printout
192  for (auto const& longopt: longopts) {
193  if (!longopt.name) break;
194  if (longopt.val == 0) continue;
195  shortopts += (char) longopt.val;
196  if (longopt.has_arg != no_argument) shortopts += ':';
197  if (longopt.has_arg == optional_argument) shortopts += ':';
198  } // for
199 
200  // ----------------------------------------------------------------------
201  // options
202  error res = error::Success;
203  char ch;
204  optind = 1;
205  bool forgiving = false;
206  while
207  ((ch = getopt_long(argc, argv, shortopts.c_str(), longopts, NULL)) != -1)
208  {
209  switch (ch) {
210  case opt::Validate:
211  params.validate = true;
212  continue;
213  case opt::Setup:
214  params.setupName = optarg;
215  continue;
216  case opt::Schema:
217  params.schemaPath = optarg;
218  continue;
219  case opt::Overwrite:
220  params.overwrite = true;
221  continue;
222  case opt::NoWrite:
223  params.dontWrite = true;
224  continue;
225  case opt::Debug:
226  if (optarg) {
227  std::istringstream sstr(optarg);
228  sstr >> params.debugLevel;
229  if (!sstr) {
230  std::cerr << "Invalid debug level: '" << optarg << "'" << std::endl;
231  res = error::InvalidNumber;
232  continue;
233  }
234  }
235  else params.debugLevel = DefaultDebugLevel;
236  continue;
237  case '?': // this is special since has a specific meaning for getopt()
238  if (optopt != '?') {
239  if (!forgiving) {
240  std::cerr
241  << "Invalid option: '" << argv[optind-1] << "'" << std::endl;
242  }
243  res = error::InvalidOption;
244  continue;
245  }
246  // follow into:
247  case opt::Help:
248  params.help = true;
249  forgiving = true;
250  continue;
251  default:
252  std::cerr << "Internal error: option '" << ch << "' not supported yet."
253  << std::endl;
254  res = error::LogicError;
255  continue;
256  } // switch
257  } // while
258 
259  // ----------------------------------------------------------------------
260  // arguments
261  if (optind >= (int) argc) {
262  if (!forgiving) std::cerr << "Source file name is required!" << std::endl;
263  return error::MissingArgument;
264  }
265  params.sourcePath = argv[optind++];
266  if (optind < (int) argc) params.destPath = argv[optind++];
267 
268  if (optind < (int) argc) {
269  if (!forgiving) {
270  std::cerr << "Spurious arguments: '" << argv[optind] << "'";
271  if (optind + 1 < (int) argc)
272  std::cerr << " and " << (argc - optind - 1) << " more";
273  std::cerr << "." << std::endl;
274  }
275  return error::ExtraArguments;
276  }
277 
278  // ----------------------------------------------------------------------
279  return res;
280 } // ConfigurationParser::parse()
then if[["$THISISATEST"==1]]
Definition: neoSmazza.sh:95
BEGIN_PROLOG could also be cerr
static constexpr const char Setup
std::string setupName
Name of the chosen setup in the GDML source.
Definition: simplifyGDML.cc:53
static const unsigned int DefaultDebugLevel
Definition: simplifyGDML.cc:92
static constexpr const char Schema
bool overwrite
Overwrite the output file if already present.
Definition: simplifyGDML.cc:59
static constexpr const char Debug
static constexpr const char NoWrite
bool help
Print usage instructions and exit.
Definition: simplifyGDML.cc:61
std::string destPath
GDML output file name.
Definition: simplifyGDML.cc:50
bool validate
Ask Geant4 to validate the source.
Definition: simplifyGDML.cc:58
std::string sourcePath
GDML input file name.
Definition: simplifyGDML.cc:49
std::string schemaPath
URL of the schema used while writing GDML.
Definition: simplifyGDML.cc:56
bool dontWrite
Do not write the output file.
Definition: simplifyGDML.cc:60
unsigned int debugLevel
Debug level.
Definition: simplifyGDML.cc:62
echo Invalid option
Definition: TrainMVA.sh:17
static constexpr const char Help
static constexpr const char Validate
static constexpr const char Overwrite
void ConfigurationParser::printHelp ( int  exitCode = 0,
const char *  progName = "simplifyGDML" 
)
static

Definition at line 116 of file simplifyGDML.cc.

117 {
118  std::cout <<
119  "Asks GEANT4 to process and rewrite a GDML file."
120  " This effectively simplifies the complexity of constructs in the GDML"
121  " code."
122  "\n"
123  "\nUsage: " << progName << " [options] [--] inputPath [outputPath]"
124  "\n"
125  "\nThe output file will contain the world volume of the specified setup."
126  "\nIt must be different from the input file:"
127  " GEANT4 will refuse to overwrite."
128  "\n"
129  "\nNOTE: the path to the GDML schema in the output may need to be fixed by"
130  " hand."
131  "\nTo allow validation, the GDML schema must be present as described in the"
132  " header of the GDML file."
133  "\nLArSoft does not necessarily distributes GDML schema, so these lines"
134  " are aimed to load them from network:"
135  "\n"
136  "\n<gdml xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
137  "\n xsi:noNamespaceSchemaLocation=\"http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd\""
138  "\n >"
139  "\n"
140  "\nOptions:"
141  "\n--validate , -V"
142  "\n ask Geant4 to validated the GDML while reading (validation output"
143  "\n will be on screen, with no effect to the rest of the program)"
144  "\n--overwrite , -f"
145  "\n not implemented yet"
146  "\n--nowrite , -r"
147  "\n only read (and validate as requested), do not write a new GDML file"
148  "\n--setup=SETUPNAME , -s SETUPNAME"
149  "\n name of path or URL to the schema to use for writing."
150  "\n By default, the '" << ConfigurationParameters::DefaultSetupName
151  << "' setup is chosen."
152  "\n--schema=SCHEMAURL , -S SCHEMAURL"
153  "\n path or URL to the schema to use for writing."
154  "\n By default, the '" << ConfigurationParameters::DefaultSchemaURL
155  << "' schema is used."
156  "\n--help , -h , -?"
157  "\n print these usage instructions and exit"
158  "\n"
159  << std::endl;
160  if (exitCode >= 0) std::exit(exitCode);
161 } // ConfigurationParser::printHelp()
static std::string const DefaultSetupName
Definition: simplifyGDML.cc:46
static std::string const DefaultSchemaURL
Definition: simplifyGDML.cc:47
BEGIN_PROLOG could also be cout

Member Data Documentation

const unsigned int ConfigurationParser::DefaultDebugLevel = 1
static

Definition at line 92 of file simplifyGDML.cc.


The documentation for this struct was generated from the following file: