-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathpyddg4.cpp
74 lines (71 loc) · 2.19 KB
/
pyddg4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : M.Frank
//
//==========================================================================
#include "TSystem.h"
#include "TInterpreter.h"
#include "DDG4/Python/DDPython.h"
#include <vector>
static int load_libs(const std::vector<char*>& libs) {
for(size_t i=0; i<libs.size(); ++i) {
int ret = gSystem->Load(libs[i]);
if ( 0 != ret ) {
::printf("+++ Failed to load library: %s [ignored]\n",libs[i]);
return ret;
}
else {
::printf("+++ Successfully loaded library: %s\n",libs[i]);
}
}
return 0;
}
int main(int argc, char** argv) {
bool have_prompt = false;
bool do_execute = false;
std::vector<char*> args;
std::vector<char*> libs;
int first_arg = 1;
int ret;
if ( argc>first_arg && strncmp(argv[first_arg],"-p",2)==0 ) {
have_prompt = true;
args.push_back(argv[0]);
++first_arg;
}
else if ( argc>first_arg && strncmp(argv[first_arg],"-e",2)==0 ) {
do_execute = true;
++first_arg;
}
for(int i=first_arg; i<argc; ++i) {
if ( 0 == ::strcmp(argv[i],"-L") )
libs.push_back(argv[++i]);
else
args.push_back(argv[i]);
}
if ( !have_prompt && args.size()>0 ) {
libs.push_back((char*)"libDDG4Python");
if ( 0 == (ret=load_libs(libs)) ) {
dd4hep::DDPython::instance().setArgs(args.size(), &args[0]);
dd4hep::DDPython::instance().setMainThread();
dd4hep::DDPython::instance().runFile(args[0]);
if ( do_execute )
return gInterpreter->ProcessLine("PyDDG4::execute()");
else
return 0;
}
return ret;
}
if ( 0 == (ret=load_libs(libs)) ) {
::printf("+++ Calling now Py_Main...\n");
ret = dd4hep::DDPython::run_interpreter(args.size(), &args[0]);
//::printf("+++ Return code Py_Main=%d\n",ret);
}
return ret;
}