ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GammaRayTelRunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GammaRayTelRunAction.cc
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 // ------------------------------------------------------------
28 // GEANT 4 class implementation file
29 // CERN Geneva Switzerland
30 //
31 //
32 // ------------ GammaRayTelRunAction ------
33 // by R.Giannitrapani, F.Longo & G.Santin (13 nov 2000)
34 // 18.11.2001 G.Santin
35 // - Modified the analysis management according to the new design
36 //
37 // ************************************************************
38 
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42 
43 #include "GammaRayTelRunAction.hh"
44 
45 #include "GammaRayTelAnalysis.hh"
46 
47 #include <stdlib.h>
48 #include "G4Run.hh"
49 #include "G4UImanager.hh"
50 #include "G4VVisManager.hh"
51 #include "G4ios.hh"
52 #include "G4Threading.hh"
53 
55  outFile(0),fileName("NULL"),fRunID(-1)
56 {;}
57 
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
60 
62 {;}
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
65 
67 {
68  fRunID = aRun->GetRunID();
69 
70  //Master mode or sequential
71  if (IsMaster())
72  G4cout << "### Run " << aRun->GetRunID() << " starts (master)." << G4endl;
73  else
74  G4cout << "### Run " << aRun->GetRunID() << " starts (worker)." << G4endl;
75 
76  // Prepare the visualization
78  {
80  UI->ApplyCommand("/vis/scene/notifyHandlers");
81  }
82 
83  // If analysis is used reset the histograms
85  // analysis->BeginOfRun(aRun->GetRunID());
86  analysis->BeginOfRun();
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
90 
92 {
93  G4cout << "End of Run " << aRun->GetRunID() << G4endl;
94 
95  // Close the file with the hits information
96 #ifdef G4STORE_DATA
97  if (outFile)
98  {
99  G4cout << "File " << fileName << G4endl;
100  outFile->close();
101  delete outFile;
102  outFile = 0;
103  }
104 #endif
105 
106  // If analysis is used, print out the histograms
108  analysis->EndOfRun();
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
112 
113 
115 {
116  if (!outFile)
117  OpenFile();
118  return outFile;
119 }
120 
121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
123 {
124  // Open the file for the tracks of this run
125 #ifdef G4STORE_DATA
126  //check that we are in a worker: returns -1 in a master and -2 in sequential
127  //one file per thread is produced
128  //Tracks_runR.N.dat, where R=run number, N=thread ID
129  char name[25];
130  if (G4Threading::G4GetThreadId() >= 0)
131  sprintf(name,"Tracks_run%d.%d.dat",fRunID,
133  else
134  sprintf(name,"Tracks_run%d.dat",fRunID);
135  if (!outFile)
136  {
137  outFile = new std::ofstream;
138  outFile->open(name);
139  fileName = G4String(name);
140  }
141  G4cout << "Open file: " << fileName << G4endl;
142 #endif
143 }
144 
145