ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
G4DAWNFILESceneHandler.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4DAWNFILESceneHandler.cc
1
//
2
// ********************************************************************
3
// * License and Disclaimer *
4
// * *
5
// * The Geant4 software is copyright of the Copyright Holders of *
6
// * the Geant4 Collaboration. It is provided under the terms and *
7
// * conditions of the Geant4 Software License, included in the file *
8
// * LICENSE and available at http://cern.ch/geant4/license . These *
9
// * include a list of copyright holders. *
10
// * *
11
// * Neither the authors of this software system, nor their employing *
12
// * institutes,nor the agencies providing financial support for this *
13
// * work make any representation or warranty, express or implied, *
14
// * regarding this software system or assume any liability for its *
15
// * use. Please see the license in the file LICENSE and URL above *
16
// * for the full disclaimer and the limitation of liability. *
17
// * *
18
// * This code implementation is the result of the scientific and *
19
// * technical work of the GEANT4 collaboration. *
20
// * By using, copying, modifying or distributing the software (or *
21
// * any work based on the software) you agree to acknowledge its *
22
// * use in resulting scientific publications, and indicate your *
23
// * acceptance of all terms of the Geant4 Software license. *
24
// ********************************************************************
25
//
26
//
27
//
28
// Satoshi TANAKA
29
// DAWNFILE scene.
30
31
32
#define __G_ANSI_C__
33
34
// #define DEBUG_FR_SCENE
35
36
//----- header files
37
#include <fstream>
38
#include <stdlib.h>
39
#include <string.h>
40
#include <sstream>
41
#include <iomanip>
42
#include "
globals.hh
"
43
#include "
G4VisManager.hh
"
44
#include "
G4FRConst.hh
"
45
#include "
G4DAWNFILE.hh
"
46
#include "
G4DAWNFILESceneHandler.hh
"
47
#include "
G4DAWNFILEViewer.hh
"
48
#include "
G4Point3D.hh
"
49
#include "
G4VisAttributes.hh
"
50
#include "
G4Scene.hh
"
51
#include "
G4Transform3D.hh
"
52
#include "
G4Polyhedron.hh
"
53
#include "
G4Box.hh
"
54
#include "
G4Cons.hh
"
55
#include "
G4Polyline.hh
"
56
#include "
G4Trd.hh
"
57
#include "
G4Tubs.hh
"
58
#include "
G4Trap.hh
"
59
#include "
G4Torus.hh
"
60
#include "
G4Sphere.hh
"
61
#include "
G4Para.hh
"
62
#include "
G4Text.hh
"
63
#include "
G4Circle.hh
"
64
#include "
G4Square.hh
"
65
#include "
G4VPhysicalVolume.hh
"
66
67
//----- constants
68
const
char
FR_ENV_CULL_INVISIBLE_OBJECTS
[] =
"G4DAWN_CULL_INVISIBLE_OBJECTS"
;
69
const
char
G4PRIM_FILE_HEADER
[] =
"g4_"
;
70
const
char
DEFAULT_G4PRIM_FILE_NAME
[] =
"g4_0000.prim"
;
71
72
// const int FR_MAX_FILE_NUM = 1 ;
73
// const int FR_MAX_FILE_NUM = 5 ;
74
// const int FR_MAX_FILE_NUM = 10 ;
75
// const int FR_MAX_FILE_NUM = 15 ;
76
// const int FR_MAX_FILE_NUM = 20 ;
77
const
int
FR_MAX_FILE_NUM
= 100 ;
78
79
81
// Driver-dependent part //
83
84
85
//----- G4DAWNFILESceneHandler, constructor
86
G4DAWNFILESceneHandler::G4DAWNFILESceneHandler
(
G4DAWNFILE
&
system
,
const
G4String
&
name
):
87
G4VSceneHandler
(system, fSceneIdCount++, name) ,
88
fSystem (system) ,
89
fPrimDest () ,
90
FRflag_in_modeling (
false
) ,
91
flag_saving_g4_prim (
false
) ,
92
COMMAND_BUF_SIZE (
G4FRofstream
::SEND_BUFMAX),
93
fPrec (9), fPrec2 (16)
94
{
95
// g4.prim filename and its directory
96
if
( std::getenv(
"G4DAWNFILE_DEST_DIR"
) == NULL ) {
97
strcpy(
fG4PrimDestDir
,
""
) ;
// output dir
98
strcpy(
fG4PrimFileName
,
DEFAULT_G4PRIM_FILE_NAME
);
// filename
99
}
else
{
100
strcpy(
fG4PrimDestDir
, std::getenv(
"G4DAWNFILE_DEST_DIR"
) );
// output dir
101
strcpy(
fG4PrimFileName
,
DEFAULT_G4PRIM_FILE_NAME
);
// filename
102
}
103
104
// maximum number of g4.prim files in the dest directory
105
fMaxFileNum
=
FR_MAX_FILE_NUM
;
// initialization
106
if
( std::getenv(
"G4DAWNFILE_MAX_FILE_NUM"
) != NULL ) {
107
108
sscanf( std::getenv(
"G4DAWNFILE_MAX_FILE_NUM"
),
"%d"
, &
fMaxFileNum
) ;
109
110
}
else
{
111
fMaxFileNum
=
FR_MAX_FILE_NUM
;
112
}
113
if
(
fMaxFileNum
< 1 ) {
fMaxFileNum
= 1 ; }
114
115
116
//----- precision control
117
if
( std::getenv(
"G4DAWNFILE_PRECISION"
) != NULL ) {
118
sscanf( std::getenv(
"G4DAWNFILE_PRECISION"
),
"%d"
, &
fPrec
) ;
119
}
else
{
120
fPrec
= 9 ;
121
}
122
fPrec2
=
fPrec
+ 7 ;
123
124
}
125
126
127
//----- G4DAWNFILESceneHandler, destructor
128
G4DAWNFILESceneHandler::~G4DAWNFILESceneHandler
()
129
{
130
#if defined DEBUG_FR_SCENE
131
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
)
132
G4cout
<<
"***** ~G4DAWNFILESceneHandler"
<<
G4endl
;
133
#endif
134
if
(
fPrimDest
.
IsOpen
())
135
{
136
//----- End of modeling
137
// !EndModeling, !DrawAll, !CloseDevice,
138
// close g4.prim
139
FREndModeling
();
140
}
141
}
142
143
//-----
144
void
G4DAWNFILESceneHandler::SetG4PrimFileName
()
145
{
146
// g4_0000.prim, g4_0001.prim, ..., g4_MAX_FILE_INDEX.prim
147
const
int
MAX_FILE_INDEX =
fMaxFileNum
- 1 ;
148
149
// dest directory (null if no environmental variables is set)
150
strcpy (
fG4PrimFileName
,
fG4PrimDestDir
) ;
151
152
// create full path name (default)
153
strcat (
fG4PrimFileName
,
DEFAULT_G4PRIM_FILE_NAME
);
154
155
// Automatic updation of file names
156
for
(
int
i = 0 ; i <
fMaxFileNum
; i++) {
157
158
// Message in the final execution
159
if
( i == MAX_FILE_INDEX )
160
{
161
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
) {
162
G4cout
<<
"==========================================="
<<
G4endl
;
163
G4cout
<<
"WARNING MESSAGE from DAWNFILE driver: "
<<
G4endl
;
164
G4cout
<<
" This file name is the final one in the "
<<
G4endl
;
165
G4cout
<<
" automatic updation of the output file name."
<<
G4endl
;
166
G4cout
<<
" You may overwrite existing files, i.e. "
<<
G4endl
;
167
G4cout
<<
" g4_XXXX.prim and g4_XXXX.eps "
<<
G4endl
;
168
G4cout
<<
"==========================================="
<<
G4endl
;
169
}
170
}
171
172
// re-determine file name as G4DAWNFILE_DEST_DIR/g4_XXXX.prim
173
std::ostringstream
filename
; filename
174
<<
fG4PrimDestDir
<<
G4PRIM_FILE_HEADER
175
<< std::setw(4) << std::setfill(
'0'
) << i <<
".prim"
;
176
strncpy(
fG4PrimFileName
,filename.str().c_str(),
sizeof
(
fG4PrimFileName
)-1);
177
fG4PrimFileName
[
sizeof
(
fG4PrimFileName
)-1] =
'\0'
;
178
179
// check validity of the file name
180
std::ifstream
fin
;
181
fin.open(
fG4PrimFileName
) ;
182
if
(!fin) {
183
// new file
184
fin.close();
185
break
;
186
}
else
{
187
// already exists (try next)
188
fin.close();
189
}
190
191
}
// for
192
193
G4cout
<<
"=========================================== "
<<
G4endl
;
194
G4cout
<<
"Output file: "
<<
fG4PrimFileName
<<
G4endl
;
195
G4cout
<<
"Destination directory (current dir if NULL): "
<<
fG4PrimDestDir
<<
G4endl
;
196
G4cout
<<
"Maximal number of files in the destination directory: "
<< fMaxFileNum <<
G4endl
;
197
G4cout
<<
"Note: "
<<
G4endl
;
198
G4cout
<<
" * The maximal number is customizable as: "
<<
G4endl
;
199
G4cout
<<
" % setenv G4DAWNFILE_MAX_FILE_NUM number "
<<
G4endl
;
200
G4cout
<<
" * The destination directory is customizable as:"
<<
G4endl
;
201
G4cout
<<
" % setenv G4DAWNFILE_DEST_DIR dir_name/ "
<<
G4endl
;
202
G4cout
<<
" ** Do not forget \"/\" at the end of the "
<<
G4endl
;
203
G4cout
<<
" dir_name, e.g. \"./tmp/\". "
<<
G4endl
;
204
G4cout
<<
"=========================================== "
<<
G4endl
;
205
206
}
// G4DAWNFILESceneHandler::SetG4PrimFileName()
207
208
209
//-----
210
void
G4DAWNFILESceneHandler::BeginSavingG4Prim
(
void
)
211
{
212
#if defined DEBUG_FR_SCENE
213
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
)
214
G4cout
<<
"***** BeginSavingG4Prim (called)\n"
;
215
#endif
216
217
if
( !
IsSavingG4Prim
() )
218
{
219
#if defined DEBUG_FR_SCENE
220
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
) {
221
G4cout
<<
"***** (started) "
;
222
G4cout
<<
"(open g4.prim, ##)"
<<
G4endl
;
223
}
224
#endif
225
SetG4PrimFileName
() ;
// result set to fG4PrimFileName
226
fPrimDest
.
Open
(
fG4PrimFileName
) ;
227
228
SendStr
(
FR_G4_PRIM_HEADER
) ;
229
flag_saving_g4_prim
=
true
;
230
}
231
}
232
233
void
G4DAWNFILESceneHandler::EndSavingG4Prim
(
void
)
234
{
235
#if defined DEBUG_FR_SCENE
236
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
)
237
G4cout
<<
"***** EndSavingG4Prim (called)\n"
;
238
#endif
239
240
if
(
IsSavingG4Prim
() )
241
{
242
#if defined DEBUG_FR_SCENE
243
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
)
244
G4cout
<<
"***** (started) (close g4.prim)"
<<
G4endl
;
245
#endif
246
fPrimDest
.
Close
() ;
247
flag_saving_g4_prim
=
false
;
248
}
249
}
250
251
252
//-----
253
void
G4DAWNFILESceneHandler::FRBeginModeling
(
void
)
254
{
255
if
( !
FRIsInModeling
() )
256
{
257
#if defined DEBUG_FR_SCENE
258
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
)
259
G4cout
<<
"***** G4DAWNFILESceneHandler::FRBeginModeling (called & started)"
<<
G4endl
;
260
#endif
261
262
//----- Send saving command and heading comment
263
BeginSavingG4Prim
();
264
265
//----- Send bounding box command
266
SendBoundingBox
();
267
268
//----- send SET_CAMERA command
269
#if defined DEBUG_FR_SCENE
270
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
)
271
G4cout
<<
"***** (!SetCamera in FRBeginModeling())"
<<
G4endl
;
272
#endif
273
SendStr
(
FR_SET_CAMERA
);
274
275
//----- open device
276
#if defined DEBUG_FR_SCENE
277
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
)
278
G4cout
<<
"***** (!OpenDevice in FRBeginModeling())"
<<
G4endl
;
279
#endif
280
SendStr
(
FR_OPEN_DEVICE
);
281
282
//----- begin sending primitives
283
#if defined DEBUG_FR_SCENE
284
if
(
G4VisManager::GetVerbosity
() >=
G4VisManager::errors
)
285
G4cout
<<
"***** (!BeginModeling in FRBeginModeling())"
<<
G4endl
;
286
#endif
287
SendStr
(
FR_BEGIN_MODELING
);
FRflag_in_modeling
=
true
;
288
289
}
// if
290
291
}
292
293
295
// Common to DAWN and DAWNFILE drivers //
297
298
#define G4FRSCENEHANDLER G4DAWNFILESceneHandler
299
#include "G4FRSceneFunc.icc"
300
#undef G4FRSCENEHANDLER
301
303
// static variables //
305
306
//----- static variables
307
G4int
G4DAWNFILESceneHandler::fSceneIdCount
= 0;
geant4
tree
geant4-10.6-release
source
visualization
FukuiRenderer
src
G4DAWNFILESceneHandler.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:54
using
1.8.2 with
ECCE GitHub integration