Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4GeneralParticleSourceData.hh
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 // -------------------------------------------------------------------
28 //
29 // GEANT4 Class file
30 //
31 //
32 // File name: G4GeneralParticleSourceData.hh
33 //
34 // Author: Andrew Green
35 //
36 // Creation date: 20 Mar 2014
37 //
38 // Class Description:
39 // This class uses the singleton pattern to create a single copy of the data
40 // needed for the G4GPS class. As yet, only the largest parts have been split
41 // off.
42 //
43 // Thread Safety:
44 // Singleton creation (G4GeneralParticleSourceData::Instance()) is thread safe.
45 // Getters are thread-safe if no other thread is adding/deleting a source or normalizing
46 // However please note that the setters are usually accessed via messenger. This should be
47 // instantiated in master thread.
48 //
49 // For convinience Lock and Unlock methods are provided that can be used to serialize calls.
50 // For example:
51 // gpsdata=G4GeneralParticleSourceData::Instance();
52 // gpsdata->Lock();
53 // gpsdata->AddASource(1.0);
54 // gpsdata->Unlock();
55 
56 
57 #ifndef G4GPS_DATA_HH
58 #define G4GPS_DATA_HH 1
59 
61 #include "G4Threading.hh"
62 
64 {
65  public:
67 
68  void AddASource(G4double intensity);
69  void DeleteASource(G4int idx);
70  void ClearSources();
71 
72  void IntensityNormalise();
73 
74  G4bool Normalised() const {return normalised;}
75 
77  G4SingleParticleSource* GetCurrentSource() const {return currentSource;}
78 
79  G4int GetSourceVectorSize() const {return G4int(sourceVector.size());}
80  G4int GetIntensityVectorSize() const {return G4int(sourceIntensity.size());}
81  G4double GetIntensity(G4int idx)const {return sourceIntensity.at(idx);}
82  G4double GetSourceProbability(G4int idx) const {return sourceProbability.at(idx);}
83 
85 
86  void SetFlatSampling(G4bool fSamp){flat_sampling = fSamp;}
87  G4bool GetFlatSampling() const { return flat_sampling; }
88 
89  void SetMultipleVertex(G4bool flag) { multiple_vertex = flag; }
90  G4bool GetMultipleVertex() const { return multiple_vertex; }
91 
92  G4int GetCurrentSourceIdx() const { return currentSourceIdx; }
93 
95  //Lock/Unlock shared mutex
96  void Lock();
97  void Unlock();
98 
99  private:
102 
103 
104  private:
105 
106  std::vector<G4SingleParticleSource*> sourceVector;
107  std::vector <G4double> sourceIntensity;
108  std::vector <G4double> sourceProbability;
109 
110  G4bool multiple_vertex;
111  G4bool flat_sampling;
112  G4bool normalised;
113 
114  G4int currentSourceIdx;
115  G4SingleParticleSource* currentSource;
116  G4Mutex mutex;
117 };
118 
119 #endif
G4SingleParticleSource * GetCurrentSource() const
int G4int
Definition: G4Types.hh:78
G4double GetSourceProbability(G4int idx) const
bool G4bool
Definition: G4Types.hh:79
G4double GetIntensity(G4int idx) const
G4int G4Mutex
Definition: G4Threading.hh:173
double G4double
Definition: G4Types.hh:76
static G4GeneralParticleSourceData * Instance()