Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:38:17

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     = "";
0063   inc += " -I" + dd4hep + "/examples/LHeD/scripts ";
0064   inc += " -I" + dd4hep;
0065   inc += " -I" + dd4hep + "/include ";
0066   inc += " -I" + clhep  + "/include ";
0067   inc += " -I" + geant4 + "/include ";
0068 
0069   std::string ext = "so";
0070   if ( !geant4.empty() )  {
0071     inc  += " -I"+geant4+"/include/Geant4";
0072 #ifdef __APPLE__
0073     libs += (" -L"+geant4+"/lib");
0074     ext = "dylib";
0075 #else
0076     libs += (" -L"+geant4+"/lib -L"+geant4+"/lib64");
0077 #endif
0078   }
0079   if ( !clhep.empty() )  {
0080     // A bit unclear how to deal with CLHEP libraries here, 
0081     // if CLHEP is not included in Geant4...
0082     inc += " -I"+clhep+"/include";
0083     std::string clhep_lib = make_str(gSystem->Getenv("CLHEP_LIBRARY_PATH"));
0084     if ( !clhep_lib.empty() ) libs += " -L"+clhep_lib+"/lib";
0085   }
0086   inc += " -Wno-shadow -g -O0" + defs;
0087 #ifndef __APPLE__
0088   libs += " -lCore -lMathCore -pthread -lm -ldl -rdynamic";
0089 #endif
0090   libs += " " +dd4hep+"/lib/libDD4hepGaudiPluginMgr." + ext;
0091   libs += " " +dd4hep+"/lib/libDDCore." + ext;
0092   libs += " " +dd4hep+"/lib/libDDG4." + ext;
0093 #ifdef __APPLE__
0094   gSystem->Load("libDD4hepGaudiPluginMgr");
0095 #endif
0096   gSystem->AddIncludePath(inc.c_str());
0097   gSystem->AddLinkedLibs(libs.c_str());
0098   std::cout << "+++ Includes:   " << gSystem->GetIncludePath() << std::endl;
0099   std::cout << "+++ Linked libs:" << gSystem->GetLinkedLibs()  << std::endl;
0100   int ret = 0;  // gSystem->Load("libDDG4Plugins");
0101   if ( 0 == ret )   {
0102     if ( command )  {
0103       processCommand(command, true);
0104     }
0105   }
0106   return ret;
0107 }