VMC Examples Version 6.6
Loading...
Searching...
No Matches
g4libs.C File Reference

Macro for loading Geant4 and Geant4 VMC libraries. More...

#include <iostream>
#include <TSystem.h>
#include <TString.h>
#include <TApplication.h>
#include <TROOT.h>
#include <string>
Include dependency graph for g4libs.C:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  g4libUtilities
 

Functions

Bool_t g4libUtilities::isLibrary (const char *libName)
 
void loadg4libs ()
 
Bool_t isBatch ()
 
Bool_t isSet (const char *variable)
 
Bool_t isMT ()
 
void vgmlibs ()
 
void g4libs ()
 

Detailed Description

Macro for loading Geant4 and Geant4 VMC libraries.

New macro for loading Geant4 and Geant4 VMC libraries with using geant4-config script provided in Geant4. Besides loading libraries, the macro also resets FPE mask to 0, in order to make sure than FPE for FE_OVERFLOW is disabled what is required for Geant4.

Definition in file g4libs.C.

Function Documentation

◆ loadg4libs()

void loadg4libs ( )

Macro function for loading Geant4 libraries from list of libraries build by geant4-config –libs

Definition at line 44 of file g4libs.C.

45{
46/// Macro function for loading Geant4 libraries
47/// from list of libraries build by geant4-config --libs
48
49 FILE* pipe = gSystem->OpenPipe("geant4-config --libs", "r");
50 std::string all_lines;
51 char line[1000];
52 while ( fgets(line, sizeof(line), pipe ) != NULL ) {
53 all_lines += line;
54 }
55
56 TString all_lines_t(all_lines.data());
57 all_lines_t.Remove(all_lines_t.First('\n'));
58 //cout << all_lines_t.Data() << endl;
59 TObjArray* libs = all_lines_t.Tokenize(" ");
60
61 //TString dynamicPath = gSystem->GetDynamicPath();
62 for (Int_t i=libs->GetEntriesFast()-1; i>=0; i-- ) {
63 TString addPath = ((TObjString*)libs->At(i))->GetString();
64 if (addPath.BeginsWith("-L")) {
65 addPath.Remove(0,2);
66 addPath.ReplaceAll("\"", "");
67 //cout << "Adding dynamic path " << addPath.Data() << endl;
68 gSystem->AddDynamicPath(addPath.Data());
69 }
70 }
71
72 cout << libs->GetEntriesFast() << endl;
73 for (Int_t i=libs->GetEntriesFast()-1; i>=0; i-- ) {
74 TString lib = ((TObjString*)libs->At(i))->GetString();
75 lib.ReplaceAll("-l", "lib");
76 //cout << "Loading |" << lib.Data() << "|" << endl;
77 if(lib.BeginsWith("lib"))
78 gSystem->Load(lib.Data());
79 }
80
81 gSystem->SetFPEMask(0);
82}

◆ isBatch()

Bool_t isBatch ( )

Helper function which testes if Root was started in batch mode

Definition at line 84 of file g4libs.C.

85{
86/// Helper function which testes if Root was started in batch mode
87
88 for ( Int_t i=0; i<gApplication->Argc(); ++i )
89 if ( TString(gROOT->GetApplication()->Argv(i)) == "-b" ) return true;
90
91 return false;
92}

◆ isSet()

Bool_t isSet ( const char * variable)

Helper function which checks if the specified environment variable is set.

Parameters
variableThe environment variable name

Definition at line 94 of file g4libs.C.

95{
96/// Helper function which checks if the specified environment variable
97/// is set.
98/// \param variable The environment variable name
99
100 TString value = gSystem->Getenv(variable);
101 if ( value != "") return true;
102
103 return false;
104}

◆ isMT()

Bool_t isMT ( )

Macro function for detecting if Geant4 libraries are built in multi-threading mode via geant4-config –has-feature multithreading

Definition at line 106 of file g4libs.C.

107{
108/// Macro function for detecting if Geant4 libraries
109/// are built in multi-threading mode via
110/// geant4-config --has-feature multithreading
111
112 FILE* pipe = gSystem->OpenPipe("geant4-config --has-feature multithreading", "r");
113 char line[10];
114 fgets(line, sizeof(line), pipe);
115 TString answer = line;
116 answer.Remove(answer.First('\n'));
117
118 return ( answer == "yes");
119}

◆ vgmlibs()

void vgmlibs ( )

Function for loading VGM libraries.

Definition at line 121 of file g4libs.C.

122{
123/// Function for loading VGM libraries.
124
125 if ( isSet("USE_VGM") ) {
126 cout << "Loading VGM libraries ... " << endl;
127 gSystem->Load("libClhepVGM");
128 gSystem->Load("libBaseVGM");
129 gSystem->Load("libGeant4GM");
130 gSystem->Load("libRootGM");
131 gSystem->Load("libXmlVGM");
132 }
133}
Bool_t isSet(const char *variable)
Definition g4libs.C:94

◆ g4libs()

void g4libs ( )

Definition at line 135 of file g4libs.C.

136{
137 // Load Geant4 libraries
138 cout << "Loading Geant4 libraries (using geant4-config) ..." << endl;
139 loadg4libs();
140
141 // VGM librares
142 vgmlibs();
143
144 // VMC library (optional)
145 if ( g4libUtilities::isLibrary("libVMCLibrary") ) {
146 cout << "Loading VMC library ..." << endl;
147 gSystem->Load("libVMCLibrary");
148 }
149
150 // G4Root library (if available)
151 cout << "Loading g4root library ..." << endl;
152 gSystem->Load("libg4root");
153
154 // Geant4 VMC library
155 cout << "Loading geant4vmc library ..." << endl;
156 gSystem->Load("libgeant4vmc");
157
158 // initialize Root threading
159 if ( isMT() ) {
160 TThread::Initialize();
161 }
162}
void vgmlibs()
Definition g4libs.C:121
void loadg4libs()
Definition g4libs.C:44
Bool_t isMT()
Definition g4libs.C:106
Bool_t isLibrary(const char *libName)
Definition g4libs.C:32