Geant4  10.01.p03
GammaRayTelRunAction.cc
Go to the documentation of this file.
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 //
27 // $Id: GammaRayTelRunAction.cc 82630 2014-07-01 09:43:00Z gcosmo $
28 // ------------------------------------------------------------
29 // GEANT 4 class implementation file
30 // CERN Geneva Switzerland
31 //
32 //
33 // ------------ GammaRayTelRunAction ------
34 // by R.Giannitrapani, F.Longo & G.Santin (13 nov 2000)
35 // 18.11.2001 G.Santin
36 // - Modified the analysis management according to the new design
37 //
38 // ************************************************************
39 
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
43 
44 #include "GammaRayTelRunAction.hh"
45 
46 #include "GammaRayTelAnalysis.hh"
47 
48 #include <stdlib.h>
49 #include "G4Run.hh"
50 #include "G4UImanager.hh"
51 #include "G4VVisManager.hh"
52 #include "G4ios.hh"
53 #include "G4Threading.hh"
54 
56  outFile(0),fileName("NULL"),fRunID(-1)
57 {;}
58 
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
61 
63 {;}
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
66 
68 {
69  fRunID = aRun->GetRunID();
70 
71  //Master mode or sequential
72  if (IsMaster())
73  G4cout << "### Run " << aRun->GetRunID() << " starts (master)." << G4endl;
74  else
75  G4cout << "### Run " << aRun->GetRunID() << " starts (worker)." << G4endl;
76 
77  // Prepare the visualization
79  {
81  UI->ApplyCommand("/vis/scene/notifyHandlers");
82  }
83 
84  // If analysis is used reset the histograms
86  // analysis->BeginOfRun(aRun->GetRunID());
87  analysis->BeginOfRun();
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
91 
93 {
94  G4cout << "End of Run " << aRun->GetRunID() << G4endl;
95 
96  // Close the file with the hits information
97 #ifdef G4STORE_DATA
98  if (outFile)
99  {
100  G4cout << "File " << fileName << G4endl;
101  outFile->close();
102  delete outFile;
103  outFile = 0;
104  }
105 #endif
106 
107  // If analysis is used, print out the histograms
109  analysis->EndOfRun();
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
113 
114 
116 {
117  if (!outFile)
118  OpenFile();
119  return outFile;
120 }
121 
122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
124 {
125  // Open the file for the tracks of this run
126 #ifdef G4STORE_DATA
127  //check that we are in a worker: returns -1 in a master and -2 in sequential
128  //one file per thread is produced
129  //Tracks_runR.N.dat, where R=run number, N=thread ID
130  char name[25];
131  if (G4Threading::G4GetThreadId() >= 0)
132  sprintf(name,"Tracks_run%d.%d.dat",fRunID,
134  else
135  sprintf(name,"Tracks_run%d.dat",fRunID);
136  if (!outFile)
137  {
138  outFile = new std::ofstream;
139  outFile->open(name);
140  fileName = G4String(name);
141  }
142  G4cout << "Open file: " << fileName << G4endl;
143 #endif
144 }
145 
146 
std::ofstream * GetOutputFile()
static G4VVisManager * GetConcreteInstance()
static GammaRayTelAnalysis * getInstance()
G4String name
Definition: TRTMaterials.hh:40
void BeginOfRunAction(const G4Run *)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
void EndOfRunAction(const G4Run *)
G4bool IsMaster() const
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
#define G4endl
Definition: G4ios.hh:61
G4int G4GetThreadId()
Definition: G4Threading.cc:127
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432