Geant4  10.01.p02
pyG4ParticleList.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 // $Id: pyG4ParticleList.cc 66892 2013-01-17 10:57:59Z gunter $
27 // ====================================================================
28 // pyG4ParticleList.cc
29 //
30 // 2005 Q
31 // ====================================================================
32 #include <boost/python.hpp>
33 #include "G4ParticleTable.hh"
34 
35 using namespace boost::python;
36 
37 // ====================================================================
38 // internal class
39 // ====================================================================
40 
42 public:
43  typedef std::vector<G4ParticleDefinition*> ParticleList;
44  typedef ParticleList::iterator p_iterator;
45 
46  static ParticleList particleTableCache;
47 
48  p_iterator p_begin() {
50  if(particleTableCache.size() != particleTable-> size() ) {
51  particleTableCache.clear();
53  theParticleIterator= particleTable-> GetIterator();
54  theParticleIterator-> reset();
55  while( (*theParticleIterator)() ){
56  G4ParticleDefinition* particle= theParticleIterator-> value();
57  particleTableCache.push_back(particle);
58  }
59  }
60  return particleTableCache.begin();
61  }
62 
63  p_iterator p_end() {
65  if(particleTableCache.size() != particleTable-> size() ) {
66  particleTableCache.clear();
68  theParticleIterator= particleTable-> GetIterator();
69  theParticleIterator-> reset();
70  while( (*theParticleIterator)() ){
71  G4ParticleDefinition* particle= theParticleIterator-> value();
72  particleTableCache.push_back(particle);
73  }
74  }
75  return particleTableCache.end();
76  }
77 };
78 
80 
81 
82 // ====================================================================
83 // module definition
84 // ====================================================================
86 {
87  class_<PyG4ParticleList>("PyG4ParticleList", "particle list")
88  .def("__iter__", iterator<PyG4ParticleList::ParticleList>())
89  .add_property("particles", range(&PyG4ParticleList::p_begin,
91  ;
92 }
93 
std::vector< G4ParticleDefinition * > ParticleList
p_iterator p_begin()
void export_PyG4ParticleList()
static G4ParticleTable * GetParticleTable()
p_iterator p_end()
static ParticleList particleTableCache
ParticleList::iterator p_iterator
#define theParticleIterator