Commit 8e79972fab2d5527896225736d73e90bab73f21d

Authored by Jürgen Knödlseder
1 parent a3fa428c

Add ctobservation::_unbinned_observations() generator to Python interface (#1828)

pyext/ctobservation.i
... ... @@ -53,13 +53,35 @@ public:
53 53 virtual void run(void) = 0;
54 54 virtual void save(void) = 0;
55 55  
56   - // Methods
  56 + // Public methods
57 57 const GObservations& obs(void) const;
  58 +
  59 + // Make methods private in Python by prepending an underscore
  60 + %rename(_first_unbinned_observation) first_unbinned_observation;
  61 + %rename(_next_unbinned_observation) next_unbinned_observation;
  62 +
  63 + // Protected methods
  64 + GCTAObservation* first_unbinned_observation(void);
  65 + GCTAObservation* next_unbinned_observation(void);
58 66 };
59 67  
60 68  
61 69 /***********************************************************************//**
62   - * @brief Likelihood tool Python extensions
  70 + * @brief Observation tool base class C++ extensions
63 71 ***************************************************************************/
64 72 %extend ctobservation {
65 73 }
  74 +
  75 +
  76 +/***********************************************************************//**
  77 + * @brief Observation tool base class Python extensions
  78 + ***************************************************************************/
  79 +%pythoncode %{
  80 +def _unbinned_observations(self):
  81 + obs = self._first_unbinned_observation()
  82 + while obs != None:
  83 + yield obs
  84 + obs = self._next_unbinned_observation()
  85 +ctool._unbinned_observations = _unbinned_observations
  86 +cscript._unbinned_observations = _unbinned_observations
  87 +%}
... ...
src/support/ctobservation.hpp
... ... @@ -65,18 +65,23 @@ public:
65 65 // Methods
66 66 const GObservations& obs(void) const;
67 67  
  68 +#ifdef SWIG
  69 +public:
  70 +#else
68 71 protected:
69   - // Protected methods
70   - void init_members(void);
71   - void copy_members(const ctobservation& app);
72   - void free_members(void);
73   -
  72 +#endif
74 73 // Iterator methods and members
75 74 GCTAObservation* first_unbinned_observation(void);
76 75 GCTAObservation* next_unbinned_observation(void);
77 76 const GCTAObservation* first_unbinned_observation(void) const;
78 77 const GCTAObservation* next_unbinned_observation(void) const;
79 78  
  79 +protected:
  80 + // Protected methods
  81 + void init_members(void);
  82 + void copy_members(const ctobservation& app);
  83 + void free_members(void);
  84 +
80 85 // Protected members
81 86 GObservations m_obs; //!< Observation container
82 87  
... ...