Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/examples/advanced/ChargeExchangeMC/ChargeExchangeMC.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/ChargeExchangeMC/ChargeExchangeMC.cc (Version 11.3.0) and /examples/advanced/ChargeExchangeMC/ChargeExchangeMC.cc (Version 10.6.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 /*                                                 26 /*
 27  * ===========================================     27  * =============================================================================
 28  *                                                 28  *
 29  *       Filename:  cexmc.cc                       29  *       Filename:  cexmc.cc
 30  *                                                 30  *
 31  *    Description:  main                           31  *    Description:  main
 32  *                                                 32  *
 33  *        Version:  1.0                            33  *        Version:  1.0
 34  *        Created:  10.10.2009 23:24:39            34  *        Created:  10.10.2009 23:24:39
 35  *       Revision:  none                           35  *       Revision:  none
 36  *       Compiler:  gcc                            36  *       Compiler:  gcc
 37  *                                                 37  *
 38  *         Author:  Alexey Radkov (),              38  *         Author:  Alexey Radkov (), 
 39  *        Company:  PNPI                           39  *        Company:  PNPI
 40  *                                                 40  *
 41  * ===========================================     41  * =============================================================================
 42  */                                                42  */
 43                                                    43 
 44 #include <set>                                     44 #include <set>
 45 #ifdef CEXMC_USE_PERSISTENCY                       45 #ifdef CEXMC_USE_PERSISTENCY
 46 #include <boost/algorithm/string.hpp>              46 #include <boost/algorithm/string.hpp>
 47 #include <boost/archive/archive_exception.hpp>     47 #include <boost/archive/archive_exception.hpp>
 48 #ifdef CEXMC_USE_CUSTOM_FILTER                     48 #ifdef CEXMC_USE_CUSTOM_FILTER
 49 #include <boost/variant/get.hpp>                   49 #include <boost/variant/get.hpp>
 50 #endif                                             50 #endif
 51 #endif                                             51 #endif
 52 #include <G4UImanager.hh>                          52 #include <G4UImanager.hh>
 53 #include <G4String.hh>                             53 #include <G4String.hh>
 54 #include <G4UIsession.hh>                          54 #include <G4UIsession.hh>
 55 #include <G4UIterminal.hh>                         55 #include <G4UIterminal.hh>
 56 #ifdef G4UI_USE_TCSH                               56 #ifdef G4UI_USE_TCSH
 57 #include <G4UItcsh.hh>                             57 #include <G4UItcsh.hh>
 58 #endif                                             58 #endif
 59 #ifdef G4UI_USE_QT                                 59 #ifdef G4UI_USE_QT
 60 #include <G4UIQt.hh>                               60 #include <G4UIQt.hh>
 61 #endif                                             61 #endif
 62 #include <G4VisExecutive.hh>                       62 #include <G4VisExecutive.hh>
 63 #include "CexmcRunManager.hh"                      63 #include "CexmcRunManager.hh"
 64 #include "CexmcHistoManager.hh"                    64 #include "CexmcHistoManager.hh"
 65 #include "CexmcSetup.hh"                           65 #include "CexmcSetup.hh"
 66 #include "CexmcPhysicsList.hh"                     66 #include "CexmcPhysicsList.hh"
 67 #include "CexmcPhysicsManager.hh"                  67 #include "CexmcPhysicsManager.hh"
 68 #include "CexmcPrimaryGeneratorAction.hh"          68 #include "CexmcPrimaryGeneratorAction.hh"
 69 #include "CexmcTrackingAction.hh"                  69 #include "CexmcTrackingAction.hh"
 70 #include "CexmcSteppingAction.hh"                  70 #include "CexmcSteppingAction.hh"
 71 #include "CexmcEventAction.hh"                     71 #include "CexmcEventAction.hh"
 72 #include "CexmcRunAction.hh"                       72 #include "CexmcRunAction.hh"
 73 #include "CexmcMessenger.hh"                       73 #include "CexmcMessenger.hh"
 74 #include "CexmcException.hh"                       74 #include "CexmcException.hh"
 75 #include "CexmcBasicPhysicsSettings.hh"            75 #include "CexmcBasicPhysicsSettings.hh"
 76 #include "CexmcCommon.hh"                          76 #include "CexmcCommon.hh"
 77                                                    77 
 78                                                    78 
 79 namespace                                          79 namespace
 80 {                                                  80 {
 81     const G4String  CexmcVisManagerVerboseLeve     81     const G4String  CexmcVisManagerVerboseLevel( "errors" );
 82 }                                                  82 }
 83                                                    83 
 84                                                    84 
 85 struct  CexmcCmdLineData                           85 struct  CexmcCmdLineData
 86 {                                                  86 {
 87     CexmcCmdLineData() : isInteractive( false      87     CexmcCmdLineData() : isInteractive( false ), startQtSession( false ),
 88                          preinitMacro( "" ), i     88                          preinitMacro( "" ), initMacro( "" ), rProject( "" ),
 89                          wProject( "" ), overr     89                          wProject( "" ), overrideExistingProject( false ),
 90                          customFilter( "" )        90                          customFilter( "" )
 91     {}                                             91     {}
 92                                                    92 
 93     G4bool                  isInteractive;         93     G4bool                  isInteractive;
 94     G4bool                  startQtSession;        94     G4bool                  startQtSession;
 95     G4String                preinitMacro;          95     G4String                preinitMacro;
 96     G4String                initMacro;             96     G4String                initMacro;
 97     G4String                rProject;              97     G4String                rProject;
 98     G4String                wProject;              98     G4String                wProject;
 99     G4bool                  overrideExistingPr     99     G4bool                  overrideExistingProject;
100     CexmcOutputDataTypeSet  outputData;           100     CexmcOutputDataTypeSet  outputData;
101     G4String                customFilter;         101     G4String                customFilter;
102 };                                                102 };
103                                                   103 
104                                                   104 
105 void  printUsage( void )                          105 void  printUsage( void )
106 {                                                 106 {
107 #ifdef CEXMC_PROG_NAME                            107 #ifdef CEXMC_PROG_NAME
108     const char *  progName( CEXMC_PROG_NAME );    108     const char *  progName( CEXMC_PROG_NAME );
109 #else                                             109 #else
110     const char *  progName( "cexmc" );            110     const char *  progName( "cexmc" );
111 #endif                                            111 #endif
112                                                   112 
113     G4cout << "Usage: " << progName << " [-i]     113     G4cout << "Usage: " << progName << " [-i] "
114 #ifdef G4UI_USE_QT                                114 #ifdef G4UI_USE_QT
115                            "[-g] "                115                            "[-g] "
116 #endif                                            116 #endif
117                            "[-p preinit_macro]    117                            "[-p preinit_macro] [-m init_macro] "
118 #ifdef CEXMC_USE_PERSISTENCY                      118 #ifdef CEXMC_USE_PERSISTENCY
119                            "[[-y] -w project]"    119                            "[[-y] -w project]" << G4endl <<
120               "             [-r project "         120               "             [-r project "
121 #ifdef CEXMC_USE_CUSTOM_FILTER                    121 #ifdef CEXMC_USE_CUSTOM_FILTER
122                            "[-f filter_script]    122                            "[-f filter_script] "
123 #endif                                            123 #endif
124                            "[-o list]]"           124                            "[-o list]]"
125 #endif                                            125 #endif
126            << G4endl;                             126            << G4endl;
127     G4cout << "or     " << progName << " [--he    127     G4cout << "or     " << progName << " [--help | -h]" << G4endl;
128     G4cout << "           -i - run in interact    128     G4cout << "           -i - run in interactive mode" << G4endl;
129 #ifdef G4UI_USE_QT                                129 #ifdef G4UI_USE_QT
130     G4cout << "           -g - start graphical    130     G4cout << "           -g - start graphical interface (Qt), implies "
131                               "interactive mod    131                               "interactive mode " << G4endl;
132 #endif                                            132 #endif
133     G4cout << "           -p - use specified p    133     G4cout << "           -p - use specified preinit macro file " << G4endl;
134     G4cout << "           -m - use specified i    134     G4cout << "           -m - use specified init macro file " << G4endl;
135 #ifdef CEXMC_USE_PERSISTENCY                      135 #ifdef CEXMC_USE_PERSISTENCY
136     G4cout << "           -w - save data in sp    136     G4cout << "           -w - save data in specified project files" << G4endl;
137     G4cout << "           -r - read data from     137     G4cout << "           -r - read data from specified project files" <<
138               G4endl;                             138               G4endl;
139 #ifdef CEXMC_USE_CUSTOM_FILTER                    139 #ifdef CEXMC_USE_CUSTOM_FILTER
140     G4cout << "           -f - use specified c    140     G4cout << "           -f - use specified custom filter script" << G4endl;
141 #endif                                            141 #endif
142     G4cout << "           -o - comma-separated    142     G4cout << "           -o - comma-separated list of data to output, "
143                               "possible values    143                               "possible values:" << G4endl <<
144               "                run, geom, even    144               "                run, geom, events" << G4endl;
145     G4cout << "           -y - force project o    145     G4cout << "           -y - force project override" << G4endl;
146 #endif                                            146 #endif
147     G4cout << "  --help | -h - print this mess    147     G4cout << "  --help | -h - print this message and exit " << G4endl;
148 }                                                 148 }
149                                                   149 
150                                                   150 
151 G4bool  parseArgs( int  argc, char **  argv, C    151 G4bool  parseArgs( int  argc, char **  argv, CexmcCmdLineData &  cmdLineData )
152 {                                                 152 {
153     if ( argc < 2 )                               153     if ( argc < 2 )
154         return false;                             154         return false;
155                                                   155 
156     for ( G4int  i( 1 ); i < argc; ++i )          156     for ( G4int  i( 1 ); i < argc; ++i )
157     {                                             157     {
158         do                                        158         do
159         {                                         159         {
160             if ( G4String( argv[ i ] ) == "--h    160             if ( G4String( argv[ i ] ) == "--help" )
161             {                                     161             {
162                 return false;                     162                 return false;
163             }                                     163             }
164             if ( G4String( argv[ i ] ) == "-h"    164             if ( G4String( argv[ i ] ) == "-h" )
165             {                                     165             {
166                 return false;                     166                 return false;
167             }                                     167             }
168             if ( G4String( argv[ i ], 2 ) == "    168             if ( G4String( argv[ i ], 2 ) == "-i" )
169             {                                     169             {
170                 cmdLineData.isInteractive = tr    170                 cmdLineData.isInteractive = true;
171                 break;                            171                 break;
172             }                                     172             }
173 #ifdef G4UI_USE_QT                                173 #ifdef G4UI_USE_QT
174             if ( G4String( argv[ i ], 2 ) == "    174             if ( G4String( argv[ i ], 2 ) == "-g" )
175             {                                     175             {
176                 cmdLineData.isInteractive = tr    176                 cmdLineData.isInteractive = true;
177                 cmdLineData.startQtSession = t    177                 cmdLineData.startQtSession = true;
178                 break;                            178                 break;
179             }                                     179             }
180 #endif                                            180 #endif
181             if ( G4String( argv[ i ], 2 ) == "    181             if ( G4String( argv[ i ], 2 ) == "-p" )
182             {                                     182             {
183                 cmdLineData.preinitMacro = arg    183                 cmdLineData.preinitMacro = argv[ i ] + 2;
184                 if ( cmdLineData.preinitMacro     184                 if ( cmdLineData.preinitMacro == "" )
185                 {                                 185                 {
186                     if ( ++i >= argc )            186                     if ( ++i >= argc )
187                         throw CexmcException(     187                         throw CexmcException( CexmcCmdLineParseException );
188                     cmdLineData.preinitMacro =    188                     cmdLineData.preinitMacro = argv[ i ];
189                 }                                 189                 }
190                 break;                            190                 break;
191             }                                     191             }
192             if ( G4String( argv[ i ], 2 ) == "    192             if ( G4String( argv[ i ], 2 ) == "-m" )
193             {                                     193             {
194                 cmdLineData.initMacro = argv[     194                 cmdLineData.initMacro = argv[ i ] + 2;
195                 if ( cmdLineData.initMacro ==     195                 if ( cmdLineData.initMacro == "" )
196                 {                                 196                 {
197                     if ( ++i >= argc )            197                     if ( ++i >= argc )
198                         throw CexmcException(     198                         throw CexmcException( CexmcCmdLineParseException );
199                     cmdLineData.initMacro = ar    199                     cmdLineData.initMacro = argv[ i ];
200                 }                                 200                 }
201                 break;                            201                 break;
202             }                                     202             }
203 #ifdef CEXMC_USE_PERSISTENCY                      203 #ifdef CEXMC_USE_PERSISTENCY
204             if ( G4String( argv[ i ], 2 ) == "    204             if ( G4String( argv[ i ], 2 ) == "-w" )
205             {                                     205             {
206                 cmdLineData.wProject = argv[ i    206                 cmdLineData.wProject = argv[ i ] + 2;
207                 if ( cmdLineData.wProject == "    207                 if ( cmdLineData.wProject == "" )
208                 {                                 208                 {
209                     if ( ++i >= argc )            209                     if ( ++i >= argc )
210                         throw CexmcException(     210                         throw CexmcException( CexmcCmdLineParseException );
211                     cmdLineData.wProject = arg    211                     cmdLineData.wProject = argv[ i ];
212                 }                                 212                 }
213                 break;                            213                 break;
214             }                                     214             }
215             if ( G4String( argv[ i ], 2 ) == "    215             if ( G4String( argv[ i ], 2 ) == "-r" )
216             {                                     216             {
217                 cmdLineData.rProject = argv[ i    217                 cmdLineData.rProject = argv[ i ] + 2;
218                 if ( cmdLineData.rProject == "    218                 if ( cmdLineData.rProject == "" )
219                 {                                 219                 {
220                     if ( ++i >= argc )            220                     if ( ++i >= argc )
221                         throw CexmcException(     221                         throw CexmcException( CexmcCmdLineParseException );
222                     cmdLineData.rProject = arg    222                     cmdLineData.rProject = argv[ i ];
223                 }                                 223                 }
224                 break;                            224                 break;
225             }                                     225             }
226             if ( G4String( argv[ i ], 2 ) == "    226             if ( G4String( argv[ i ], 2 ) == "-y" )
227             {                                     227             {
228                 cmdLineData.overrideExistingPr    228                 cmdLineData.overrideExistingProject = true;
229                 break;                            229                 break;
230             }                                     230             }
231             if ( G4String( argv[ i ], 2 ) == "    231             if ( G4String( argv[ i ], 2 ) == "-o" )
232             {                                     232             {
233                 std::string  outputData( argv[    233                 std::string  outputData( argv[ i ] + 2 );
234                 if ( outputData == "" )           234                 if ( outputData == "" )
235                 {                                 235                 {
236                     if ( ++i >= argc )            236                     if ( ++i >= argc )
237                         throw CexmcException(     237                         throw CexmcException( CexmcCmdLineParseException );
238                     outputData = argv[ i ];       238                     outputData = argv[ i ];
239                 }                                 239                 }
240                 std::set< std::string >  token    240                 std::set< std::string >  tokens;
241                 boost::split( tokens, outputDa    241                 boost::split( tokens, outputData, boost::is_any_of( "," ) );
242                 for ( std::set< std::string >:    242                 for ( std::set< std::string >::iterator  k( tokens.begin() );
243                                                   243                                                         k != tokens.end(); ++k )
244                 {                                 244                 {
245                     do                            245                     do
246                     {                             246                     {
247                         if ( *k == "run" )        247                         if ( *k == "run" )
248                         {                         248                         {
249                             cmdLineData.output    249                             cmdLineData.outputData.insert( CexmcOutputRun );
250                             break;                250                             break;
251                         }                         251                         }
252                         if ( *k == "geom" )       252                         if ( *k == "geom" )
253                         {                         253                         {
254                             cmdLineData.output    254                             cmdLineData.outputData.insert(
255                                                   255                                                           CexmcOutputGeometry );
256                             break;                256                             break;
257                         }                         257                         }
258                         if ( *k == "events" )     258                         if ( *k == "events" )
259                         {                         259                         {
260                             cmdLineData.output    260                             cmdLineData.outputData.insert( CexmcOutputEvents );
261                             break;                261                             break;
262                         }                         262                         }
263                         throw CexmcException(     263                         throw CexmcException( CexmcCmdLineParseException );
264                     } while ( false );            264                     } while ( false );
265                 }                                 265                 }
266                 break;                            266                 break;
267             }                                     267             }
268 #ifdef CEXMC_USE_CUSTOM_FILTER                    268 #ifdef CEXMC_USE_CUSTOM_FILTER
269             if ( G4String( argv[ i ], 2 ) == "    269             if ( G4String( argv[ i ], 2 ) == "-f" )
270             {                                     270             {
271                 cmdLineData.customFilter = arg    271                 cmdLineData.customFilter = argv[ i ] + 2;
272                 if ( cmdLineData.customFilter     272                 if ( cmdLineData.customFilter == "" )
273                 {                                 273                 {
274                     if ( ++i >= argc )            274                     if ( ++i >= argc )
275                         throw CexmcException(     275                         throw CexmcException( CexmcCmdLineParseException );
276                     cmdLineData.customFilter =    276                     cmdLineData.customFilter = argv[ i ];
277                 }                                 277                 }
278                 break;                            278                 break;
279             }                                     279             }
280 #endif                                            280 #endif
281 #endif                                            281 #endif
282                                                   282 
283             throw CexmcException( CexmcCmdLine    283             throw CexmcException( CexmcCmdLineParseException );
284                                                   284 
285         } while ( false );                        285         } while ( false );
286     }                                             286     }
287                                                   287 
288     return true;                                  288     return true;
289 }                                                 289 }
290                                                   290 
291                                                   291 
292 int  main( int  argc, char **  argv )             292 int  main( int  argc, char **  argv )
293 {                                                 293 {
294                                                   294 
295     G4UIsession *     session( NULL );            295     G4UIsession *     session( NULL );
296                                                   296 
297                                                   297 
298     CexmcCmdLineData  cmdLineData;                298     CexmcCmdLineData  cmdLineData;
299 #ifdef CEXMC_USE_PERSISTENCY                      299 #ifdef CEXMC_USE_PERSISTENCY
300     G4bool            outputDataOnly( false );    300     G4bool            outputDataOnly( false );
301 #endif                                            301 #endif
302                                                   302 
303     try                                           303     try
304     {                                             304     {
305         if ( ! parseArgs( argc, argv, cmdLineD    305         if ( ! parseArgs( argc, argv, cmdLineData ) )
306         {                                         306         {
307             printUsage();                         307             printUsage();
308             return 0;                             308             return 0;
309         }                                         309         }
310 #ifdef CEXMC_USE_PERSISTENCY                      310 #ifdef CEXMC_USE_PERSISTENCY
311         if ( cmdLineData.rProject != "" &&        311         if ( cmdLineData.rProject != "" &&
312              cmdLineData.rProject == cmdLineDa    312              cmdLineData.rProject == cmdLineData.wProject )
313             throw CexmcException( CexmcCmdLine    313             throw CexmcException( CexmcCmdLineParseException );
314         if ( cmdLineData.rProject == "" && ! c    314         if ( cmdLineData.rProject == "" && ! cmdLineData.outputData.empty() )
315             throw CexmcException( CexmcCmdLine    315             throw CexmcException( CexmcCmdLineParseException );
316 #ifdef CEXMC_USE_CUSTOM_FILTER                    316 #ifdef CEXMC_USE_CUSTOM_FILTER
317         if ( cmdLineData.rProject == "" && ! c    317         if ( cmdLineData.rProject == "" && ! cmdLineData.customFilter.empty() )
318             throw CexmcException( CexmcCmdLine    318             throw CexmcException( CexmcCmdLineParseException );
319 #endif                                            319 #endif
320         if ( cmdLineData.wProject != "" && ! c    320         if ( cmdLineData.wProject != "" && ! cmdLineData.outputData.empty() )
321             throw CexmcException( CexmcCmdLine    321             throw CexmcException( CexmcCmdLineParseException );
322         outputDataOnly = ! cmdLineData.outputD    322         outputDataOnly = ! cmdLineData.outputData.empty();
323 #endif                                            323 #endif
324     }                                             324     }
325     catch ( CexmcException &  e )                 325     catch ( CexmcException &  e )
326     {                                             326     {
327         G4cout << e.what() << G4endl;             327         G4cout << e.what() << G4endl;
328         return 1;                                 328         return 1;
329     }                                             329     }
330     catch ( ... )                                 330     catch ( ... )
331     {                                             331     {
332         G4cout << "Unknown exception caught wh    332         G4cout << "Unknown exception caught when parsing args" << G4endl;
333         return 1;                                 333         return 1;
334     }                                             334     }
335                                                   335 
336     CexmcRunManager *  runManager( NULL );        336     CexmcRunManager *  runManager( NULL );
337     CexmcMessenger::Instance();                   337     CexmcMessenger::Instance();
338                                                   338 
339     G4VisManager *     visManager( NULL );        339     G4VisManager *     visManager( NULL );
340                                                   340 
341 #ifdef CEXMC_USE_ROOT                             341 #ifdef CEXMC_USE_ROOT
342     CexmcHistoManager::Instance();                342     CexmcHistoManager::Instance();
343 #endif                                            343 #endif
344                                                   344 
345     try                                           345     try
346     {                                             346     {
347         runManager = new CexmcRunManager( cmdL    347         runManager = new CexmcRunManager( cmdLineData.wProject,
348                                           cmdL    348                                           cmdLineData.rProject,
349                                           cmdL    349                                           cmdLineData.overrideExistingProject );
350 #ifdef CEXMC_USE_PERSISTENCY                      350 #ifdef CEXMC_USE_PERSISTENCY
351 #ifdef CEXMC_USE_CUSTOM_FILTER                    351 #ifdef CEXMC_USE_CUSTOM_FILTER
352         runManager->SetCustomFilter( cmdLineDa    352         runManager->SetCustomFilter( cmdLineData.customFilter );
353 #endif                                            353 #endif
354                                                   354 
355         if ( outputDataOnly )                     355         if ( outputDataOnly )
356         {                                         356         {
357             /* we will need an arbitrary physi    357             /* we will need an arbitrary physics list to get access to particle
358              * table if events output was orde    358              * table if events output was ordered */
359             CexmcOutputDataTypeSet::const_iter    359             CexmcOutputDataTypeSet::const_iterator  found(
360                             cmdLineData.output    360                             cmdLineData.outputData.find( CexmcOutputEvents ) );
361             if ( found != cmdLineData.outputDa    361             if ( found != cmdLineData.outputData.end() )
362                 runManager->SetUserInitializat    362                 runManager->SetUserInitialization(
363                                 CexmcChargeExc    363                                 CexmcChargeExchangePMFactory::
364                                             Cr    364                                             Create( CexmcPionZeroProduction ) );
365             runManager->PrintReadData( cmdLine    365             runManager->PrintReadData( cmdLineData.outputData );
366             delete runManager;                    366             delete runManager;
367             return 0;                             367             return 0;
368         }                                         368         }
369 #endif                                            369 #endif
370                                                   370 
371         G4UImanager *  uiManager( G4UImanager:    371         G4UImanager *  uiManager( G4UImanager::GetUIpointer() );
372                                                   372 
373         if ( cmdLineData.preinitMacro != "" )     373         if ( cmdLineData.preinitMacro != "" )
374             uiManager->ApplyCommand( "/control    374             uiManager->ApplyCommand( "/control/execute " +
375                                      cmdLineDa    375                                      cmdLineData.preinitMacro );
376                                                   376 
377         CexmcProductionModelType  productionMo    377         CexmcProductionModelType  productionModelType(
378                                         runMan    378                                         runManager->GetProductionModelType() );
379                                                   379 
380         if ( productionModelType == CexmcUnkno    380         if ( productionModelType == CexmcUnknownProductionModel )
381             throw CexmcException( CexmcPreinit    381             throw CexmcException( CexmcPreinitException );
382                                                   382 
383         G4VUserPhysicsList *    physicsList( C    383         G4VUserPhysicsList *    physicsList( CexmcChargeExchangePMFactory::
384                                                   384                                                 Create( productionModelType ) );
385         CexmcPhysicsManager *   physicsManager    385         CexmcPhysicsManager *   physicsManager(
386                         dynamic_cast< CexmcPhy    386                         dynamic_cast< CexmcPhysicsManager * >( physicsList ) );
387         CexmcProductionModel *  productionMode    387         CexmcProductionModel *  productionModel(
388                                         physic    388                                         physicsManager->GetProductionModel() );
389                                                   389 
390         if ( ! productionModel )                  390         if ( ! productionModel )
391             throw CexmcException( CexmcWeirdEx    391             throw CexmcException( CexmcWeirdException );
392                                                   392 
393         G4cout << CEXMC_LINE_START << "Product    393         G4cout << CEXMC_LINE_START << "Production model '" <<
394                 productionModel->GetName() <<     394                 productionModel->GetName() << "' instantiated" << G4endl;
395                                                   395 
396         runManager->SetUserInitialization( phy    396         runManager->SetUserInitialization( physicsList );
397                                                   397 
398         CexmcSetup *   setup( new CexmcSetup(     398         CexmcSetup *   setup( new CexmcSetup( runManager->GetGdmlFileName(),
399                                     runManager    399                                     runManager->ShouldGdmlFileBeValidated() ) );
400                                                   400 
401         runManager->SetUserInitialization( set    401         runManager->SetUserInitialization( setup );
402                                                   402 
403         runManager->Initialize();                 403         runManager->Initialize();
404                                                   404 
405         runManager->SetPhysicsManager( physics    405         runManager->SetPhysicsManager( physicsManager );
406                                                   406 
407         runManager->SetUserAction( new CexmcPr    407         runManager->SetUserAction( new CexmcPrimaryGeneratorAction(
408                                                   408                                                             physicsManager ) );
409                                                   409 
410         runManager->SetUserAction( new CexmcEv    410         runManager->SetUserAction( new CexmcEventAction( physicsManager ) );
411                                                   411 
412         runManager->SetUserAction( new CexmcRu    412         runManager->SetUserAction( new CexmcRunAction( physicsManager ) );
413                                                   413 
414         runManager->SetUserAction( new CexmcTr    414         runManager->SetUserAction( new CexmcTrackingAction( physicsManager ) );
415                                                   415 
416         runManager->SetUserAction( new CexmcSt    416         runManager->SetUserAction( new CexmcSteppingAction( physicsManager ) );
417                                                   417 
418 #ifdef CEXMC_USE_ROOT                             418 #ifdef CEXMC_USE_ROOT
419         CexmcHistoManager::Instance()->Initial    419         CexmcHistoManager::Instance()->Initialize();
420 #endif                                            420 #endif
421                                                   421 
422                                                   422 
423         if ( cmdLineData.isInteractive )          423         if ( cmdLineData.isInteractive )
424         {                                         424         {
425             visManager = new G4VisExecutive( C    425             visManager = new G4VisExecutive( CexmcVisManagerVerboseLevel );
426             visManager->Initialize();             426             visManager->Initialize();
427         }                                         427         }
428                                                   428 
429                                                   429 
430 #ifdef CEXMC_USE_PERSISTENCY                      430 #ifdef CEXMC_USE_PERSISTENCY
431         if ( runManager->ProjectIsRead() )        431         if ( runManager->ProjectIsRead() )
432         {                                         432         {
433             runManager->ReadProject();            433             runManager->ReadProject();
434             runManager->PrintReadRunData();       434             runManager->PrintReadRunData();
435         }                                         435         }
436 #endif                                            436 #endif
437                                                   437 
438         if ( cmdLineData.initMacro != "" )        438         if ( cmdLineData.initMacro != "" )
439             uiManager->ApplyCommand( "/control    439             uiManager->ApplyCommand( "/control/execute " +
440                                      cmdLineDa    440                                      cmdLineData.initMacro );
441                                                   441 
442         if ( cmdLineData.isInteractive )          442         if ( cmdLineData.isInteractive )
443             productionModel->PrintInitialData(    443             productionModel->PrintInitialData();
444                                                   444 
445                                                   445 
446         if ( cmdLineData.isInteractive )          446         if ( cmdLineData.isInteractive )
447         {                                         447         {
448             if ( cmdLineData.startQtSession )     448             if ( cmdLineData.startQtSession )
449             {                                     449             {
450 #ifdef G4UI_USE_QT                                450 #ifdef G4UI_USE_QT
451                 /* no need to pass all command    451                 /* no need to pass all command line options to QApplication */
452                 session = new G4UIQt( 1, argv     452                 session = new G4UIQt( 1, argv );
453                 const G4String &  guiMacroName    453                 const G4String &  guiMacroName( runManager->GetGuiMacroName() );
454                 if ( guiMacroName != "" )         454                 if ( guiMacroName != "" )
455                     uiManager->ApplyCommand( "    455                     uiManager->ApplyCommand( "/control/execute " +
456                                              g    456                                              guiMacroName );
457 #ifdef CEXMC_USE_ROOTQT                           457 #ifdef CEXMC_USE_ROOTQT
458                 CexmcHistoManager::Instance()-    458                 CexmcHistoManager::Instance()->EnableLiveHistograms( session );
459 #endif                                            459 #endif
460 #endif                                            460 #endif
461             }                                     461             }
462             else                                  462             else
463             {                                     463             {
464 #ifdef G4UI_USE_TCSH                              464 #ifdef G4UI_USE_TCSH
465                 session = new G4UIterminal( ne    465                 session = new G4UIterminal( new G4UItcsh );
466 #else                                             466 #else
467                 session = new G4UIterminal;       467                 session = new G4UIterminal;
468 #endif                                            468 #endif
469             }                                     469             }
470             if ( session )                        470             if ( session )
471                 session->SessionStart();          471                 session->SessionStart();
472         }                                         472         }
473                                                   473 
474 #ifdef CEXMC_USE_PERSISTENCY                      474 #ifdef CEXMC_USE_PERSISTENCY
475         if ( runManager->ProjectIsSaved() )       475         if ( runManager->ProjectIsSaved() )
476             runManager->SaveProject();            476             runManager->SaveProject();
477 #endif                                            477 #endif
478     }                                             478     }
479     catch ( CexmcException &  e )                 479     catch ( CexmcException &  e )
480     {                                             480     {
481         G4cout << e.what() << G4endl;             481         G4cout << e.what() << G4endl;
482     }                                             482     }
483 #ifdef CEXMC_USE_PERSISTENCY                      483 #ifdef CEXMC_USE_PERSISTENCY
484     catch ( boost::archive::archive_exception     484     catch ( boost::archive::archive_exception &  e )
485     {                                             485     {
486         G4cout << CEXMC_LINE_START << "Seriali    486         G4cout << CEXMC_LINE_START << "Serialization error: " << e.what() <<
487                   G4endl;                         487                   G4endl;
488     }                                             488     }
489 #ifdef CEXMC_USE_CUSTOM_FILTER                    489 #ifdef CEXMC_USE_CUSTOM_FILTER
490     catch ( boost::bad_get &  e )                 490     catch ( boost::bad_get &  e )
491     {                                             491     {
492         G4cout << CEXMC_LINE_START << "Custom     492         G4cout << CEXMC_LINE_START << "Custom filter error: " << e.what() <<
493                   G4endl;                         493                   G4endl;
494     }                                             494     }
495 #endif                                            495 #endif
496 #endif                                            496 #endif
497     catch ( ... )                                 497     catch ( ... )
498     {                                             498     {
499         G4cout << "Unknown exception caught" <    499         G4cout << "Unknown exception caught" << G4endl;
500     }                                             500     }
501                                                   501 
502 #ifdef CEXMC_USE_ROOT                             502 #ifdef CEXMC_USE_ROOT
503     CexmcHistoManager::Destroy();                 503     CexmcHistoManager::Destroy();
504 #endif                                            504 #endif
505                                                   505 
506     CexmcMessenger::Destroy();                    506     CexmcMessenger::Destroy();
507                                                   507 
508     delete session;                               508     delete session;
509     delete visManager;                            509     delete visManager;
510     delete runManager;                            510     delete runManager;
511                                                   511 
512     return 0;                                     512     return 0;
513 }                                                 513 }
514                                                   514 
515                                                   515