DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
pyddg4.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #include "TSystem.h"
14 #include "TInterpreter.h"
15 #include "DDG4/Python/DDPython.h"
16 #include <vector>
17 
18 static int load_libs(const std::vector<char*>& libs) {
19  for(size_t i=0; i<libs.size(); ++i) {
20  int ret = gSystem->Load(libs[i]);
21  if ( 0 != ret ) {
22  ::printf("+++ Failed to load library: %s [ignored]\n",libs[i]);
23  return ret;
24  }
25  else {
26  ::printf("+++ Successfully loaded library: %s\n",libs[i]);
27  }
28  }
29  return 0;
30 }
31 
32 int main(int argc, char** argv) {
33  bool have_prompt = false;
34  bool do_execute = false;
35  std::vector<char*> args;
36  std::vector<char*> libs;
37  int first_arg = 1;
38  int ret;
39 
40  if ( argc>first_arg && strncmp(argv[first_arg],"-p",2)==0 ) {
41  have_prompt = true;
42  args.push_back(argv[0]);
43  ++first_arg;
44  }
45  else if ( argc>first_arg && strncmp(argv[first_arg],"-e",2)==0 ) {
46  do_execute = true;
47  ++first_arg;
48  }
49  for(int i=first_arg; i<argc; ++i) {
50  if ( 0 == ::strcmp(argv[i],"-L") )
51  libs.push_back(argv[++i]);
52  else
53  args.push_back(argv[i]);
54  }
55  if ( !have_prompt && args.size()>0 ) {
56  libs.push_back((char*)"libDDG4Python");
57  if ( 0 == (ret=load_libs(libs)) ) {
58  dd4hep::DDPython::instance().setArgs(args.size(), &args[0]);
61  if ( do_execute )
62  return gInterpreter->ProcessLine("PyDDG4::execute()");
63  else
64  return 0;
65  }
66  return ret;
67  }
68  if ( 0 == (ret=load_libs(libs)) ) {
69  ::printf("+++ Calling now Py_Main...\n");
70  ret = dd4hep::DDPython::run_interpreter(args.size(), &args[0]);
71  //::printf("+++ Return code Py_Main=%d\n",ret);
72  }
73  return ret;
74 }
dd4hep::DDPython::setMainThread
static void setMainThread()
Definition: DDPython.cpp:324
dd4hep::DDPython::run_interpreter
static int run_interpreter(int argc, char **argv)
Start the interpreter in normal mode without hacks like 'python.exe' does.
Definition: DDPython.cpp:333
dd4hep::DDPython::setArgs
int setArgs(int argc, char **argv) const
Definition: DDPython.cpp:209
DDPython.h
dd4hep::DDPython::instance
static DDPython instance()
Object instantiator.
Definition: DDPython.cpp:190
dd4hep::DDPython::runFile
int runFile(const std::string &fname) const
Definition: DDPython.cpp:248
main
int main(int argc, char **argv)
Definition: pyddg4.cpp:32