| 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 | if(!fRunManager) {
|
|---|
| 177 | Lib::Out out(fSession.printer());
|
|---|
| 178 | out << "G4Lab::Manager::initialize :"
|
|---|
| 179 | << " no G4RunManager."
|
|---|
| 180 | << Lib::endl;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | accessorManager->addAccessor(new PhysicalVolumeAccessor(fSession));
|
|---|
| 184 | accessorManager->addAccessor
|
|---|
| 185 | (new TrajectoryContainerAccessor(fSession,fRunManager));
|
|---|
| 186 | accessorManager->addAccessor
|
|---|
| 187 | (new TrajectoryAccessor(fSession,fRunManager));
|
|---|
| 188 | accessorManager->addAccessor
|
|---|
| 189 | (new PhysicsTableAccessor(fSession,*this,aida));
|
|---|
| 190 |
|
|---|
| 191 | // Declare HitsCollections types :
|
|---|
| 192 | if(fRunManager) {
|
|---|
| 193 | if(!fRunManager->GetUserDetectorConstruction()) {
|
|---|
| 194 | Lib::Out out(fSession.printer());
|
|---|
| 195 | out << "G4Lab::Manager::initialize :"
|
|---|
| 196 | << " G4RunManager did not receive yet the"
|
|---|
| 197 | << " user detector construction class."
|
|---|
| 198 | << Lib::endl;
|
|---|
| 199 | out << "G4Lab::Manager::initialize :"
|
|---|
| 200 | << " We can't then build the hits collection types."
|
|---|
| 201 | << Lib::endl;
|
|---|
| 202 | } else {
|
|---|
| 203 | fRunManager->Initialize(); //FIXME : should be able to check if done.
|
|---|
| 204 | G4SDManager* sdManager = G4SDManager::GetSDMpointer();
|
|---|
| 205 | if(sdManager) {
|
|---|
| 206 | G4HCtable* hcTable = sdManager->GetHCtable();
|
|---|
| 207 | if(hcTable) {
|
|---|
| 208 | int number = hcTable->entries();
|
|---|
| 209 | for(int index=0;index<number;index++) {
|
|---|
| 210 | G4String hcName = hcTable->GetHCname(index);
|
|---|
| 211 | accessorManager->addAccessor
|
|---|
| 212 | (new HitsCollectionAccessor(fSession,fRunManager,hcName));
|
|---|
| 213 | if(fSession.verboseLevel()) {
|
|---|
| 214 | Lib::Out out(fSession.printer());
|
|---|
| 215 | out << "G4Lab::Manager::initialize :"
|
|---|
| 216 | << " declare HitsCollection type " << Lib::sout(hcName)
|
|---|
| 217 | << Lib::endl;
|
|---|
| 218 | }
|
|---|
| 219 | }
|
|---|
| 220 | }
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | //Declare the generic HitsCollection type :
|
|---|
| 226 | accessorManager->addAccessor
|
|---|
| 227 | (new HitsCollectionAccessor(fSession,fRunManager));
|
|---|
| 228 |
|
|---|
| 229 | // Should be initialized once after Inventor and HEPVis :
|
|---|
| 230 | SoG4Trajectories::initClass();
|
|---|
| 231 | SoG4RunManager::initClass();
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 | return true;
|
|---|
| 235 | }
|
|---|
| 236 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 237 | void G4Lab::Manager::addAccessor(
|
|---|
| 238 | Slash::Data::IAccessor* aAccessor
|
|---|
| 239 | )
|
|---|
| 240 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 241 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 242 | {
|
|---|
| 243 | Slash::Data::IProcessor* accessorManager =
|
|---|
| 244 | Lib_findManager(fSession,"AccessorManager",Slash::Data::IProcessor);
|
|---|
| 245 | if(!accessorManager) {
|
|---|
| 246 | Lib::Out out(fSession.printer());
|
|---|
| 247 | out << "G4Lab::Manager::addAccessor :"
|
|---|
| 248 | << " AccessorManager not found." << Lib::endl;
|
|---|
| 249 | return;
|
|---|
| 250 | }
|
|---|
| 251 | accessorManager->addAccessor(aAccessor);
|
|---|
| 252 | }
|
|---|
| 253 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 254 | void G4Lab::Manager::executeG4Script(
|
|---|
| 255 | const std::string& aString
|
|---|
| 256 | )
|
|---|
| 257 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 258 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 259 | {
|
|---|
| 260 | if(!fScriptManager) return;
|
|---|
| 261 | fScriptManager->executeScript("G4",aString);
|
|---|
| 262 | }
|
|---|
| 263 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 264 | std::string G4Lab::Manager::completeCommand(
|
|---|
| 265 | const std::string& aString
|
|---|
| 266 | )
|
|---|
| 267 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 268 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 269 | {
|
|---|
| 270 | if(!fUIsession) return "";
|
|---|
| 271 | return fUIsession->completeCommand(aString);
|
|---|
| 272 | }
|
|---|
| 273 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 274 | bool G4Lab::Manager::executeScript(
|
|---|
| 275 | const std::string& aString
|
|---|
| 276 | ,void*
|
|---|
| 277 | )
|
|---|
| 278 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 279 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 280 | {
|
|---|
| 281 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 282 | if(!UI) return false;
|
|---|
| 283 | std::vector<std::string> text;
|
|---|
| 284 | Lib::smanip::lines(aString,text);
|
|---|
| 285 | int linen = text.size();
|
|---|
| 286 | if(linen) {
|
|---|
| 287 | for(int count=0;count<linen;count++) {
|
|---|
| 288 | std::string line = text[count];
|
|---|
| 289 | Lib::smanip::strip(line);
|
|---|
| 290 | if( (line[0]=='\0') || (line[0]=='#') ) continue;
|
|---|
| 291 | UI->ApplyCommand(line);
|
|---|
| 292 | }
|
|---|
| 293 | }
|
|---|
| 294 | return true;
|
|---|
| 295 | }
|
|---|
| 296 | #include <G4TransportationManager.hh>
|
|---|
| 297 | #include <G4Navigator.hh>
|
|---|
| 298 | #include <G4ParticleTable.hh>
|
|---|
| 299 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 300 | std::string G4Lab::Manager::physicalVolumes(
|
|---|
| 301 | )
|
|---|
| 302 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 303 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 304 | {
|
|---|
| 305 | #define UNLIMITED (-1)
|
|---|
| 306 | G4TransportationManager* tsp =
|
|---|
| 307 | G4TransportationManager::GetTransportationManager();
|
|---|
| 308 | if(!tsp) {
|
|---|
| 309 | Lib::Out out(fSession.printer());
|
|---|
| 310 | out << "G4Lab::Manager::physicalVolumes : "
|
|---|
| 311 | << "can't find the G4TransportationManager."
|
|---|
| 312 | << Lib::endl;
|
|---|
| 313 | return "";
|
|---|
| 314 | }
|
|---|
| 315 | G4Navigator* nav = tsp->GetNavigatorForTracking();
|
|---|
| 316 | if(!nav) {
|
|---|
| 317 | Lib::Out out(fSession.printer());
|
|---|
| 318 | out << "G4Lab::Manager::physicalVolumes : "
|
|---|
| 319 | << "can't get the G4Navigator on G4TransportationManager."
|
|---|
| 320 | << Lib::endl;
|
|---|
| 321 | return "";
|
|---|
| 322 | }
|
|---|
| 323 | G4VPhysicalVolume* topVolume = nav->GetWorldVolume();
|
|---|
| 324 | if(!topVolume) {
|
|---|
| 325 | Lib::Out out(fSession.printer());
|
|---|
| 326 | out << "G4Lab::Manager::physicalVolumes : "
|
|---|
| 327 | << "no world volume in G4Navigator." << Lib::endl;
|
|---|
| 328 | return "";
|
|---|
| 329 | }
|
|---|
| 330 | std::string sout;
|
|---|
| 331 | sout += "<tree>";
|
|---|
| 332 | XML_VisitedVolume xmlVisitedVolume(sout);
|
|---|
| 333 | GeometryVisitor geometryVisitor;
|
|---|
| 334 | geometryVisitor.visit(topVolume,
|
|---|
| 335 | UNLIMITED,
|
|---|
| 336 | G4Transform3D(),
|
|---|
| 337 | &xmlVisitedVolume);
|
|---|
| 338 | sout += "</tree>";
|
|---|
| 339 | return sout;
|
|---|
| 340 | }
|
|---|
| 341 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 342 | std::string G4Lab::Manager::hitsCollections(
|
|---|
| 343 | )
|
|---|
| 344 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 345 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 346 | {
|
|---|
| 347 | G4SDManager* sdManager = G4SDManager::GetSDMpointer();
|
|---|
| 348 | if(!sdManager) return "";
|
|---|
| 349 | G4HCtable* hcTable = sdManager->GetHCtable();
|
|---|
| 350 | if(!hcTable) return "";
|
|---|
| 351 | std::string sout;
|
|---|
| 352 | sout += "<tree>";
|
|---|
| 353 | int number = hcTable->entries();
|
|---|
| 354 | for(int index=0;index<number;index++) {
|
|---|
| 355 | G4String hcName = hcTable->GetHCname(index);
|
|---|
| 356 | sout += "<treeItem><label>";
|
|---|
| 357 | sout += hcName;
|
|---|
| 358 | sout += "</label></treeItem>";
|
|---|
| 359 | }
|
|---|
| 360 | sout += "</tree>";
|
|---|
| 361 | return sout;
|
|---|
| 362 | }
|
|---|
| 363 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 364 | std::string G4Lab::Manager::digitsCollections(
|
|---|
| 365 | )
|
|---|
| 366 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 367 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 368 | {
|
|---|
| 369 | G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
|
|---|
| 370 | if(!digiManager) return "";
|
|---|
| 371 | G4DCtable* dcTable = digiManager->GetDCtable();
|
|---|
| 372 | if(!dcTable) return "";
|
|---|
| 373 | std::string sout;
|
|---|
| 374 | sout += "<tree>";
|
|---|
| 375 | int number = dcTable->entries();
|
|---|
| 376 | for(int index=0;index<number;index++) {
|
|---|
| 377 | G4String dcName = dcTable->GetDCname(index);
|
|---|
| 378 | sout += "<treeItem><label>";
|
|---|
| 379 | sout += dcName;
|
|---|
| 380 | sout += "</label></treeItem>";
|
|---|
| 381 | }
|
|---|
| 382 | sout += "</tree>";
|
|---|
| 383 | return sout;
|
|---|
| 384 | }
|
|---|
| 385 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 386 | void G4Lab::Manager::setRunBeginScript(
|
|---|
| 387 | const std::string& aInterp
|
|---|
| 388 | ,const std::string& aScript
|
|---|
| 389 | )
|
|---|
| 390 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 391 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 392 | {
|
|---|
| 393 | fState->setRunBeginScript(aInterp,aScript);
|
|---|
| 394 | }
|
|---|
| 395 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 396 | void G4Lab::Manager::setRunEndScript(
|
|---|
| 397 | const std::string& aInterp
|
|---|
| 398 | ,const std::string& aScript
|
|---|
| 399 | )
|
|---|
| 400 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 401 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 402 | {
|
|---|
| 403 | fState->setRunEndScript(aInterp,aScript);
|
|---|
| 404 | }
|
|---|
| 405 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 406 | void G4Lab::Manager::setEventBeginScript(
|
|---|
| 407 | const std::string& aInterp
|
|---|
| 408 | ,const std::string& aScript
|
|---|
| 409 | )
|
|---|
| 410 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 411 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 412 | {
|
|---|
| 413 | fState->setEventBeginScript(aInterp,aScript);
|
|---|
| 414 | }
|
|---|
| 415 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 416 | void G4Lab::Manager::setEventEndScript(
|
|---|
| 417 | const std::string& aInterp
|
|---|
| 418 | ,const std::string& aScript
|
|---|
| 419 | )
|
|---|
| 420 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 421 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 422 | {
|
|---|
| 423 | fState->setEventEndScript(aInterp,aScript);
|
|---|
| 424 | }
|
|---|
| 425 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 426 | std::string G4Lab::Manager::name(
|
|---|
| 427 | ) const
|
|---|
| 428 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 429 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 430 | {
|
|---|
| 431 | return fName;
|
|---|
| 432 | }
|
|---|
| 433 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 434 | void* G4Lab::Manager::cast(
|
|---|
| 435 | const std::string& aClass
|
|---|
| 436 | ) const
|
|---|
| 437 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 438 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 439 | {
|
|---|
| 440 | if_Lib_SCast(G4Lab::Manager)
|
|---|
| 441 | else if_Lib_SCast(Slash::Core::IManager)
|
|---|
| 442 | else if_Lib_SCast(IGeant4Manager)
|
|---|
| 443 | else return 0;
|
|---|
| 444 | }
|
|---|
| 445 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 446 | G4RunManager* G4Lab::Manager::runManager(
|
|---|
| 447 | ) const
|
|---|
| 448 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 449 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 450 | {
|
|---|
| 451 | return fRunManager;
|
|---|
| 452 | }
|
|---|
| 453 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 454 | G4SDManager* G4Lab::Manager::sdManager(
|
|---|
| 455 | ) const
|
|---|
| 456 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 457 | // Used by callbacks if having not shared libs for Geant4.
|
|---|
| 458 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 459 | {
|
|---|
| 460 | return G4SDManager::GetSDMpointer();
|
|---|
| 461 | }
|
|---|
| 462 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 463 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 464 | void G4Lab::Manager::beamOn(
|
|---|
| 465 | int aNumber
|
|---|
| 466 | )
|
|---|
| 467 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 468 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 469 | {
|
|---|
| 470 | if(!fRunManager) return;
|
|---|
| 471 | fRunManager->BeamOn(aNumber);
|
|---|
| 472 | }
|
|---|
| 473 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 474 | void G4Lab::Manager::abortRun(
|
|---|
| 475 | )
|
|---|
| 476 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 477 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 478 | {
|
|---|
| 479 | if(!fRunManager) return;
|
|---|
| 480 | fRunManager->AbortRun();
|
|---|
| 481 | }
|
|---|
| 482 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 483 | bool G4Lab::Manager::isRunning(
|
|---|
| 484 | )
|
|---|
| 485 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 486 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 487 | {
|
|---|
| 488 | return fState->isRunning();
|
|---|
| 489 | }
|
|---|
| 490 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 491 | void G4Lab::Manager::particleTableDump(
|
|---|
| 492 | )
|
|---|
| 493 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 494 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 495 | {
|
|---|
| 496 | G4ParticleTable* table = G4ParticleTable::GetParticleTable();
|
|---|
| 497 | if(!table) return;
|
|---|
| 498 | table->DumpTable("ALL");
|
|---|
| 499 | }
|
|---|
| 500 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 501 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 502 | // From G4VBasicShell (tag geant4-05-00-ref-01)
|
|---|
| 503 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 504 | static G4String Complete(
|
|---|
| 505 | G4String commandName
|
|---|
| 506 | )
|
|---|
| 507 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 508 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 509 | {
|
|---|
| 510 | G4String rawCommandLine = commandName;
|
|---|
| 511 | G4String commandLine = rawCommandLine.strip(G4String::both);
|
|---|
| 512 | size_t i = commandLine.index(" ");
|
|---|
| 513 | if( i != std::string::npos ) return rawCommandLine; // Already entering parameters,
|
|---|
| 514 | // assume command path is correct.
|
|---|
| 515 | G4String commandString = commandLine;
|
|---|
| 516 | //G4String targetCom = ModifyPath(commandString);
|
|---|
| 517 | G4String targetCom = commandString;
|
|---|
| 518 | G4UIcommandTree* tree = G4UImanager::GetUIpointer()->GetTree();
|
|---|
| 519 | G4String value = FindMatchingPath(tree,targetCom);
|
|---|
| 520 | if(value=="") return rawCommandLine;
|
|---|
| 521 | return value;
|
|---|
| 522 | }
|
|---|
| 523 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 524 | static G4String FindMatchingPath(
|
|---|
| 525 | G4UIcommandTree* aTree
|
|---|
| 526 | ,G4String aCommandPath
|
|---|
| 527 | )
|
|---|
| 528 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 529 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 530 | // From intercoms/src/G4UIcommandTree::FindPath.
|
|---|
| 531 | {
|
|---|
| 532 | G4String empty = "";
|
|---|
| 533 | if(aTree==NULL) return empty;
|
|---|
| 534 | G4String pathName = aTree->GetPathName();
|
|---|
| 535 | if( aCommandPath.index( pathName ) == std::string::npos ) return empty;
|
|---|
| 536 | G4String remainingPath = aCommandPath;
|
|---|
| 537 | remainingPath.remove(0,pathName.length());
|
|---|
| 538 | size_t i = remainingPath.first('/');
|
|---|
| 539 | if( i == std::string::npos ) {
|
|---|
| 540 | // Look for number of matching commands :
|
|---|
| 541 | std::vector<G4UIcommand*> commands;
|
|---|
| 542 | G4int n_commandEntry = aTree->GetCommandEntry();
|
|---|
| 543 | for( G4int i_thCommand = 1; i_thCommand <= n_commandEntry; i_thCommand++ ) {
|
|---|
| 544 | G4UIcommand* cmd = aTree->GetCommand(i_thCommand);
|
|---|
| 545 | G4String ss = cmd->GetCommandName();
|
|---|
| 546 | ss.resize(remainingPath.length());
|
|---|
| 547 | if( remainingPath == ss ) commands.push_back(cmd);
|
|---|
| 548 | }
|
|---|
| 549 | n_commandEntry = commands.size();
|
|---|
| 550 | if(n_commandEntry==1) {
|
|---|
| 551 | return (pathName + commands[0]->GetCommandName());
|
|---|
| 552 | } else if (n_commandEntry>=2) {
|
|---|
| 553 | G4cout << "Matching commands :" << G4endl;
|
|---|
| 554 | for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ ) {
|
|---|
| 555 | G4UIcommand* cmd = commands[i_thCommand];
|
|---|
| 556 | G4cout << cmd->GetCommandName() << G4endl;
|
|---|
| 557 | }
|
|---|
| 558 | return empty;
|
|---|
| 559 | }
|
|---|
| 560 | // Look for sub tree :
|
|---|
| 561 | std::vector<G4UIcommandTree*> trees;
|
|---|
| 562 | G4String nextPath = pathName;
|
|---|
| 563 | nextPath.append(remainingPath);
|
|---|
| 564 | G4int n_treeEntry = aTree->GetTreeEntry();
|
|---|
| 565 | for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) {
|
|---|
| 566 | G4UIcommandTree* tree = aTree->GetTree(i_thTree);
|
|---|
| 567 | G4String ss = tree->GetPathName();
|
|---|
| 568 | ss.resize(nextPath.length());
|
|---|
| 569 | if( nextPath == ss ) trees.push_back(tree);
|
|---|
| 570 | }
|
|---|
| 571 | n_treeEntry = trees.size();
|
|---|
| 572 | if(n_treeEntry==1) {
|
|---|
| 573 | return trees[0]->GetPathName();
|
|---|
| 574 | } else if (n_treeEntry>=2) {
|
|---|
| 575 | G4cout << "Matching directories :" << G4endl;
|
|---|
| 576 | for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ ) {
|
|---|
| 577 | G4UIcommandTree* tree = trees[i_thTree];
|
|---|
| 578 | G4cout << tree->GetPathName() << G4endl;
|
|---|
| 579 | }
|
|---|
| 580 | return empty;
|
|---|
| 581 | } else {
|
|---|
| 582 | return empty; // No match.
|
|---|
| 583 | }
|
|---|
| 584 | } else {
|
|---|
| 585 | // Find path
|
|---|
| 586 | G4String nextPath = pathName;
|
|---|
| 587 | nextPath.append(remainingPath(0,i+1));
|
|---|
| 588 | G4int n_treeEntry = aTree->GetTreeEntry();
|
|---|
| 589 | for( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) {
|
|---|
| 590 | G4UIcommandTree* tree = aTree->GetTree(i_thTree);
|
|---|
| 591 | if( nextPath == tree->GetPathName() ) {
|
|---|
| 592 | return FindMatchingPath(tree,aCommandPath );
|
|---|
| 593 | }
|
|---|
| 594 | }
|
|---|
| 595 | }
|
|---|
| 596 | return empty;
|
|---|
| 597 | }
|
|---|