GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
Application.cpp
1 #include "TEveBrowser.h"
2 #include "TEveViewer.h"
3 #include "TGLLightSet.h"
4 
5 #include "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  COUT(ERROR) << R"(Must provide at least one between input file (-i) and geometry file (-g))" << ENDL;
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 
39  delete _FileManager;
40  delete _MainWindow;
41  delete _GeoManager;
42 }
43 
44 void EDApplication::NextEvent() {
45  static const std::string routineName("EDApplication::NextEvent");
46 
47  _FileManager->NextEvent();
48  _evtLoaded = _FileManager->GetNevent();
49  _MainWindow->SetEventNumber(_evtLoaded + 1);
50 }
51 
52 void EDApplication::PrevEvent() {
53  static const std::string routineName("EDApplication::PrevEvent");
54 
55  _FileManager->PrevEvent();
56  _evtLoaded = _FileManager->GetNevent();
57  _MainWindow->SetEventNumber(_evtLoaded + 1);
58 }
59 
60 void EDApplication::LoadEvent() {
61  static const std::string routineName("EDApplication::LoadEvent");
62 
63  if (_evtToBeLoaded == _evtLoaded)
64  return;
65 
66  _FileManager->ReadEvent(_evtToBeLoaded);
67  _evtLoaded = _evtToBeLoaded;
68  _MainWindow->SetEventNumber(_evtLoaded + 1);
69 }
70 
71 void EDApplication::SetFileToBeLoaded(char *text) { _fileToBeLoaded = text; }
72 
73 void EDApplication::SetEventToBeLoaded(char *text) {
74  _evtToBeLoaded = atoi(text) - 1;
75  if (_evtToBeLoaded < 0)
76  _evtToBeLoaded = 0;
77 }
78 
79 void EDApplication::SetDisplayDetector(char *det) {
80  static const std::string routineName("EDApplication::SetDisplayDetector");
81 
82  Bool_t s = kTRUE;
83  if (gTQSender) { // check that this is coming from a signal
84  TGCheckButton *but = (TGCheckButton *)gTQSender;
85  s = but->IsDown();
86  }
87 
88  _MainWindow->SetDisplayDetector(det, s);
89 }
90 
91 void EDApplication::SetDisplayPartHits(Bool_t s) { _MainWindow->SetDisplayPartHits(s); }
92 
93 void EDApplication::LoadRootFile() {
94  static const std::string routineName("EDApplication::LoadRootFile");
95 
96  if (!_fileToBeLoaded.CompareTo(_fileLoaded))
97  return;
98 
99  _FileManager->Load(_fileToBeLoaded);
100  _fileLoaded = _fileToBeLoaded;
101 
102  if (_MainWindow && _FileManager->FileIsLoaded()) {
103  _MainWindow->SetFileName(_fileLoaded);
104  _MainWindow->UpdateFileEntries();
105  _MainWindow->CreateMaps();
106  _FileManager->ReadEvent(0, true);
107  _MainWindow->SetEventNumber(0);
108  }
109 }
110 
111 void EDApplication::HandleArgs() {
112 
113  int parse_status = argp_parse(&argp, Argc(), Argv(), 0, 0, &args);
114  if (parse_status)
115  exit(42);
116 }
117 
118 void EDApplication::InitGUI() {
119 
120  TEveUtil::SetupEnvironment();
121  TEveUtil::SetupGUI();
122  _MainWindow = new MainWindow();
123  if (!args.flag_debug) {
124  _MainWindow->GetBrowser()->HideBottomTab();
125  }
126 
127  LoadGeometry();
128 }
129 
130 void EDApplication::LoadGeometry() {
131  static const std::string routineName("EDApplication::EDApplication");
132 
133  const std::string geoFileName = args.geofilename ? args.geofilename : args.infilename;
134 
135  _GeoManager = new LeonardGeoManager(_MainWindow->GetGeometry(geoFileName));
136 
137  _GeoManager->DefaultColors();
138 
139  _MainWindow->AddGlobalElement(_GeoManager->GetEveGeoTopNode());
140  _GeoManager->GetEveGeoTopNode()->ExpandIntoListTreesRecursively();
141 
142  _MainWindow->FullRedraw3D(kTRUE);
143 
144  _MainWindow->GetDefaultGLViewer()->GetClipSet()->SetClipType(TGLClip::EType(2));
145 
146  _MainWindow->GetDefaultGLViewer()->ResetCameras();
147  _MainWindow->GetDefaultGLViewer()->CurrentCamera().RotateRad(-TMath::Pi() / 6, -9 * TMath::Pi() / 12);
148  _MainWindow->GetDefaultGLViewer()->GetLightSet()->SetUseSpecular(false);
149 }
150 
151 int EDApplication::ParseArgs(int key, char *arg, struct argp_state *state) {
152 
153  struct arguments *a = (struct arguments *)state->input;
154 
155  switch (key) {
156  case 'd': {
157  a->flag_debug = kTRUE;
158  break;
159  }
160  case 'i': {
161  a->infilename = arg;
162  break;
163  }
164  case 'g': {
165  a->geofilename = arg;
166  break;
167  }
168  case ARGP_KEY_ARG: {
169  argp_failure(state, 1, 0, "No arguments requested");
170  break;
171  }
172  case ARGP_KEY_INIT: {
173  a->infilename = NULL;
174  a->geofilename = NULL;
175  a->flag_debug = false;
176  break;
177  }
178  case ARGP_KEY_END: {
179  if (a->geofilename == nullptr && a->infilename == nullptr) {
180  argp_failure(state, 1, 0, R"(Must provide at least one between input file (-i) and geometry file (-g))");
181  }
182  // if (!a->geofilename)
183  // argp_failure(
184  // state, 1, 0,
185  // "No geometry file specified \nUse -G flag to provide VGM geometry");
186  // std::cout << std::endl;
187  break;
188  }
189  }
190 
191  return 0;
192 }
193 
194 // -- Static for cli parsing
195 struct argp_option EDApplication::options[] = {{"debug", 'd', 0, 0, "Enable Debug Info", 0},
196  {"input-file", 'i', "FILE", 0, "Input file", 0},
197  {"geometry", 'g', "FILE", 0, "Geometry file", 0},
198  {0, 0, 0, 0, 0, 0}};
199 struct argp EDApplication::argp = {options, EDApplication::ParseArgs, 0, 0, 0, 0, 0};
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76