-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
147 lines (132 loc) · 3.72 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//----------------------------------*-C++-*----------------------------------//
// Copyright 2020-2023 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file main.cc
//! \brief Geometry and event display for Celeritas.
//---------------------------------------------------------------------------//
#include <iostream>
#include <string>
#include "EventViewer.hh"
#include "MainViewer.hh"
//---------------------------------------------------------------------------//
/*!
* Terminal input options.
*/
struct TerminalInput
{
std::string gdml_file;
std::string root_file;
std::size_t event_id{0};
int vis_level{1};
bool is_cms{false};
bool show_steps{false};
// Only the GDML input is necessary
explicit operator bool() const { return !gdml_file.empty(); }
};
//---------------------------------------------------------------------------//
/*!
* Execute with parsed input.
*/
void run(TerminalInput const& input)
{
// Initialize main viewer
MainViewer evd(input.gdml_file);
evd.set_vis_level(input.vis_level);
if (input.is_cms)
{
// Temporary option to hide cms building
evd.add_cms_volume();
}
else
{
evd.add_world_volume();
}
if (!input.root_file.empty())
{
// Initialize event viewer
EventViewer event_viewer(input.root_file);
event_viewer.show_step_points(input.show_steps);
event_viewer.add_event(input.event_id);
}
// Start GUI
evd.start_viewer();
};
//---------------------------------------------------------------------------//
/*!
* Parse terminal input parameters.
*/
TerminalInput parse(int argc, char* argv[])
{
TerminalInput input;
for (int i = 1; i < argc; i++)
{
std::string arg_i(argv[i]);
if (arg_i == "-vis")
{
// Set vis level
input.vis_level = std::stoi(argv[i + 1]);
i++;
}
else if (arg_i == "-e")
{
// Set event number
input.event_id = std::stol(argv[i + 1]);
i++;
}
else if (arg_i == "-s")
{
// Draw step points
input.show_steps = true;
}
else if (arg_i == "-cms")
{
// Temporary: select cms detector only
input.is_cms = true;
}
else if (arg_i.length() > 4
&& arg_i.substr(arg_i.length() - 4) == "gdml")
{
// Fetch gdml file
input.gdml_file = argv[i];
}
else if (arg_i.length() > 4
&& arg_i.substr(arg_i.length() - 4) == "root")
{
// Fetch root simulation file
input.root_file = argv[i];
}
else
{
// Skip unknown parameters
std::cout << "[WARNING] Parameter " << arg_i
<< " not known. Skipping..." << std::endl;
}
}
return input;
}
//---------------------------------------------------------------------------//
/*!
* Run Celeritas event display based on terminal input options.
* See README for details.
*/
int main(int argc, char* argv[])
{
if (argc == 1)
{
// No arguments, print help
std::cout << "Check README.md for information." << std::endl;
return EXIT_FAILURE;
}
auto const input = parse(argc, argv);
if (!input)
{
std::cout << "[ERROR] No GDML file specified. Check README.md for "
"information."
<< std::endl;
return EXIT_FAILURE;
}
run(input);
return EXIT_SUCCESS;
}