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

Old macro for loading Geant4 and Geant4 VMC libraries. More...

#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <TSystem.h>
#include <Riostream.h>
#include <TCint.h>
#include <TError.h>
#include <TMath.h>
#include <TApplication.h>
#include <TROOT.h>
Include dependency graph for g4libs_old.C:

Go to the source code of this file.

Functions

void loadg4libs ()
 
void g4libs ()
 
string NoSpaces (string s)
 
Bool_t isLibrary (const char *libName)
 
Bool_t isBatch ()
 
Bool_t isSet (const char *variable)
 
void vgmlibs ()
 
void GetLinkLine (string &all_lines)
 
void HandleLinkLine (const char *str, const char *what)
 
void unloadg4libs ()
 

Detailed Description

Old macro for loading Geant4 and Geant4 VMC libraries.

Macro for loading Geant4 and Geant4 VMC libraries with using liblist utility 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.

Author
Christian Holm Christensen, NBI; Dmitry Naumov, JINR

Definition in file g4libs_old.C.

Function Documentation

◆ loadg4libs()

void loadg4libs ( )

The function to unload Geant4 libraries

Definition at line 213 of file g4libs_old.C.

214{
215/// The function to unload Geant4 libraries
216
217 // CLHEP
218 gSystem->Load("libCLHEP");
219
220 // xerces-c library if GDML is activated
221 if ( isSet("G4LIB_BUILD_GDML") ) {
222 gSystem->Load("libxerces-c");
223 }
224
225 // Get the string with the list of libraries
226 string all_lines;
227 GetLinkLine(all_lines);
228
229 // Load Geant4 libraries
230 cout << "Loading Geant4 libraries (using liblist) ..." << endl;
231 HandleLinkLine(all_lines.c_str(),"l");
232
233 // VGM librares
234 vgmlibs();
235
236 // G4Root library (if available)
237 if ( isLibrary("libg4root") ) {
238 cout << "Loading g4root library ..." << endl;
239 gSystem->Load("libg4root");
240 }
241
242 // Geant4 VMC library
243 cout << "Loading geant4vmc library ..." << endl;
244 gSystem->Load("libgeant4vmc");
245
246 // Geant4 VMC GUI library
247 // (if available and Root is not running in batch mode)
248 if ( isLibrary("libgeant4vmc_gui") && ! isBatch() ) {
249 cout << "Loading geant4vmc_gui library ... " << endl;
250 gSystem->Load("libgeant4vmc_gui");
251 }
252}
void vgmlibs()
Definition g4libs_old.C:95
void HandleLinkLine(const char *str, const char *what)
Definition g4libs_old.C:129
void GetLinkLine(string &all_lines)
Definition g4libs_old.C:109
Bool_t isSet(const char *variable)
Definition g4libs_old.C:83
Bool_t isBatch()
Definition g4libs_old.C:73
Bool_t isLibrary(const char *libName)
Definition g4libs_old.C:62

◆ g4libs()

void g4libs ( )

Function for loading all libraries for running VMC with Geant4

Definition at line 44 of file g4libs_old.C.

45{
46/// Function for loading all libraries for running VMC with Geant4
47 loadg4libs();
48
49 gSystem->SetFPEMask(0);
50}
void loadg4libs()
Definition g4libs_old.C:213

◆ NoSpaces()

string NoSpaces ( string s)

???

Definition at line 52 of file g4libs_old.C.

53{
54/// ???
55
56 std::stringstream str(s);
57 std::string token;
58 std::getline(str, token, '\n');
59 return token;
60}

◆ isLibrary()

Bool_t isLibrary ( const char * libName)

Helper function which testes the existence of the given library

Parameters
libNameThe library name

Definition at line 62 of file g4libs_old.C.

63{
64/// Helper function which testes the existence of the given library
65/// \param libName The library name
66
67 if (TString(gSystem->DynamicPathName(libName, kTRUE)) != TString(""))
68 return kTRUE;
69 else
70 return kFALSE;
71}

◆ isBatch()

Bool_t isBatch ( )

Helper function which testes if Root was started in batch mode

Definition at line 73 of file g4libs_old.C.

74{
75/// Helper function which testes if Root was started in batch mode
76
77 for ( Int_t i=0; i<gApplication->Argc(); ++i )
78 if ( TString(gROOT->GetApplication()->Argv(i)) == "-b" ) return true;
79
80 return false;
81}

◆ 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 83 of file g4libs_old.C.

84{
85/// Helper function which checks if the specified environment variable
86/// is set.
87/// \param variable The environment variable name
88
89 TString value = gSystem->Getenv(variable);
90 if ( value != "") return true;
91
92 return false;
93}

◆ vgmlibs()

void vgmlibs ( )

Function for loading VGM libraries.

Definition at line 95 of file g4libs_old.C.

