1 | |
---|
2 | // this : |
---|
3 | #include <G4Lab/Manager.h> |
---|
4 | |
---|
5 | // Other includes : |
---|
6 | |
---|
7 | // Inventor : |
---|
8 | #include <Inventor/nodes/SoNode.h> |
---|
9 | |
---|
10 | #ifdef WIN32 |
---|
11 | #undef pascal // Clash between windef.h and Geant4/SystemOfUnits.hh |
---|
12 | #endif |
---|
13 | |
---|
14 | // Geant4 : |
---|
15 | #include <G4UImanager.hh> |
---|
16 | #include <G4UIsession.hh> |
---|
17 | #include <G4RunManager.hh> |
---|
18 | #include <G4UIcommandTree.hh> |
---|
19 | #include <G4SDManager.hh> |
---|
20 | #include <G4DigiManager.hh> |
---|
21 | |
---|
22 | // Lib : |
---|
23 | #include <Slash/Core/IManager.h> |
---|
24 | #include <Slash/Core/ISession.h> |
---|
25 | #include <Slash/Data/IProcessor.h> |
---|
26 | #include <Lib/Manager.h> |
---|
27 | #include <Lib/Cast.h> |
---|
28 | #include <Lib/Out.h> |
---|
29 | #include <Lib/sout.h> |
---|
30 | #include <Lib/smanip.h> |
---|
31 | |
---|
32 | // OnX : |
---|
33 | #include <Slash/UI/IScriptManager.h> |
---|
34 | |
---|
35 | // AIDA : |
---|
36 | #include <AIDA/IAnalysisFactory.h> |
---|
37 | |
---|
38 | // G4Lab : |
---|
39 | #include <G4Lab/PhysicalVolumeAccessor.h> |
---|
40 | #include <G4Lab/TrajectoryContainerAccessor.h> |
---|
41 | #include <G4Lab/TrajectoryAccessor.h> |
---|
42 | #include <G4Lab/PhysicsTableAccessor.h> |
---|
43 | #include <G4Lab/HitsCollectionAccessor.h> |
---|
44 | #include <G4Lab/Tree.h> |
---|
45 | #include <G4Lab/State.h> |
---|
46 | #include <G4Lab/SoG4Trajectories.h> |
---|
47 | #include <G4Lab/SoG4RunManager.h> |
---|
48 | |
---|
49 | // From G4VBasicShell (tag geant4-05-00-ref-01) |
---|
50 | static G4String Complete(G4String); |
---|
51 | static G4String FindMatchingPath(G4UIcommandTree*,G4String); |
---|
52 | |
---|
53 | // Class to redirect G4 output to OnX console and do command completion : |
---|
54 | // Avoid establishing a relationship with G4interfaces (by inheriting |
---|
55 | // G4VBasicShell). This library may be reconstructed with various GUI drivers. |
---|
56 | |
---|
57 | namespace G4Lab { |
---|
58 | class UIsession : public G4UIsession { |
---|
59 | public: //G4UIsession |
---|
60 | virtual G4int ReceiveG4cout(G4String aString){ |
---|
61 | fOut << aString; |
---|
62 | return 0; |
---|
63 | } |
---|
64 | virtual G4int ReceiveG4cerr(G4String aString){ |
---|
65 | fOut << aString; |
---|
66 | return 0; |
---|
67 | } |
---|
68 | public: |
---|
69 | UIsession(Slash::Core::IWriter& aPrinter):fOut(aPrinter){} |
---|
70 | std::string completeCommand(const std::string& aString) { |
---|
71 | return Complete(aString); |
---|
72 | } |
---|
73 | private: |
---|
74 | Lib::Out fOut; |
---|
75 | }; |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | ////////////////////////////////////////////////////////////////////////////// |
---|
80 | ////////////////////////////////////////////////////////////////////////////// |
---|
81 | ////////////////////////////////////////////////////////////////////////////// |
---|
82 | G4Lab::Manager::Manager( |
---|
83 | Slash::Core::ISession& aSession |
---|
84 | ,const std::string& aName |
---|
85 | ,G4RunManager* aRunManager |
---|
86 | ,bool aDeleteRunManager |
---|
87 | ) |
---|
88 | :fSession(aSession) |
---|
89 | ,fName(aName) |
---|
90 | ,fUIsession(0) |
---|
91 | ,fState(0) |
---|
92 | ,fScriptManager(0) |
---|
93 | ,fRunManager(aRunManager) |
---|
94 | ,fDeleteRunManager(aDeleteRunManager) |
---|
95 | ////////////////////////////////////////////////////////////////////////////// |
---|
96 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
97 | { |
---|
98 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
99 | if(UI) { |
---|
100 | fUIsession = new UIsession(fSession.printer()); |
---|
101 | UI->SetSession(fUIsession); |
---|
102 | UI->SetCoutDestination(fUIsession); |
---|
103 | } |
---|
104 | |
---|
105 | fScriptManager = |
---|
106 | Lib_findManager(fSession,"ScriptManager",Slash::UI::IScriptManager); |
---|
107 | if(!fScriptManager) { |
---|
108 | Lib::Out out(fSession.printer()); |
---|
109 | out << "G4Lab::Manager::Manager :" |
---|
110 | << " ScriptManager not found." |
---|
111 | << Lib::endl; |
---|
112 | } else { |
---|
113 | fScriptManager->addInterpreter("G4","","","","","",executeScript,0); |
---|
114 | } |
---|
115 | |
---|
116 | // The G4Lab::State will be deleted by the run manager. |
---|
117 | fState = new G4Lab::State(fScriptManager); |
---|
118 | } |
---|
119 | ////////////////////////////////////////////////////////////////////////////// |
---|
120 | G4Lab::Manager::~Manager( |
---|
121 | ) |
---|
122 | ////////////////////////////////////////////////////////////////////////////// |
---|
123 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
124 | { |
---|
125 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
126 | if(UI) { |
---|
127 | UI->SetSession(0); |
---|
128 | UI->SetCoutDestination(0); |
---|
129 | } |
---|
130 | delete fUIsession; |
---|
131 | |
---|
132 | // We should remove G4Lab things in the AccessorManager... |
---|
133 | |
---|
134 | // The G4Lab::State is deleted by the run manager. |
---|
135 | |
---|
136 | if(fDeleteRunManager) { |
---|
137 | delete fRunManager; |
---|
138 | fRunManager = 0; |
---|
139 | } else { |
---|
140 | // The fRunManager is deleted by the user. |
---|
141 | } |
---|
142 | } |
---|
143 | ////////////////////////////////////////////////////////////////////////////// |
---|
144 | AIDA::IAnalysisFactory* G4Lab::Manager::findAIDA( |
---|
145 | ) |
---|
146 | ////////////////////////////////////////////////////////////////////////////// |
---|
147 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
148 | { |
---|
149 | AIDA::IAnalysisFactory* aida = |
---|
150 | Lib_findManager(fSession,"AnalysisFactory",AIDA::IAnalysisFactory); |
---|
151 | if(!aida) { |
---|
152 | if(!fScriptManager) return 0; |
---|
153 | fScriptManager->executeScript("Session","OnXLab OnXLab_createAIDA"); |
---|
154 | aida = Lib_findManager(fSession,"AnalysisFactory",AIDA::IAnalysisFactory); |
---|
155 | } |
---|
156 | return aida; |
---|
157 | } |
---|
158 | ////////////////////////////////////////////////////////////////////////////// |
---|
159 | bool G4Lab::Manager::initialize( |
---|
160 | ) |
---|
161 | ////////////////////////////////////////////////////////////////////////////// |
---|
162 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
163 | { |
---|
164 | AIDA::IAnalysisFactory* aida = |
---|
165 | Lib_findManager(fSession,"AnalysisFactory",AIDA::IAnalysisFactory); |
---|
166 | |
---|
167 | Slash::Data::IProcessor* accessorManager = |
---|
168 | Lib_findManager(fSession,"AccessorManager",Slash::Data::IProcessor); |
---|
169 | if(!accessorManager) { |
---|
170 | Lib::Out out(fSession.printer()); |
---|
171 | out << "G4Lab::Manager::initialize :" |
---|
172 | << " AccessorManager not found." << Lib::endl; |
---|
173 | return false; |
---|
174 | } else { |
---|
175 | if(!accessorManager->findAccessor("PV")) { |
---|
176 | accessorManager->addAccessor(new PhysicalVolumeAccessor(fSession)); |
---|
177 | accessorManager->addAccessor(new TrajectoryContainerAccessor(fSession)); |
---|
178 | accessorManager->addAccessor(new TrajectoryAccessor(fSession)); |
---|
179 | accessorManager->addAccessor(new PhysicsTableAccessor(fSession,aida)); |
---|
180 | |
---|
181 | // Declare HitsCollections types : |
---|
182 | if(fRunManager) { |
---|
183 | if(!fRunManager->GetUserDetectorConstruction()) { |
---|
184 | Lib::Out out(fSession.printer()); |
---|
185 | out << "G4Lab::Manager::initialize :" |
---|
186 | << " G4RunManager did not receive yet the" |
---|
187 | << " user detector construction class." |
---|
188 | << Lib::endl; |
---|
189 | out << "G4Lab::Manager::initialize :" |
---|
190 | << " We can't then build the hits collection types." |
---|
191 | << Lib::endl; |
---|
192 | } else { |
---|
193 | fRunManager->Initialize(); //FIXME : should be able to check if done. |
---|
194 | G4SDManager* sdManager = G4SDManager::GetSDMpointer(); |
---|
195 | if(sdManager) { |
---|
196 | G4HCtable* hcTable = sdManager->GetHCtable(); |
---|
197 | if(hcTable) { |
---|
198 | int number = hcTable->entries(); |
---|
199 | for(int index=0;index<number;index++) { |
---|
200 | G4String hcName = hcTable->GetHCname(index); |
---|
201 | accessorManager->addAccessor |
---|
202 | (new HitsCollectionAccessor(fSession,hcName)); |
---|
203 | if(fSession.verboseLevel()) { |
---|
204 | Lib::Out out(fSession.printer()); |
---|
205 | out << "G4Lab::Manager::initialize :" |
---|
206 | << " declare HitsCollection type " << Lib::sout(hcName) |
---|
207 | << Lib::endl; |
---|
208 | } |
---|
209 | } |
---|
210 | } |
---|
211 | } |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | //Declare the generic HitsCollection type : |
---|
216 | accessorManager->addAccessor(new HitsCollectionAccessor(fSession)); |
---|
217 | |
---|
218 | // Should be initialized once after Inventor and HEPVis : |
---|
219 | SoG4Trajectories::initClass(); |
---|
220 | SoG4RunManager::initClass(); |
---|
221 | } |
---|
222 | } |
---|
223 | return true; |
---|
224 | } |
---|
225 | ////////////////////////////////////////////////////////////////////////////// |
---|
226 | void G4Lab::Manager::addAccessor( |
---|
227 | Slash::Data::IAccessor* aAccessor |
---|
228 | ) |
---|
229 | ////////////////////////////////////////////////////////////////////////////// |
---|
230 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
231 | { |
---|
232 | Slash::Data::IProcessor* accessorManager = |
---|
233 | Lib_findManager(fSession,"AccessorManager",Slash::Data::IProcessor); |
---|
234 | if(!accessorManager) { |
---|
235 | Lib::Out out(fSession.printer()); |
---|
236 | out << "G4Lab::Manager::addAccessor :" |
---|
237 | << " AccessorManager not found." << Lib::endl; |
---|
238 | return; |
---|
239 | } |
---|
240 | accessorManager->addAccessor(aAccessor); |
---|
241 | } |
---|
242 | ////////////////////////////////////////////////////////////////////////////// |
---|
243 | void G4Lab::Manager::executeG4Script( |
---|
244 | const std::string& aString |
---|
245 | ) |
---|
246 | ////////////////////////////////////////////////////////////////////////////// |
---|
247 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
248 | { |
---|
249 | if(!fScriptManager) return; |
---|
250 | fScriptManager->executeScript("G4",aString); |
---|
251 | } |
---|
252 | ////////////////////////////////////////////////////////////////////////////// |
---|
253 | std::string G4Lab::Manager::completeCommand( |
---|
254 | const std::string& aString |
---|
255 | ) |
---|
256 | ////////////////////////////////////////////////////////////////////////////// |
---|
257 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
258 | { |
---|
259 | if(!fUIsession) return ""; |
---|
260 | return fUIsession->completeCommand(aString); |
---|
261 | } |
---|
262 | ////////////////////////////////////////////////////////////////////////////// |
---|
263 | bool G4Lab::Manager::executeScript( |
---|
264 | const std::string& aString |
---|
265 | ,void* |
---|
266 | ) |
---|
267 | ////////////////////////////////////////////////////////////////////////////// |
---|
268 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
269 | { |
---|
270 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
271 | if(!UI) return false; |
---|
272 | std::vector<std::string> text; |
---|
273 | Lib::smanip::lines(aString,text); |
---|
274 | int linen = text.size(); |
---|
275 | if(linen) { |
---|
276 | for(int count=0;count<linen;count++) { |
---|
277 | std::string line = text[count]; |
---|
278 | Lib::smanip::strip(line); |
---|
279 | if( (line[0]=='\0') || (line[0]=='#') ) continue; |
---|
280 | UI->ApplyCommand(line); |
---|
281 | } |
---|
282 | } |
---|
283 | return true; |
---|
284 | } |
---|
285 | #include <G4TransportationManager.hh> |
---|
286 | #include <G4Navigator.hh> |
---|
287 | #include <G4ParticleTable.hh> |
---|
288 | ////////////////////////////////////////////////////////////////////////////// |
---|
289 | std::string G4Lab::Manager::physicalVolumes( |
---|
290 | ) |
---|
291 | ////////////////////////////////////////////////////////////////////////////// |
---|
292 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
293 | { |
---|
294 | #define UNLIMITED (-1) |
---|
295 | G4TransportationManager* tsp = |
---|
296 | G4TransportationManager::GetTransportationManager(); |
---|
297 | if(!tsp) { |
---|
298 | Lib::Out out(fSession.printer()); |
---|
299 | out << "G4Lab::Manager::physicalVolumes : " |
---|
300 | << "can't find the G4TransportationManager." |
---|
301 | << Lib::endl; |
---|
302 | return ""; |
---|
303 | } |
---|
304 | G4Navigator* nav = tsp->GetNavigatorForTracking(); |
---|
305 | if(!nav) { |
---|
306 | Lib::Out out(fSession.printer()); |
---|
307 | out << "G4Lab::Manager::physicalVolumes : " |
---|
308 | << "can't get the G4Navigator on G4TransportationManager." |
---|
309 | << Lib::endl; |
---|
310 | return ""; |
---|
311 | } |
---|
312 | G4VPhysicalVolume* topVolume = nav->GetWorldVolume(); |
---|
313 | if(!topVolume) { |
---|
314 | Lib::Out out(fSession.printer()); |
---|
315 | out << "G4Lab::Manager::physicalVolumes : " |
---|
316 | << "no world volume in G4Navigator." << Lib::endl; |
---|
317 | return ""; |
---|
318 | } |
---|
319 | std::string sout; |
---|
320 | sout += "<tree>"; |
---|
321 | XML_VisitedVolume xmlVisitedVolume(sout); |
---|
322 | GeometryVisitor geometryVisitor; |
---|
323 | geometryVisitor.visit(topVolume, |
---|
324 | UNLIMITED, |
---|
325 | G4Transform3D(), |
---|
326 | &xmlVisitedVolume); |
---|
327 | sout += "</tree>"; |
---|
328 | return sout; |
---|
329 | } |
---|
330 | ////////////////////////////////////////////////////////////////////////////// |
---|
331 | std::string G4Lab::Manager::hitsCollections( |
---|
332 | ) |
---|
333 | ////////////////////////////////////////////////////////////////////////////// |
---|
334 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
335 | { |
---|
336 | G4SDManager* sdManager = G4SDManager::GetSDMpointer(); |
---|
337 | if(!sdManager) return ""; |
---|
338 | G4HCtable* hcTable = sdManager->GetHCtable(); |
---|
339 | if(!hcTable) return ""; |
---|
340 | std::string sout; |
---|
341 | sout += "<tree>"; |
---|
342 | int number = hcTable->entries(); |
---|
343 | for(int index=0;index<number;index++) { |
---|
344 | G4String hcName = hcTable->GetHCname(index); |
---|
345 | sout += "<treeItem><label>"; |
---|
346 | sout += hcName; |
---|
347 | sout += "</label></treeItem>"; |
---|
348 | } |
---|
349 | sout += "</tree>"; |
---|
350 | return sout; |
---|
351 | } |
---|
352 | ////////////////////////////////////////////////////////////////////////////// |
---|
353 | std::string G4Lab::Manager::digitsCollections( |
---|
354 | ) |
---|
355 | ////////////////////////////////////////////////////////////////////////////// |
---|
356 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
357 | { |
---|
358 | G4DigiManager* digiManager = G4DigiManager::GetDMpointer(); |
---|
359 | if(!digiManager) return ""; |
---|
360 | G4DCtable* dcTable = digiManager->GetDCtable(); |
---|
361 | if(!dcTable) return ""; |
---|
362 | std::string sout; |
---|
363 | sout += "<tree>"; |
---|
364 | int number = dcTable->entries(); |
---|
365 | for(int index=0;index<number;index++) { |
---|
366 | G4String dcName = dcTable->GetDCname(index); |
---|
367 | sout += "<treeItem><label>"; |
---|
368 | sout += dcName; |
---|
369 | sout += "</label></treeItem>"; |
---|
370 | } |
---|
371 | sout += "</tree>"; |
---|
372 | return sout; |
---|
373 | } |
---|
374 | ////////////////////////////////////////////////////////////////////////////// |
---|
375 | void G4Lab::Manager::setRunBeginScript( |
---|
376 | const std::string& aInterp |
---|
377 | ,const std::string& aScript |
---|
378 | ) |
---|
379 | ////////////////////////////////////////////////////////////////////////////// |
---|
380 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
381 | { |
---|
382 | fState->setRunBeginScript(aInterp,aScript); |
---|
383 | } |
---|
384 | ////////////////////////////////////////////////////////////////////////////// |
---|
385 | void G4Lab::Manager::setRunEndScript( |
---|
386 | const std::string& aInterp |
---|
387 | ,const std::string& aScript |
---|
388 | ) |
---|
389 | ////////////////////////////////////////////////////////////////////////////// |
---|
390 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
391 | { |
---|
392 | fState->setRunEndScript(aInterp,aScript); |
---|
393 | } |
---|
394 | ////////////////////////////////////////////////////////////////////////////// |
---|
395 | void G4Lab::Manager::setEventBeginScript( |
---|
396 | const std::string& aInterp |
---|
397 | ,const std::string& aScript |
---|
398 | ) |
---|
399 | ////////////////////////////////////////////////////////////////////////////// |
---|
400 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
401 | { |
---|
402 | fState->setEventBeginScript(aInterp,aScript); |
---|
403 | } |
---|
404 | ////////////////////////////////////////////////////////////////////////////// |
---|
405 | void G4Lab::Manager::setEventEndScript( |
---|
406 | const std::string& aInterp |
---|
407 | ,const std::string& aScript |
---|
408 | ) |
---|
409 | ////////////////////////////////////////////////////////////////////////////// |
---|
410 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
411 | { |
---|
412 | fState->setEventEndScript(aInterp,aScript); |
---|
413 | } |
---|
414 | ////////////////////////////////////////////////////////////////////////////// |
---|
415 | std::string G4Lab::Manager::name( |
---|
416 | ) const |
---|
417 | ////////////////////////////////////////////////////////////////////////////// |
---|
418 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
419 | { |
---|
420 | return fName; |
---|
421 | } |
---|
422 | ////////////////////////////////////////////////////////////////////////////// |
---|
423 | void* G4Lab::Manager::cast( |
---|
424 | const std::string& aClass |
---|
425 | ) const |
---|
426 | ////////////////////////////////////////////////////////////////////////////// |
---|
427 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
428 | { |
---|
429 | if_Lib_SCast(G4Lab::Manager) |
---|
430 | else if_Lib_SCast(Slash::Core::IManager) |
---|
431 | else if_Lib_SCast(IGeant4Manager) |
---|
432 | else return 0; |
---|
433 | } |
---|
434 | ////////////////////////////////////////////////////////////////////////////// |
---|
435 | G4RunManager* G4Lab::Manager::runManager( |
---|
436 | ) const |
---|
437 | ////////////////////////////////////////////////////////////////////////////// |
---|
438 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
439 | { |
---|
440 | return fRunManager; |
---|
441 | } |
---|
442 | ////////////////////////////////////////////////////////////////////////////// |
---|
443 | G4SDManager* G4Lab::Manager::sdManager( |
---|
444 | ) const |
---|
445 | ////////////////////////////////////////////////////////////////////////////// |
---|
446 | // Used by callbacks if having not shared libs for Geant4. |
---|
447 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
448 | { |
---|
449 | return G4SDManager::GetSDMpointer(); |
---|
450 | } |
---|
451 | ////////////////////////////////////////////////////////////////////////////// |
---|
452 | ////////////////////////////////////////////////////////////////////////////// |
---|
453 | void G4Lab::Manager::beamOn( |
---|
454 | int aNumber |
---|
455 | ) |
---|
456 | ////////////////////////////////////////////////////////////////////////////// |
---|
457 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
458 | { |
---|
459 | if(!fRunManager) return; |
---|
460 | fRunManager->BeamOn(aNumber); |
---|
461 | } |
---|
462 | ////////////////////////////////////////////////////////////////////////////// |
---|
463 | void G4Lab::Manager::abortRun( |
---|
464 | ) |
---|
465 | ////////////////////////////////////////////////////////////////////////////// |
---|
466 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
467 | { |
---|
468 | if(!fRunManager) return; |
---|
469 | fRunManager->AbortRun(); |
---|
470 | } |
---|
471 | ////////////////////////////////////////////////////////////////////////////// |
---|
472 | bool G4Lab::Manager::isRunning( |
---|
473 | ) |
---|
474 | ////////////////////////////////////////////////////////////////////////////// |
---|
475 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
476 | { |
---|
477 | return fState->isRunning(); |
---|
478 | } |
---|
479 | ////////////////////////////////////////////////////////////////////////////// |
---|
480 | void G4Lab::Manager::particleTableDump( |
---|
481 | ) |
---|
482 | ////////////////////////////////////////////////////////////////////////////// |
---|
483 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
484 | { |
---|
485 | G4ParticleTable* table = G4ParticleTable::GetParticleTable(); |
---|
486 | if(!table) return; |
---|
487 | table->DumpTable("ALL"); |
---|
488 | } |
---|
489 | ////////////////////////////////////////////////////////////////////////////// |
---|
490 | ////////////////////////////////////////////////////////////////////////////// |
---|
491 | // From G4VBasicShell (tag geant4-05-00-ref-01) |
---|
492 | ////////////////////////////////////////////////////////////////////////////// |
---|
493 | static G4String Complete( |
---|
494 | G4String commandName |
---|
495 | ) |
---|
496 | ////////////////////////////////////////////////////////////////////////////// |
---|
497 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
498 | { |
---|
499 | G4String rawCommandLine = commandName; |
---|
500 | G4String commandLine = rawCommandLine.strip(G4String::both); |
---|
501 | size_t i = commandLine.index(" "); |
---|
502 | if( i != std::string::npos ) return rawCommandLine; // Already entering parameters, |
---|
503 | // assume command path is correct. |
---|
504 | G4String commandString = commandLine; |
---|
505 | //G4String targetCom = ModifyPath(commandString); |
---|
506 | G4String targetCom = commandString; |
---|
507 | G4UIcommandTree* tree = G4UImanager::GetUIpointer()->GetTree(); |
---|
508 | G4String value = FindMatchingPath(tree,targetCom); |
---|
509 | if(value=="") return rawCommandLine; |
---|
510 | return value; |
---|
511 | } |
---|
512 | ////////////////////////////////////////////////////////////////////////////// |
---|
513 | static G4String FindMatchingPath( |
---|
514 | G4UIcommandTree* aTree |
---|
515 | ,G4String aCommandPath |
---|
516 | ) |
---|
517 | ////////////////////////////////////////////////////////////////////////////// |
---|
518 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
519 | // From intercoms/src/G4UIcommandTree::FindPath. |
---|
520 | { |
---|
521 | G4String empty = ""; |
---|
522 | if(aTree==NULL) return empty; |
---|
523 | G4String pathName = aTree->GetPathName(); |
---|
524 | if( aCommandPath.index( pathName ) == std::string::npos ) return empty; |
---|
525 | G4String remainingPath = aCommandPath; |
---|
526 | remainingPath.remove(0,pathName.length()); |
---|
527 | size_t i = remainingPath.first('/'); |
---|
528 | if( i == std::string::npos ) { |
---|
529 | // Look for number of matching commands : |
---|
530 | std::vector<G4UIcommand*> commands; |
---|
531 | G4int n_commandEntry = aTree->GetCommandEntry(); |
---|
532 | for( G4int i_thCommand = 1; i_thCommand <= n_commandEntry; i_thCommand++ ) { |
---|
533 | G4UIcommand* cmd = aTree->GetCommand(i_thCommand); |
---|
534 | G4String ss = cmd->GetCommandName(); |
---|
535 | ss.resize(remainingPath.length()); |
---|
536 | if( remainingPath == ss ) commands.push_back(cmd); |
---|
537 | } |
---|
538 | n_commandEntry = commands.size(); |
---|
539 | if(n_commandEntry==1) { |
---|
540 | return (pathName + commands[0]->GetCommandName()); |
---|
541 | } else if (n_commandEntry>=2) { |
---|
542 | G4cout << "Matching commands :" << G4endl; |
---|
543 | for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ ) { |
---|
544 | G4UIcommand* cmd = commands[i_thCommand]; |
---|
545 | G4cout << cmd->GetCommandName() << G4endl; |
---|
546 | } |
---|
547 | return empty; |
---|
548 | } |
---|
549 | // Look for sub tree : |
---|
550 | std::vector<G4UIcommandTree*> trees; |
---|
551 | G4String nextPath = pathName; |
---|
552 | nextPath.append(remainingPath); |
---|
553 | G4int n_treeEntry = aTree->GetTreeEntry(); |
---|
554 | for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) { |
---|
555 | G4UIcommandTree* tree = aTree->GetTree(i_thTree); |
---|
556 | G4String ss = tree->GetPathName(); |
---|
557 | ss.resize(nextPath.length()); |
---|
558 | if( nextPath == ss ) trees.push_back(tree); |
---|
559 | } |
---|
560 | n_treeEntry = trees.size(); |
---|
561 | if(n_treeEntry==1) { |
---|
562 | return trees[0]->GetPathName(); |
---|
563 | } else if (n_treeEntry>=2) { |
---|
564 | G4cout << "Matching directories :" << G4endl; |
---|
565 | for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ ) { |
---|
566 | G4UIcommandTree* tree = trees[i_thTree]; |
---|
567 | G4cout << tree->GetPathName() << G4endl; |
---|
568 | } |
---|
569 | return empty; |
---|
570 | } else { |
---|
571 | return empty; // No match. |
---|
572 | } |
---|
573 | } else { |
---|
574 | // Find path |
---|
575 | G4String nextPath = pathName; |
---|
576 | nextPath.append(remainingPath(0,i+1)); |
---|
577 | G4int n_treeEntry = aTree->GetTreeEntry(); |
---|
578 | for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) { |
---|
579 | G4UIcommandTree* tree = aTree->GetTree(i_thTree); |
---|
580 | if( nextPath == tree->GetPathName() ) { |
---|
581 | return FindMatchingPath(tree,aCommandPath ); |
---|
582 | } |
---|
583 | } |
---|
584 | } |
---|
585 | return empty; |
---|
586 | } |
---|