[989] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // G4cout_test02 |
---|
| 27 | // -------------------------------------------------------------- |
---|
| 28 | |
---|
| 29 | #include "G4RunManager.hh" |
---|
| 30 | #include "G4UImanager.hh" |
---|
| 31 | #include "G4UIsession.hh" |
---|
| 32 | |
---|
| 33 | #include "ExN01DetectorConstruction.hh" |
---|
| 34 | #include "ExN01PhysicsList.hh" |
---|
| 35 | #include "ExN01PrimaryGeneratorAction.hh" |
---|
| 36 | #include "MySession.hh" |
---|
| 37 | #include "G4UIterminal.hh" |
---|
| 38 | #include "G4UItcsh.hh" |
---|
| 39 | |
---|
| 40 | int main() |
---|
| 41 | { |
---|
| 42 | |
---|
| 43 | // Construct the default run manager |
---|
| 44 | G4RunManager* runManager = new G4RunManager; |
---|
| 45 | |
---|
| 46 | // set mandatory initialization classes |
---|
| 47 | runManager->SetUserInitialization(new ExN01DetectorConstruction); |
---|
| 48 | runManager->SetUserInitialization(new ExN01PhysicsList); |
---|
| 49 | |
---|
| 50 | // set mandatory user action class |
---|
| 51 | runManager->SetUserAction(new ExN01PrimaryGeneratorAction); |
---|
| 52 | |
---|
| 53 | // Initialize G4 kernel |
---|
| 54 | runManager->Initialize(); |
---|
| 55 | |
---|
| 56 | // get the pointer to the User Interface manager |
---|
| 57 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 58 | // construct two sessions which receive G4cout/G4cerr |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | G4UIsession * termSession = new G4UIterminal(new G4UItcsh); |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | // get the pointer to the UI manager and set verbosities |
---|
| 65 | UI->ApplyCommand("/run/verbose 1"); |
---|
| 66 | UI->ApplyCommand("/event/verbose 1"); |
---|
| 67 | UI->ApplyCommand("/tracking/verbose 1"); |
---|
| 68 | |
---|
| 69 | // First, start tcsh session to see if all works well |
---|
| 70 | |
---|
| 71 | UI->SetCoutDestination(termSession); |
---|
| 72 | termSession->SessionStart(); |
---|
| 73 | |
---|
| 74 | // OK now end this interactive session |
---|
| 75 | delete termSession; |
---|
| 76 | // delete termSession; |
---|
| 77 | |
---|
| 78 | G4cout << "term session end. now mySession starts to take a log file" << G4endl; |
---|
| 79 | |
---|
| 80 | // outputs are directed to the loggingSession from now on |
---|
| 81 | MySession * LoggingSession = new MySession; |
---|
| 82 | UI->SetCoutDestination(LoggingSession); |
---|
| 83 | // session->SessionStart(); // not required in this case |
---|
| 84 | // because we start a batch run directly here |
---|
| 85 | int numberOfEvent = 100; |
---|
| 86 | runManager->BeamOn(numberOfEvent); |
---|
| 87 | |
---|
| 88 | G4cout << "loggingSession is now deleted" << G4endl; |
---|
| 89 | |
---|
| 90 | delete LoggingSession; |
---|
| 91 | // delete termSession; |
---|
| 92 | |
---|
| 93 | G4cout << "oooooooooooooooooooooooooooooooooooooooooooooooooo"<< G4endl; |
---|
| 94 | G4cout << "The output of G4cout/G4cerr is logged to a file" << G4endl; |
---|
| 95 | // << LoggingSession->logFileName << "\"." << G4endl; |
---|
| 96 | G4cout << "Please have a look." << G4endl; |
---|
| 97 | G4cout << "oooooooooooooooooooooooooooooooooooooooooooooooooo" << G4endl; |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | // job termination |
---|
| 102 | delete runManager; |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | return 0; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|