96{
97/// Function for loading VGM libraries.
98
99 if ( isSet("USE_VGM") ) {
100 cout << "Loading VGM libraries ... " << endl;
101 gSystem->Load("libClhepVGM");
102 gSystem->Load("libBaseVGM");
103 gSystem->Load("libGeant4GM");
104 gSystem->Load("libRootGM");
105 gSystem->Load("libXmlVGM");
106 }
107}

◆ GetLinkLine()

void GetLinkLine ( string & all_lines)

Build the string with the list of libraries using liblist

Definition at line 109 of file g4libs_old.C.

110{
111/// Build the string with the list of libraries using liblist
112
113 // Geant4 lib directory
114 TString g4lib = gSystem->Getenv("G4LIB");
115 if ( g4lib.Length() == 0 )
116 g4lib = gSystem->Getenv("G4INSTALL") + TString("/lib");
117 g4lib += "/"+TString(gSystem->Getenv("G4SYSTEM"));
118
119 // Build the string with the list of libraries using liblist
120 TString command
121 = "echo -L"+g4lib+" `" + g4lib+"/liblist -m "+g4lib +" < " + g4lib+"/libname.map`";
122 FILE* pipe = gSystem->OpenPipe(command, "r");
123 char line[100];
124 while ( fgets(line, sizeof(line), pipe ) != NULL ) {
125 all_lines += line;
126 }
127}

◆ HandleLinkLine()

void HandleLinkLine ( const char * str,
const char * what )

Tokenize the input string and load/unload the libraries from the list.

Parameters
strThe string output from Geant4 liblist
whatThe option specifying whether we want to load ('l') or unload ('u') libraries

Definition at line 129 of file g4libs_old.C.

130{
131/// Tokenize the input string and load/unload the libraries
132/// from the list.
133/// \param str The string output from Geant4 liblist
134/// \param what The option specifying whether we want to load ('l') or
135/// unload ('u') libraries
136
137 // Fill the libs names in the vector
138 std::vector<std::string> libs;
139 std::stringstream sstream(str);
140 unsigned int w = 0;
141 while ( ! sstream.eof() ) {
142 // Read one string
143 std::string token;
144 std::getline(sstream, token, ' ');
145
146 // Check stream status
147 if ( sstream.bad() ) break;
148
149 // Check that we got a meaningful tokenonent
150 if ( token.empty() || std::isspace(token[0]) ) continue;
151
152 if ( token[0] != '-' ) {
153 Warning("LoadLibraryList", "Unknown element %s", token.c_str());
154 continue;
155 }
156
157 std::string dir_or_file = token.substr(2,token.size()-2);
158 if ( token[1] == 'L' ) {
159 std::stringstream path;
160 path << gSystem->GetDynamicPath() << ":"
161 << dir_or_file;
162 gSystem->SetDynamicPath(path.str().c_str());
163 }
164 else if ( token[1] == 'l' ) {
165 std::stringstream ln;
166 ln << "lib" << NoSpaces(dir_or_file) << '.' << gSystem->GetSoExt();
167 std::string lib(ln.str());
168 libs.push_back(lib);
169 if ( lib.length() > w ) w = lib.length();
170 }
171 else {
172 Warning("LoadLibraryList", "Unknown option %s in",
173 token.c_str(), str);
174 continue;
175 }
176 }
177
178 // Process the vector with libs names and load libraries
179 size_t n = libs.size();
180 TString sWhat(what);
181 Bool_t load = sWhat.Contains("l");
182 if (!load && !sWhat.Contains("u")) {
183 std::cerr << " Unknown load action " << what << std::endl;
184 return;
185 }
186
187 for ( size_t i = 0; i < n; ++i ) {
188 size_t idx = n - i - 1;
189
190 // Uncomment to debug
191 // size_t m = TMath::Log10(n)+1;
192 // string say=" Loading ";
193 // if ( TString(what).Contains("u") ) say = " Unloading ";
194 // std::cout << say << std::setw(m) << (i+1)
195 // << "/" << std::setw(m) << n
196 // << ": " << std::setw(w) << libs[idx] // << std::endl;
197 // << std::flush;
198
199 int result = 0;
200 if ( libs[idx].c_str() ) {
201 if (load)
202 result = gSystem->Load(libs[idx].c_str());
203 else
204 gSystem->Unload(libs[idx].c_str());
205 }
206 // Uncomment to debug
207 // if ( TString(what).Contains("l") )
208 // std::cout << ( result < 0 ? " failed" : " ok" ) << "\r";
209 }
210 // std::cout << "\n Done" << std::endl;
211}
string NoSpaces(string s)
Definition g4libs_old.C:52

◆ unloadg4libs()

void unloadg4libs ( )

The function to unload Geant4 libraries

Definition at line 254 of file g4libs_old.C.

255{
256/// The function to unload Geant4 libraries
257
258 // Get the string with the list of libraries
259 string all_lines;
260 GetLinkLine(all_lines);
261
262 // Load Geant4 libraries
263 cout << "Unloading Geant4 libraries ..." << endl;
264 HandleLinkLine(all_lines.c_str(),"u");
265}