29 #include "Geant4/G4GDMLParser.hh" 
   70   = G4GDML_DEFAULT_SCHEMALOCATION;
 
   76     "\n  output file: '" << 
destPath << 
"'" 
   79     "\n  validate:     " << std::boolalpha << 
validate <<
 
   80     "\n  only read:    " << std::boolalpha << 
dontWrite <<
 
   81     "\n  overwrite:    " << std::boolalpha << 
overwrite <<
 
   82     "\n  print help:   " << std::boolalpha << 
help <<
 
  107     (
int exitCode = 0, 
const char* progName = 
"simplifyGDML");
 
  116   (
int exitCode , 
const char* progName )
 
  119       "Asks GEANT4 to process and rewrite a GDML file." 
  120       " This effectively simplifies the complexity of constructs in the GDML" 
  123     "\nUsage:  " << progName << 
"  [options] [--] inputPath [outputPath]" 
  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." 
  129     "\nNOTE: the path to the GDML schema in the output may need to be fixed by" 
  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:" 
  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\"" 
  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)" 
  145     "\n    not implemented yet" 
  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." 
  151       << 
"' setup is chosen." 
  152     "\n--schema=SCHEMAURL , -S SCHEMAURL" 
  153     "\n    path or URL to the schema to use for writing." 
  155       << 
"' schema is used." 
  157     "\n    print these usage instructions and exit" 
  166   static constexpr 
const char Schema    = 
'S';
 
  167   static constexpr 
const char Setup     = 
's';
 
  170   static constexpr 
const char Debug     = 
'd';
 
  171   static constexpr 
const char Help      = 
'h';
 
  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      },
 
  191   std::string shortopts = 
":"; 
 
  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 += 
':';
 
  202   error res = error::Success;
 
  205   bool forgiving = 
false;
 
  207     ((ch = getopt_long(argc, argv, shortopts.c_str(), longopts, NULL)) != -1)
 
  227           std::istringstream sstr(optarg);
 
  230             std::cerr << 
"Invalid debug level: '" << optarg << 
"'" << std::endl;
 
  231             res = error::InvalidNumber;
 
  241               << 
"Invalid option: '" << argv[optind-1] << 
"'" << std::endl;
 
  243           res = error::InvalidOption;
 
  252         std::cerr << 
"Internal error: option '" << ch << 
"' not supported yet." 
  254         res = error::LogicError;
 
  261   if (optind >= (
int) argc) {
 
  262     if (!forgiving) 
std::cerr << 
"Source file name is required!" << std::endl;
 
  263     return error::MissingArgument;
 
  266   if (optind < (
int) argc) params.
destPath = argv[optind++];
 
  268   if (optind < (
int) argc) {
 
  270       std::cerr << 
"Spurious arguments: '" << argv[optind] << 
"'";
 
  271       if (optind + 1 < (
int) argc)
 
  272         std::cerr << 
" and " << (argc - optind - 1) << 
" more";
 
  275     return error::ExtraArguments;
 
  284   auto const iExt = name.find(
".gdml");
 
  285   if (iExt == std::string::npos) name.append(suffix);
 
  286   else name.insert(iExt, suffix);
 
  291   return access(path.c_str(), F_OK);
 
  298   decltype(
auto) worldVolume = parser.GetWorldVolume(params.
setupName);
 
  300     std::cerr << 
"Failed to find the world volume for setup '" 
  309     << 
"\nFetching the world volume for setup '" << params.
setupName << 
"'..." 
  313     std::cerr << 
"Failed to find the world volume for setup '" 
  320       std::cout << 
"Overwriting the destination file..." << std::endl;
 
  325         << 
"' already exists." << std::endl;
 
  331     << 
"\nWriting '" << params.
destPath << 
"'..." << std::endl;
 
  333     (params.
destPath, worldVolume, 
false );
 
  345 int main(
int argc, 
char** argv) {
 
  372     << 
"\nReading '" << params.
sourcePath << 
"'..." << std::endl;
 
  376     << 
"\nFetching the world volume for setup '" << params.
setupName << 
"'..." 
  384       std::cerr << 
"Output path ignored since we don't write anything." 
  390     if (res != 0) 
return res;
 
xrootd XRootD root ROOT X Schema
then if[["$THISISATEST"==1]]
BEGIN_PROLOG could also be cerr
static constexpr const char Setup
std::string setupName
Name of the chosen setup in the GDML source. 
static const unsigned int DefaultDebugLevel
static constexpr const char Schema
static std::string const DefaultSetupName
bool overwrite
Overwrite the output file if already present. 
static constexpr const char Debug
static constexpr const char NoWrite
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
bool exists(std::string path)
bool help
Print usage instructions and exit. 
std::string destPath
GDML output file name. 
bool validate
Ask Geant4 to validate the source. 
static std::string const DefaultSchemaURL
std::string sourcePath
GDML input file name. 
static void printHelp(int exitCode=0, const char *progName="simplifyGDML")
static error parse(ConfigurationParameters ¶ms, unsigned int argc, char **argv)
G4VPhysicalVolume * readWorldVolume(G4GDMLParser &parser, ConfigurationParameters const ¶ms)
std::string addNameSuffix(std::string name, std::string suffix)
std::string schemaPath
URL of the schema used while writing GDML. 
bool dontWrite
Do not write the output file. 
unsigned int debugLevel
Debug level. 
static const unsigned int StartingDebugLevel
int main(int argc, char **argv)
int writeWorld(G4GDMLParser &parser, ConfigurationParameters const ¶ms)
BEGIN_PROLOG could also be cout
static constexpr const char Help
static constexpr const char Validate
static constexpr const char Overwrite