GGS(GenericGEANT4Simulation)Software  2.99.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Macros
Application.cpp
1 #include "TEveBrowser.h"
2 #include "TEveViewer.h"
3 #include "TGLLightSet.h"
4 
5 #include "display/application/Application.h"
6 
7 EDApplication::EDApplication(int argc, char **argv)
8  : TApplication("GGSLeonard", &argc, argv, 0, -1), _MainWindow(0), _FileManager(0) {
9  static const std::string routineName("EDApplication::EDApplication");
10 
11  gApplication = this;
12  _fileLoaded = _fileToBeLoaded = "";
13 
14  _FileManager = new GGSFileManager();
15 
16  HandleArgs();
17  if (args.flag_debug)
18  GGSSmartLog::verboseLevel = GGSSmartLog::DEBUG; // Print only DEBUG messages or more important
19 
20  if (args.geofilename == nullptr && args.infilename == nullptr) {
21  GGSCOUT(ERROR) << R"(Must provide at least one between input file (-i) and geometry file (-g))" << GGSENDL;
22  }
23 
24  InitGUI();
25 
26  if (args.infilename) {
27  _fileToBeLoaded = args.infilename;
28  LoadRootFile();
29  }
30 
31  if (_FileManager->FileIsLoaded()) {
32  _MainWindow->SetFileName(_fileLoaded);
33  _FileManager->ReadEvent(0);
34  }
35 }
36 
37 EDApplication::~EDApplication() {
38  delete _FileManager;
39  delete _MainWindow;
40  // delete _GeoManager;
41 }
42 
43 void EDApplication::NextEvent() {
44  static const std::string routineName("EDApplication::NextEvent");
45 
46  _FileManager->NextEvent();
47  _evtLoaded = _FileManager->GetNevent();
48  _MainWindow->SetEventNumber(_evtLoaded + 1);
49 }
50 
51 void EDApplication::PrevEvent() {
52  static const std::string routineName("EDApplication::PrevEvent");
53 
54  _FileManager->PrevEvent();
55  _evtLoaded = _FileManager->GetNevent();
56  _MainWindow->SetEventNumber(_evtLoaded + 1);
57 }
58 
59 void EDApplication::LoadEvent() {
60  static const std::string routineName("EDApplication::LoadEvent");
61 
62  if (_evtToBeLoaded == _evtLoaded)
63  return;
64 
65  _FileManager->ReadEvent(_evtToBeLoaded);
66  _evtLoaded = _evtToBeLoaded;
67  _MainWindow->SetEventNumber(_evtLoaded + 1);
68 }
69 
70 void EDApplication::SetFileToBeLoaded(char *text) { _fileToBeLoaded = text; }
71 
72 void EDApplication::SetEventToBeLoaded(char *text) {
73  _evtToBeLoaded = atoi(text) - 1;
74  if (_evtToBeLoaded < 0)
75  _evtToBeLoaded = 0;
76 }
77 
78 void EDApplication::SetDisplayDetector(char *det) {
79  static const std::string routineName("EDApplication::SetDisplayDetector");
80 
81  Bool_t s = kTRUE;
82  if (gTQSender) { // check that this is coming from a signal
83  TGCheckButton *but = (TGCheckButton *)gTQSender;
84  s = but->IsDown();
85  }
86 
87  _MainWindow->SetDisplayDetector(det, s);
88 }
89 
90 void EDApplication::SetDisplayPartHits(Bool_t s) { _MainWindow->SetDisplayPartHits(s); }
91 
92 void EDApplication::LoadRootFile() {
93  static const std::string routineName("EDApplication::LoadRootFile");
94 
95  if (!_fileToBeLoaded.CompareTo(_fileLoaded))
96  return;
97 
98  _FileManager->Load(_fileToBeLoaded);
99  _fileLoaded = _fileToBeLoaded;
100 
101  if (_MainWindow && _FileManager->FileIsLoaded()) {
102  _MainWindow->SetFileName(_fileLoaded);
103  _MainWindow->UpdateFileEntries();
104  _MainWindow->CreateMaps();
105  _FileManager->ReadEvent(0, true);
106  _MainWindow->SetEventNumber(0);
107  }
108 }
109 
110 void EDApplication::HandleArgs() {
111 
112  int parse_status = argp_parse(&argp, Argc(), Argv(), 0, 0, &args);
113  if (parse_status)
114  exit(42);
115 }
116 
117 void EDApplication::InitGUI() {
118 
119  TEveUtil::SetupEnvironment();
120  TEveUtil::SetupGUI();
121  _MainWindow = new MainWindow();
122  if (!args.flag_debug) {
123  _MainWindow->GetBrowser()->HideBottomTab();
124  }
125 
126  LoadGeometry();
127 }
128 
129 void EDApplication::LoadGeometry() {
130  static const std::string routineName("EDApplication::EDApplication");
131 
132  const std::string geoFileName = args.geofilename ? args.geofilename : args.infilename;
133 
134 #ifdef USE_TGEOGDML
135  if (geoFileName.substr(geoFileName.size() - 5) == ".gdml") {
136  TGeoManager::LockDefaultUnits(kFALSE);
137  TGeoManager::SetDefaultUnits(TGeoManager::EDefaultUnits::kRootUnits);
138  }
139 #endif
140 
141  if (GGSSmartLog::verboseLevel < GGSSmartLog::DEBUG) {
142  GGSSmartLog::MuteOutput();
143  }
144  _MainWindow->GetGeometry(geoFileName);
145  GGSSmartLog::UnmuteOutput();
146  _GeoManager = new LeonardGeoManager();
147 
148  gGeoManager->DefaultColors();
149 
150  _MainWindow->AddGlobalElement(_GeoManager->GetEveGeoTopNode());
151  _GeoManager->GetEveGeoTopNode()->ExpandIntoListTreesRecursively();
152 
153  _MainWindow->FullRedraw3D(kTRUE);
154 
155  _MainWindow->GetDefaultGLViewer()->GetClipSet()->SetClipType(TGLClip::EType(2));
156 
157  _MainWindow->GetDefaultGLViewer()->ResetCameras();
158  _MainWindow->GetDefaultGLViewer()->CurrentCamera().RotateRad(-TMath::Pi() / 6, -9 * TMath::Pi() / 12);
159  _MainWindow->GetDefaultGLViewer()->GetLightSet()->SetUseSpecular(false);
160 }
161 
162 int EDApplication::ParseArgs(int key, char *arg, struct argp_state *state) {
163 
164  struct arguments *a = (struct arguments *)state->input;
165 
166  switch (key) {
167  case 'd': {
168  a->flag_debug = kTRUE;
169  break;
170  }
171  case 'i': {
172  a->infilename = arg;
173  break;
174  }
175  case 'g': {
176  a->geofilename = arg;
177  break;
178  }
179  case ARGP_KEY_ARG: {
180  argp_failure(state, 1, 0, "No arguments requested");
181  break;
182  }
183  case ARGP_KEY_INIT: {
184  a->infilename = NULL;
185  a->geofilename = NULL;
186  a->flag_debug = false;
187  break;
188  }
189  case ARGP_KEY_END: {
190  if (a->geofilename == nullptr && a->infilename == nullptr) {
191  argp_failure(state, 1, 0, R"(Must provide at least one between input file (-i) and geometry file (-g))");
192  }
193  // if (!a->geofilename)
194  // argp_failure(
195  // state, 1, 0,
196  // "No geometry file specified \nUse -G flag to provide VGM geometry");
197  // std::cout << std::endl;
198  break;
199  }
200  }
201 
202  return 0;
203 }
204 
205 // -- Static for cli parsing
206 struct argp_option EDApplication::options[] = {{"debug", 'd', 0, 0, "Enable Debug Info", 0},
207  {"input-file", 'i', "FILE", 0, "Input file", 0},
208  {"geometry", 'g', "FILE", 0, "Geometry file", 0},
209  {0, 0, 0, 0, 0, 0}};
210 struct argp EDApplication::argp = {options, EDApplication::ParseArgs, 0, 0, 0, 0, 0};
#define GGSENDL
Definition: GGSSmartLog.h:131