VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
macro
g4libs.C
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Virtual Monte Carlo examples
3
// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4
// All rights reserved.
5
//
6
// For the licensing terms see geant4_vmc/LICENSE.
7
// Contact: root-vmc@cern.ch
8
//-------------------------------------------------
9
10
/// \file g4libs.C
11
/// \brief Macro for loading Geant4 and Geant4 VMC libraries
12
///
13
/// New macro for loading Geant4 and Geant4 VMC libraries
14
/// with using geant4-config script provided in Geant4.
15
/// Besides loading libraries, the macro also resets
16
/// FPE mask to 0, in order to make sure than FPE for
17
/// FE_OVERFLOW is disabled what is required for Geant4.
18
19
#if !defined(__CINT__) || defined(__MAKECINT__)
20
21
#include <iostream>
22
23
#include <TSystem.h>
24
#include <TString.h>
25
#include <TApplication.h>
26
#include <TROOT.h>
27
#include <string>
28
29
#endif
30
31
namespace
g4libUtilities
{
32
Bool_t
isLibrary
(
const
char
* libName)
33
{
34
/// Helper function which testes the existence of the given library
35
/// \param libName The library name
36
37
if
(TString(gSystem->DynamicPathName(libName, kTRUE)) != TString(
""
))
38
return
kTRUE;
39
else
40
return
kFALSE;
41
}
42
}
43
44
void
loadg4libs
()
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
}
83
84
Bool_t
isBatch
()
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
}
93
94
Bool_t
isSet
(
const
char
* variable)
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
}
105
106
Bool_t
isMT
()
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
}
120
121
void
vgmlibs
()
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
}
134
135
void
g4libs
()
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
}
vgmlibs
void vgmlibs()
Definition
g4libs.C:121
loadg4libs
void loadg4libs()
Definition
g4libs.C:44
isSet
Bool_t isSet(const char *variable)
Definition
g4libs.C:94
isBatch
Bool_t isBatch()
Definition
g4libs.C:84
g4libs
void g4libs()
Definition
g4libs.C:135
isMT
Bool_t isMT()
Definition
g4libs.C:106
g4libUtilities
Definition
g4libs.C:31
g4libUtilities::isLibrary
Bool_t isLibrary(const char *libName)
Definition
g4libs.C:32
Generated on
for VMC Examples by
1.17.0