Skip to content
Snippets Groups Projects
initAClick.C 2.74 KiB
Newer Older
Markus Frank's avatar
Markus Frank committed
// $Id: $
//==========================================================================
//  AIDA Detector description implementation for LCD
//--------------------------------------------------------------------------
// 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
//
//==========================================================================

// ROOT include files
#include "TInterpreter.h"
#include "TSystem.h"
#include "RVersion.h"
Markus Frank's avatar
Markus Frank committed

// C/C++ include files
#include <iostream>
#include <string>

using namespace std;
string make_str(const char* data)  {
  if ( !data )   {
    cout << "make_str:  '" << (data ? data : "Bad-Pointer") << "'" << endl;
    return string("");
  }
  return string(data);
}
Markus Frank's avatar
Markus Frank committed
/// Process a single command in the ROOT interpreter
Markus Frank's avatar
Markus Frank committed
int processCommand(const char* command, bool end_process)   {
  int status;
  // Disabling auto-parse is a hack required by a bug in ROOT
  gInterpreter->SetClassAutoparsing(false);
  status = gInterpreter->ProcessLine(command);
  gInterpreter->SetClassAutoparsing(true);
  ::printf("+++ Status(%s) = %d\n",command,status);
  if ( end_process )  {
    gInterpreter->ProcessLine("gSystem->Exit(0)");
  }
Markus Frank's avatar
Markus Frank committed
  return status;
}

Markus Frank's avatar
Markus Frank committed
/// Process a ROOT AClick given a file
Markus Frank's avatar
Markus Frank committed
int processMacro(const char* macro, bool end_process)   {
  int status;
  string cmd = ".X ";
  cmd += macro;
  cmd += ".C+()";
  return processCommand(cmd.c_str(), end_process);
Markus Frank's avatar
Markus Frank committed
/// Initialize the ROOT environment to compile and execute a ROOT AClick
int initAClick(const char* command=0)  {
Markus Frank's avatar
Markus Frank committed
  string rootsys = make_str(gSystem->Getenv("ROOTSYS"));
  string g4_base = make_str(gSystem->Getenv("G4INSTALL"));
  string dd4hep  = make_str(gSystem->Getenv("DD4hepINSTALL"));
Markus Frank's avatar
Markus Frank committed
  string libs = (" -L"+rootsys+"/lib");
  string inc  = " -I"+dd4hep+"/examples/DDG4/examples" +
    " -I"+dd4hep +
    " -I"+dd4hep+"/include" +
    " -I"+g4_base+"/include/Geant4" +
    " -Wno-shadow -g -O0";
  if ( ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) )
    libs += " -lCore -lMathCore";
  else
    libs += " -lCore -lCint -lMathCore";
  libs += " -pthread -lm -ldl -rdynamic";
  libs += " -L"+dd4hep+"/lib -lDDCore -lDDG4 -lDDSegmentation";
Markus Frank's avatar
Markus Frank committed
  libs += (" -L"+g4_base+"/lib -L"+g4_base+"/lib64 -lG4event -lG4tracking -lG4particles");
  gSystem->AddIncludePath(inc.c_str());
  gSystem->AddLinkedLibs(libs.c_str());
Markus Frank's avatar
Markus Frank committed
  cout << "+++ Includes:   " << gSystem->GetIncludePath() << endl;
  cout << "+++ Linked libs:" << gSystem->GetLinkedLibs()  << endl;
  int ret = gSystem->Load("libDDG4Plugins");
  if ( 0 == ret )   {
    if ( command )  {
Markus Frank's avatar
Markus Frank committed
      processCommand(command, true);
  return ret;