Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:30

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #include "TSystem.h"
0014 #include "TInterpreter.h"
0015 #include "DDG4/Python/DDPython.h"
0016 #include <vector>
0017 
0018 static int load_libs(const std::vector<char*>& libs)  {
0019   for(size_t i=0; i<libs.size(); ++i)   {
0020     int ret = gSystem->Load(libs[i]);
0021     if ( 0 != ret )   {
0022       ::printf("+++ Failed to load library: %s [ignored]\n",libs[i]);
0023       return ret;
0024     }
0025     else  {
0026       ::printf("+++ Successfully loaded library: %s\n",libs[i]);
0027     }
0028   }
0029   return 0;
0030 }
0031 
0032 int main(int argc, char** argv)   {
0033   bool have_prompt = false;
0034   bool do_execute = false;
0035   std::vector<char*> args;
0036   std::vector<char*> libs;
0037   int first_arg = 1;
0038   int ret;
0039 
0040   if ( argc>first_arg && strncmp(argv[first_arg],"-p",2)==0 )  {
0041     have_prompt = true;
0042     args.push_back(argv[0]);
0043     ++first_arg;
0044   }
0045   else if ( argc>first_arg && strncmp(argv[first_arg],"-e",2)==0 )  {
0046     do_execute = true;
0047     ++first_arg;
0048   }
0049   for(int i=first_arg; i<argc; ++i)  {
0050     if ( 0 == ::strcmp(argv[i],"-L") )
0051       libs.push_back(argv[++i]);
0052     else
0053       args.push_back(argv[i]);
0054   }
0055   if ( !have_prompt && args.size()>0 )  {
0056     libs.push_back((char*)"libDDG4Python");
0057     if ( 0 == (ret=load_libs(libs)) )   {
0058       dd4hep::DDPython::instance().setArgs(args.size(), &args[0]);
0059       dd4hep::DDPython::instance().setMainThread();
0060       dd4hep::DDPython::instance().runFile(args[0]);
0061       if ( do_execute )
0062         return gInterpreter->ProcessLine("PyDDG4::execute()");
0063       else 
0064         return 0;
0065     }
0066     return ret;
0067   }
0068   if ( 0 == (ret=load_libs(libs)) )   {
0069     ::printf("+++ Calling now Py_Main...\n");
0070     ret = dd4hep::DDPython::run_interpreter(args.size(), &args[0]);
0071     //::printf("+++ Return code Py_Main=%d\n",ret);
0072   }
0073   return ret;
0074 }