Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:19

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 
0014 // ROOT include files
0015 #include "TInterpreter.h"
0016 #include "TSystem.h"
0017 #include "RVersion.h"
0018 
0019 // C/C++ include files
0020 #include <iostream>
0021 #include <string>
0022 
0023 std::string make_str(const char* data)  {
0024   if ( !data )   {
0025     std::cout << "make_str:  '" << (data ? data : "Bad-Pointer") << "'" << std::endl;
0026     return std::string("");
0027   }
0028   return std::string(data);
0029 }
0030 
0031 /// Process a single command in the ROOT interpreter
0032 int processCommand(const char* command, bool end_process)   {
0033   int status;
0034   // Disabling auto-parse is a hack required by a bug in ROOT
0035   gInterpreter->SetClassAutoparsing(false);
0036   status = gInterpreter->ProcessLine(command);
0037   gInterpreter->SetClassAutoparsing(true);
0038   ::printf("+++ Status(%s) = %d\n",command,status);
0039   if ( end_process )  {
0040     gInterpreter->ProcessLine("gSystem->Exit(0)");
0041   }
0042   return status;
0043 }
0044 
0045 /// Process a ROOT AClick given a file
0046 int processMacro(const char* macro, bool end_process)   {
0047   std::string cmd = ".X ";
0048   cmd += macro;
0049   cmd += ".C+()";
0050   return processCommand(cmd.c_str(), end_process);
0051 }
0052 
0053 /// Initialize the ROOT environment to compile and execute a ROOT AClick
0054 int initAClick(const char* command=0)  {
0055   std::string rootsys = make_str(gSystem->Getenv("ROOTSYS"));
0056   std::string geant4  = make_str(gSystem->Getenv("G4INSTALL"));
0057   std::string dd4hep  = make_str(gSystem->Getenv("DD4hepINSTALL"));
0058   std::string clhep   = make_str(gSystem->Getenv("CLHEP_ROOT_DIR"));
0059   std::string defs    = "";
0060   // lib/root is used in spack (key4hep)
0061   std::string libs    = " -L"+rootsys+"/lib" + " -L"+rootsys+"/lib/root";
0062   std::string inc     = " -I"+dd4hep+"/examples/DDG4/examples -I"+dd4hep + " -I"+dd4hep+"/include ";
0063   std::string ext = "so";
0064   if ( !geant4.empty() )  {
0065     inc  += " -I"+geant4+"/include/Geant4";
0066 #ifdef __APPLE__
0067     libs += (" -L"+geant4+"/lib");
0068     ext = "dylib";
0069 #else
0070     libs += (" -L"+geant4+"/lib -L"+geant4+"/lib64");
0071 #endif
0072   }
0073   if ( !clhep.empty() )  {
0074     // A bit unclear how to deal with CLHEP libraries here, 
0075     // if CLHEP is not included in Geant4...
0076     inc += " -I"+clhep+"/include";
0077     std::string clhep_lib = make_str(gSystem->Getenv("CLHEP_LIBRARY_PATH"));
0078     if ( !clhep_lib.empty() ) libs += " -L"+clhep_lib+"/lib";
0079   }
0080   inc += " -Wno-shadow -g -O0" + defs;
0081 #ifndef __APPLE__
0082   libs += " -lCore -lMathCore -pthread -lm -ldl -rdynamic";
0083 #endif
0084   //libs += " " +dd4hep+"/lib/libDD4hepGaudiPluginMgr." + ext;
0085   //libs += " " +dd4hep+"/lib/libDDCore."+ ext;
0086   //libs += " " +dd4hep+"/lib/libDDG4."+ ext;
0087   libs += " -L" +dd4hep+"/lib ";  // -lDD4hepGaudiPluginMgr -lDDCore -lDDG4";
0088 #ifdef __APPLE__
0089   int ret = gSystem->Load("libDD4hepGaudiPluginMgr");
0090 #else
0091   //int ret = gSystem->Load("libDDG4Plugins");
0092   int ret = gSystem->Load("libDD4hepGaudiPluginMgr");
0093 #endif
0094   gSystem->AddIncludePath(inc.c_str());
0095   gSystem->AddLinkedLibs(libs.c_str());
0096   std::cout << "+++ Includes:   " << gSystem->GetIncludePath() << std::endl;
0097   std::cout << "+++ Linked libs:" << gSystem->GetLinkedLibs()  << std::endl;
0098   if ( command )  {
0099     processCommand(command, true);
0100   }
0101   return ret;
0102 }