Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve help replies (See issue 1409) #1416

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion UtilityApps/src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ int main(int argc,char** argv) {
if ( i==1 && argv[i][0] != '-' ) av.emplace_back("-input");
if ( strncmp(argv[i],"-load-only",4) == 0 ) dry = true, av.emplace_back(argv[i]);
else if ( strncmp(argv[i],"-dry-run",4) == 0 ) dry = true, av.emplace_back(argv[i]);
else if ( strncmp(argv[i],"-help",4) == 0 ) help = true, av.emplace_back(argv[i]);
else if ( strncmp(argv[i],"-h",2) == 0 ) help = true;
else if ( strncmp(argv[i],"-help",4) == 0 ) help = true;
else if ( strncmp(argv[i],"--help",4) == 0 ) help = true;
else if ( strncmp(argv[i],"-visopt",4) == 0 ) visopt = argv[++i];
else if ( strncmp(argv[i],"-level", 4) == 0 ) level = argv[++i];
else if ( strncmp(argv[i],"-option",4) == 0 ) opt = argv[++i];
Expand Down
46 changes: 27 additions & 19 deletions UtilityApps/src/run_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ namespace {

//______________________________________________________________________________
struct Args {
bool volmgr, dry_run, destroy, interpreter, ui;
dd4hep::PrintLevel print;
bool volmgr, dry_run, destroy, interpreter, ui, help;
dd4hep::PrintLevel print;
std::vector<const char*> geo_files, build_types;
std::vector<std::vector<const char*> > plugins;

//____________________________________________________________________________
Args() {
help = false;
ui = false;
volmgr = false;
dry_run = false;
Expand All @@ -148,6 +149,10 @@ namespace {
build_types.emplace_back("BUILD_DEFAULT");
}
}
else if ( ::strncmp(argv[i],"-help",5)==0 )
help = true;
else if ( ::strncmp(argv[i],"--help",6)==0 )
help = true;
else if ( ::strncmp(argv[i],"-load_only",5)==0 )
dry_run = true;
else if ( ::strncmp(argv[i],"-dry-run",5)==0 )
Expand Down Expand Up @@ -315,55 +320,58 @@ namespace dd4hep {
Args arguments;
arguments.interpreter = false;

for(int i=1; i<argc;++i) {
if ( argv[i][0]=='-' ) {
for( int i=1; i < argc; ++i ) {
if( argv[i][0]=='-' ) {
if ( arguments.handle(i,argc,argv) )
continue;
}
else {
usage_plugin_runner();
}
}
if ( !arguments.dry_run &&
if( !arguments.dry_run &&
!arguments.ui &&
!arguments.interpreter &&
arguments.plugins.empty() &&
arguments.geo_files.empty() )
{
usage_plugin_runner();
}
if( arguments.help ) {
usage_plugin_runner();
}
std::unique_ptr<TRint> interpreter;
dd4hep::Detector& description = dd4hep_instance();
// Load compact files if required by plugin
if ( !arguments.geo_files.empty() ) {
if( !arguments.geo_files.empty() ) {
load_compact(description, arguments);
}
else {
std::cout << "geoPluginRun: No geometry input supplied. "
<< "No geometry will be loaded." << std::endl << std::flush;
}
// Attach UI instance if requested to ease interaction from the ROOT prompt
if ( arguments.ui ) {
if( arguments.ui ) {
run_plugin(description,"DD4hep_InteractiveUI",0,0);
}
// Create volume manager and populate it required
if ( arguments.volmgr ) {
if( arguments.volmgr ) {
run_plugin(description,"DD4hep_VolumeManager",0,0);
}
if ( arguments.interpreter ) {
if( arguments.interpreter ) {
std::pair<int, char**> a(0,0);
interpreter.reset(new TRint("geoPluginRun", &a.first, a.second));
}
// Execute plugin
for(size_t i=0; i<arguments.plugins.size(); ++i) {
for( size_t i=0; i < arguments.plugins.size(); ++i ) {
std::vector<const char*>& plug = arguments.plugins[i];
int num_args = int(plug.size())-2;
TTimeStamp start;
char text[32];
long result = run_plugin(description, plug[0], num_args, (char**)&plug[1]);
TTimeStamp stop;
::snprintf(text,sizeof(text),"[%8.3f sec]",stop.AsDouble()-start.AsDouble());
if ( result == EINVAL ) {
if (result == EINVAL ) {
std::cout << "geoPluginRun: FAILED to execute dd4hep plugin: '" << plug[0]
<< "' with args (" << num_args << ") :[ ";
for(size_t j = 1; j < plug.size(); ++j) {
Expand All @@ -374,33 +382,33 @@ namespace dd4hep {
}
std::cout << "geoPluginRun: " << text <<" Executed dd4hep plugin: '" << plug[0]
<< "' with args (" << num_args << ") :[ ";
for(size_t j=1; j<plug.size(); ++j) {
for( size_t j=1; j < plug.size(); ++j ) {
if ( plug[j] ) std::cout << plug[j] << " ";
}
std::cout << "]" << std::endl << std::flush;
}
if ( arguments.plugins.empty() ) {
if( arguments.plugins.empty() ) {
// Create an interactive ROOT application
if ( !arguments.dry_run ) {
if( !arguments.dry_run ) {
long result = 0;
std::pair<int, char**> a(0,0);
if ( arguments.interpreter ) {
if( arguments.interpreter ) {
TRint app(name, &a.first, a.second);
result = arguments.run(description, name);
if ( result != EINVAL ) app.Run();
if( result != EINVAL ) app.Run();
}
else
result = arguments.run(description, name);
if ( result == EINVAL ) usage_default(name);
if( result == EINVAL ) usage_default(name);
}
else {
else {
std::cout << "The geometry was loaded. Application now exiting." << std::endl;
}
}
if ( !arguments.dry_run && interpreter.get() ) {
interpreter->Run();
}
try {
try {
if ( arguments.destroy ) description.destroyInstance();
}
catch(const std::exception& e) {
Expand Down
Loading