dbselect
Loading...
Searching...
No Matches
test_dbselect.cc
Go to the documentation of this file.
1
30// dbselect
31#include "dbselectView.h"
32#include "dbselect_options.h"
33
34// qt
35#include <QApplication>
36#include <QMainWindow>
37#include <QTimer>
38
39// geant4
40#include "G4RunManagerFactory.hh"
41#include "QBBC.hh"
42
43
62int main(int argc, char* argv[]) {
63 auto gopts = std::make_shared<GOptions>(argc, argv, dbselect::defineOptions());
64 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, DBSELECT_LOGGER);
65
66 log->info(0, "dbselect", "Starting dbselect example...");
67
68 // Optional GUI setup (only if --gui is passed)
69 QApplication* app = nullptr;
70 QMainWindow* window = nullptr;
71
72 // Geant4 initialization (required before using detector construction in many setups).
73 auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
74 auto physicsList = new QBBC;
75 runManager->SetUserInitialization(physicsList);
76
77 if (gopts->getSwitch("gui")) {
78 log->info(0, "Running dbselect in GUI mode...");
79 app = new QApplication(argc, argv);
80 window = new QMainWindow();
81 window->setWindowTitle(QString::fromUtf8("dbselect example"));
82 }
83
84 // building detector
85 // this is global, changed at main scope
86 // this will also load the digitization plugins
87 auto gdetector = new GDetectorConstruction(gopts);
88
89 // If GUI, show the window and run Qt loop
90 if (gopts->getSwitch("gui")) {
91 auto dbselect = new DBSelectView(gopts, gdetector, window);
92 window->setCentralWidget(dbselect);
93 window->show();
94
95 /* ---------- testing reload_geometry after 0.5s ---------- */
96 QTimer::singleShot(100, [dbselect] {
97 dbselect->reload_geometry(); // stop the event loop
98 });
99
100 /* ---------- quit after 0.5s ---------- */
101 QTimer::singleShot(500, []
102 {
103 QCoreApplication::quit(); // stop the event loop
104 });
105
106 int appResult = QApplication::exec();
107
108 // Clean up GUI resources
109 delete dbselect;
110 delete window;
111 delete app;
112
113 return appResult;
114 }
115
116 // CLI mode
117 log->info(0, "Running dbselect in command line mode...");
118
119 return EXIT_SUCCESS;
120}
Qt widget used to select experiment/system configurations from an SQLite geometry database.
constexpr const char * DBSELECT_LOGGER
Logger name used by the dbselect module.
#define SFUNCTION_NAME
Namespace containing dbselect module functions.
GOptions defineOptions()
Define and return the option set used by the dbselect module.
int main(int argc, char *argv[])