27 void usage(
int argc,
char** argv) {
29 "Usage: -plugin <name> -arg [-arg] \n"
30 " name: factory name DD4hep_Python \n"
31 " -import <string> import a python module, making its classes available.\n"
32 " -macro <string> load a python script as if it were a macro. \n"
33 " -exec <string> execute a python statement (e.g. \"import ROOT\". \n"
34 " -eval <string> evaluate a python expression (e.g. \"1+1\") \n"
35 " -prompt enter an interactive python session (exit with ^D) \n"
36 " -dd4hep Equivalent to -exec \"import dd4hep\" \n"
37 " -help Show this online help message. \n"
39 " Note: entries can be given multiple times and are executed in exactly the \n"
40 " order specified at the command line! \n"
42 "\tArguments given: " << arguments(argc,argv) << endl << flush;
54 long call_python(
Detector& ,
int argc,
char** argv) {
56 vector<pair<string, string> > commands;
57 for(
int i = 0; i < argc && argv[i]; ++i) {
58 if ( 0 == ::strncmp(
"-import",argv[i],2) )
59 commands.emplace_back(
"import",argv[++i]);
60 else if ( 0 == ::strncmp(
"-dd4hep", argv[i],2) )
61 commands.emplace_back(
"exec",
"import dd4hep");
62 else if ( 0 == ::strncmp(
"-macro", argv[i],2) )
63 commands.emplace_back(
"macro",argv[++i]);
64 else if ( 0 == ::strncmp(
"-exec", argv[i],2) )
65 commands.emplace_back(
"exec",argv[++i]);
66 else if ( 0 == ::strncmp(
"-eval", argv[i],2) )
67 commands.emplace_back(
"calc",argv[++i]);
68 else if ( 0 == ::strncmp(
"-prompt", argv[i],2) )
69 commands.emplace_back(
"prompt",
"");
73 if ( commands.empty() ) {
76 for(
const auto& c : commands) {
77 Bool_t result = kFALSE;
80 result = TPython::Import(c.second.c_str());
83 TPython::LoadMacro(c.second.c_str());
87 result = TPython::Exec(c.second.c_str());
91 TPython::Exec(c.second.c_str());
103 if ( result != kTRUE ) {
104 except(
"DD4hep_Python",
"+++ Failed to invoke the statement: %s",c.second.c_str());
109 except(
"DD4hep_Python",
"+++ No commands file name given.");