source: snovis/trunk/source/G4Lab/cxx/Callbacks.cxx@ 288

Last change on this file since 288 was 233, checked in by barrand, 19 years ago
  • Property svn:eol-style set to native
File size: 11.4 KB
Line 
1// There is no explicit dependancy to G4 libs
2// due to the fact that we can't have DLLs for them
3// on Windows and Darwin. We pass through the
4// IGeant4Manager interface and the Lib type manager
5// to access Geant4 from the GUI callbacks.
6
7#include <OnX/Helpers/OnX.h>
8
9// Lib :
10#include <Slash/Core/ISession.h>
11#include <Lib/Manager.h>
12#include <Lib/smanip.h>
13#include <Lib/Printer.h>
14#include <Lib/Out.h>
15
16// OnX :
17#include <Slash/UI/IUI.h>
18
19// G4Lab :
20#include <G4Lab/Interfaces/IGeant4Manager.h>
21
22// AIDA :
23#include <AIDA/IAnalysisFactory.h>
24#include <AIDA/IPlotterFactory.h>
25#include <AIDA/IPlotter.h>
26#include <AIDA/IPlotterRegion.h>
27
28// From Lab/Callbacks/AIAA.h
29//////////////////////////////////////////////////////////////////////////////
30static AIDA::IAnalysisFactory* find_aida(
31 Slash::Core::ISession& aSession
32)
33//////////////////////////////////////////////////////////////////////////////
34//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
35{
36 return Lib_findManager(aSession,"AnalysisFactory",AIDA::IAnalysisFactory);
37}
38
39extern "C" {
40
41//////////////////////////////////////////////////////////////////////////////
42void data_PV_dump(
43 Slash::UI::IUI& aUI
44)
45//////////////////////////////////////////////////////////////////////////////
46//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
47{
48 Slash::Core::ISession& session = aUI.session();
49
50 data_collect(session,"PV");
51
52 std::string svalue;
53 session.parameterValue("AccessorManager.dumpMode",svalue);
54 data_dump(session,svalue);
55
56}
57//////////////////////////////////////////////////////////////////////////////
58void data_PhysicsTable_dump(
59 Slash::UI::IUI& aUI
60)
61//////////////////////////////////////////////////////////////////////////////
62//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
63{
64 Slash::Core::ISession& session = aUI.session();
65
66 data_collect(session,"PhysicsTable");
67
68 std::string svalue;
69 session.parameterValue("AccessorManager.dumpMode",svalue);
70 data_dump(session,svalue);
71
72}
73//////////////////////////////////////////////////////////////////////////////
74void data_CrossSestion_annihil_positron_vis(
75 Slash::UI::IUI& aUI
76)
77//////////////////////////////////////////////////////////////////////////////
78//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
79{
80 Slash::Core::ISession& session = aUI.session();
81
82 data_collect(session,"PhysicsTable",
83 "table==\"CrossSection\" and process==\"annihil\" and particle==\"e+\"");
84 data_visualize(session);
85}
86//////////////////////////////////////////////////////////////////////////////
87void G4_dump_ParticleTables(
88 Slash::UI::IUI& aUI
89)
90//////////////////////////////////////////////////////////////////////////////
91//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
92{
93 IGeant4Manager* g4Manager =
94 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
95 if(!g4Manager) {
96 Lib::Out out(aUI.session().printer());
97 out << "G4Lab_dump_ParticleTables :"
98 << " Geant4Manager not found."
99 << Lib::endl;
100 return;
101 }
102 g4Manager->particleTableDump();
103}
104//////////////////////////////////////////////////////////////////////////////
105//////////////////////////////////////////////////////////////////////////////
106//////////////////////////////////////////////////////////////////////////////
107void G4Lab_consolePrompt_complete(
108 Slash::UI::IUI& aUI
109)
110//////////////////////////////////////////////////////////////////////////////
111//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
112{
113 IGeant4Manager* g4Manager =
114 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
115 if(!g4Manager) {
116 Lib::Out out(aUI.session().printer());
117 out << "G4Lab_consolePrompt_complete :"
118 << " Geant4Manager not found."
119 << Lib::endl;
120 return;
121 }
122
123 std::string prompt;
124 if(!aUI.parameterValue("consolePrompt.value",prompt)) return;
125 if(prompt=="G4") {
126 aUI.setParameter("consoleCommandLine.value",
127 g4Manager->completeCommand(aUI.callbackValue()));
128 }
129}
130//////////////////////////////////////////////////////////////////////////////
131//////////////////////////////////////////////////////////////////////////////
132//////////////////////////////////////////////////////////////////////////////
133//////////////////////////////////////////////////////////////////////////////
134void G4Lab_exit(
135 Slash::UI::IUI& aUI
136)
137//////////////////////////////////////////////////////////////////////////////
138//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
139{
140 IGeant4Manager* g4Manager =
141 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
142 if(!g4Manager) return;
143 if(g4Manager->isRunning()) {
144 g4Manager->abortRun();
145 aUI.exit();
146 aUI.executeScript("DLD bg","OnX ui_exit");
147 } else {
148 aUI.exit();
149 }
150}
151//////////////////////////////////////////////////////////////////////////////
152void G4Lab_nextEvent(
153 Slash::UI::IUI& aUI
154)
155//////////////////////////////////////////////////////////////////////////////
156//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
157{
158 IGeant4Manager* g4Manager =
159 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
160 if(!g4Manager) return;
161 if(!g4Manager->isRunning()) {
162 aUI.warn("No run started.");
163 } else {
164 aUI.exit();
165 }
166}
167//////////////////////////////////////////////////////////////////////////////
168/// G4Lab/scripts/OnX ////////////////////////////////////////////////////////
169//////////////////////////////////////////////////////////////////////////////
170//////////////////////////////////////////////////////////////////////////////
171void G4Lab_InputRun_ok(
172 Slash::UI::IUI& aUI
173)
174//////////////////////////////////////////////////////////////////////////////
175//FIXME : have a better exit ! (Handle properly the case
176// where we exit whilst in a run.
177//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
178{
179 std::string action;
180 if(!aUI.parameterValue("G4Lab_InputRun_input_action.value",action)) return;
181
182 IGeant4Manager* g4Manager =
183 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
184 if(!g4Manager) {
185 Lib::Out out(aUI.session().printer());
186 out << "G4Lab_InputRun_ok :"
187 << " Geant4Manager not found."
188 << Lib::endl;
189 return;
190 }
191
192 if(action=="Start run") {
193 std::string snumber;
194 if(!aUI.parameterValue("G4Lab_InputRun_input_number.value",snumber))
195 return;
196 int number;
197 if(!Lib::smanip::toint(snumber,number)) return;
198
199 g4Manager->beamOn(number);
200
201 } else if(action=="Abort run") {
202 g4Manager->executeG4Script("/run/abort");
203
204 } else if(action=="Next event") {
205 aUI.exit();
206 }
207}
208//////////////////////////////////////////////////////////////////////////////
209void G4Lab_InputGun_ok(
210 Slash::UI::IUI& aUI
211)
212//////////////////////////////////////////////////////////////////////////////
213//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
214{
215 std::string direction;
216 if(!aUI.parameterValue("G4Lab_InputGun_input_direction.value",direction)) return;
217
218 std::string energy;
219 if(!aUI.parameterValue("G4Lab_InputGun_input_energy.value",energy)) return;
220
221 std::string particle;
222 if(!aUI.parameterValue("G4Lab_InputGun_input_particle.value",particle)) return;
223
224 IGeant4Manager* g4Manager =
225 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
226 if(!g4Manager) {
227 Lib::Out out(aUI.session().printer());
228 out << "G4Lab_InputGun_ok :"
229 << " Geant4Manager not found."
230 << Lib::endl;
231 return;
232 }
233
234 g4Manager->executeG4Script("/gun/particle "+particle);
235 g4Manager->executeG4Script("/gun/direction "+direction);
236 g4Manager->executeG4Script("/gun/energy "+energy);
237
238}
239//////////////////////////////////////////////////////////////////////////////
240/// For a standard tree widget ///////////////////////////////////////////////
241//////////////////////////////////////////////////////////////////////////////
242//////////////////////////////////////////////////////////////////////////////
243void G4Lab_tree_option(
244 Slash::UI::IUI& aUI
245)
246//////////////////////////////////////////////////////////////////////////////
247//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
248{
249 std::string item = aUI.callbackValue();
250 if(item=="PhysicalVolumes") {
251
252 IGeant4Manager* g4Manager =
253 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
254 if(!g4Manager) {
255 Lib::Out out(aUI.session().printer());
256 out << "G4Simple_tree_option :"
257 << " Geant4Manager not found."
258 << Lib::endl;
259 return;
260 }
261
262 tree_set(aUI,"mainTree.items",g4Manager->physicalVolumes());
263
264 } else if(item=="PhysicsTables") {
265
266 data_collect(aUI.session(),"PhysicsTable");
267 std::vector<std::string> vs = data_values(aUI.session(),"name");
268 tree_set(aUI,"mainTree.items",Lib::smanip::tostring(vs,"\n"));
269
270 } else if(item=="HitsCollections") {
271
272 IGeant4Manager* g4Manager =
273 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
274 if(!g4Manager) {
275 Lib::Out out(aUI.session().printer());
276 out << "G4Simple_tree_option :"
277 << " Geant4Manager not found."
278 << Lib::endl;
279 return;
280 }
281
282 tree_set(aUI,"mainTree.items",g4Manager->hitsCollections());
283
284 } else if(item=="DigitsCollections") {
285
286 IGeant4Manager* g4Manager =
287 Lib_findManager(aUI.session(),"Geant4Manager",IGeant4Manager);
288 if(!g4Manager) {
289 Lib::Out out(aUI.session().printer());
290 out << "G4Simple_tree_option :"
291 << " Geant4Manager not found."
292 << Lib::endl;
293 return;
294 }
295
296 tree_set(aUI,"mainTree.items",g4Manager->digitsCollections());
297
298 } else {
299
300 aUI.executeScript("DLD","OnXLab OnXLab_tree_option");
301
302 }
303}
304//////////////////////////////////////////////////////////////////////////////
305void G4Lab_tree_select(
306 Slash::UI::IUI& aUI
307)
308//////////////////////////////////////////////////////////////////////////////
309//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
310{
311 std::string what;
312 if(!aUI.parameterValue("optionTree.value",what)) return;
313
314 if(what == "AIDA trees") {
315 aUI.executeScript("DLD","OnXLab OnXLab_mainTree_selection");
316 } else {
317 std::string selection;
318 if(!aUI.parameterValue("mainTree.selection",selection)) return;
319 std::vector<std::string> items;
320 Lib::smanip::lines(selection,items);
321 if(!items.size()) return;
322 if(what=="PhysicalVolumes") {
323 what = "PV";
324 data_collect(aUI.session(),what,"name==\""+items[items.size()-1]+"\"");
325 data_visualize(aUI.session());
326 } else if( (what=="HitsCollections") ||
327 (what=="DigitsCollections") ) {
328 what = items[items.size()-1];
329 data_collect(aUI.session(),what);
330 data_visualize(aUI.session());
331 } else if(what=="PhysicsTables") {
332 what = "PhysicsTable";
333 // Clear current region :
334 AIDA::IAnalysisFactory* aida = find_aida(aUI.session());
335 if(aida) {
336 AIDA::IPlotterFactory* fac = aida->createPlotterFactory();
337 if(fac) {
338 AIDA::IPlotter* plotter = fac->create();
339 delete fac;
340 if(plotter) {
341 AIDA::IPlotterRegion& region = plotter->currentRegion();
342 region.clear();
343 delete plotter;
344 }
345 }
346 }
347 data_collect(aUI.session(),what,"name==\""+items[items.size()-1]+"\"");
348 data_visualize(aUI.session());
349 }
350 }
351}
352
353} // extern "C"
Note: See TracBrowser for help on using the repository browser.