Skip to content

Commit b00cc2b

Browse files
committed
exiting gui after 0.5 seconds in the examples, added logger to gstreamer but example not ready yet
1 parent 39b1232 commit b00cc2b

82 files changed

Lines changed: 664 additions & 780 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

g4dialog/examples/g4dialog_example.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// qt
1010
#include <QApplication>
1111
#include <QMainWindow>
12+
#include <QTimer>
1213

1314
int main(int argc, char* argv[]) {
1415

@@ -20,27 +21,29 @@ int main(int argc, char* argv[]) {
2021
auto visManager = new G4VisExecutive;
2122
visManager->Initialize();
2223

23-
// main window
24+
// main window and controls
2425
auto window = new QMainWindow();
2526
window->setWindowTitle(QString::fromUtf8("displayUI example"));
26-
27-
// controls
2827
auto g4dialog = new G4Dialog(gopts, window);
2928
window->setCentralWidget(g4dialog);
3029

31-
3230
log->info(0, "g4 dialog example started");
31+
int ret = EXIT_SUCCESS;
3332

3433
if (gopts->getSwitch("gui")) {
3534
window->show();
36-
return app.exec();
35+
36+
// --- quit after 0.5 s ---
37+
QTimer::singleShot(500, &app, &QCoreApplication::quit); // ⬅️ key line :contentReference[oaicite:0]{index=0}
38+
39+
ret = QApplication::exec(); // returns when the timer fires
3740
}
3841

3942
delete g4dialog;
4043
delete window;
4144
delete visManager;
4245
delete gopts;
4346

44-
return EXIT_SUCCESS;
47+
return ret;
4548

4649
}

g4display/examples/g4display_example.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// geant4
22
#include "G4VisExecutive.hh"
33
#include "G4RunManagerFactory.hh"
4-
#include "FTFP_BERT.hh"
54

65
// g4display
76
#include "g4SceneProperties.h"
@@ -14,8 +13,10 @@
1413
// qt
1514
#include <QApplication>
1615
#include <QMainWindow>
16+
#include <QTimer>
1717

1818
int main(int argc, char* argv[]) {
19+
1920
// Initialize options and logging
2021
auto gopts = new GOptions(argc, argv, g4display::defineOptions());
2122
auto log = new GLogger(gopts, G4DISPLAY_LOGGER, "g4display example");
@@ -24,7 +25,6 @@ int main(int argc, char* argv[]) {
2425
// Optional GUI setup (only if --gui is passed)
2526
QApplication* app = nullptr;
2627
QMainWindow* window = nullptr;
27-
G4Display* g4display = nullptr;
2828

2929
if (gopts->getSwitch("gui")) {
3030
log->info(0, "g4display", "Running in GUI mode...");
@@ -38,19 +38,25 @@ int main(int argc, char* argv[]) {
3838

3939
auto g4SceneProperties = new G4SceneProperties(gopts);
4040

41-
// If GUI, show window and run Qt loop
41+
// If GUI, show the window and run Qt loop
4242
if (gopts->getSwitch("gui")) {
4343

44-
g4display = new G4Display(gopts, window);
44+
auto g4display = new G4Display(gopts, window);
4545
window->setCentralWidget(g4display);
4646
window->show();
47+
48+
/* ---------- quit after 0.5 s ---------- */
49+
QTimer::singleShot(500, []
50+
{
51+
QCoreApplication::quit(); // stop the event loop
52+
});
53+
4754
int appResult = QApplication::exec();
4855

4956
// Clean up GUI resources
5057
delete g4display;
5158
delete window;
5259
delete app;
53-
app = nullptr;
5460

5561
// Clean up Geant4 and custom logic
5662
delete g4SceneProperties;

g4display/g4Text.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace g4display {
1919

2020
st_item.text = gopts->get_variable_in_option<string>(g4t_item, "text", goptions::NODFLT);
2121
st_item.color = gopts->get_variable_in_option<string>(g4t_item, "color", "black");
22-
st_item.x = gopts->get_variable_in_option<float>(g4t_item, "x", 0);
23-
st_item.y = gopts->get_variable_in_option<float>(g4t_item, "y", 0);
24-
st_item.z = gopts->get_variable_in_option<float>(g4t_item, "z", GNOT_SPECIFIED_SCENE_TEXT_Z);
22+
st_item.x = gopts->get_variable_in_option<double>(g4t_item, "x", 0);
23+
st_item.y = gopts->get_variable_in_option<double>(g4t_item, "y", 0);
24+
st_item.z = gopts->get_variable_in_option<double>(g4t_item, "z", GNOT_SPECIFIED_SCENE_TEXT_Z);
2525
st_item.size = gopts->get_variable_in_option<double>(g4t_item, "size", 24.0);
2626
st.push_back(st_item);
2727
}

g4display/g4Text.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace g4display {
1313
struct G4SceneText {
1414
string text;
1515
string color;
16-
float x;
17-
float y;
18-
float z = GNOT_SPECIFIED_SCENE_TEXT_Z;
16+
double x;
17+
double y;
18+
double z = GNOT_SPECIFIED_SCENE_TEXT_Z;
1919
int size;
2020
};
2121

g4display/tabs/g4displayview.cc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ using namespace gutilities;
2121
* @param logger Pointer to the shared GLogger instance for logging.
2222
* @param parent Optional pointer to the parent QWidget.
2323
*/
24-
G4DisplayView::G4DisplayView(GOptions* gopts, std::shared_ptr<GLogger> logger, QWidget* parent) : QWidget(parent), log(logger) {
24+
G4DisplayView::G4DisplayView(GOptions* gopts, std::shared_ptr<GLogger> logger, QWidget* parent) : QWidget(parent), log(logger) {
2525
log->debug(CONSTRUCTOR, "G4DisplayView");
2626

2727
G4Camera jcamera = getG4Camera(gopts);
2828

2929
double thetaValue = getG4Number(jcamera.theta);
30-
double phiValue = getG4Number(jcamera.phi);
30+
double phiValue = getG4Number(jcamera.phi);
3131

3232
vector<string> toggle_button_titles;
3333
toggle_button_titles.emplace_back("Hidden\nLines");
@@ -159,8 +159,8 @@ G4DisplayView::G4DisplayView(GOptions* gopts, std::shared_ptr<GLogger> logger,
159159

160160
// slice style: Intersection or Union
161161
QGroupBox* sliceChoiceBox = new QGroupBox(tr("Slices Style"));
162-
sliceSectn = new QRadioButton(tr("&Intersection"), sliceChoiceBox);
163-
sliceUnion = new QRadioButton(tr("&Union"), sliceChoiceBox);
162+
sliceSectn = new QRadioButton(tr("&Intersection"), sliceChoiceBox);
163+
sliceUnion = new QRadioButton(tr("&Union"), sliceChoiceBox);
164164
sliceSectn->setChecked(true);
165165

166166
connect(sliceSectn, &QRadioButton::toggled, this, &G4DisplayView::slice);
@@ -186,17 +186,17 @@ G4DisplayView::G4DisplayView(GOptions* gopts, std::shared_ptr<GLogger> logger,
186186
connect(sliceYEdit, &QLineEdit::returnPressed, this, &G4DisplayView::slice);
187187
connect(sliceZEdit, &QLineEdit::returnPressed, this, &G4DisplayView::slice);
188188

189-
connect(sliceXActi, &QCheckBox::stateChanged, this, &G4DisplayView::slice);
190-
connect(sliceYActi, &QCheckBox::stateChanged, this, &G4DisplayView::slice);
191-
connect(sliceZActi, &QCheckBox::stateChanged, this, &G4DisplayView::slice);
189+
connect(sliceXActi, &QCheckBox::checkStateChanged, this, &G4DisplayView::slice);
190+
connect(sliceYActi, &QCheckBox::checkStateChanged, this, &G4DisplayView::slice);
191+
connect(sliceZActi, &QCheckBox::checkStateChanged, this, &G4DisplayView::slice);
192192

193-
connect(sliceXInve, &QCheckBox::stateChanged, this, &G4DisplayView::slice);
194-
connect(sliceYInve, &QCheckBox::stateChanged, this, &G4DisplayView::slice);
195-
connect(sliceZInve, &QCheckBox::stateChanged, this, &G4DisplayView::slice);
193+
connect(sliceXInve, &QCheckBox::checkStateChanged, this, &G4DisplayView::slice);
194+
connect(sliceYInve, &QCheckBox::checkStateChanged, this, &G4DisplayView::slice);
195+
connect(sliceZInve, &QCheckBox::checkStateChanged, this, &G4DisplayView::slice);
196196

197197

198198
QGroupBox* fieldPrecisionBox = new QGroupBox(tr("Number of Field Points"));
199-
field_npoints = new QLineEdit(QString::number(field_NPOINTS), this);
199+
field_npoints = new QLineEdit(QString::number(field_NPOINTS), this);
200200
field_npoints->setMaximumWidth(40);
201201

202202
QFont font = field_npoints->font();
@@ -234,8 +234,8 @@ G4DisplayView::G4DisplayView(GOptions* gopts, std::shared_ptr<GLogger> logger,
234234
void G4DisplayView::changeCameraDirection() {
235235
// Construct the command using the current slider values.
236236
string command = "/vis/viewer/set/viewpointThetaPhi " +
237-
to_string(cameraTheta->value()) + " " +
238-
to_string(cameraPhi->value());
237+
to_string(cameraTheta->value()) + " " +
238+
to_string(cameraPhi->value());
239239
// Send the command to the Geant4 UImanager.
240240
G4UImanager::GetUIpointer()->ApplyCommand(command);
241241
}
@@ -248,8 +248,8 @@ void G4DisplayView::changeCameraDirection() {
248248
*/
249249
void G4DisplayView::changeLightDirection() {
250250
string command = "/vis/viewer/set/lightsThetaPhi " +
251-
to_string(lightTheta->value()) + " " +
252-
to_string(lightPhi->value());
251+
to_string(lightTheta->value()) + " " +
252+
to_string(lightPhi->value());
253253
G4UImanager::GetUIpointer()->ApplyCommand(command);
254254
}
255255

@@ -280,21 +280,21 @@ void G4DisplayView::slice() {
280280

281281
if (sliceXActi->isChecked()) {
282282
string command = "/vis/viewer/addCutawayPlane " + sliceXEdit->text().toStdString() + " 0 0 mm " +
283-
to_string(sliceXInve->isChecked() ? -1 : 1) + " 0 0 ";
283+
to_string(sliceXInve->isChecked() ? -1 : 1) + " 0 0 ";
284284
cout << "X " << command << endl;
285285
g4uim->ApplyCommand(command);
286286
}
287287

288288
if (sliceYActi->isChecked()) {
289289
string command = "/vis/viewer/addCutawayPlane 0 " + sliceYEdit->text().toStdString() + " 0 mm 0 " +
290-
to_string(sliceYInve->isChecked() ? -1 : 1) + " 0 ";
290+
to_string(sliceYInve->isChecked() ? -1 : 1) + " 0 ";
291291
cout << "Y " << command << endl;
292292
g4uim->ApplyCommand(command);
293293
}
294294

295295
if (sliceZActi->isChecked()) {
296296
string command = "/vis/viewer/addCutawayPlane 0 0 " + sliceZEdit->text().toStdString() + " mm 0 0 " +
297-
to_string(sliceZInve->isChecked() ? -1 : 1);
297+
to_string(sliceZInve->isChecked() ? -1 : 1);
298298
cout << "Z " << command << endl;
299299
g4uim->ApplyCommand(command);
300300
}
@@ -382,7 +382,7 @@ void G4DisplayView::field_precision_changed() {
382382
g4uim->ApplyCommand("/vis/scene/removeModel Field");
383383

384384
string npoints = to_string(field_NPOINTS);
385-
command = string("/vis/scene/add/magneticField ") + npoints;
385+
command = string("/vis/scene/add/magneticField ") + npoints;
386386
G4UImanager::GetUIpointer()->ApplyCommand(command);
387387
}
388388
}

g4display/tabs/g4displayview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class G4DisplayView : public QWidget {
3434
* @param logger Pointer to the GLogger instance for logging messages. Must not be null. Passed from parent G4Display.
3535
* @param parent Optional parent QWidget for Qt's memory management.
3636
*/
37-
G4DisplayView(GOptions* gopts, std::shared_ptr<GLogger>, QWidget* parent = nullptr);
37+
G4DisplayView(GOptions* gopts, std::shared_ptr<GLogger> logger, QWidget* parent = nullptr);
3838

3939
/**
4040
* @brief Destructor. Logs the destruction event using the provided logger.

gdata/event/gDataCollection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GDataCollection {
1818
* \brief Constructs a GDataCollection.
1919
* \param logger Pointer to a GLogger instance.
2020
*/
21-
explicit GDataCollection(std::shared_ptr<GLogger> logger) : log(std::move(logger)) {
21+
explicit GDataCollection(std::shared_ptr<GLogger> logger) : log(logger) {
2222
log->debug(CONSTRUCTOR, "GDataCollection");
2323
trueInfosData = new std::vector<GTrueInfoData*>;
2424
digitizedData = new std::vector<GDigitizedData*>;

gdata/event/gDigitizedData.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <map>
1010
#include <vector>
1111

12-
GDigitizedData::GDigitizedData(GHit *ghit, const std::shared_ptr<GLogger>& logger) : log(std::move(logger)) {
12+
GDigitizedData::GDigitizedData(GHit *ghit, const std::shared_ptr<GLogger>& logger) : log(logger) {
1313
log->debug(CONSTRUCTOR, "GDigitizedData");
1414
gidentity = ghit->getGID();
1515
}
@@ -25,18 +25,18 @@ std::map<std::string, int> GDigitizedData::getIntObservablesMap(int which) const
2525
return filteredIntObservablesMap;
2626
}
2727

28-
std::map<std::string, float> GDigitizedData::getFltObservablesMap(int which) const {
29-
std::map<std::string, float> filteredFltObservablesMap;
28+
std::map<std::string, double> GDigitizedData::getDblObservablesMap(int which) const {
29+
std::map<std::string, double> filteredDblObservablesMap;
3030
for (const auto& [varName, value] : doubleObservablesMap) {
3131
if (validVarName(varName, which)) {
32-
filteredFltObservablesMap[varName] = value;
32+
filteredDblObservablesMap[varName] = value;
3333
}
3434
}
3535
log->debug(NORMAL, " getting ", which, " from doubleObservablesMap.");
36-
return filteredFltObservablesMap;
36+
return filteredDblObservablesMap;
3737
}
3838

39-
bool GDigitizedData::validVarName(const std::string& varName, int which) const {
39+
bool GDigitizedData::validVarName(const std::string& varName, int which) {
4040
bool isSROVar = (varName == CRATESTRINGID || varName == SLOTSTRINGID || varName == CHANNELSTRINGID ||
4141
varName == CHARGEATELECTRONICS || varName == TIMEATELECTRONICS);
4242
if (which == 0) {
@@ -57,7 +57,7 @@ void GDigitizedData::includeVariable(const std::string& vname, int value) {
5757
}
5858

5959
void GDigitizedData::includeVariable(const std::string& vname, double value) {
60-
log->debug(NORMAL, "Including float variable ", vname, " with value ", value);
60+
log->debug(NORMAL, "double variable ", vname, " with value ", value);
6161
doubleObservablesMap[vname] = value;
6262
}
6363

@@ -69,22 +69,22 @@ int GDigitizedData::getTimeAtElectronics() {
6969
return intObservablesMap[TIMEATELECTRONICS];
7070
}
7171

72-
int GDigitizedData::getIntObservable(std::string varName) {
72+
int GDigitizedData::getIntObservable(const std::string& varName) {
7373
if (intObservablesMap.find(varName) == intObservablesMap.end()) {
7474
log->error(EC__VARIABLENOTFOUND, "variable name <" + varName + "> not found in GDigitizedData::intObservablesMap");
7575
}
7676
return intObservablesMap[varName];
7777
}
7878

79-
float GDigitizedData::getFltObservable(std::string varName) {
79+
double GDigitizedData::getDblObservable(const std::string& varName) {
8080
if (doubleObservablesMap.find(varName) == doubleObservablesMap.end()) {
8181
log->error(EC__VARIABLENOTFOUND, "variable name <" + varName + "> not found in GDigitizedData::doubleObservablesMap");
8282
}
8383
return doubleObservablesMap[varName];
8484
}
8585

8686
std::string GDigitizedData::getIdentityString() {
87-
std::string identifierString = "";
87+
std::string identifierString;
8888
for (size_t i = 0; i < gidentity.size() - 1; i++) {
8989
identifierString += gidentity[i].getName() + "->" + std::to_string(gidentity[i].getValue()) + ", ";
9090
}

gdata/event/gDigitizedData.h

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class GDigitizedData {
3838
void includeVariable(const std::string& vname, int value);
3939
void includeVariable(const std::string& vname, double value);
4040
// void includeVariable(std::string vname, std::vector<int> values);
41-
// void includeVariable(std::string vname, std::vector<float> values);
4241

4342
/**
4443
* \brief Returns the filtered map of integer observables.
@@ -48,11 +47,11 @@ class GDigitizedData {
4847
[[nodiscard]] std::map<std::string, int> getIntObservablesMap(int which) const;
4948

5049
/**
51-
* \brief Returns the filtered map of float observables.
50+
* \brief Returns the filtered map of double observables.
5251
* \param which 0: returns non-streaming variables; 1: returns streaming variables.
53-
* \return A map of variable names to float values.
52+
* \return A map of variable names to double values.
5453
*/
55-
[[nodiscard]] std::map<std::string, float> getFltObservablesMap(int which) const;
54+
[[nodiscard]] std::map<std::string, double> getDblObservablesMap(int which) const;
5655

5756
/**
5857
* \brief Gets the time at electronics.
@@ -63,31 +62,27 @@ class GDigitizedData {
6362
*/
6463
int getTimeAtElectronics();
6564

66-
int getIntObservable(std::string varName);
67-
float getFltObservable(std::string varName);
65+
int getIntObservable(const std::string& varName);
66+
double getDblObservable(const std::string& varName);
6867

6968
/**
7069
* \brief Returns the map of integer array observables.
7170
* \return A map of variable names to vectors of integers.
7271
*/
73-
[[nodiscard]] inline std::map<std::string, std::vector<int>> getArrayIntObservablesMap() const {
74-
return arrayIntObservablesMap;
75-
}
72+
[[nodiscard]] inline std::map<std::string, std::vector<int>> getArrayIntObservablesMap() const { return arrayIntObservablesMap; }
7673

7774
/**
78-
* \brief Returns the map of float array observables.
79-
* \return A map of variable names to vectors of floats.
75+
* \brief Returns the map of double array observables.
76+
* \return A map of variable names to vectors of double.
8077
*/
81-
[[nodiscard]] inline std::map<std::string, std::vector<double>> getArrayFltObservablesMap() const {
82-
return arrayDoubleObservablesMap;
83-
}
78+
[[nodiscard]] inline std::map<std::string, std::vector<double>> getArrayDblObservablesMap() const { return arrayDoubleObservablesMap; }
8479

8580
private:
86-
std::map<std::string, int> intObservablesMap; ///< Map of integer observables.
87-
std::map<std::string, double> doubleObservablesMap; ///< Map of float observables.
88-
std::map<std::string, std::vector<int>> arrayIntObservablesMap; ///< Map of integer array observables.
89-
std::map<std::string, std::vector<double>> arrayDoubleObservablesMap; ///< Map of float array observables.
90-
std::vector<GIdentifier> gidentity; ///< Identity extracted from the hit.
91-
[[nodiscard]] bool validVarName(const std::string& varName, int which) const; ///< Validates variable names.
92-
std::shared_ptr<GLogger> log; ///< Logger instance
81+
std::map<std::string, int> intObservablesMap; ///< Map of integer observables.
82+
std::map<std::string, double> doubleObservablesMap; ///< Map of double observables.
83+
std::map<std::string, std::vector<int>> arrayIntObservablesMap; ///< Map of integer array observables.
84+
std::map<std::string, std::vector<double>> arrayDoubleObservablesMap; ///< Map of double array observables.
85+
std::vector<GIdentifier> gidentity; ///< Identity extracted from the hit.
86+
[[nodiscard]] static bool validVarName(const std::string& varName, int which); ///< Validates variable names.
87+
std::shared_ptr<GLogger> log; ///< Logger instance
9388
};

gdata/event/gEventDataCollection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GEventDataCollection {
2222
* \param header Pointer to the event header.
2323
* \param logger Pointer to a GLogger instance (using the 'gdata' name).
2424
*/
25-
GEventDataCollection(GEventDataCollectionHeader* header, std::shared_ptr<GLogger> logger) : log(std::move(logger)),
25+
GEventDataCollection(GEventDataCollectionHeader* header, std::shared_ptr<GLogger> logger) : log(logger),
2626
gheader(header) {
2727
log->debug(CONSTRUCTOR, "GEventDataCollection");
2828
gdataCollectionMap = new std::map<std::string, GDataCollection*>();

0 commit comments

Comments
 (0)