Skip to content

Commit db315ad

Browse files
Improve help replies (See issue #1409)
1 parent 55af2dd commit db315ad

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

UtilityApps/src/display.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ int main(int argc,char** argv) {
2323
if ( i==1 && argv[i][0] != '-' ) av.emplace_back("-input");
2424
if ( strncmp(argv[i],"-load-only",4) == 0 ) dry = true, av.emplace_back(argv[i]);
2525
else if ( strncmp(argv[i],"-dry-run",4) == 0 ) dry = true, av.emplace_back(argv[i]);
26-
else if ( strncmp(argv[i],"-help",4) == 0 ) help = true, av.emplace_back(argv[i]);
26+
else if ( strncmp(argv[i],"-h",2) == 0 ) help = true;
27+
else if ( strncmp(argv[i],"-help",4) == 0 ) help = true;
28+
else if ( strncmp(argv[i],"--help",4) == 0 ) help = true;
2729
else if ( strncmp(argv[i],"-visopt",4) == 0 ) visopt = argv[++i];
2830
else if ( strncmp(argv[i],"-level", 4) == 0 ) level = argv[++i];
2931
else if ( strncmp(argv[i],"-option",4) == 0 ) opt = argv[++i];

UtilityApps/src/run_plugin.h

+27-19
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,14 @@ namespace {
121121

122122
//______________________________________________________________________________
123123
struct Args {
124-
bool volmgr, dry_run, destroy, interpreter, ui;
125-
dd4hep::PrintLevel print;
124+
bool volmgr, dry_run, destroy, interpreter, ui, help;
125+
dd4hep::PrintLevel print;
126126
std::vector<const char*> geo_files, build_types;
127127
std::vector<std::vector<const char*> > plugins;
128128

129129
//____________________________________________________________________________
130130
Args() {
131+
help = false;
131132
ui = false;
132133
volmgr = false;
133134
dry_run = false;
@@ -148,6 +149,10 @@ namespace {
148149
build_types.emplace_back("BUILD_DEFAULT");
149150
}
150151
}
152+
else if ( ::strncmp(argv[i],"-help",5)==0 )
153+
help = true;
154+
else if ( ::strncmp(argv[i],"--help",6)==0 )
155+
help = true;
151156
else if ( ::strncmp(argv[i],"-load_only",5)==0 )
152157
dry_run = true;
153158
else if ( ::strncmp(argv[i],"-dry-run",5)==0 )
@@ -315,55 +320,58 @@ namespace dd4hep {
315320
Args arguments;
316321
arguments.interpreter = false;
317322

318-
for(int i=1; i<argc;++i) {
319-
if ( argv[i][0]=='-' ) {
323+
for( int i=1; i < argc; ++i ) {
324+
if( argv[i][0]=='-' ) {
320325
if ( arguments.handle(i,argc,argv) )
321326
continue;
322327
}
323328
else {
324329
usage_plugin_runner();
325330
}
326331
}
327-
if ( !arguments.dry_run &&
332+
if( !arguments.dry_run &&
328333
!arguments.ui &&
329334
!arguments.interpreter &&
330335
arguments.plugins.empty() &&
331336
arguments.geo_files.empty() )
332337
{
333338
usage_plugin_runner();
334339
}
340+
if( arguments.help ) {
341+
usage_plugin_runner();
342+
}
335343
std::unique_ptr<TRint> interpreter;
336344
dd4hep::Detector& description = dd4hep_instance();
337345
// Load compact files if required by plugin
338-
if ( !arguments.geo_files.empty() ) {
346+
if( !arguments.geo_files.empty() ) {
339347
load_compact(description, arguments);
340348
}
341349
else {
342350
std::cout << "geoPluginRun: No geometry input supplied. "
343351
<< "No geometry will be loaded." << std::endl << std::flush;
344352
}
345353
// Attach UI instance if requested to ease interaction from the ROOT prompt
346-
if ( arguments.ui ) {
354+
if( arguments.ui ) {
347355
run_plugin(description,"DD4hep_InteractiveUI",0,0);
348356
}
349357
// Create volume manager and populate it required
350-
if ( arguments.volmgr ) {
358+
if( arguments.volmgr ) {
351359
run_plugin(description,"DD4hep_VolumeManager",0,0);
352360
}
353-
if ( arguments.interpreter ) {
361+
if( arguments.interpreter ) {
354362
std::pair<int, char**> a(0,0);
355363
interpreter.reset(new TRint("geoPluginRun", &a.first, a.second));
356364
}
357365
// Execute plugin
358-
for(size_t i=0; i<arguments.plugins.size(); ++i) {
366+
for( size_t i=0; i < arguments.plugins.size(); ++i ) {
359367
std::vector<const char*>& plug = arguments.plugins[i];
360368
int num_args = int(plug.size())-2;
361369
TTimeStamp start;
362370
char text[32];
363371
long result = run_plugin(description, plug[0], num_args, (char**)&plug[1]);
364372
TTimeStamp stop;
365373
::snprintf(text,sizeof(text),"[%8.3f sec]",stop.AsDouble()-start.AsDouble());
366-
if ( result == EINVAL ) {
374+
if (result == EINVAL ) {
367375
std::cout << "geoPluginRun: FAILED to execute dd4hep plugin: '" << plug[0]
368376
<< "' with args (" << num_args << ") :[ ";
369377
for(size_t j = 1; j < plug.size(); ++j) {
@@ -374,33 +382,33 @@ namespace dd4hep {
374382
}
375383
std::cout << "geoPluginRun: " << text <<" Executed dd4hep plugin: '" << plug[0]
376384
<< "' with args (" << num_args << ") :[ ";
377-
for(size_t j=1; j<plug.size(); ++j) {
385+
for( size_t j=1; j < plug.size(); ++j ) {
378386
if ( plug[j] ) std::cout << plug[j] << " ";
379387
}
380388
std::cout << "]" << std::endl << std::flush;
381389
}
382-
if ( arguments.plugins.empty() ) {
390+
if( arguments.plugins.empty() ) {
383391
// Create an interactive ROOT application
384-
if ( !arguments.dry_run ) {
392+
if( !arguments.dry_run ) {
385393
long result = 0;
386394
std::pair<int, char**> a(0,0);
387-
if ( arguments.interpreter ) {
395+
if( arguments.interpreter ) {
388396
TRint app(name, &a.first, a.second);
389397
result = arguments.run(description, name);
390-
if ( result != EINVAL ) app.Run();
398+
if( result != EINVAL ) app.Run();
391399
}
392400
else
393401
result = arguments.run(description, name);
394-
if ( result == EINVAL ) usage_default(name);
402+
if( result == EINVAL ) usage_default(name);
395403
}
396-
else {
404+
else {
397405
std::cout << "The geometry was loaded. Application now exiting." << std::endl;
398406
}
399407
}
400408
if ( !arguments.dry_run && interpreter.get() ) {
401409
interpreter->Run();
402410
}
403-
try {
411+
try {
404412
if ( arguments.destroy ) description.destroyInstance();
405413
}
406414
catch(const std::exception& e) {

0 commit comments

Comments
 (0)