Commit 7364643153c27855e4b1195fc3fc196fe481ea0d
1 parent
26cc8e40
Make Python objects pickle-able (#1938)
Showing
94 changed files
with
1787 additions
and
429 deletions
NEWS
| 1 | New Features and Important Changes in GammaLib 1.6.0 | 1 | New Features and Important Changes in GammaLib 1.6.0 |
| 2 | 2 | ||
| 3 | -21 June 2018 | 3 | +22 June 2018 |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 1. Introduction | 6 | 1. Introduction |
| @@ -49,9 +49,20 @@ The following methods have been added: | @@ -49,9 +49,20 @@ The following methods have been added: | ||
| 49 | - GPha::ancrfile() | 49 | - GPha::ancrfile() |
| 50 | - GFitsHeaderCard boolean constructor | 50 | - GFitsHeaderCard boolean constructor |
| 51 | - GFitsHDU::card(std::string&, bool&, std::string&) | 51 | - GFitsHDU::card(std::string&, bool&, std::string&) |
| 52 | +- GObservation::has_events() | ||
| 53 | +- GModelSpatialPointSource::type(std::string&) | ||
| 54 | +- GModelSpectralPlaw::type(std::string&) | ||
| 55 | +- GModelSpatialRadialProfileGauss(GSkyDir&, double&) | ||
| 56 | +- GModelSpatialRadialProfileGauss::sigma() | ||
| 57 | +- GXml::GXml(GXmlDocument&) | ||
| 58 | +- GXml::root() | ||
| 59 | +- GXmlElement::attributes() | ||
| 60 | +- GXmlElement::attribute(int&) | ||
| 61 | +- GXmlDocument::GXmlDocument(GFilename&, std::string&, std::string&, std::string&) | ||
| 52 | - GCTAInstDir::theta() | 62 | - GCTAInstDir::theta() |
| 53 | - GCTAInstDir::phi() | 63 | - GCTAInstDir::phi() |
| 54 | - GCTAEventAtom(GCTAInstDir&, GEnergy&, GTime&) | 64 | - GCTAEventAtom(GCTAInstDir&, GEnergy&, GTime&) |
| 65 | +- GCTAEventAtom::index(int&) | ||
| 55 | - GCTABackground::rate_ebin() | 66 | - GCTABackground::rate_ebin() |
| 56 | - GCTABackgroundPerfTable::rate_ebin() | 67 | - GCTABackgroundPerfTable::rate_ebin() |
| 57 | - GCTABackground3D::rate_ebin() | 68 | - GCTABackground3D::rate_ebin() |
| @@ -62,8 +73,8 @@ The following methods have been added: | @@ -62,8 +73,8 @@ The following methods have been added: | ||
| 62 | - GCTAModelRadialAcceptance::radial(GCTAModelRadial*) | 73 | - GCTAModelRadialAcceptance::radial(GCTAModelRadial*) |
| 63 | - GCTAModelRadialAcceptance::spectral(GModelSpectral*) | 74 | - GCTAModelRadialAcceptance::spectral(GModelSpectral*) |
| 64 | - GCTAModelRadialAcceptance::temporal(GModelTemporal*) | 75 | - GCTAModelRadialAcceptance::temporal(GModelTemporal*) |
| 65 | -- GModelSpatialRadialProfileGauss(GSkyDir&, double&) | ||
| 66 | -- GModelSpatialRadialProfileGauss::sigma() | 76 | +- GCTAModelIrfBackground::spectral(GModelSpectral*) |
| 77 | +- GCTAModelIrfBackground::temporal(GModelTemporal*) | ||
| 67 | 78 | ||
| 68 | The following methods have been removed: | 79 | The following methods have been removed: |
| 69 | - none | 80 | - none |
include/GModelSpatialComposite.hpp
| @@ -78,6 +78,7 @@ public: | @@ -78,6 +78,7 @@ public: | ||
| 78 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 78 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 79 | 79 | ||
| 80 | // Other methods | 80 | // Other methods |
| 81 | + void type(const std::string& type); | ||
| 81 | int components(void) const; | 82 | int components(void) const; |
| 82 | void append(const GModelSpatial& component, | 83 | void append(const GModelSpatial& component, |
| 83 | const std::string& name = "", | 84 | const std::string& name = "", |
| @@ -131,6 +132,21 @@ std::string GModelSpatialComposite::type(void) const | @@ -131,6 +132,21 @@ std::string GModelSpatialComposite::type(void) const | ||
| 131 | 132 | ||
| 132 | 133 | ||
| 133 | /***********************************************************************//** | 134 | /***********************************************************************//** |
| 135 | + * @brief Set model type | ||
| 136 | + * | ||
| 137 | + * @param[in] type Model type. | ||
| 138 | + * | ||
| 139 | + * Set the type of the spatial model. | ||
| 140 | + ***************************************************************************/ | ||
| 141 | +inline | ||
| 142 | +void GModelSpatialComposite::type(const std::string& type) | ||
| 143 | +{ | ||
| 144 | + m_type = type; | ||
| 145 | + return; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | + | ||
| 149 | +/***********************************************************************//** | ||
| 134 | * @brief Return class code | 150 | * @brief Return class code |
| 135 | * | 151 | * |
| 136 | * @return GModelSpatialComposite. | 152 | * @return GModelSpatialComposite. |
include/GModelSpatialPointSource.hpp
| @@ -81,6 +81,7 @@ public: | @@ -81,6 +81,7 @@ public: | ||
| 81 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 81 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 82 | 82 | ||
| 83 | // Other methods | 83 | // Other methods |
| 84 | + void type(const std::string& type); | ||
| 84 | double ra(void) const; | 85 | double ra(void) const; |
| 85 | double dec(void) const; | 86 | double dec(void) const; |
| 86 | void ra(const double& ra); | 87 | void ra(const double& ra); |
| @@ -120,7 +121,7 @@ std::string GModelSpatialPointSource::classname(void) const | @@ -120,7 +121,7 @@ std::string GModelSpatialPointSource::classname(void) const | ||
| 120 | * | 121 | * |
| 121 | * @return Model type. | 122 | * @return Model type. |
| 122 | * | 123 | * |
| 123 | - * Returns the type of the spatial model. | 124 | + * Returns the type of the spatial point source model. |
| 124 | ***************************************************************************/ | 125 | ***************************************************************************/ |
| 125 | inline | 126 | inline |
| 126 | std::string GModelSpatialPointSource::type(void) const | 127 | std::string GModelSpatialPointSource::type(void) const |
| @@ -130,6 +131,21 @@ std::string GModelSpatialPointSource::type(void) const | @@ -130,6 +131,21 @@ std::string GModelSpatialPointSource::type(void) const | ||
| 130 | 131 | ||
| 131 | 132 | ||
| 132 | /***********************************************************************//** | 133 | /***********************************************************************//** |
| 134 | + * @brief Set model type | ||
| 135 | + * | ||
| 136 | + * @param[in] type Model type. | ||
| 137 | + * | ||
| 138 | + * Set the type of the spatial point source model. | ||
| 139 | + ***************************************************************************/ | ||
| 140 | +inline | ||
| 141 | +void GModelSpatialPointSource::type(const std::string& type) | ||
| 142 | +{ | ||
| 143 | + m_type = type; | ||
| 144 | + return; | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | + | ||
| 148 | +/***********************************************************************//** | ||
| 133 | * @brief Return class code | 149 | * @brief Return class code |
| 134 | * | 150 | * |
| 135 | * @return GModelSpatialPointSource. | 151 | * @return GModelSpatialPointSource. |
include/GModelSpectralBrokenPlaw.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralBrokenPlaw.hpp - Broken power law spectrum class * | 2 | * GModelSpectralBrokenPlaw.hpp - Broken power law spectrum class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2017 by Anneli Schulz * | 4 | + * copyright (C) 2013-2018 by Anneli Schulz * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -104,6 +104,7 @@ public: | @@ -104,6 +104,7 @@ public: | ||
| 104 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 104 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 105 | 105 | ||
| 106 | // Other methods | 106 | // Other methods |
| 107 | + void type(const std::string& type); | ||
| 107 | double prefactor(void) const; | 108 | double prefactor(void) const; |
| 108 | double index1(void) const; | 109 | double index1(void) const; |
| 109 | double index2(void) const; | 110 | double index2(void) const; |
| @@ -176,6 +177,21 @@ std::string GModelSpectralBrokenPlaw::type(void) const | @@ -176,6 +177,21 @@ std::string GModelSpectralBrokenPlaw::type(void) const | ||
| 176 | 177 | ||
| 177 | 178 | ||
| 178 | /***********************************************************************//** | 179 | /***********************************************************************//** |
| 180 | + * @brief Set model type | ||
| 181 | + * | ||
| 182 | + * @param[in] type Model type. | ||
| 183 | + * | ||
| 184 | + * Set the type of the spectral broken power law model. | ||
| 185 | + ***************************************************************************/ | ||
| 186 | +inline | ||
| 187 | +void GModelSpectralBrokenPlaw::type(const std::string& type) | ||
| 188 | +{ | ||
| 189 | + m_type = type; | ||
| 190 | + return; | ||
| 191 | +} | ||
| 192 | + | ||
| 193 | + | ||
| 194 | +/***********************************************************************//** | ||
| 179 | * @brief Return pre factor | 195 | * @brief Return pre factor |
| 180 | * | 196 | * |
| 181 | * @return Pre factor (ph/cm2/s/MeV). | 197 | * @return Pre factor (ph/cm2/s/MeV). |
include/GModelSpectralConst.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralConst.hpp - Spectral constant model class * | 2 | * GModelSpectralConst.hpp - Spectral constant model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2009-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -89,6 +89,7 @@ public: | @@ -89,6 +89,7 @@ public: | ||
| 89 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 89 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 90 | 90 | ||
| 91 | // Other methods | 91 | // Other methods |
| 92 | + void type(const std::string& type); | ||
| 92 | double value(void) const; | 93 | double value(void) const; |
| 93 | void value(const double& value); | 94 | void value(const double& value); |
| 94 | 95 | ||
| @@ -131,6 +132,21 @@ std::string GModelSpectralConst::type(void) const | @@ -131,6 +132,21 @@ std::string GModelSpectralConst::type(void) const | ||
| 131 | 132 | ||
| 132 | 133 | ||
| 133 | /***********************************************************************//** | 134 | /***********************************************************************//** |
| 135 | + * @brief Set model type | ||
| 136 | + * | ||
| 137 | + * @param[in] type Model type. | ||
| 138 | + * | ||
| 139 | + * Set the type of the constant spectral model. | ||
| 140 | + ***************************************************************************/ | ||
| 141 | +inline | ||
| 142 | +void GModelSpectralConst::type(const std::string& type) | ||
| 143 | +{ | ||
| 144 | + m_type = type; | ||
| 145 | + return; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | + | ||
| 149 | +/***********************************************************************//** | ||
| 134 | * @brief Return model value | 150 | * @brief Return model value |
| 135 | * | 151 | * |
| 136 | * @return Model value (ph/cm2/s/MeV). | 152 | * @return Model value (ph/cm2/s/MeV). |
include/GModelSpectralExpInvPlaw.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralExpInvPlaw.hpp - Exponential cut off power law model * | 2 | * GModelSpectralExpInvPlaw.hpp - Exponential cut off power law model * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016 by Alexander Ziegler * | 4 | + * copyright (C) 2016-2018 by Alexander Ziegler * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -106,6 +106,7 @@ public: | @@ -106,6 +106,7 @@ public: | ||
| 106 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 106 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 107 | 107 | ||
| 108 | // Other methods | 108 | // Other methods |
| 109 | + void type(const std::string& type); | ||
| 109 | double prefactor(void) const; | 110 | double prefactor(void) const; |
| 110 | void prefactor(const double& prefactor); | 111 | void prefactor(const double& prefactor); |
| 111 | double index(void) const; | 112 | double index(void) const; |
| @@ -213,6 +214,21 @@ std::string GModelSpectralExpInvPlaw::type(void) const | @@ -213,6 +214,21 @@ std::string GModelSpectralExpInvPlaw::type(void) const | ||
| 213 | 214 | ||
| 214 | 215 | ||
| 215 | /***********************************************************************//** | 216 | /***********************************************************************//** |
| 217 | + * @brief Set model type | ||
| 218 | + * | ||
| 219 | + * @param[in] type Model type. | ||
| 220 | + * | ||
| 221 | + * Set the type of the exponentially cut off power law model. | ||
| 222 | + ***************************************************************************/ | ||
| 223 | +inline | ||
| 224 | +void GModelSpectralExpInvPlaw::type(const std::string& type) | ||
| 225 | +{ | ||
| 226 | + m_type = type; | ||
| 227 | + return; | ||
| 228 | +} | ||
| 229 | + | ||
| 230 | + | ||
| 231 | +/***********************************************************************//** | ||
| 216 | * @brief Return pre factor | 232 | * @brief Return pre factor |
| 217 | * | 233 | * |
| 218 | * @return Pre factor (ph/cm2/s/MeV). | 234 | * @return Pre factor (ph/cm2/s/MeV). |
include/GModelSpectralExpPlaw.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralExpPlaw.hpp - Exponential cut off power law model * | 2 | * GModelSpectralExpPlaw.hpp - Exponential cut off power law model * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -102,6 +102,7 @@ public: | @@ -102,6 +102,7 @@ public: | ||
| 102 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 102 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 103 | 103 | ||
| 104 | // Other methods | 104 | // Other methods |
| 105 | + void type(const std::string& type); | ||
| 105 | double prefactor(void) const; | 106 | double prefactor(void) const; |
| 106 | void prefactor(const double& prefactor); | 107 | void prefactor(const double& prefactor); |
| 107 | double index(void) const; | 108 | double index(void) const; |
| @@ -207,6 +208,21 @@ std::string GModelSpectralExpPlaw::type(void) const | @@ -207,6 +208,21 @@ std::string GModelSpectralExpPlaw::type(void) const | ||
| 207 | 208 | ||
| 208 | 209 | ||
| 209 | /***********************************************************************//** | 210 | /***********************************************************************//** |
| 211 | + * @brief Set model type | ||
| 212 | + * | ||
| 213 | + * @param[in] type Model type. | ||
| 214 | + * | ||
| 215 | + * Set the type of the exponentially cut off power law model. | ||
| 216 | + ***************************************************************************/ | ||
| 217 | +inline | ||
| 218 | +void GModelSpectralExpPlaw::type(const std::string& type) | ||
| 219 | +{ | ||
| 220 | + m_type = type; | ||
| 221 | + return; | ||
| 222 | +} | ||
| 223 | + | ||
| 224 | + | ||
| 225 | +/***********************************************************************//** | ||
| 210 | * @brief Return pre factor | 226 | * @brief Return pre factor |
| 211 | * | 227 | * |
| 212 | * @return Pre factor (ph/cm2/s/MeV). | 228 | * @return Pre factor (ph/cm2/s/MeV). |
include/GModelSpectralLogParabola.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralLogParabola.hpp - Log parabola spectral model class * | 2 | * GModelSpectralLogParabola.hpp - Log parabola spectral model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2016 by Michael Mayer * | 4 | + * copyright (C) 2012-2018 by Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -103,6 +103,7 @@ public: | @@ -103,6 +103,7 @@ public: | ||
| 103 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 103 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 104 | 104 | ||
| 105 | // Other methods | 105 | // Other methods |
| 106 | + void type(const std::string& type); | ||
| 106 | double prefactor(void) const; | 107 | double prefactor(void) const; |
| 107 | void prefactor(const double& prefactor); | 108 | void prefactor(const double& prefactor); |
| 108 | double index(void) const; | 109 | double index(void) const; |
| @@ -207,7 +208,7 @@ std::string GModelSpectralLogParabola::classname(void) const | @@ -207,7 +208,7 @@ std::string GModelSpectralLogParabola::classname(void) const | ||
| 207 | /***********************************************************************//** | 208 | /***********************************************************************//** |
| 208 | * @brief Return model type | 209 | * @brief Return model type |
| 209 | * | 210 | * |
| 210 | - * @return "LogParabola". | 211 | + * @return Model type. |
| 211 | * | 212 | * |
| 212 | * Returns the type of the log parabola spectral model. | 213 | * Returns the type of the log parabola spectral model. |
| 213 | ***************************************************************************/ | 214 | ***************************************************************************/ |
| @@ -219,6 +220,21 @@ std::string GModelSpectralLogParabola::type(void) const | @@ -219,6 +220,21 @@ std::string GModelSpectralLogParabola::type(void) const | ||
| 219 | 220 | ||
| 220 | 221 | ||
| 221 | /***********************************************************************//** | 222 | /***********************************************************************//** |
| 223 | + * @brief Set model type | ||
| 224 | + * | ||
| 225 | + * @param[in] type Model type. | ||
| 226 | + * | ||
| 227 | + * Set the type of the log parabola spectral model. | ||
| 228 | + ***************************************************************************/ | ||
| 229 | +inline | ||
| 230 | +void GModelSpectralLogParabola::type(const std::string& type) | ||
| 231 | +{ | ||
| 232 | + m_type = type; | ||
| 233 | + return; | ||
| 234 | +} | ||
| 235 | + | ||
| 236 | + | ||
| 237 | +/***********************************************************************//** | ||
| 222 | * @brief Return pre factor | 238 | * @brief Return pre factor |
| 223 | * | 239 | * |
| 224 | * @return Pre factor (ph/cm2/s/MeV). | 240 | * @return Pre factor (ph/cm2/s/MeV). |
include/GModelSpectralPlaw.hpp
| @@ -96,6 +96,7 @@ public: | @@ -96,6 +96,7 @@ public: | ||
| 96 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 96 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 97 | 97 | ||
| 98 | // Other methods | 98 | // Other methods |
| 99 | + void type(const std::string& type); | ||
| 99 | double prefactor(void) const; | 100 | double prefactor(void) const; |
| 100 | double index(void) const; | 101 | double index(void) const; |
| 101 | GEnergy pivot(void) const; | 102 | GEnergy pivot(void) const; |
| @@ -160,6 +161,21 @@ std::string GModelSpectralPlaw::type(void) const | @@ -160,6 +161,21 @@ std::string GModelSpectralPlaw::type(void) const | ||
| 160 | 161 | ||
| 161 | 162 | ||
| 162 | /***********************************************************************//** | 163 | /***********************************************************************//** |
| 164 | + * @brief Set model type | ||
| 165 | + * | ||
| 166 | + * @param[in] type Model type. | ||
| 167 | + * | ||
| 168 | + * Set the type of the spectral power law model. | ||
| 169 | + ***************************************************************************/ | ||
| 170 | +inline | ||
| 171 | +void GModelSpectralPlaw::type(const std::string& type) | ||
| 172 | +{ | ||
| 173 | + m_type = type; | ||
| 174 | + return; | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | + | ||
| 178 | +/***********************************************************************//** | ||
| 163 | * @brief Return pre factor | 179 | * @brief Return pre factor |
| 164 | * | 180 | * |
| 165 | * @return Pre factor (ph/cm2/s/MeV). | 181 | * @return Pre factor (ph/cm2/s/MeV). |
include/GModelSpectralPlawEnergyFlux.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralPlawEnergyFlux.hpp - Spectral power law model class * | 2 | * GModelSpectralPlawEnergyFlux.hpp - Spectral power law model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016 by Michael Mayer * | 4 | + * copyright (C) 2016-2018 by Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -112,6 +112,7 @@ public: | @@ -112,6 +112,7 @@ public: | ||
| 112 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 112 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 113 | 113 | ||
| 114 | // Other methods | 114 | // Other methods |
| 115 | + void type(const std::string& type); | ||
| 115 | double eflux(void) const; | 116 | double eflux(void) const; |
| 116 | void eflux(const double& eflux); | 117 | void eflux(const double& eflux); |
| 117 | double index(void) const; | 118 | double index(void) const; |
| @@ -177,6 +178,21 @@ std::string GModelSpectralPlawEnergyFlux::type(void) const | @@ -177,6 +178,21 @@ std::string GModelSpectralPlawEnergyFlux::type(void) const | ||
| 177 | 178 | ||
| 178 | 179 | ||
| 179 | /***********************************************************************//** | 180 | /***********************************************************************//** |
| 181 | + * @brief Set model type | ||
| 182 | + * | ||
| 183 | + * @param[in] type Model type. | ||
| 184 | + * | ||
| 185 | + * Set the type of the spectral power law model. | ||
| 186 | + ***************************************************************************/ | ||
| 187 | +inline | ||
| 188 | +void GModelSpectralPlawEnergyFlux::type(const std::string& type) | ||
| 189 | +{ | ||
| 190 | + m_type = type; | ||
| 191 | + return; | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | + | ||
| 195 | +/***********************************************************************//** | ||
| 180 | * @brief Return energy flux | 196 | * @brief Return energy flux |
| 181 | * | 197 | * |
| 182 | * @return Energy flux (erg/cm2/s). | 198 | * @return Energy flux (erg/cm2/s). |
include/GModelSpectralPlawPhotonFlux.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralPlawPhotonFlux.hpp - Spectral power law model class * | 2 | * GModelSpectralPlawPhotonFlux.hpp - Spectral power law model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -112,6 +112,7 @@ public: | @@ -112,6 +112,7 @@ public: | ||
| 112 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 112 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 113 | 113 | ||
| 114 | // Other methods | 114 | // Other methods |
| 115 | + void type(const std::string& type); | ||
| 115 | double flux(void) const; | 116 | double flux(void) const; |
| 116 | void flux(const double& flux); | 117 | void flux(const double& flux); |
| 117 | double index(void) const; | 118 | double index(void) const; |
| @@ -177,6 +178,21 @@ std::string GModelSpectralPlawPhotonFlux::type(void) const | @@ -177,6 +178,21 @@ std::string GModelSpectralPlawPhotonFlux::type(void) const | ||
| 177 | 178 | ||
| 178 | 179 | ||
| 179 | /***********************************************************************//** | 180 | /***********************************************************************//** |
| 181 | + * @brief Set model type | ||
| 182 | + * | ||
| 183 | + * @param[in] type Model type. | ||
| 184 | + * | ||
| 185 | + * Set the type of the spectral power law model. | ||
| 186 | + ***************************************************************************/ | ||
| 187 | +inline | ||
| 188 | +void GModelSpectralPlawPhotonFlux::type(const std::string& type) | ||
| 189 | +{ | ||
| 190 | + m_type = type; | ||
| 191 | + return; | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | + | ||
| 195 | +/***********************************************************************//** | ||
| 180 | * @brief Return photon flux | 196 | * @brief Return photon flux |
| 181 | * | 197 | * |
| 182 | * @return Photon flux (ph/cm2/s). | 198 | * @return Photon flux (ph/cm2/s). |
include/GModelSpectralSmoothBrokenPlaw.hpp
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | * GModelSpectralSmoothBrokenPlaw.hpp * | 2 | * GModelSpectralSmoothBrokenPlaw.hpp * |
| 3 | * Smoothly broken power law spectrum class * | 3 | * Smoothly broken power law spectrum class * |
| 4 | * ----------------------------------------------------------------------- * | 4 | * ----------------------------------------------------------------------- * |
| 5 | - * copyright (C) 2017 by Josh Cardenzana * | 5 | + * copyright (C) 2017-2018 by Josh Cardenzana * |
| 6 | * ----------------------------------------------------------------------- * | 6 | * ----------------------------------------------------------------------- * |
| 7 | * * | 7 | * * |
| 8 | * This program is free software: you can redistribute it and/or modify * | 8 | * This program is free software: you can redistribute it and/or modify * |
| @@ -118,6 +118,7 @@ public: | @@ -118,6 +118,7 @@ public: | ||
| 118 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 118 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 119 | 119 | ||
| 120 | // Other methods | 120 | // Other methods |
| 121 | + void type(const std::string& type); | ||
| 121 | double prefactor(void) const; | 122 | double prefactor(void) const; |
| 122 | double index1(void) const; | 123 | double index1(void) const; |
| 123 | double index2(void) const; | 124 | double index2(void) const; |
| @@ -253,6 +254,21 @@ std::string GModelSpectralSmoothBrokenPlaw::type(void) const | @@ -253,6 +254,21 @@ std::string GModelSpectralSmoothBrokenPlaw::type(void) const | ||
| 253 | 254 | ||
| 254 | 255 | ||
| 255 | /***********************************************************************//** | 256 | /***********************************************************************//** |
| 257 | + * @brief Set model type | ||
| 258 | + * | ||
| 259 | + * @param[in] type Model type. | ||
| 260 | + * | ||
| 261 | + * Set the type of the spectral smoothly broken power law model. | ||
| 262 | + ***************************************************************************/ | ||
| 263 | +inline | ||
| 264 | +void GModelSpectralSmoothBrokenPlaw::type(const std::string& type) | ||
| 265 | +{ | ||
| 266 | + m_type = type; | ||
| 267 | + return; | ||
| 268 | +} | ||
| 269 | + | ||
| 270 | + | ||
| 271 | +/***********************************************************************//** | ||
| 256 | * @brief Return pre factor | 272 | * @brief Return pre factor |
| 257 | * | 273 | * |
| 258 | * @return Pre factor (ph/cm2/s/MeV). | 274 | * @return Pre factor (ph/cm2/s/MeV). |
include/GModelSpectralSuperExpPlaw.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralSuperExpPlaw.hpp - Super exp. cut off power law model * | 2 | * GModelSpectralSuperExpPlaw.hpp - Super exp. cut off power law model * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2014-2016 by Michael Mayer * | 4 | + * copyright (C) 2014-2018 by Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -107,6 +107,7 @@ public: | @@ -107,6 +107,7 @@ public: | ||
| 107 | virtual std::string print(const GChatter& chatter = NORMAL) const; | 107 | virtual std::string print(const GChatter& chatter = NORMAL) const; |
| 108 | 108 | ||
| 109 | // Other methods | 109 | // Other methods |
| 110 | + void type(const std::string& type); | ||
| 110 | double prefactor(void) const; | 111 | double prefactor(void) const; |
| 111 | void prefactor(const double& prefactor); | 112 | void prefactor(const double& prefactor); |
| 112 | double index1(void) const; | 113 | double index1(void) const; |
| @@ -213,7 +214,7 @@ std::string GModelSpectralSuperExpPlaw::classname(void) const | @@ -213,7 +214,7 @@ std::string GModelSpectralSuperExpPlaw::classname(void) const | ||
| 213 | * | 214 | * |
| 214 | * @return "SuperExpCutoff". | 215 | * @return "SuperExpCutoff". |
| 215 | * | 216 | * |
| 216 | - * Returns the type of the exponentially cut off power law model. | 217 | + * Returns the type of the super exponentially cut off power law model. |
| 217 | ***************************************************************************/ | 218 | ***************************************************************************/ |
| 218 | inline | 219 | inline |
| 219 | std::string GModelSpectralSuperExpPlaw::type(void) const | 220 | std::string GModelSpectralSuperExpPlaw::type(void) const |
| @@ -223,6 +224,21 @@ std::string GModelSpectralSuperExpPlaw::type(void) const | @@ -223,6 +224,21 @@ std::string GModelSpectralSuperExpPlaw::type(void) const | ||
| 223 | 224 | ||
| 224 | 225 | ||
| 225 | /***********************************************************************//** | 226 | /***********************************************************************//** |
| 227 | + * @brief Set model type | ||
| 228 | + * | ||
| 229 | + * @param[in] type Model type. | ||
| 230 | + * | ||
| 231 | + * Set the type of the super exponentially cut off power law model. | ||
| 232 | + ***************************************************************************/ | ||
| 233 | +inline | ||
| 234 | +void GModelSpectralSuperExpPlaw::type(const std::string& type) | ||
| 235 | +{ | ||
| 236 | + m_type = type; | ||
| 237 | + return; | ||
| 238 | +} | ||
| 239 | + | ||
| 240 | + | ||
| 241 | +/***********************************************************************//** | ||
| 226 | * @brief Return pre factor | 242 | * @brief Return pre factor |
| 227 | * | 243 | * |
| 228 | * @return Pre factor (ph/cm2/s/MeV). | 244 | * @return Pre factor (ph/cm2/s/MeV). |
include/GObservation.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GObservation.hpp - Abstract observation base class * | 2 | * GObservation.hpp - Abstract observation base class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -113,6 +113,7 @@ public: | @@ -113,6 +113,7 @@ public: | ||
| 113 | const GModelPar& par) const; | 113 | const GModelPar& par) const; |
| 114 | 114 | ||
| 115 | // Implemented methods | 115 | // Implemented methods |
| 116 | + bool has_events(void) const; | ||
| 116 | void name(const std::string& name); | 117 | void name(const std::string& name); |
| 117 | void id(const std::string& id); | 118 | void id(const std::string& id); |
| 118 | void statistic(const std::string& statistic); | 119 | void statistic(const std::string& statistic); |
| @@ -215,6 +216,18 @@ protected: | @@ -215,6 +216,18 @@ protected: | ||
| 215 | 216 | ||
| 216 | 217 | ||
| 217 | /***********************************************************************//** | 218 | /***********************************************************************//** |
| 219 | + * @brief Signal if observation has events | ||
| 220 | + * | ||
| 221 | + * @return True if observation contains events. | ||
| 222 | + ***************************************************************************/ | ||
| 223 | +inline | ||
| 224 | +bool GObservation::has_events(void) const | ||
| 225 | +{ | ||
| 226 | + return (m_events != NULL); | ||
| 227 | +} | ||
| 228 | + | ||
| 229 | + | ||
| 230 | +/***********************************************************************//** | ||
| 218 | * @brief Set observation name | 231 | * @brief Set observation name |
| 219 | * | 232 | * |
| 220 | * @param[in] name Observation name. | 233 | * @param[in] name Observation name. |
include/GOptimizerPar.hpp
| @@ -171,9 +171,9 @@ protected: | @@ -171,9 +171,9 @@ protected: | ||
| 171 | mutable double m_factor_gradient; //!< Function gradient factor | 171 | mutable double m_factor_gradient; //!< Function gradient factor |
| 172 | double m_scale; //!< Parameter scaling (true = factor * scale) | 172 | double m_scale; //!< Parameter scaling (true = factor * scale) |
| 173 | bool m_free; //!< Parameter is free | 173 | bool m_free; //!< Parameter is free |
| 174 | - bool m_has_min; //!< Parameter has minimum boundary | ||
| 175 | - bool m_has_max; //!< Parameter has maximum boundary | ||
| 176 | - bool m_has_grad; //!< Parameter has analytic gradient | 174 | + bool m_has_min; //!< Parameter has minimum boundary |
| 175 | + bool m_has_max; //!< Parameter has maximum boundary | ||
| 176 | + bool m_has_grad; //!< Parameter has analytic gradient | ||
| 177 | }; | 177 | }; |
| 178 | 178 | ||
| 179 | 179 |
include/GXml.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXml.hpp - XML class * | 2 | * GXml.hpp - XML class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -181,6 +181,7 @@ public: | @@ -181,6 +181,7 @@ public: | ||
| 181 | GXml(void); | 181 | GXml(void); |
| 182 | GXml(const GXml& xml); | 182 | GXml(const GXml& xml); |
| 183 | explicit GXml(const std::string& xml); | 183 | explicit GXml(const std::string& xml); |
| 184 | + explicit GXml(const GXmlDocument& root); | ||
| 184 | virtual ~GXml(void); | 185 | virtual ~GXml(void); |
| 185 | 186 | ||
| 186 | // Operators | 187 | // Operators |
| @@ -189,33 +190,35 @@ public: | @@ -189,33 +190,35 @@ public: | ||
| 189 | const GXmlNode* operator[](const int& index) const; | 190 | const GXmlNode* operator[](const int& index) const; |
| 190 | 191 | ||
| 191 | // Methods | 192 | // Methods |
| 192 | - void clear(void); | ||
| 193 | - GXml* clone(void) const; | ||
| 194 | - std::string classname(void) const; | ||
| 195 | - int size(void) const; | ||
| 196 | - bool is_empty(void) const; | ||
| 197 | - GXmlNode* set(const int& index, const GXmlNode& node); | ||
| 198 | - GXmlNode* append(const GXmlNode& node); | ||
| 199 | - GXmlElement* append(const std::string& segment); | ||
| 200 | - GXmlNode* insert(const int& index, const GXmlNode& node); | ||
| 201 | - void remove(const int& index); | ||
| 202 | - void reserve(const int& num); | ||
| 203 | - void extend(const GXmlNode& node); | ||
| 204 | - int elements(void) const; | ||
| 205 | - int elements(const std::string& name) const; | ||
| 206 | - GXmlElement* element(const int& index); | ||
| 207 | - const GXmlElement* element(const int& index) const; | ||
| 208 | - GXmlElement* element(const std::string& name); | ||
| 209 | - const GXmlElement* element(const std::string& name) const; | ||
| 210 | - GXmlElement* element(const std::string& name, const int& index); | ||
| 211 | - const GXmlElement* element(const std::string& name, const int& index) const; | ||
| 212 | - void load(const GFilename& filename); | ||
| 213 | - void save(const GFilename& filename) const; | ||
| 214 | - void read(const GUrl& url); | ||
| 215 | - void write(GUrl& url, const int& indent = 0) const; | ||
| 216 | - std::string print(const GChatter& chatter = NORMAL) const; | ||
| 217 | - std::string print(const GChatter& chatter = NORMAL, | ||
| 218 | - const int& indent = 0) const; | 193 | + void clear(void); |
| 194 | + GXml* clone(void) const; | ||
| 195 | + std::string classname(void) const; | ||
| 196 | + int size(void) const; | ||
| 197 | + bool is_empty(void) const; | ||
| 198 | + GXmlNode* set(const int& index, const GXmlNode& node); | ||
| 199 | + GXmlNode* append(const GXmlNode& node); | ||
| 200 | + GXmlElement* append(const std::string& segment); | ||
| 201 | + GXmlNode* insert(const int& index, const GXmlNode& node); | ||
| 202 | + void remove(const int& index); | ||
| 203 | + void reserve(const int& num); | ||
| 204 | + void extend(const GXmlNode& node); | ||
| 205 | + int elements(void) const; | ||
| 206 | + int elements(const std::string& name) const; | ||
| 207 | + GXmlElement* element(const int& index); | ||
| 208 | + const GXmlElement* element(const int& index) const; | ||
| 209 | + GXmlElement* element(const std::string& name); | ||
| 210 | + const GXmlElement* element(const std::string& name) const; | ||
| 211 | + GXmlElement* element(const std::string& name, const int& index); | ||
| 212 | + const GXmlElement* element(const std::string& name, const int& index) const; | ||
| 213 | + const GXmlDocument& root(void) const; | ||
| 214 | + void root(const GXmlDocument& root); | ||
| 215 | + void load(const GFilename& filename); | ||
| 216 | + void save(const GFilename& filename) const; | ||
| 217 | + void read(const GUrl& url); | ||
| 218 | + void write(GUrl& url, const int& indent = 0) const; | ||
| 219 | + std::string print(const GChatter& chatter = NORMAL) const; | ||
| 220 | + std::string print(const GChatter& chatter = NORMAL, | ||
| 221 | + const int& indent = 0) const; | ||
| 219 | 222 | ||
| 220 | protected: | 223 | protected: |
| 221 | // Protected enumerators | 224 | // Protected enumerators |
| @@ -278,4 +281,29 @@ bool GXml::is_empty(void) const | @@ -278,4 +281,29 @@ bool GXml::is_empty(void) const | ||
| 278 | return m_root.is_empty(); | 281 | return m_root.is_empty(); |
| 279 | } | 282 | } |
| 280 | 283 | ||
| 284 | + | ||
| 285 | +/***********************************************************************//** | ||
| 286 | + * @brief Return document root | ||
| 287 | + * | ||
| 288 | + * @return Document root. | ||
| 289 | + ***************************************************************************/ | ||
| 290 | +inline | ||
| 291 | +const GXmlDocument& GXml::root(void) const | ||
| 292 | +{ | ||
| 293 | + return m_root; | ||
| 294 | +} | ||
| 295 | + | ||
| 296 | + | ||
| 297 | +/***********************************************************************//** | ||
| 298 | + * @brief Set document root | ||
| 299 | + * | ||
| 300 | + * @param[in] root Document root. | ||
| 301 | + ***************************************************************************/ | ||
| 302 | +inline | ||
| 303 | +void GXml::root(const GXmlDocument& root) | ||
| 304 | +{ | ||
| 305 | + m_root = root; | ||
| 306 | + return; | ||
| 307 | +} | ||
| 308 | + | ||
| 281 | #endif /* GXML_HPP */ | 309 | #endif /* GXML_HPP */ |
include/GXmlDocument.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlDocument.hpp - XML document node class definition * | 2 | * GXmlDocument.hpp - XML document node class definition * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -53,6 +53,10 @@ class GXmlDocument : public GXmlNode { | @@ -53,6 +53,10 @@ class GXmlDocument : public GXmlNode { | ||
| 53 | public: | 53 | public: |
| 54 | // Constructors and destructors | 54 | // Constructors and destructors |
| 55 | GXmlDocument(void); | 55 | GXmlDocument(void); |
| 56 | + GXmlDocument(const GFilename& filename, | ||
| 57 | + const std::string& version, | ||
| 58 | + const std::string& encoding, | ||
| 59 | + const std::string& standalone); | ||
| 56 | GXmlDocument(const GXmlDocument& node); | 60 | GXmlDocument(const GXmlDocument& node); |
| 57 | virtual ~GXmlDocument(void); | 61 | virtual ~GXmlDocument(void); |
| 58 | 62 |
include/GXmlElement.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlElement.hpp - XML element node class definition * | 2 | * GXmlElement.hpp - XML element node class definition * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -65,6 +65,8 @@ public: | @@ -65,6 +65,8 @@ public: | ||
| 65 | virtual std::string classname(void) const; | 65 | virtual std::string classname(void) const; |
| 66 | const std::string& name(void) const; | 66 | const std::string& name(void) const; |
| 67 | void name(const std::string& name); | 67 | void name(const std::string& name); |
| 68 | + int attributes(void) const; | ||
| 69 | + const GXmlAttribute* attribute(const int& index) const; | ||
| 68 | std::string attribute(const std::string& name) const; | 70 | std::string attribute(const std::string& name) const; |
| 69 | void attribute(const std::string& name, | 71 | void attribute(const std::string& name, |
| 70 | const std::string& value); | 72 | const std::string& value); |
| @@ -138,4 +140,16 @@ GXmlNode::NodeType GXmlElement::type(void) const | @@ -138,4 +140,16 @@ GXmlNode::NodeType GXmlElement::type(void) const | ||
| 138 | return (NT_ELEMENT); | 140 | return (NT_ELEMENT); |
| 139 | } | 141 | } |
| 140 | 142 | ||
| 143 | + | ||
| 144 | +/***********************************************************************//** | ||
| 145 | + * @brief Return number of attributes | ||
| 146 | + * | ||
| 147 | + * @return Number of attributes. | ||
| 148 | + ***************************************************************************/ | ||
| 149 | +inline | ||
| 150 | +int GXmlElement::attributes(void) const | ||
| 151 | +{ | ||
| 152 | + return (m_attr.size()); | ||
| 153 | +} | ||
| 154 | + | ||
| 141 | #endif /* GXMLELEMENT_HPP */ | 155 | #endif /* GXMLELEMENT_HPP */ |
inst/cta/include/GCTAEventAtom.hpp
| @@ -75,6 +75,7 @@ public: | @@ -75,6 +75,7 @@ public: | ||
| 75 | const unsigned long& event_id(void) const; | 75 | const unsigned long& event_id(void) const; |
| 76 | const int& mc_id(void) const; | 76 | const int& mc_id(void) const; |
| 77 | const float& phase(void) const; | 77 | const float& phase(void) const; |
| 78 | + void index(const int& index); | ||
| 78 | void event_id(const unsigned long& id); | 79 | void event_id(const unsigned long& id); |
| 79 | void mc_id(const int& id); | 80 | void mc_id(const int& id); |
| 80 | void phase(const float& phase); | 81 | void phase(const float& phase); |
| @@ -234,6 +235,19 @@ const float& GCTAEventAtom::phase(void) const | @@ -234,6 +235,19 @@ const float& GCTAEventAtom::phase(void) const | ||
| 234 | 235 | ||
| 235 | 236 | ||
| 236 | /***********************************************************************//** | 237 | /***********************************************************************//** |
| 238 | + * @brief Set event index | ||
| 239 | + * | ||
| 240 | + * @param[in] index Event index. | ||
| 241 | + ***************************************************************************/ | ||
| 242 | +inline | ||
| 243 | +void GCTAEventAtom::index(const int& index) | ||
| 244 | +{ | ||
| 245 | + m_index = index; | ||
| 246 | + return; | ||
| 247 | +} | ||
| 248 | + | ||
| 249 | + | ||
| 250 | +/***********************************************************************//** | ||
| 237 | * @brief Set event identifier | 251 | * @brief Set event identifier |
| 238 | * | 252 | * |
| 239 | * @param[in] id Event identifier. | 253 | * @param[in] id Event identifier. |
inst/cta/include/GCTAModelIrfBackground.hpp
| @@ -77,6 +77,8 @@ public: | @@ -77,6 +77,8 @@ public: | ||
| 77 | // Other methods | 77 | // Other methods |
| 78 | GModelSpectral* spectral(void) const; | 78 | GModelSpectral* spectral(void) const; |
| 79 | GModelTemporal* temporal(void) const; | 79 | GModelTemporal* temporal(void) const; |
| 80 | + void spectral(const GModelSpectral* spectral); | ||
| 81 | + void temporal(const GModelTemporal* temporal); | ||
| 80 | 82 | ||
| 81 | private: | 83 | private: |
| 82 | // Methods | 84 | // Methods |
inst/cta/pyext/GCTAModelIrfBackground.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GCTAModelIrfBackground.i - CTA IRF background model class * | 2 | * GCTAModelIrfBackground.i - CTA IRF background model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2014-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2014-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -62,6 +62,8 @@ public: | @@ -62,6 +62,8 @@ public: | ||
| 62 | // Other methods | 62 | // Other methods |
| 63 | GModelSpectral* spectral(void) const; | 63 | GModelSpectral* spectral(void) const; |
| 64 | GModelTemporal* temporal(void) const; | 64 | GModelTemporal* temporal(void) const; |
| 65 | + void spectral(const GModelSpectral* spectral); | ||
| 66 | + void temporal(const GModelTemporal* temporal); | ||
| 65 | }; | 67 | }; |
| 66 | 68 | ||
| 67 | /***********************************************************************//** | 69 | /***********************************************************************//** |
| @@ -71,4 +73,14 @@ public: | @@ -71,4 +73,14 @@ public: | ||
| 71 | GCTAModelIrfBackground copy() { | 73 | GCTAModelIrfBackground copy() { |
| 72 | return (*self); | 74 | return (*self); |
| 73 | } | 75 | } |
| 76 | +%pythoncode { | ||
| 77 | + def __getstate__(self): | ||
| 78 | + args = gammalib.GModelData.__getstate__(self), self.spectral(), \ | ||
| 79 | + self.temporal() | ||
| 80 | + return args | ||
| 81 | + def __setstate__(self, state): | ||
| 82 | + gammalib.GModelData.__setstate__(self, state[0]) | ||
| 83 | + self.spectral(state[1]) | ||
| 84 | + self.temporal(state[2]) | ||
| 85 | +} | ||
| 74 | }; | 86 | }; |
inst/cta/pyext/cta.i
| @@ -162,6 +162,66 @@ | @@ -162,6 +162,66 @@ | ||
| 162 | } | 162 | } |
| 163 | $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | 163 | $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); |
| 164 | } | 164 | } |
| 165 | +%typemap(out) GModelSpatial* { | ||
| 166 | + char classname[80]; | ||
| 167 | + strcpy(classname, "_p_"); | ||
| 168 | + strcat(classname, result->classname().c_str()); | ||
| 169 | + swig_type_info *myinfo = SWIGTYPE_p_GModelSpatial; | ||
| 170 | + swig_cast_info *mycast = 0; | ||
| 171 | + mycast = myinfo->cast; | ||
| 172 | + while (mycast != 0) { | ||
| 173 | + if (strcmp(classname, mycast->type->name) == 0) { | ||
| 174 | + myinfo = mycast->type; | ||
| 175 | + break; | ||
| 176 | + } | ||
| 177 | + mycast = mycast->next; | ||
| 178 | + } | ||
| 179 | + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | ||
| 180 | +} | ||
| 181 | +%typemap(out) GModelSpectral* { | ||
| 182 | + if ($1 == NULL) { | ||
| 183 | + $result = Py_None; | ||
| 184 | + Py_INCREF(Py_None); // Py_None is a singleton so increment its reference | ||
| 185 | + } | ||
| 186 | + else { | ||
| 187 | + char classname[80]; | ||
| 188 | + strcpy(classname, "_p_"); | ||
| 189 | + strcat(classname, result->classname().c_str()); | ||
| 190 | + swig_type_info *myinfo = SWIGTYPE_p_GModelSpectral; | ||
| 191 | + swig_cast_info *mycast = 0; | ||
| 192 | + mycast = myinfo->cast; | ||
| 193 | + while (mycast != 0) { | ||
| 194 | + if (strcmp(classname, mycast->type->name) == 0) { | ||
| 195 | + myinfo = mycast->type; | ||
| 196 | + break; | ||
| 197 | + } | ||
| 198 | + mycast = mycast->next; | ||
| 199 | + } | ||
| 200 | + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | ||
| 201 | + } | ||
| 202 | +} | ||
| 203 | +%typemap(out) GModelTemporal* { | ||
| 204 | + if ($1 == NULL) { | ||
| 205 | + $result = Py_None; | ||
| 206 | + Py_INCREF(Py_None); // Py_None is a singleton so increment its reference | ||
| 207 | + } | ||
| 208 | + else { | ||
| 209 | + char classname[80]; | ||
| 210 | + strcpy(classname, "_p_"); | ||
| 211 | + strcat(classname, result->classname().c_str()); | ||
| 212 | + swig_type_info *myinfo = SWIGTYPE_p_GModelTemporal; | ||
| 213 | + swig_cast_info *mycast = 0; | ||
| 214 | + mycast = myinfo->cast; | ||
| 215 | + while (mycast != 0) { | ||
| 216 | + if (strcmp(classname, mycast->type->name) == 0) { | ||
| 217 | + myinfo = mycast->type; | ||
| 218 | + break; | ||
| 219 | + } | ||
| 220 | + mycast = mycast->next; | ||
| 221 | + } | ||
| 222 | + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | ||
| 223 | + } | ||
| 224 | +} | ||
| 165 | 225 | ||
| 166 | /* __ CTA ________________________________________________________________ */ | 226 | /* __ CTA ________________________________________________________________ */ |
| 167 | %include "GCTAObservation.i" | 227 | %include "GCTAObservation.i" |
inst/cta/src/GCTAModelIrfBackground.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GCTAModelIrfBackground.cpp - CTA IRF background model class * | 2 | * GCTAModelIrfBackground.cpp - CTA IRF background model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2014-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2014-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -268,6 +268,60 @@ GCTAModelIrfBackground* GCTAModelIrfBackground::clone(void) const | @@ -268,6 +268,60 @@ GCTAModelIrfBackground* GCTAModelIrfBackground::clone(void) const | ||
| 268 | 268 | ||
| 269 | 269 | ||
| 270 | /***********************************************************************//** | 270 | /***********************************************************************//** |
| 271 | + * @brief Set spectral model component | ||
| 272 | + * | ||
| 273 | + * @param[in] spectral Pointer to spectral model component. | ||
| 274 | + * | ||
| 275 | + * Sets the spectral model component of the model. | ||
| 276 | + ***************************************************************************/ | ||
| 277 | +void GCTAModelIrfBackground::spectral(const GModelSpectral* spectral) | ||
| 278 | +{ | ||
| 279 | + // Free spectral model component only if it differs from current | ||
| 280 | + // component. This prevents unintential deallocation of the argument | ||
| 281 | + if ((m_spectral != NULL) && (m_spectral != spectral)) { | ||
| 282 | + delete m_spectral; | ||
| 283 | + } | ||
| 284 | + | ||
| 285 | + // Clone spectral model component if it exists, otherwise set pointer | ||
| 286 | + // to NULL | ||
| 287 | + m_spectral = (spectral != NULL) ? spectral->clone() : NULL; | ||
| 288 | + | ||
| 289 | + // Set parameter pointers | ||
| 290 | + set_pointers(); | ||
| 291 | + | ||
| 292 | + // Return | ||
| 293 | + return; | ||
| 294 | +} | ||
| 295 | + | ||
| 296 | + | ||
| 297 | +/***********************************************************************//** | ||
| 298 | + * @brief Set temporal model component | ||
| 299 | + * | ||
| 300 | + * @param[in] temporal Pointer to temporal model component. | ||
| 301 | + * | ||
| 302 | + * Sets the temporal model component of the model. | ||
| 303 | + ***************************************************************************/ | ||
| 304 | +void GCTAModelIrfBackground::temporal(const GModelTemporal* temporal) | ||
| 305 | +{ | ||
| 306 | + // Free temporal model component only if it differs from current | ||
| 307 | + // component. This prevents unintential deallocation of the argument | ||
| 308 | + if ((m_temporal != NULL) && (m_temporal != temporal)) { | ||
| 309 | + delete m_temporal; | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + // Clone temporal model component if it exists, otherwise set pointer | ||
| 313 | + // to NULL | ||
| 314 | + m_temporal = (temporal != NULL) ? temporal->clone() : NULL; | ||
| 315 | + | ||
| 316 | + // Set parameter pointers | ||
| 317 | + set_pointers(); | ||
| 318 | + | ||
| 319 | + // Return | ||
| 320 | + return; | ||
| 321 | +} | ||
| 322 | + | ||
| 323 | + | ||
| 324 | +/***********************************************************************//** | ||
| 271 | * @brief Evaluate function | 325 | * @brief Evaluate function |
| 272 | * | 326 | * |
| 273 | * @param[in] event Observed event. | 327 | * @param[in] event Observed event. |
inst/cta/test/test_CTA.py
| @@ -342,6 +342,105 @@ class Test(gammalib.GPythonTestSuite): | @@ -342,6 +342,105 @@ class Test(gammalib.GPythonTestSuite): | ||
| 342 | # Return | 342 | # Return |
| 343 | return | 343 | return |
| 344 | 344 | ||
| 345 | + # Test class pickeling | ||
| 346 | + def _test_pickeling(self): | ||
| 347 | + """ | ||
| 348 | + Test class pickeling | ||
| 349 | + """ | ||
| 350 | + # Perform pickeling tests of empty classes | ||
| 351 | + #test_support._pickeling(self, gammalib.GCTAAeff2D()) | ||
| 352 | + #test_support._pickeling(self, gammalib.GCTAAeffArf()) | ||
| 353 | + #test_support._pickeling(self, gammalib.GCTAAeffPerfTable()) | ||
| 354 | + #test_support._pickeling(self, gammalib.GCTABackground3D()) | ||
| 355 | + #test_support._pickeling(self, gammalib.GCTABackgroundPerfTable()) | ||
| 356 | + #test_support._pickeling(self, gammalib.GCTACubeBackground()) | ||
| 357 | + #test_support._pickeling(self, gammalib.GCTACubeEdisp()) | ||
| 358 | + #test_support._pickeling(self, gammalib.GCTACubeExposure()) | ||
| 359 | + #test_support._pickeling(self, gammalib.GCTACubePsf()) | ||
| 360 | + #test_support._pickeling(self, gammalib.GCTACubeSourceDiffuse()) | ||
| 361 | + #test_support._pickeling(self, gammalib.GCTACubeSourcePoint()) | ||
| 362 | + #test_support._pickeling(self, gammalib.GCTAEdisp2D()) | ||
| 363 | + #test_support._pickeling(self, gammalib.GCTAEdispPerfTable()) | ||
| 364 | + #test_support._pickeling(self, gammalib.GCTAEdispRmf()) | ||
| 365 | + test_support._pickeling(self, gammalib.GCTAEventAtom()) | ||
| 366 | + #test_support._pickeling(self, gammalib.GCTAEventBin()) | ||
| 367 | + #test_support._pickeling(self, gammalib.GCTAEventCube()) | ||
| 368 | + #test_support._pickeling(self, gammalib.GCTAEventList()) | ||
| 369 | + test_support._pickeling(self, gammalib.GCTAInstDir()) | ||
| 370 | + #test_support._pickeling(self, gammalib.GCTAModelAeffBackground()) | ||
| 371 | + #test_support._pickeling(self, gammalib.GCTAModelCubeBackground()) | ||
| 372 | + test_support._pickeling(self, gammalib.GCTAModelIrfBackground()) | ||
| 373 | + #test_support._pickeling(self, gammalib.GCTAModelRadialAcceptance()) | ||
| 374 | + #test_support._pickeling(self, gammalib.GCTAModelRadialGauss()) | ||
| 375 | + #test_support._pickeling(self, gammalib.GCTAModelRadialPolynom()) | ||
| 376 | + #test_support._pickeling(self, gammalib.GCTAModelRadialProfile()) | ||
| 377 | + #test_support._pickeling(self, gammalib.GCTAObservation()) | ||
| 378 | + #test_support._pickeling(self, gammalib.GCTAOnOffObservation()) | ||
| 379 | + #test_support._pickeling(self, gammalib.GCTAPointing()) | ||
| 380 | + #test_support._pickeling(self, gammalib.GCTAPsf2D()) | ||
| 381 | + #test_support._pickeling(self, gammalib.GCTAPsfKing()) | ||
| 382 | + #test_support._pickeling(self, gammalib.GCTAPsfPerfTable()) | ||
| 383 | + #test_support._pickeling(self, gammalib.GCTAPsfTable()) | ||
| 384 | + #test_support._pickeling(self, gammalib.GCTAPsfVector()) | ||
| 385 | + #test_support._pickeling(self, gammalib.GCTAResponseCube()) | ||
| 386 | + #test_support._pickeling(self, gammalib.GCTAResponseIrf()) | ||
| 387 | + #test_support._pickeling(self, gammalib.GCTAResponseTable()) | ||
| 388 | + #test_support._pickeling(self, gammalib.GCTARoi()) | ||
| 389 | + | ||
| 390 | + # Setup test | ||
| 391 | + list = self._setup_eventlist() | ||
| 392 | + atom = list[0] | ||
| 393 | + dir = gammalib.GSkyDir() | ||
| 394 | + instdir = gammalib.GCTAInstDir(dir) | ||
| 395 | + pivot = gammalib.GEnergy(1.0,'TeV') | ||
| 396 | + plaw = gammalib.GModelSpectralPlaw(1.0,-2.0,pivot) | ||
| 397 | + instdir.detx(2.0) | ||
| 398 | + instdir.dety(-3.0) | ||
| 399 | + | ||
| 400 | + # Perform pickeling tests of filled classes | ||
| 401 | + #test_support._pickeling(self, gammalib.GCTAAeff2D()) | ||
| 402 | + #test_support._pickeling(self, gammalib.GCTAAeffArf()) | ||
| 403 | + #test_support._pickeling(self, gammalib.GCTAAeffPerfTable()) | ||
| 404 | + #test_support._pickeling(self, gammalib.GCTABackground3D()) | ||
| 405 | + #test_support._pickeling(self, gammalib.GCTABackgroundPerfTable()) | ||
| 406 | + #test_support._pickeling(self, gammalib.GCTACubeBackground()) | ||
| 407 | + #test_support._pickeling(self, gammalib.GCTACubeEdisp()) | ||
| 408 | + #test_support._pickeling(self, gammalib.GCTACubeExposure()) | ||
| 409 | + #test_support._pickeling(self, gammalib.GCTACubePsf()) | ||
| 410 | + #test_support._pickeling(self, gammalib.GCTACubeSourceDiffuse()) | ||
| 411 | + #test_support._pickeling(self, gammalib.GCTACubeSourcePoint()) | ||
| 412 | + #test_support._pickeling(self, gammalib.GCTAEdisp2D()) | ||
| 413 | + #test_support._pickeling(self, gammalib.GCTAEdispPerfTable()) | ||
| 414 | + #test_support._pickeling(self, gammalib.GCTAEdispRmf()) | ||
| 415 | + test_support._pickeling(self, gammalib.GCTAEventAtom(atom)) | ||
| 416 | + #test_support._pickeling(self, gammalib.GCTAEventBin()) | ||
| 417 | + #test_support._pickeling(self, gammalib.GCTAEventCube()) | ||
| 418 | + #test_support._pickeling(self, gammalib.GCTAEventList()) | ||
| 419 | + test_support._pickeling(self, gammalib.GCTAInstDir(instdir)) | ||
| 420 | + #test_support._pickeling(self, gammalib.GCTAModelAeffBackground()) | ||
| 421 | + #test_support._pickeling(self, gammalib.GCTAModelCubeBackground()) | ||
| 422 | + test_support._pickeling(self, gammalib.GCTAModelIrfBackground(plaw)) | ||
| 423 | + #test_support._pickeling(self, gammalib.GCTAModelRadialAcceptance()) | ||
| 424 | + #test_support._pickeling(self, gammalib.GCTAModelRadialGauss()) | ||
| 425 | + #test_support._pickeling(self, gammalib.GCTAModelRadialPolynom()) | ||
| 426 | + #test_support._pickeling(self, gammalib.GCTAModelRadialProfile()) | ||
| 427 | + #test_support._pickeling(self, gammalib.GCTAObservation()) | ||
| 428 | + #test_support._pickeling(self, gammalib.GCTAOnOffObservation()) | ||
| 429 | + #test_support._pickeling(self, gammalib.GCTAPointing()) | ||
| 430 | + #test_support._pickeling(self, gammalib.GCTAPsf2D()) | ||
| 431 | + #test_support._pickeling(self, gammalib.GCTAPsfKing()) | ||
| 432 | + #test_support._pickeling(self, gammalib.GCTAPsfPerfTable()) | ||
| 433 | + #test_support._pickeling(self, gammalib.GCTAPsfTable()) | ||
| 434 | + #test_support._pickeling(self, gammalib.GCTAPsfVector()) | ||
| 435 | + #test_support._pickeling(self, gammalib.GCTAResponseCube()) | ||
| 436 | + #test_support._pickeling(self, gammalib.GCTAResponseIrf()) | ||
| 437 | + #test_support._pickeling(self, gammalib.GCTAResponseTable()) | ||
| 438 | + #test_support._pickeling(self, gammalib.GCTARoi()) | ||
| 439 | + | ||
| 440 | + # Return | ||
| 441 | + return | ||
| 442 | + | ||
| 443 | + | ||
| 345 | # Set test functions | 444 | # Set test functions |
| 346 | def set(self): | 445 | def set(self): |
| 347 | """ | 446 | """ |
| @@ -358,6 +457,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -358,6 +457,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 358 | self.append(self._test_edisp, 'Test CTA energy dispersion classes') | 457 | self.append(self._test_edisp, 'Test CTA energy dispersion classes') |
| 359 | self.append(self._test_response, 'Test CTA response classes') | 458 | self.append(self._test_response, 'Test CTA response classes') |
| 360 | self.append(self._test_onoff, 'Test CTA On/Off analysis') | 459 | self.append(self._test_onoff, 'Test CTA On/Off analysis') |
| 460 | + self.append(self._test_pickeling, 'Test pickeling of "cta" classes') | ||
| 361 | 461 | ||
| 362 | # Return | 462 | # Return |
| 363 | return | 463 | return |
pyext/GEbounds.i
| @@ -133,9 +133,9 @@ public: | @@ -133,9 +133,9 @@ public: | ||
| 133 | } | 133 | } |
| 134 | %pythoncode { | 134 | %pythoncode { |
| 135 | def __getstate__(self): | 135 | def __getstate__(self): |
| 136 | - args = tuple([self.emin(i) for i in range(self.size())]), \ | ||
| 137 | - tuple([self.emin(i) for i in range(self.size())]) | ||
| 138 | - return args | 136 | + state = tuple([self.emin(i) for i in range(self.size())]), \ |
| 137 | + tuple([self.emin(i) for i in range(self.size())]) | ||
| 138 | + return state | ||
| 139 | def __setstate__(self, state): | 139 | def __setstate__(self, state): |
| 140 | self.__init__() | 140 | self.__init__() |
| 141 | size = len(state[0]) | 141 | size = len(state[0]) |
pyext/GEnergies.i
| @@ -137,12 +137,13 @@ public: | @@ -137,12 +137,13 @@ public: | ||
| 137 | } | 137 | } |
| 138 | %pythoncode { | 138 | %pythoncode { |
| 139 | def __getstate__(self): | 139 | def __getstate__(self): |
| 140 | - args = tuple([x for x in self]) | ||
| 141 | - return args | 140 | + state = tuple([x for x in self]), |
| 141 | + return state | ||
| 142 | def __setstate__(self, state): | 142 | def __setstate__(self, state): |
| 143 | self.__init__() | 143 | self.__init__() |
| 144 | - self.reserve(len(state)) | ||
| 145 | - for x in state: | 144 | + size = len(state[0]) |
| 145 | + self.reserve(size) | ||
| 146 | + for x in state[0]: | ||
| 146 | self.append(x) | 147 | self.append(x) |
| 147 | } | 148 | } |
| 148 | }; | 149 | }; |
pyext/GEnergy.i
| @@ -146,10 +146,10 @@ public: | @@ -146,10 +146,10 @@ public: | ||
| 146 | } | 146 | } |
| 147 | %pythoncode { | 147 | %pythoncode { |
| 148 | def __getstate__(self): | 148 | def __getstate__(self): |
| 149 | - args = self.MeV() | ||
| 150 | - return args | 149 | + state = self.MeV(), |
| 150 | + return state | ||
| 151 | def __setstate__(self, state): | 151 | def __setstate__(self, state): |
| 152 | self.__init__() | 152 | self.__init__() |
| 153 | - self.MeV(state) | 153 | + self.MeV(state[0]) |
| 154 | } | 154 | } |
| 155 | }; | 155 | }; |
pyext/GEvents.i
| @@ -99,8 +99,8 @@ public: | @@ -99,8 +99,8 @@ public: | ||
| 99 | } | 99 | } |
| 100 | %pythoncode { | 100 | %pythoncode { |
| 101 | def __getstate__(self): | 101 | def __getstate__(self): |
| 102 | - args = self.gti(), self.ebounds() | ||
| 103 | - return args | 102 | + state = self.gti(), self.ebounds() |
| 103 | + return state | ||
| 104 | def __setstate__(self, state): | 104 | def __setstate__(self, state): |
| 105 | self.__init__() | 105 | self.__init__() |
| 106 | self.gti(state[0]) | 106 | self.gti(state[0]) |
pyext/GFilename.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GFilename.i - Filename class * | 2 | * GFilename.i - Filename class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2015-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2015-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -91,4 +91,11 @@ public: | @@ -91,4 +91,11 @@ public: | ||
| 91 | GFilename copy() { | 91 | GFilename copy() { |
| 92 | return (*self); | 92 | return (*self); |
| 93 | } | 93 | } |
| 94 | +%pythoncode { | ||
| 95 | + def __getstate__(self): | ||
| 96 | + state = (self.__repr__(),) | ||
| 97 | + return state | ||
| 98 | + def __setstate__(self, state): | ||
| 99 | + self.__init__(state[0]) | ||
| 100 | +} | ||
| 94 | }; | 101 | }; |
pyext/GGti.i
| @@ -119,10 +119,10 @@ public: | @@ -119,10 +119,10 @@ public: | ||
| 119 | } | 119 | } |
| 120 | %pythoncode { | 120 | %pythoncode { |
| 121 | def __getstate__(self): | 121 | def __getstate__(self): |
| 122 | - args = tuple([self.tstart(i) for i in range(self.size())]), \ | ||
| 123 | - tuple([self.tstop(i) for i in range(self.size())]), \ | ||
| 124 | - self.reference() | ||
| 125 | - return args | 122 | + state = tuple([self.tstart(i) for i in range(self.size())]), \ |
| 123 | + tuple([self.tstop(i) for i in range(self.size())]), \ | ||
| 124 | + self.reference() | ||
| 125 | + return state | ||
| 126 | def __setstate__(self, state): | 126 | def __setstate__(self, state): |
| 127 | self.__init__() | 127 | self.__init__() |
| 128 | size = len(state[0]) | 128 | size = len(state[0]) |
pyext/GModel.i
| @@ -108,4 +108,18 @@ public: | @@ -108,4 +108,18 @@ public: | ||
| 108 | (*self)[name] = val; | 108 | (*self)[name] = val; |
| 109 | return; | 109 | return; |
| 110 | } | 110 | } |
| 111 | +%pythoncode { | ||
| 112 | + def __getstate__(self): | ||
| 113 | + state = self.name(), self.instruments(), self.ids(), self.tscalc(), \ | ||
| 114 | + self.has_ts(), self.ts() | ||
| 115 | + return state | ||
| 116 | + def __setstate__(self, state): | ||
| 117 | + self.__init__() | ||
| 118 | + self.name(state[0]) | ||
| 119 | + self.instruments(state[1]) | ||
| 120 | + self.ids(state[2]) | ||
| 121 | + self.tscalc(state[3]) | ||
| 122 | + if state[4]: | ||
| 123 | + self.ts(state[5]) | ||
| 124 | +} | ||
| 111 | }; | 125 | }; |
pyext/GModelData.i
| @@ -64,4 +64,11 @@ public: | @@ -64,4 +64,11 @@ public: | ||
| 64 | * @brief GModelData class extension | 64 | * @brief GModelData class extension |
| 65 | ***************************************************************************/ | 65 | ***************************************************************************/ |
| 66 | %extend GModelData { | 66 | %extend GModelData { |
| 67 | +%pythoncode { | ||
| 68 | + def __getstate__(self): | ||
| 69 | + state = gammalib.GModel.__getstate__(self) | ||
| 70 | + return state | ||
| 71 | + def __setstate__(self, state): | ||
| 72 | + gammalib.GModel.__setstate__(self, state) | ||
| 73 | +} | ||
| 67 | }; | 74 | }; |
pyext/GModelPar.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelPar.i - Model parameter class * | 2 | * GModelPar.i - Model parameter class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2015 by Juergen Knoedlseder * | 4 | + * copyright (C) 2009-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -59,4 +59,12 @@ public: | @@ -59,4 +59,12 @@ public: | ||
| 59 | GModelPar copy() { | 59 | GModelPar copy() { |
| 60 | return (*self); | 60 | return (*self); |
| 61 | } | 61 | } |
| 62 | +%pythoncode { | ||
| 63 | + def __getstate__(self): | ||
| 64 | + state = gammalib.GOptimizerPar.__getstate__(self) | ||
| 65 | + return state | ||
| 66 | + def __setstate__(self, state): | ||
| 67 | + self.__init__() | ||
| 68 | + gammalib.GOptimizerPar.__setstate__(self, state) | ||
| 69 | +} | ||
| 62 | }; | 70 | }; |
pyext/GModelSky.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSky.i - Sky model class * | 2 | * GModelSky.i - Sky model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -93,4 +93,19 @@ public: | @@ -93,4 +93,19 @@ public: | ||
| 93 | GModelSky copy() { | 93 | GModelSky copy() { |
| 94 | return (*self); | 94 | return (*self); |
| 95 | } | 95 | } |
| 96 | +%pythoncode { | ||
| 97 | + def __getstate__(self): | ||
| 98 | + state = (gammalib.GModel.__getstate__(self), | ||
| 99 | + self.type(), self.spatial(), self.spectral(), self.temporal()) | ||
| 100 | + return state | ||
| 101 | + def __setstate__(self, state): | ||
| 102 | + self.__init__(state[1]) | ||
| 103 | + gammalib.GModel.__setstate__(self, state[0]) | ||
| 104 | + if state[2] != None: | ||
| 105 | + self.spatial(state[2]) | ||
| 106 | + if state[3] != None: | ||
| 107 | + self.spectral(state[3]) | ||
| 108 | + if state[4] != None: | ||
| 109 | + self.temporal(state[4]) | ||
| 110 | +} | ||
| 96 | }; | 111 | }; |
pyext/GModelSpatialComposite.i
| @@ -62,6 +62,7 @@ public: | @@ -62,6 +62,7 @@ public: | ||
| 62 | virtual void write(GXmlElement& xml) const; | 62 | virtual void write(GXmlElement& xml) const; |
| 63 | 63 | ||
| 64 | // Other methods | 64 | // Other methods |
| 65 | + void type(const std::string& type); | ||
| 65 | int components(void) const; | 66 | int components(void) const; |
| 66 | void append(const GModelSpatial& component, | 67 | void append(const GModelSpatial& component, |
| 67 | const std::string& name = "", | 68 | const std::string& name = "", |
| @@ -80,4 +81,13 @@ public: | @@ -80,4 +81,13 @@ public: | ||
| 80 | GModelSpatialComposite copy() { | 81 | GModelSpatialComposite copy() { |
| 81 | return (*self); | 82 | return (*self); |
| 82 | } | 83 | } |
| 84 | +%pythoncode { | ||
| 85 | + def __getstate__(self): | ||
| 86 | + xml = gammalib.GXmlElement() | ||
| 87 | + self.write(xml) | ||
| 88 | + state = xml, | ||
| 89 | + return state | ||
| 90 | + def __setstate__(self, state): | ||
| 91 | + self.__init__(state[0]) | ||
| 92 | +} | ||
| 83 | }; | 93 | }; |
pyext/GModelSpatialPointSource.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpatialPointSource.i - Spatial point source model class * | 2 | * GModelSpatialPointSource.i - Spatial point source model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2009-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -64,6 +64,7 @@ public: | @@ -64,6 +64,7 @@ public: | ||
| 64 | virtual GSkyRegion* region(void) const; | 64 | virtual GSkyRegion* region(void) const; |
| 65 | 65 | ||
| 66 | // Other methods | 66 | // Other methods |
| 67 | + void type(const std::string& type); | ||
| 67 | double ra(void) const; | 68 | double ra(void) const; |
| 68 | double dec(void) const; | 69 | double dec(void) const; |
| 69 | void ra(const double& ra); | 70 | void ra(const double& ra); |
| @@ -80,4 +81,14 @@ public: | @@ -80,4 +81,14 @@ public: | ||
| 80 | GModelSpatialPointSource copy() { | 81 | GModelSpatialPointSource copy() { |
| 81 | return (*self); | 82 | return (*self); |
| 82 | } | 83 | } |
| 84 | +%pythoncode { | ||
| 85 | + def __getstate__(self): | ||
| 86 | + state = self.type(), self[0], self[1] | ||
| 87 | + return state | ||
| 88 | + def __setstate__(self, state): | ||
| 89 | + self.__init__() | ||
| 90 | + self.type(state[0]) | ||
| 91 | + self[0] = state[1] | ||
| 92 | + self[1] = state[2] | ||
| 93 | +} | ||
| 83 | }; | 94 | }; |
pyext/GModelSpectralBrokenPlaw.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralBrokenPlaw.i - Broken power law spectrum class * | 2 | * GModelSpectralBrokenPlaw.i - Broken power law spectrum class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2016 by Anneli Schulz * | 4 | + * copyright (C) 2013-2018 by Anneli Schulz * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -71,6 +71,7 @@ public: | @@ -71,6 +71,7 @@ public: | ||
| 71 | virtual void write(GXmlElement& xml) const; | 71 | virtual void write(GXmlElement& xml) const; |
| 72 | 72 | ||
| 73 | // Other methods | 73 | // Other methods |
| 74 | + void type(const std::string& type); | ||
| 74 | double prefactor(void) const; | 75 | double prefactor(void) const; |
| 75 | double index1(void) const; | 76 | double index1(void) const; |
| 76 | double index2(void) const; | 77 | double index2(void) const; |
| @@ -89,4 +90,16 @@ public: | @@ -89,4 +90,16 @@ public: | ||
| 89 | GModelSpectralBrokenPlaw copy() { | 90 | GModelSpectralBrokenPlaw copy() { |
| 90 | return (*self); | 91 | return (*self); |
| 91 | } | 92 | } |
| 93 | +%pythoncode { | ||
| 94 | + def __getstate__(self): | ||
| 95 | + state = (self.type(), self[0], self[1], self[2], self[3]) | ||
| 96 | + return state | ||
| 97 | + def __setstate__(self, state): | ||
| 98 | + self.__init__() | ||
| 99 | + self.type(state[0]) | ||
| 100 | + self[0] = state[1] | ||
| 101 | + self[1] = state[2] | ||
| 102 | + self[2] = state[3] | ||
| 103 | + self[3] = state[4] | ||
| 104 | +} | ||
| 92 | }; | 105 | }; |
pyext/GModelSpectralComposite.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralComposite.i - Spectral composite model class * | 2 | * GModelSpectralComposite.i - Spectral composite model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016 Michael Mayer * | 4 | + * copyright (C) 2016-2018 Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -77,4 +77,13 @@ public: | @@ -77,4 +77,13 @@ public: | ||
| 77 | GModelSpectralComposite copy() { | 77 | GModelSpectralComposite copy() { |
| 78 | return (*self); | 78 | return (*self); |
| 79 | } | 79 | } |
| 80 | +%pythoncode { | ||
| 81 | + def __getstate__(self): | ||
| 82 | + xml = gammalib.GXmlElement() | ||
| 83 | + self.write(xml) | ||
| 84 | + state = xml, | ||
| 85 | + return state | ||
| 86 | + def __setstate__(self, state): | ||
| 87 | + self.__init__(state[0]) | ||
| 88 | +} | ||
| 80 | }; | 89 | }; |
pyext/GModelSpectralConst.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralConst.i - Spectral constant model class * | 2 | * GModelSpectralConst.i - Spectral constant model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -62,6 +62,7 @@ public: | @@ -62,6 +62,7 @@ public: | ||
| 62 | virtual void write(GXmlElement& xml) const; | 62 | virtual void write(GXmlElement& xml) const; |
| 63 | 63 | ||
| 64 | // Other methods | 64 | // Other methods |
| 65 | + void type(const std::string& type); | ||
| 65 | double value(void) const; | 66 | double value(void) const; |
| 66 | void value(const double& value); | 67 | void value(const double& value); |
| 67 | }; | 68 | }; |
| @@ -74,4 +75,13 @@ public: | @@ -74,4 +75,13 @@ public: | ||
| 74 | GModelSpectralConst copy() { | 75 | GModelSpectralConst copy() { |
| 75 | return (*self); | 76 | return (*self); |
| 76 | } | 77 | } |
| 78 | +%pythoncode { | ||
| 79 | + def __getstate__(self): | ||
| 80 | + state = (self.type(), self[0]) | ||
| 81 | + return state | ||
| 82 | + def __setstate__(self, state): | ||
| 83 | + self.__init__() | ||
| 84 | + self.type(state[0]) | ||
| 85 | + self[0] = state[1] | ||
| 86 | +} | ||
| 77 | }; | 87 | }; |
pyext/GModelSpectralExpInvPlaw.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralExpInvPlaw.i - Exponential cut off power law model * | 2 | * GModelSpectralExpInvPlaw.i - Exponential cut off power law model * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016 by Alexander Ziegler * | 4 | + * copyright (C) 2016-2018 by Alexander Ziegler * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -76,6 +76,7 @@ public: | @@ -76,6 +76,7 @@ public: | ||
| 76 | virtual void write(GXmlElement& xml) const; | 76 | virtual void write(GXmlElement& xml) const; |
| 77 | 77 | ||
| 78 | // Other methods | 78 | // Other methods |
| 79 | + void type(const std::string& type); | ||
| 79 | double prefactor(void) const; | 80 | double prefactor(void) const; |
| 80 | void prefactor(const double& prefactor); | 81 | void prefactor(const double& prefactor); |
| 81 | double index(void) const; | 82 | double index(void) const; |
| @@ -96,4 +97,16 @@ public: | @@ -96,4 +97,16 @@ public: | ||
| 96 | GModelSpectralExpInvPlaw copy() { | 97 | GModelSpectralExpInvPlaw copy() { |
| 97 | return (*self); | 98 | return (*self); |
| 98 | } | 99 | } |
| 100 | +%pythoncode { | ||
| 101 | + def __getstate__(self): | ||
| 102 | + state = (self.type(), self[0], self[1], self[2], self[3]) | ||
| 103 | + return state | ||
| 104 | + def __setstate__(self, state): | ||
| 105 | + self.__init__() | ||
| 106 | + self.type(state[0]) | ||
| 107 | + self[0] = state[1] | ||
| 108 | + self[1] = state[2] | ||
| 109 | + self[2] = state[3] | ||
| 110 | + self[3] = state[4] | ||
| 111 | +} | ||
| 99 | }; | 112 | }; |
pyext/GModelSpectralExpPlaw.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralExpPlaw.i - Exponential cut off power law model * | 2 | * GModelSpectralExpPlaw.i - Exponential cut off power law model * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2009-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -71,6 +71,7 @@ public: | @@ -71,6 +71,7 @@ public: | ||
| 71 | virtual void write(GXmlElement& xml) const; | 71 | virtual void write(GXmlElement& xml) const; |
| 72 | 72 | ||
| 73 | // Other methods | 73 | // Other methods |
| 74 | + void type(const std::string& type); | ||
| 74 | double prefactor(void) const; | 75 | double prefactor(void) const; |
| 75 | void prefactor(const double& prefactor); | 76 | void prefactor(const double& prefactor); |
| 76 | double index(void) const; | 77 | double index(void) const; |
| @@ -89,4 +90,16 @@ public: | @@ -89,4 +90,16 @@ public: | ||
| 89 | GModelSpectralExpPlaw copy() { | 90 | GModelSpectralExpPlaw copy() { |
| 90 | return (*self); | 91 | return (*self); |
| 91 | } | 92 | } |
| 93 | +%pythoncode { | ||
| 94 | + def __getstate__(self): | ||
| 95 | + state = (self.type(), self[0], self[1], self[2], self[3]) | ||
| 96 | + return state | ||
| 97 | + def __setstate__(self, state): | ||
| 98 | + self.__init__() | ||
| 99 | + self.type(state[0]) | ||
| 100 | + self[0] = state[1] | ||
| 101 | + self[1] = state[2] | ||
| 102 | + self[2] = state[3] | ||
| 103 | + self[3] = state[4] | ||
| 104 | +} | ||
| 92 | }; | 105 | }; |
pyext/GModelSpectralFunc.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralFunc.i - Spectral function model class * | 2 | * GModelSpectralFunc.i - Spectral function model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -78,4 +78,13 @@ public: | @@ -78,4 +78,13 @@ public: | ||
| 78 | GModelSpectralFunc copy() { | 78 | GModelSpectralFunc copy() { |
| 79 | return (*self); | 79 | return (*self); |
| 80 | } | 80 | } |
| 81 | +%pythoncode { | ||
| 82 | + def __getstate__(self): | ||
| 83 | + xml = gammalib.GXmlElement() | ||
| 84 | + self.write(xml) | ||
| 85 | + state = xml, | ||
| 86 | + return state | ||
| 87 | + def __setstate__(self, state): | ||
| 88 | + self.__init__(state[0]) | ||
| 89 | +} | ||
| 81 | }; | 90 | }; |
pyext/GModelSpectralGauss.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralGauss.i - Spectral gaussian model class * | 2 | * GModelSpectralGauss.i - Spectral gaussian model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2014-2016 by Christoph Deil & Ellis Owen * | 4 | + * copyright (C) 2014-2018 by Christoph Deil & Ellis Owen * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -81,4 +81,14 @@ public: | @@ -81,4 +81,14 @@ public: | ||
| 81 | GModelSpectralGauss copy() { | 81 | GModelSpectralGauss copy() { |
| 82 | return (*self); | 82 | return (*self); |
| 83 | } | 83 | } |
| 84 | +%pythoncode { | ||
| 85 | + def __getstate__(self): | ||
| 86 | + state = (self[0], self[1], self[2]) | ||
| 87 | + return state | ||
| 88 | + def __setstate__(self, state): | ||
| 89 | + self.__init__() | ||
| 90 | + self[0] = state[0] | ||
| 91 | + self[1] = state[1] | ||
| 92 | + self[2] = state[2] | ||
| 93 | +} | ||
| 84 | }; | 94 | }; |
pyext/GModelSpectralLogParabola.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralLogParabola.i - Log parabola spectral model class * | 2 | * GModelSpectralLogParabola.i - Log parabola spectral model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2016 by Michael Mayer * | 4 | + * copyright (C) 2012-2018 by Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -71,6 +71,7 @@ public: | @@ -71,6 +71,7 @@ public: | ||
| 71 | virtual void write(GXmlElement& xml) const; | 71 | virtual void write(GXmlElement& xml) const; |
| 72 | 72 | ||
| 73 | // Other methods | 73 | // Other methods |
| 74 | + void type(const std::string& type); | ||
| 74 | double prefactor(void) const; | 75 | double prefactor(void) const; |
| 75 | void prefactor(const double& prefactor); | 76 | void prefactor(const double& prefactor); |
| 76 | double index(void) const; | 77 | double index(void) const; |
| @@ -89,4 +90,16 @@ public: | @@ -89,4 +90,16 @@ public: | ||
| 89 | GModelSpectralLogParabola copy() { | 90 | GModelSpectralLogParabola copy() { |
| 90 | return (*self); | 91 | return (*self); |
| 91 | } | 92 | } |
| 93 | +%pythoncode { | ||
| 94 | + def __getstate__(self): | ||
| 95 | + state = (self.type(), self[0], self[1], self[2], self[3]) | ||
| 96 | + return state | ||
| 97 | + def __setstate__(self, state): | ||
| 98 | + self.__init__() | ||
| 99 | + self.type(state[0]) | ||
| 100 | + self[0] = state[1] | ||
| 101 | + self[1] = state[2] | ||
| 102 | + self[2] = state[3] | ||
| 103 | + self[3] = state[4] | ||
| 104 | +} | ||
| 92 | }; | 105 | }; |
pyext/GModelSpectralMultiplicative.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralMultiplicative.i - Multiplicative spectral model class * | 2 | * GModelSpectralMultiplicative.i - Multiplicative spectral model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016 Michael Mayer * | 4 | + * copyright (C) 2016-2018 Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -76,4 +76,13 @@ public: | @@ -76,4 +76,13 @@ public: | ||
| 76 | GModelSpectralMultiplicative copy() { | 76 | GModelSpectralMultiplicative copy() { |
| 77 | return (*self); | 77 | return (*self); |
| 78 | } | 78 | } |
| 79 | +%pythoncode { | ||
| 80 | + def __getstate__(self): | ||
| 81 | + xml = gammalib.GXmlElement() | ||
| 82 | + self.write(xml) | ||
| 83 | + state = xml, | ||
| 84 | + return state | ||
| 85 | + def __setstate__(self, state): | ||
| 86 | + self.__init__(state[0]) | ||
| 87 | +} | ||
| 79 | }; | 88 | }; |
pyext/GModelSpectralNodes.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralNodes.i - Spectral nodes model class * | 2 | * GModelSpectralNodes.i - Spectral nodes model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2012-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -84,4 +84,16 @@ public: | @@ -84,4 +84,16 @@ public: | ||
| 84 | GModelSpectralNodes copy() { | 84 | GModelSpectralNodes copy() { |
| 85 | return (*self); | 85 | return (*self); |
| 86 | } | 86 | } |
| 87 | +%pythoncode { | ||
| 88 | + def __getstate__(self): | ||
| 89 | + xml = gammalib.GXmlElement() | ||
| 90 | + self.write(xml) | ||
| 91 | + state = xml, | ||
| 92 | + return state | ||
| 93 | + def __setstate__(self, state): | ||
| 94 | + if state[0].elements('node') == 0: | ||
| 95 | + self.__init__() | ||
| 96 | + else: | ||
| 97 | + self.__init__(state[0]) | ||
| 98 | +} | ||
| 87 | }; | 99 | }; |
pyext/GModelSpectralPlaw.i
| @@ -69,6 +69,7 @@ public: | @@ -69,6 +69,7 @@ public: | ||
| 69 | virtual void write(GXmlElement& xml) const; | 69 | virtual void write(GXmlElement& xml) const; |
| 70 | 70 | ||
| 71 | // Other methods | 71 | // Other methods |
| 72 | + void type(const std::string& type); | ||
| 72 | double prefactor(void) const; | 73 | double prefactor(void) const; |
| 73 | double index(void) const; | 74 | double index(void) const; |
| 74 | GEnergy pivot(void) const; | 75 | GEnergy pivot(void) const; |
| @@ -85,4 +86,15 @@ public: | @@ -85,4 +86,15 @@ public: | ||
| 85 | GModelSpectralPlaw copy() { | 86 | GModelSpectralPlaw copy() { |
| 86 | return (*self); | 87 | return (*self); |
| 87 | } | 88 | } |
| 89 | +%pythoncode { | ||
| 90 | + def __getstate__(self): | ||
| 91 | + state = (self.type(), self[0], self[1], self[2]) | ||
| 92 | + return state | ||
| 93 | + def __setstate__(self, state): | ||
| 94 | + self.__init__() | ||
| 95 | + self.type(state[0]) | ||
| 96 | + self[0] = state[1] | ||
| 97 | + self[1] = state[2] | ||
| 98 | + self[2] = state[3] | ||
| 99 | +} | ||
| 88 | }; | 100 | }; |
pyext/GModelSpectralPlawEnergyFlux.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralPlawEnergyFlux.i - Spectral power law model class * | 2 | * GModelSpectralPlawEnergyFlux.i - Spectral power law model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016 by Michael Mayer * | 4 | + * copyright (C) 2016-2018 by Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -71,6 +71,7 @@ public: | @@ -71,6 +71,7 @@ public: | ||
| 71 | virtual void write(GXmlElement& xml) const; | 71 | virtual void write(GXmlElement& xml) const; |
| 72 | 72 | ||
| 73 | // Other methods | 73 | // Other methods |
| 74 | + void type(const std::string& type); | ||
| 74 | double eflux(void) const; | 75 | double eflux(void) const; |
| 75 | void eflux(const double& eflux); | 76 | void eflux(const double& eflux); |
| 76 | double index(void) const; | 77 | double index(void) const; |
| @@ -89,4 +90,16 @@ public: | @@ -89,4 +90,16 @@ public: | ||
| 89 | GModelSpectralPlawEnergyFlux copy() { | 90 | GModelSpectralPlawEnergyFlux copy() { |
| 90 | return (*self); | 91 | return (*self); |
| 91 | } | 92 | } |
| 93 | +%pythoncode { | ||
| 94 | + def __getstate__(self): | ||
| 95 | + state = (self.type(), self[0], self[1], self[2], self[3]) | ||
| 96 | + return state | ||
| 97 | + def __setstate__(self, state): | ||
| 98 | + self.__init__() | ||
| 99 | + self.type(state[0]) | ||
| 100 | + self[0] = state[1] | ||
| 101 | + self[1] = state[2] | ||
| 102 | + self[2] = state[3] | ||
| 103 | + self[3] = state[4] | ||
| 104 | +} | ||
| 92 | }; | 105 | }; |
pyext/GModelSpectralPlawPhotonFlux.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralPlawPhotonFlux.i - Spectral power law model class * | 2 | * GModelSpectralPlawPhotonFlux.i - Spectral power law model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -71,6 +71,7 @@ public: | @@ -71,6 +71,7 @@ public: | ||
| 71 | virtual void write(GXmlElement& xml) const; | 71 | virtual void write(GXmlElement& xml) const; |
| 72 | 72 | ||
| 73 | // Other methods | 73 | // Other methods |
| 74 | + void type(const std::string& type); | ||
| 74 | double flux(void) const; | 75 | double flux(void) const; |
| 75 | void flux(const double& flux); | 76 | void flux(const double& flux); |
| 76 | double index(void) const; | 77 | double index(void) const; |
| @@ -89,4 +90,16 @@ public: | @@ -89,4 +90,16 @@ public: | ||
| 89 | GModelSpectralPlawPhotonFlux copy() { | 90 | GModelSpectralPlawPhotonFlux copy() { |
| 90 | return (*self); | 91 | return (*self); |
| 91 | } | 92 | } |
| 93 | +%pythoncode { | ||
| 94 | + def __getstate__(self): | ||
| 95 | + state = (self.type(), self[0], self[1], self[2], self[3]) | ||
| 96 | + return state | ||
| 97 | + def __setstate__(self, state): | ||
| 98 | + self.__init__() | ||
| 99 | + self.type(state[0]) | ||
| 100 | + self[0] = state[1] | ||
| 101 | + self[1] = state[2] | ||
| 102 | + self[2] = state[3] | ||
| 103 | + self[3] = state[4] | ||
| 104 | +} | ||
| 92 | }; | 105 | }; |
pyext/GModelSpectralSmoothBrokenPlaw.i
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | * GModelSpectralSmoothBrokenPlaw.i * | 2 | * GModelSpectralSmoothBrokenPlaw.i * |
| 3 | * Smoothly broken power law spectrum class * | 3 | * Smoothly broken power law spectrum class * |
| 4 | * ----------------------------------------------------------------------- * | 4 | * ----------------------------------------------------------------------- * |
| 5 | - * copyright (C) 2017 by Josh Cardenzana * | 5 | + * copyright (C) 2017-2018 by Josh Cardenzana * |
| 6 | * ----------------------------------------------------------------------- * | 6 | * ----------------------------------------------------------------------- * |
| 7 | * * | 7 | * * |
| 8 | * This program is free software: you can redistribute it and/or modify * | 8 | * This program is free software: you can redistribute it and/or modify * |
| @@ -76,6 +76,7 @@ public: | @@ -76,6 +76,7 @@ public: | ||
| 76 | virtual void write(GXmlElement& xml) const; | 76 | virtual void write(GXmlElement& xml) const; |
| 77 | 77 | ||
| 78 | // Other methods | 78 | // Other methods |
| 79 | + void type(const std::string& type); | ||
| 79 | double prefactor(void) const; | 80 | double prefactor(void) const; |
| 80 | double index1(void) const; | 81 | double index1(void) const; |
| 81 | double index2(void) const; | 82 | double index2(void) const; |
| @@ -98,4 +99,18 @@ public: | @@ -98,4 +99,18 @@ public: | ||
| 98 | GModelSpectralSmoothBrokenPlaw copy() { | 99 | GModelSpectralSmoothBrokenPlaw copy() { |
| 99 | return (*self); | 100 | return (*self); |
| 100 | } | 101 | } |
| 102 | +%pythoncode { | ||
| 103 | + def __getstate__(self): | ||
| 104 | + state = (self.type(), self[0], self[1], self[2], self[3], self[4], self[5]) | ||
| 105 | + return state | ||
| 106 | + def __setstate__(self, state): | ||
| 107 | + self.__init__() | ||
| 108 | + self.type(state[0]) | ||
| 109 | + self[0] = state[1] | ||
| 110 | + self[1] = state[2] | ||
| 111 | + self[2] = state[3] | ||
| 112 | + self[3] = state[4] | ||
| 113 | + self[4] = state[5] | ||
| 114 | + self[5] = state[6] | ||
| 115 | +} | ||
| 101 | }; | 116 | }; |
pyext/GModelSpectralSuperExpPlaw.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelSpectralSuperExpPlaw.i - Super exp. cut off power law model * | 2 | * GModelSpectralSuperExpPlaw.i - Super exp. cut off power law model * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2014-2016 by Michael Mayer * | 4 | + * copyright (C) 2014-2018 by Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -73,6 +73,7 @@ public: | @@ -73,6 +73,7 @@ public: | ||
| 73 | virtual void write(GXmlElement& xml) const; | 73 | virtual void write(GXmlElement& xml) const; |
| 74 | 74 | ||
| 75 | // Other methods | 75 | // Other methods |
| 76 | + void type(const std::string& type); | ||
| 76 | double prefactor(void) const; | 77 | double prefactor(void) const; |
| 77 | void prefactor(const double& prefactor); | 78 | void prefactor(const double& prefactor); |
| 78 | double index1(void) const; | 79 | double index1(void) const; |
| @@ -93,4 +94,17 @@ public: | @@ -93,4 +94,17 @@ public: | ||
| 93 | GModelSpectralSuperExpPlaw copy() { | 94 | GModelSpectralSuperExpPlaw copy() { |
| 94 | return (*self); | 95 | return (*self); |
| 95 | } | 96 | } |
| 97 | +%pythoncode { | ||
| 98 | + def __getstate__(self): | ||
| 99 | + state = (self.type(), self[0], self[1], self[2], self[3], self[4]) | ||
| 100 | + return state | ||
| 101 | + def __setstate__(self, state): | ||
| 102 | + self.__init__() | ||
| 103 | + self.type(state[0]) | ||
| 104 | + self[0] = state[1] | ||
| 105 | + self[1] = state[2] | ||
| 106 | + self[2] = state[3] | ||
| 107 | + self[3] = state[4] | ||
| 108 | + self[4] = state[5] | ||
| 109 | +} | ||
| 96 | }; | 110 | }; |
pyext/GModelTemporalConst.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelTemporalConst.i - Temporal constant model class * | 2 | * GModelTemporalConst.i - Temporal constant model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2009-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -70,4 +70,12 @@ public: | @@ -70,4 +70,12 @@ public: | ||
| 70 | GModelTemporalConst copy() { | 70 | GModelTemporalConst copy() { |
| 71 | return (*self); | 71 | return (*self); |
| 72 | } | 72 | } |
| 73 | +%pythoncode { | ||
| 74 | + def __getstate__(self): | ||
| 75 | + state = self[0], | ||
| 76 | + return state | ||
| 77 | + def __setstate__(self, state): | ||
| 78 | + self.__init__() | ||
| 79 | + self[0] = state[0] | ||
| 80 | +} | ||
| 73 | }; | 81 | }; |
pyext/GModelTemporalLightCurve.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelTemporalLightCurve.i - Temporal light curve model class * | 2 | * GModelTemporalLightCurve.i - Temporal light curve model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2017-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -72,4 +72,13 @@ public: | @@ -72,4 +72,13 @@ public: | ||
| 72 | GModelTemporalLightCurve copy() { | 72 | GModelTemporalLightCurve copy() { |
| 73 | return (*self); | 73 | return (*self); |
| 74 | } | 74 | } |
| 75 | +%pythoncode { | ||
| 76 | + def __getstate__(self): | ||
| 77 | + xml = gammalib.GXmlElement() | ||
| 78 | + self.write(xml) | ||
| 79 | + state = xml, | ||
| 80 | + return state | ||
| 81 | + def __setstate__(self, state): | ||
| 82 | + self.__init__(state[0]) | ||
| 83 | +} | ||
| 75 | }; | 84 | }; |
pyext/GModelTemporalPhaseCurve.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelTemporalPhaseCurve.i - Temporal phase curve model class * | 2 | * GModelTemporalPhaseCurve.i - Temporal phase curve model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2017-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -91,4 +91,13 @@ public: | @@ -91,4 +91,13 @@ public: | ||
| 91 | GModelTemporalPhaseCurve copy() { | 91 | GModelTemporalPhaseCurve copy() { |
| 92 | return (*self); | 92 | return (*self); |
| 93 | } | 93 | } |
| 94 | +%pythoncode { | ||
| 95 | + def __getstate__(self): | ||
| 96 | + xml = gammalib.GXmlElement() | ||
| 97 | + self.write(xml) | ||
| 98 | + state = xml, | ||
| 99 | + return state | ||
| 100 | + def __setstate__(self, state): | ||
| 101 | + self.__init__(state[0]) | ||
| 102 | +} | ||
| 94 | }; | 103 | }; |
pyext/GModels.i
| @@ -144,4 +144,15 @@ public: | @@ -144,4 +144,15 @@ public: | ||
| 144 | GModels copy() { | 144 | GModels copy() { |
| 145 | return (*self); | 145 | return (*self); |
| 146 | } | 146 | } |
| 147 | +%pythoncode { | ||
| 148 | + def __getstate__(self): | ||
| 149 | + state = tuple([x for x in self]), | ||
| 150 | + return state | ||
| 151 | + def __setstate__(self, state): | ||
| 152 | + self.__init__() | ||
| 153 | + size = len(state[0]) | ||
| 154 | + self.reserve(size) | ||
| 155 | + for x in state[0]: | ||
| 156 | + self.append(x) | ||
| 157 | +} | ||
| 147 | }; | 158 | }; |
pyext/GObservation.i
| @@ -92,6 +92,7 @@ public: | @@ -92,6 +92,7 @@ public: | ||
| 92 | const GModelPar& par) const; | 92 | const GModelPar& par) const; |
| 93 | 93 | ||
| 94 | // Implemented methods | 94 | // Implemented methods |
| 95 | + bool has_events(void) const; | ||
| 95 | void name(const std::string& name); | 96 | void name(const std::string& name); |
| 96 | void id(const std::string& id); | 97 | void id(const std::string& id); |
| 97 | void statistic(const std::string& statistic); | 98 | void statistic(const std::string& statistic); |
| @@ -107,13 +108,18 @@ public: | @@ -107,13 +108,18 @@ public: | ||
| 107 | %extend GObservation { | 108 | %extend GObservation { |
| 108 | %pythoncode { | 109 | %pythoncode { |
| 109 | def __getstate__(self): | 110 | def __getstate__(self): |
| 110 | - args = (self.name(), self.id(), self.statistic(), self.events()) | 111 | + if self.has_events(): |
| 112 | + events = self.events() | ||
| 113 | + else: | ||
| 114 | + events = None | ||
| 115 | + args = (self.name(), self.id(), self.statistic(), events) | ||
| 111 | return args | 116 | return args |
| 112 | def __setstate__(self, state): | 117 | def __setstate__(self, state): |
| 113 | self.__init__() | 118 | self.__init__() |
| 114 | self.name(state[0]) | 119 | self.name(state[0]) |
| 115 | self.id(state[1]) | 120 | self.id(state[1]) |
| 116 | self.statistic(state[2]) | 121 | self.statistic(state[2]) |
| 117 | - self.events(state[3]) | 122 | + if state[3] != None: |
| 123 | + self.events(state[3]) | ||
| 118 | } | 124 | } |
| 119 | }; | 125 | }; |
pyext/GObservations.i
| @@ -170,8 +170,8 @@ typedef GObservations::likelihood likelihood; | @@ -170,8 +170,8 @@ typedef GObservations::likelihood likelihood; | ||
| 170 | } | 170 | } |
| 171 | %pythoncode { | 171 | %pythoncode { |
| 172 | def __getstate__(self): | 172 | def __getstate__(self): |
| 173 | - args = self.models(), tuple([x for x in self]) | ||
| 174 | - return args | 173 | + state = self.models(), tuple([x for x in self]) |
| 174 | + return state | ||
| 175 | def __setstate__(self, state): | 175 | def __setstate__(self, state): |
| 176 | self.__init__() | 176 | self.__init__() |
| 177 | self.models(state[0]) | 177 | self.models(state[0]) |
pyext/GOptimizerPar.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GOptimizerPar.i - Optimizer parameter class * | 2 | * GOptimizerPar.i - Optimizer parameter class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2015 by Juergen Knoedlseder * | 4 | + * copyright (C) 2013-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -107,4 +107,30 @@ public: | @@ -107,4 +107,30 @@ public: | ||
| 107 | GOptimizerPar copy() { | 107 | GOptimizerPar copy() { |
| 108 | return (*self); | 108 | return (*self); |
| 109 | } | 109 | } |
| 110 | +%pythoncode { | ||
| 111 | + def __getstate__(self): | ||
| 112 | + state = self.name(), self.unit(), \ | ||
| 113 | + self.factor_value(), self.factor_error(), self.factor_min(), \ | ||
| 114 | + self.factor_max(), self.factor_gradient(), self.scale(), \ | ||
| 115 | + self.is_free(), self.has_min(), self.has_max(), self.has_grad() | ||
| 116 | + return state | ||
| 117 | + def __setstate__(self, state): | ||
| 118 | + self.__init__() | ||
| 119 | + self.name(state[0]) | ||
| 120 | + self.unit(state[1]) | ||
| 121 | + self.scale(state[7]) | ||
| 122 | + self.factor_value(state[2]) | ||
| 123 | + self.factor_error(state[3]) | ||
| 124 | + if state[8]: | ||
| 125 | + self.free() | ||
| 126 | + else: | ||
| 127 | + self.fix() | ||
| 128 | + if state[9]: | ||
| 129 | + self.factor_min(state[4]) | ||
| 130 | + if state[10]: | ||
| 131 | + self.factor_max(state[5]) | ||
| 132 | + if state[11]: | ||
| 133 | + self.factor_gradient(state[6]) | ||
| 134 | + self.has_grad(state[11]) | ||
| 135 | +} | ||
| 110 | }; | 136 | }; |
pyext/GPhases.i
| @@ -97,9 +97,9 @@ public: | @@ -97,9 +97,9 @@ public: | ||
| 97 | } | 97 | } |
| 98 | %pythoncode { | 98 | %pythoncode { |
| 99 | def __getstate__(self): | 99 | def __getstate__(self): |
| 100 | - args = tuple([self.pmin(i) for i in range(self.size())]), \ | ||
| 101 | - tuple([self.pmax(i) for i in range(self.size())]) | ||
| 102 | - return args | 100 | + state = tuple([self.pmin(i) for i in range(self.size())]), \ |
| 101 | + tuple([self.pmax(i) for i in range(self.size())]) | ||
| 102 | + return state | ||
| 103 | def __setstate__(self, state): | 103 | def __setstate__(self, state): |
| 104 | self.__init__() | 104 | self.__init__() |
| 105 | size = len(state[0]) | 105 | size = len(state[0]) |
pyext/GPhoton.i
| @@ -80,10 +80,6 @@ public: | @@ -80,10 +80,6 @@ public: | ||
| 80 | args = self.dir(), self.energy(), self.time(), self.mc_id() | 80 | args = self.dir(), self.energy(), self.time(), self.mc_id() |
| 81 | return args | 81 | return args |
| 82 | def __setstate__(self, state): | 82 | def __setstate__(self, state): |
| 83 | - self.__init__() | ||
| 84 | - self.dir(state[0]) | ||
| 85 | - self.energy(state[1]) | ||
| 86 | - self.time(state[2]) | ||
| 87 | - self.mc_id(state[3]) | 83 | + self.__init__(state[0], state[1], state[2], state[3]) |
| 88 | } | 84 | } |
| 89 | }; | 85 | }; |
pyext/GPhotons.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GPhotons.i - Photon container class * | 2 | * GPhotons.i - Photon container class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2015 by Juergen Knoedlseder * | 4 | + * copyright (C) 2012-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -117,4 +117,14 @@ public: | @@ -117,4 +117,14 @@ public: | ||
| 117 | GPhotons copy() { | 117 | GPhotons copy() { |
| 118 | return (*self); | 118 | return (*self); |
| 119 | } | 119 | } |
| 120 | +%pythoncode { | ||
| 121 | + def __getstate__(self): | ||
| 122 | + state = tuple([x for x in self]), | ||
| 123 | + return state | ||
| 124 | + def __setstate__(self, state): | ||
| 125 | + self.__init__() | ||
| 126 | + self.reserve(len(state[0])) | ||
| 127 | + for x in state[0]: | ||
| 128 | + self.append(x) | ||
| 129 | +} | ||
| 120 | }; | 130 | }; |
pyext/GSkyDir.i
| @@ -84,8 +84,8 @@ public: | @@ -84,8 +84,8 @@ public: | ||
| 84 | } | 84 | } |
| 85 | %pythoncode { | 85 | %pythoncode { |
| 86 | def __getstate__(self): | 86 | def __getstate__(self): |
| 87 | - args = self.ra(), self.dec() | ||
| 88 | - return args | 87 | + state = self.ra(), self.dec() |
| 88 | + return state | ||
| 89 | def __setstate__(self, state): | 89 | def __setstate__(self, state): |
| 90 | self.__init__() | 90 | self.__init__() |
| 91 | self.radec(state[0], state[1]) | 91 | self.radec(state[0], state[1]) |
pyext/GSource.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GSource.i - Source class * | 2 | * GSource.i - Source class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2015 by Juergen Knoedlseder * | 4 | + * copyright (C) 2012-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -65,4 +65,17 @@ public: | @@ -65,4 +65,17 @@ public: | ||
| 65 | GSource copy() { | 65 | GSource copy() { |
| 66 | return (*self); | 66 | return (*self); |
| 67 | } | 67 | } |
| 68 | +%pythoncode { | ||
| 69 | + def __getstate__(self): | ||
| 70 | + state = (self.name(), self.model(), self.energy(), self.time()) | ||
| 71 | + return state | ||
| 72 | + def __setstate__(self, state): | ||
| 73 | + self.__init__() | ||
| 74 | + self.name(state[0]) | ||
| 75 | + if state[1] != None: | ||
| 76 | + self.__model = state[1].copy() ## Store a copy | ||
| 77 | + self.model(self.__model) | ||
| 78 | + self.energy(state[2]) | ||
| 79 | + self.time(state[3]) | ||
| 80 | +} | ||
| 68 | }; | 81 | }; |
pyext/GTime.i
| @@ -124,10 +124,10 @@ public: | @@ -124,10 +124,10 @@ public: | ||
| 124 | } | 124 | } |
| 125 | %pythoncode { | 125 | %pythoncode { |
| 126 | def __getstate__(self): | 126 | def __getstate__(self): |
| 127 | - args = self.secs() | ||
| 128 | - return args | 127 | + state = self.secs(), |
| 128 | + return state | ||
| 129 | def __setstate__(self, state): | 129 | def __setstate__(self, state): |
| 130 | self.__init__() | 130 | self.__init__() |
| 131 | - self.secs(state) | 131 | + self.secs(state[0]) |
| 132 | } | 132 | } |
| 133 | }; | 133 | }; |
pyext/GTimeReference.i
| @@ -87,8 +87,8 @@ public: | @@ -87,8 +87,8 @@ public: | ||
| 87 | } | 87 | } |
| 88 | %pythoncode { | 88 | %pythoncode { |
| 89 | def __getstate__(self): | 89 | def __getstate__(self): |
| 90 | - args = (self.mjdref(), self.timeunit(), self.timesys(), self.timeref()) | ||
| 91 | - return args | 90 | + state = (self.mjdref(), self.timeunit(), self.timesys(), self.timeref()) |
| 91 | + return state | ||
| 92 | def __setstate__(self, state): | 92 | def __setstate__(self, state): |
| 93 | self.__init__(state[0], state[1], state[2], state[3]) | 93 | self.__init__(state[0], state[1], state[2], state[3]) |
| 94 | } | 94 | } |
pyext/GTimes.i
| @@ -121,12 +121,12 @@ public: | @@ -121,12 +121,12 @@ public: | ||
| 121 | } | 121 | } |
| 122 | %pythoncode { | 122 | %pythoncode { |
| 123 | def __getstate__(self): | 123 | def __getstate__(self): |
| 124 | - args = tuple([x for x in self]) | ||
| 125 | - return args | 124 | + state = tuple([x for x in self]), |
| 125 | + return state | ||
| 126 | def __setstate__(self, state): | 126 | def __setstate__(self, state): |
| 127 | self.__init__() | 127 | self.__init__() |
| 128 | - self.reserve(len(state)) | ||
| 129 | - for x in state: | 128 | + self.reserve(len(state[0])) |
| 129 | + for x in state[0]: | ||
| 130 | self.append(x) | 130 | self.append(x) |
| 131 | } | 131 | } |
| 132 | }; | 132 | }; |
pyext/GXml.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXml.i - XML class * | 2 | * GXml.i - XML class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -42,30 +42,33 @@ public: | @@ -42,30 +42,33 @@ public: | ||
| 42 | GXml(void); | 42 | GXml(void); |
| 43 | GXml(const GXml& xml); | 43 | GXml(const GXml& xml); |
| 44 | explicit GXml(const std::string& filename); | 44 | explicit GXml(const std::string& filename); |
| 45 | + explicit GXml(const GXmlDocument& root); | ||
| 45 | virtual ~GXml(void); | 46 | virtual ~GXml(void); |
| 46 | 47 | ||
| 47 | // Methods | 48 | // Methods |
| 48 | - void clear(void); | ||
| 49 | - GXml* clone(void) const; | ||
| 50 | - std::string classname(void) const; | ||
| 51 | - int size(void) const; | ||
| 52 | - bool is_empty(void) const; | ||
| 53 | - GXmlNode* set(const int& index, const GXmlNode& node); | ||
| 54 | - GXmlNode* append(const GXmlNode& node); | ||
| 55 | - GXmlElement* append(const std::string& segment); | ||
| 56 | - GXmlNode* insert(const int& index, const GXmlNode& node); | ||
| 57 | - void remove(const int& index); | ||
| 58 | - void reserve(const int& num); | ||
| 59 | - void extend(const GXmlNode& node); | ||
| 60 | - int elements(void) const; | ||
| 61 | - int elements(const std::string& name) const; | ||
| 62 | - GXmlElement* element(const int& index); | ||
| 63 | - GXmlElement* element(const std::string& name); | ||
| 64 | - GXmlElement* element(const std::string& name, const int& index); | ||
| 65 | - void load(const GFilename& filename); | ||
| 66 | - void save(const GFilename& filename) const; | ||
| 67 | - void read(const GUrl& url); | ||
| 68 | - void write(GUrl& url, const int& indent = 0) const; | 49 | + void clear(void); |
| 50 | + GXml* clone(void) const; | ||
| 51 | + std::string classname(void) const; | ||
| 52 | + int size(void) const; | ||
| 53 | + bool is_empty(void) const; | ||
| 54 | + GXmlNode* set(const int& index, const GXmlNode& node); | ||
| 55 | + GXmlNode* append(const GXmlNode& node); | ||
| 56 | + GXmlElement* append(const std::string& segment); | ||
| 57 | + GXmlNode* insert(const int& index, const GXmlNode& node); | ||
| 58 | + void remove(const int& index); | ||
| 59 | + void reserve(const int& num); | ||
| 60 | + void extend(const GXmlNode& node); | ||
| 61 | + int elements(void) const; | ||
| 62 | + int elements(const std::string& name) const; | ||
| 63 | + GXmlElement* element(const int& index); | ||
| 64 | + GXmlElement* element(const std::string& name); | ||
| 65 | + GXmlElement* element(const std::string& name, const int& index); | ||
| 66 | + const GXmlDocument& root(void) const; | ||
| 67 | + void root(const GXmlDocument& root); | ||
| 68 | + void load(const GFilename& filename); | ||
| 69 | + void save(const GFilename& filename) const; | ||
| 70 | + void read(const GUrl& url); | ||
| 71 | + void write(GUrl& url, const int& indent = 0) const; | ||
| 69 | }; | 72 | }; |
| 70 | 73 | ||
| 71 | 74 | ||
| @@ -131,4 +134,11 @@ public: | @@ -131,4 +134,11 @@ public: | ||
| 131 | GXml copy() { | 134 | GXml copy() { |
| 132 | return (*self); | 135 | return (*self); |
| 133 | } | 136 | } |
| 137 | +%pythoncode { | ||
| 138 | + def __getstate__(self): | ||
| 139 | + state = (self.root(),) | ||
| 140 | + return state | ||
| 141 | + def __setstate__(self, state): | ||
| 142 | + self.__init__(state[0]) | ||
| 143 | +} | ||
| 134 | }; | 144 | }; |
pyext/GXmlAttribute.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlAttribute.i - XML attribute class * | 2 | * GXmlAttribute.i - XML attribute class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2015 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -61,4 +61,11 @@ public: | @@ -61,4 +61,11 @@ public: | ||
| 61 | GXmlAttribute copy() { | 61 | GXmlAttribute copy() { |
| 62 | return (*self); | 62 | return (*self); |
| 63 | } | 63 | } |
| 64 | +%pythoncode { | ||
| 65 | + def __getstate__(self): | ||
| 66 | + state = (self.name(), self.value()) | ||
| 67 | + return state | ||
| 68 | + def __setstate__(self, state): | ||
| 69 | + self.__init__(state[0], state[1]) | ||
| 70 | +} | ||
| 64 | }; | 71 | }; |
pyext/GXmlComment.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlComment.i - XML comment node class * | 2 | * GXmlComment.i - XML comment node class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2015 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -62,4 +62,12 @@ public: | @@ -62,4 +62,12 @@ public: | ||
| 62 | GXmlComment copy() { | 62 | GXmlComment copy() { |
| 63 | return (*self); | 63 | return (*self); |
| 64 | } | 64 | } |
| 65 | +%pythoncode { | ||
| 66 | + def __getstate__(self): | ||
| 67 | + state = (self.comment(),) | ||
| 68 | + return state | ||
| 69 | + def __setstate__(self, state): | ||
| 70 | + self.__init__() | ||
| 71 | + self.comment(state[0]) | ||
| 72 | +} | ||
| 65 | }; | 73 | }; |
pyext/GXmlDocument.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlDocument.i - XML document node class * | 2 | * GXmlDocument.i - XML document node class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -38,6 +38,10 @@ class GXmlDocument : public GXmlNode { | @@ -38,6 +38,10 @@ class GXmlDocument : public GXmlNode { | ||
| 38 | public: | 38 | public: |
| 39 | // Constructors and destructors | 39 | // Constructors and destructors |
| 40 | GXmlDocument(void); | 40 | GXmlDocument(void); |
| 41 | + GXmlDocument(const GFilename& filename, | ||
| 42 | + const std::string& version, | ||
| 43 | + const std::string& encoding, | ||
| 44 | + const std::string& standalone); | ||
| 41 | GXmlDocument(const GXmlDocument& node); | 45 | GXmlDocument(const GXmlDocument& node); |
| 42 | virtual ~GXmlDocument(void); | 46 | virtual ~GXmlDocument(void); |
| 43 | 47 | ||
| @@ -67,4 +71,15 @@ public: | @@ -67,4 +71,15 @@ public: | ||
| 67 | GXmlDocument copy() { | 71 | GXmlDocument copy() { |
| 68 | return (*self); | 72 | return (*self); |
| 69 | } | 73 | } |
| 74 | +%pythoncode { | ||
| 75 | + def __getstate__(self): | ||
| 76 | + state = (self.filename(), self.version(), self.encoding(), self.standalone()) | ||
| 77 | + return state | ||
| 78 | + def __setstate__(self, state): | ||
| 79 | + self.__init__() | ||
| 80 | + self.filename(state[0]) | ||
| 81 | + self.version(state[1]) | ||
| 82 | + self.encoding(state[2]) | ||
| 83 | + self.standalone(state[3]) | ||
| 84 | +} | ||
| 70 | }; | 85 | }; |
pyext/GXmlElement.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlElement.i - XML element node class definition * | 2 | * GXmlElement.i - XML element node class definition * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -48,6 +48,8 @@ public: | @@ -48,6 +48,8 @@ public: | ||
| 48 | virtual std::string classname(void) const; | 48 | virtual std::string classname(void) const; |
| 49 | const std::string& name(void) const; | 49 | const std::string& name(void) const; |
| 50 | void name(const std::string& name); | 50 | void name(const std::string& name); |
| 51 | + int attributes(void) const; | ||
| 52 | + const GXmlAttribute* attribute(const int& index) const; | ||
| 51 | std::string attribute(const std::string& name) const; | 53 | std::string attribute(const std::string& name) const; |
| 52 | void attribute(const std::string& name, const std::string& value); | 54 | void attribute(const std::string& name, const std::string& value); |
| 53 | bool has_attribute(const std::string& name) const; | 55 | bool has_attribute(const std::string& name) const; |
| @@ -119,4 +121,18 @@ public: | @@ -119,4 +121,18 @@ public: | ||
| 119 | GXmlElement copy() { | 121 | GXmlElement copy() { |
| 120 | return (*self); | 122 | return (*self); |
| 121 | } | 123 | } |
| 124 | +%pythoncode { | ||
| 125 | + def __getstate__(self): | ||
| 126 | + state = (gammalib.GXmlNode.__getstate__(self), self.name(), | ||
| 127 | + tuple([self.attribute(i) for i in range(self.attributes())])) | ||
| 128 | + return state | ||
| 129 | + def __setstate__(self, state): | ||
| 130 | + gammalib.GXmlNode.__setstate__(self, state[0]) | ||
| 131 | + self.__init__() | ||
| 132 | + self.name(state[1]) | ||
| 133 | + for i in range(len(state[2])): | ||
| 134 | + name = state[2][i].name() | ||
| 135 | + value = state[2][i].value() | ||
| 136 | + self.attribute(name, value) | ||
| 137 | +} | ||
| 122 | }; | 138 | }; |
pyext/GXmlNode.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlNode.i - Abstract XML node base class * | 2 | * GXmlNode.i - Abstract XML node base class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -114,4 +114,16 @@ public: | @@ -114,4 +114,16 @@ public: | ||
| 114 | throw GException::out_of_range("__setitem__(int)", index, self->size()); | 114 | throw GException::out_of_range("__setitem__(int)", index, self->size()); |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | +%pythoncode { | ||
| 118 | + def __getstate__(self): | ||
| 119 | + state = (self.parent(), tuple([x for x in self])) | ||
| 120 | + return state | ||
| 121 | + def __setstate__(self, state): | ||
| 122 | + self.__init__() | ||
| 123 | + self.reserve(len(state[1])) | ||
| 124 | + if state[0] != None: | ||
| 125 | + self.parent(state[0]) | ||
| 126 | + for x in state[1]: | ||
| 127 | + self.append(x) | ||
| 128 | +} | ||
| 117 | }; | 129 | }; |
pyext/GXmlPI.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlPI.i - XML PI node class definition * | 2 | * GXmlPI.i - XML PI node class definition * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2015 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -62,4 +62,12 @@ public: | @@ -62,4 +62,12 @@ public: | ||
| 62 | GXmlPI copy() { | 62 | GXmlPI copy() { |
| 63 | return (*self); | 63 | return (*self); |
| 64 | } | 64 | } |
| 65 | +%pythoncode { | ||
| 66 | + def __getstate__(self): | ||
| 67 | + state = (self.pi(),) | ||
| 68 | + return state | ||
| 69 | + def __setstate__(self, state): | ||
| 70 | + self.__init__() | ||
| 71 | + self.pi(state[0]) | ||
| 72 | +} | ||
| 65 | }; | 73 | }; |
pyext/GXmlText.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlText.i - XML text node class * | 2 | * GXmlText.i - XML text node class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2015 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -62,4 +62,11 @@ public: | @@ -62,4 +62,11 @@ public: | ||
| 62 | GXmlText copy() { | 62 | GXmlText copy() { |
| 63 | return (*self); | 63 | return (*self); |
| 64 | } | 64 | } |
| 65 | +%pythoncode { | ||
| 66 | + def __getstate__(self): | ||
| 67 | + state = (self.text(),) | ||
| 68 | + return state | ||
| 69 | + def __setstate__(self, state): | ||
| 70 | + self.__init__(state[0]) | ||
| 71 | +} | ||
| 65 | }; | 72 | }; |
pyext/gammalib/model.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * model.i - Model module * | 2 | * model.i - Model module * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -76,52 +76,70 @@ | @@ -76,52 +76,70 @@ | ||
| 76 | $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | 76 | $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); |
| 77 | } | 77 | } |
| 78 | %typemap(out) GModelSpatial* { | 78 | %typemap(out) GModelSpatial* { |
| 79 | - char classname[80]; | ||
| 80 | - strcpy(classname, "_p_"); | ||
| 81 | - strcat(classname, result->classname().c_str()); | ||
| 82 | - swig_type_info *myinfo = SWIGTYPE_p_GModelSpatial; | ||
| 83 | - swig_cast_info *mycast = 0; | ||
| 84 | - mycast = myinfo->cast; | ||
| 85 | - while (mycast != 0) { | ||
| 86 | - if (strcmp(classname, mycast->type->name) == 0) { | ||
| 87 | - myinfo = mycast->type; | ||
| 88 | - break; | 79 | + if ($1 == NULL) { |
| 80 | + $result = Py_None; | ||
| 81 | + Py_INCREF(Py_None); // Py_None is a singleton so increment its reference | ||
| 82 | + } | ||
| 83 | + else { | ||
| 84 | + char classname[80]; | ||
| 85 | + strcpy(classname, "_p_"); | ||
| 86 | + strcat(classname, result->classname().c_str()); | ||
| 87 | + swig_type_info *myinfo = SWIGTYPE_p_GModelSpatial; | ||
| 88 | + swig_cast_info *mycast = 0; | ||
| 89 | + mycast = myinfo->cast; | ||
| 90 | + while (mycast != 0) { | ||
| 91 | + if (strcmp(classname, mycast->type->name) == 0) { | ||
| 92 | + myinfo = mycast->type; | ||
| 93 | + break; | ||
| 94 | + } | ||
| 95 | + mycast = mycast->next; | ||
| 89 | } | 96 | } |
| 90 | - mycast = mycast->next; | 97 | + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); |
| 91 | } | 98 | } |
| 92 | - $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | ||
| 93 | } | 99 | } |
| 94 | %typemap(out) GModelSpectral* { | 100 | %typemap(out) GModelSpectral* { |
| 95 | - char classname[80]; | ||
| 96 | - strcpy(classname, "_p_"); | ||
| 97 | - strcat(classname, result->classname().c_str()); | ||
| 98 | - swig_type_info *myinfo = SWIGTYPE_p_GModelSpectral; | ||
| 99 | - swig_cast_info *mycast = 0; | ||
| 100 | - mycast = myinfo->cast; | ||
| 101 | - while (mycast != 0) { | ||
| 102 | - if (strcmp(classname, mycast->type->name) == 0) { | ||
| 103 | - myinfo = mycast->type; | ||
| 104 | - break; | 101 | + if ($1 == NULL) { |
| 102 | + $result = Py_None; | ||
| 103 | + Py_INCREF(Py_None); // Py_None is a singleton so increment its reference | ||
| 104 | + } | ||
| 105 | + else { | ||
| 106 | + char classname[80]; | ||
| 107 | + strcpy(classname, "_p_"); | ||
| 108 | + strcat(classname, result->classname().c_str()); | ||
| 109 | + swig_type_info *myinfo = SWIGTYPE_p_GModelSpectral; | ||
| 110 | + swig_cast_info *mycast = 0; | ||
| 111 | + mycast = myinfo->cast; | ||
| 112 | + while (mycast != 0) { | ||
| 113 | + if (strcmp(classname, mycast->type->name) == 0) { | ||
| 114 | + myinfo = mycast->type; | ||
| 115 | + break; | ||
| 116 | + } | ||
| 117 | + mycast = mycast->next; | ||
| 105 | } | 118 | } |
| 106 | - mycast = mycast->next; | 119 | + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); |
| 107 | } | 120 | } |
| 108 | - $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | ||
| 109 | } | 121 | } |
| 110 | %typemap(out) GModelTemporal* { | 122 | %typemap(out) GModelTemporal* { |
| 111 | - char classname[80]; | ||
| 112 | - strcpy(classname, "_p_"); | ||
| 113 | - strcat(classname, result->classname().c_str()); | ||
| 114 | - swig_type_info *myinfo = SWIGTYPE_p_GModelTemporal; | ||
| 115 | - swig_cast_info *mycast = 0; | ||
| 116 | - mycast = myinfo->cast; | ||
| 117 | - while (mycast != 0) { | ||
| 118 | - if (strcmp(classname, mycast->type->name) == 0) { | ||
| 119 | - myinfo = mycast->type; | ||
| 120 | - break; | 123 | + if ($1 == NULL) { |
| 124 | + $result = Py_None; | ||
| 125 | + Py_INCREF(Py_None); // Py_None is a singleton so increment its reference | ||
| 126 | + } | ||
| 127 | + else { | ||
| 128 | + char classname[80]; | ||
| 129 | + strcpy(classname, "_p_"); | ||
| 130 | + strcat(classname, result->classname().c_str()); | ||
| 131 | + swig_type_info *myinfo = SWIGTYPE_p_GModelTemporal; | ||
| 132 | + swig_cast_info *mycast = 0; | ||
| 133 | + mycast = myinfo->cast; | ||
| 134 | + while (mycast != 0) { | ||
| 135 | + if (strcmp(classname, mycast->type->name) == 0) { | ||
| 136 | + myinfo = mycast->type; | ||
| 137 | + break; | ||
| 138 | + } | ||
| 139 | + mycast = mycast->next; | ||
| 121 | } | 140 | } |
| 122 | - mycast = mycast->next; | 141 | + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); |
| 123 | } | 142 | } |
| 124 | - $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | ||
| 125 | } | 143 | } |
| 126 | %typemap(out) GSkyRegion* { | 144 | %typemap(out) GSkyRegion* { |
| 127 | char classname[80]; | 145 | char classname[80]; |
| @@ -183,6 +201,7 @@ | @@ -183,6 +201,7 @@ | ||
| 183 | %include "GModelSpectralPlawPhotonFlux.i" | 201 | %include "GModelSpectralPlawPhotonFlux.i" |
| 184 | %include "GModelSpectralPlawEnergyFlux.i" | 202 | %include "GModelSpectralPlawEnergyFlux.i" |
| 185 | %include "GModelSpectralComposite.i" | 203 | %include "GModelSpectralComposite.i" |
| 204 | +%include "GModelSpectralMultiplicative.i" | ||
| 186 | %include "GModelTemporal.i" | 205 | %include "GModelTemporal.i" |
| 187 | %include "GModelTemporalRegistry.i" | 206 | %include "GModelTemporalRegistry.i" |
| 188 | %include "GModelTemporalConst.i" | 207 | %include "GModelTemporalConst.i" |
pyext/gammalib/obs.i
| @@ -151,6 +151,28 @@ | @@ -151,6 +151,28 @@ | ||
| 151 | } | 151 | } |
| 152 | $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | 152 | $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); |
| 153 | } | 153 | } |
| 154 | +%typemap(out) GModelSpatial* { | ||
| 155 | + if ($1 == NULL) { | ||
| 156 | + $result = Py_None; | ||
| 157 | + Py_INCREF(Py_None); // Py_None is a singleton so increment its reference | ||
| 158 | + } | ||
| 159 | + else { | ||
| 160 | + char classname[80]; | ||
| 161 | + strcpy(classname, "_p_"); | ||
| 162 | + strcat(classname, result->classname().c_str()); | ||
| 163 | + swig_type_info *myinfo = SWIGTYPE_p_GModelSpatial; | ||
| 164 | + swig_cast_info *mycast = 0; | ||
| 165 | + mycast = myinfo->cast; | ||
| 166 | + while (mycast != 0) { | ||
| 167 | + if (strcmp(classname, mycast->type->name) == 0) { | ||
| 168 | + myinfo = mycast->type; | ||
| 169 | + break; | ||
| 170 | + } | ||
| 171 | + mycast = mycast->next; | ||
| 172 | + } | ||
| 173 | + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | ||
| 174 | + } | ||
| 175 | +} | ||
| 154 | 176 | ||
| 155 | /* __ Observation handling _______________________________________________ */ | 177 | /* __ Observation handling _______________________________________________ */ |
| 156 | %include "GEnergy.i" | 178 | %include "GEnergy.i" |
pyext/gammalib/xml.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * xml.i - XML module * | 2 | * xml.i - XML module * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -52,20 +52,26 @@ | @@ -52,20 +52,26 @@ | ||
| 52 | 52 | ||
| 53 | /* __ Typemaps ___________________________________________________________ */ | 53 | /* __ Typemaps ___________________________________________________________ */ |
| 54 | %typemap(out) GXmlNode* { | 54 | %typemap(out) GXmlNode* { |
| 55 | - char classname[80]; | ||
| 56 | - strcpy(classname, "_p_"); | ||
| 57 | - strcat(classname, result->classname().c_str()); | ||
| 58 | - swig_type_info *myinfo = SWIGTYPE_p_GXmlNode; | ||
| 59 | - swig_cast_info *mycast = 0; | ||
| 60 | - mycast = myinfo->cast; | ||
| 61 | - while (mycast != 0) { | ||
| 62 | - if (strcmp(classname, mycast->type->name) == 0) { | ||
| 63 | - myinfo = mycast->type; | ||
| 64 | - break; | 55 | + if ($1 == NULL) { |
| 56 | + $result = Py_None; | ||
| 57 | + Py_INCREF(Py_None); // Py_None is a singleton so increment its reference | ||
| 58 | + } | ||
| 59 | + else { | ||
| 60 | + char classname[80]; | ||
| 61 | + strcpy(classname, "_p_"); | ||
| 62 | + strcat(classname, result->classname().c_str()); | ||
| 63 | + swig_type_info *myinfo = SWIGTYPE_p_GXmlNode; | ||
| 64 | + swig_cast_info *mycast = 0; | ||
| 65 | + mycast = myinfo->cast; | ||
| 66 | + while (mycast != 0) { | ||
| 67 | + if (strcmp(classname, mycast->type->name) == 0) { | ||
| 68 | + myinfo = mycast->type; | ||
| 69 | + break; | ||
| 70 | + } | ||
| 71 | + mycast = mycast->next; | ||
| 65 | } | 72 | } |
| 66 | - mycast = mycast->next; | 73 | + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); |
| 67 | } | 74 | } |
| 68 | - $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); | ||
| 69 | } | 75 | } |
| 70 | 76 | ||
| 71 | /* __ XML module _________________________________________________________ */ | 77 | /* __ XML module _________________________________________________________ */ |
src/model/GModelSpatialComposite.cpp
| @@ -381,15 +381,23 @@ void GModelSpatialComposite::read(const GXmlElement& xml) | @@ -381,15 +381,23 @@ void GModelSpatialComposite::read(const GXmlElement& xml) | ||
| 381 | } | 381 | } |
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | - // If there is a "scale_min" attribute set the minimum accordingly | 384 | + // If there is a "scale_min" attribute set the minimum accordingly; |
| 385 | + // otherwise remove minimum | ||
| 385 | if (spec->has_attribute("scale_min")) { | 386 | if (spec->has_attribute("scale_min")) { |
| 386 | scale.min(gammalib::todouble(spec->attribute("scale_min"))); | 387 | scale.min(gammalib::todouble(spec->attribute("scale_min"))); |
| 387 | } | 388 | } |
| 389 | + else { | ||
| 390 | + scale.remove_min(); | ||
| 391 | + } | ||
| 388 | 392 | ||
| 389 | - // If there is a "scale_max" attribute set the maximum accordingly | 393 | + // If there is a "scale_max" attribute set the maximum accordingly; |
| 394 | + // otherwise remove maximum | ||
| 390 | if (spec->has_attribute("scale_max")) { | 395 | if (spec->has_attribute("scale_max")) { |
| 391 | scale.max(gammalib::todouble(spec->attribute("scale_max"))); | 396 | scale.max(gammalib::todouble(spec->attribute("scale_max"))); |
| 392 | } | 397 | } |
| 398 | + else { | ||
| 399 | + scale.remove_max(); | ||
| 400 | + } | ||
| 393 | 401 | ||
| 394 | } // endif: there was a scale attribute | 402 | } // endif: there was a scale attribute |
| 395 | 403 | ||
| @@ -505,8 +513,12 @@ void GModelSpatialComposite::write(GXmlElement& xml) const | @@ -505,8 +513,12 @@ void GModelSpatialComposite::write(GXmlElement& xml) const | ||
| 505 | if (m_scales[i]->is_free()) { | 513 | if (m_scales[i]->is_free()) { |
| 506 | matching_model->attribute("scale_error", | 514 | matching_model->attribute("scale_error", |
| 507 | gammalib::str(m_scales[i]->error())); | 515 | gammalib::str(m_scales[i]->error())); |
| 516 | + } | ||
| 517 | + if (m_scales[i]->has_min()) { | ||
| 508 | matching_model->attribute("scale_min", | 518 | matching_model->attribute("scale_min", |
| 509 | gammalib::str(m_scales[i]->min())); | 519 | gammalib::str(m_scales[i]->min())); |
| 520 | + } | ||
| 521 | + if (m_scales[i]->has_max()) { | ||
| 510 | matching_model->attribute("scale_max", | 522 | matching_model->attribute("scale_max", |
| 511 | gammalib::str(m_scales[i]->max())); | 523 | gammalib::str(m_scales[i]->max())); |
| 512 | } | 524 | } |
src/model/GModelSpectralFunc.cpp
| @@ -823,62 +823,67 @@ void GModelSpectralFunc::load_nodes(const GFilename& filename) | @@ -823,62 +823,67 @@ void GModelSpectralFunc::load_nodes(const GFilename& filename) | ||
| 823 | // Set filename | 823 | // Set filename |
| 824 | m_filename = filename; | 824 | m_filename = filename; |
| 825 | 825 | ||
| 826 | - // Load file | ||
| 827 | - GCsv csv = GCsv(filename.url()); | 826 | + // Continue only if filename is not empty |
| 827 | + if (!filename.is_empty()) { | ||
| 828 | 828 | ||
| 829 | - // Check if there are at least 2 nodes | ||
| 830 | - if (csv.nrows() < 2) { | ||
| 831 | - throw GException::file_function_data(G_LOAD_NODES, filename.url(), | ||
| 832 | - csv.nrows()); | ||
| 833 | - } | ||
| 834 | - | ||
| 835 | - // Check if there are at least 2 columns | ||
| 836 | - if (csv.ncols() < 2) { | ||
| 837 | - throw GException::file_function_columns(G_LOAD_NODES, filename.url(), | ||
| 838 | - csv.ncols()); | ||
| 839 | - } | 829 | + // Load file |
| 830 | + GCsv csv = GCsv(filename.url()); | ||
| 840 | 831 | ||
| 841 | - // Setup nodes | ||
| 842 | - double last_energy = 0.0; | ||
| 843 | - for (int i = 0; i < csv.nrows(); ++i) { | ||
| 844 | - | ||
| 845 | - // Get log10 of node energy and value. Make sure they are valid. | ||
| 846 | - double log10energy; | ||
| 847 | - double log10value; | ||
| 848 | - if (csv.real(i,0) > 0) { | ||
| 849 | - log10energy = std::log10(csv.real(i,0)); | ||
| 850 | - } | ||
| 851 | - else { | ||
| 852 | - throw GException::file_function_value(G_LOAD_NODES, filename.url(), | ||
| 853 | - csv.real(i,0), "Energy value must be positive."); | ||
| 854 | - } | ||
| 855 | - if (csv.real(i,1) > 0) { | ||
| 856 | - log10value = std::log10(csv.real(i,1)); | ||
| 857 | - } | ||
| 858 | - else { | ||
| 859 | - throw GException::file_function_value(G_LOAD_NODES, filename.url(), | ||
| 860 | - csv.real(i,1), "Intensity value must be positive."); | 832 | + // Check if there are at least 2 nodes |
| 833 | + if (csv.nrows() < 2) { | ||
| 834 | + throw GException::file_function_data(G_LOAD_NODES, filename.url(), | ||
| 835 | + csv.nrows()); | ||
| 861 | } | 836 | } |
| 862 | 837 | ||
| 863 | - // Make sure that energies are increasing | ||
| 864 | - if (csv.real(i,0) <= last_energy) { | ||
| 865 | - throw GException::file_function_value(G_LOAD_NODES, filename.url(), | ||
| 866 | - csv.real(i,0), "Energy values must be monotonically increasing."); | 838 | + // Check if there are at least 2 columns |
| 839 | + if (csv.ncols() < 2) { | ||
| 840 | + throw GException::file_function_columns(G_LOAD_NODES, filename.url(), | ||
| 841 | + csv.ncols()); | ||
| 867 | } | 842 | } |
| 868 | 843 | ||
| 869 | - // Append log10 of node energy and value | ||
| 870 | - m_lin_nodes.append(csv.real(i,0)); | ||
| 871 | - m_log_nodes.append(log10energy); | ||
| 872 | - m_lin_values.push_back(csv.real(i,1)); | ||
| 873 | - m_log_values.push_back(log10value); | 844 | + // Setup nodes |
| 845 | + double last_energy = 0.0; | ||
| 846 | + for (int i = 0; i < csv.nrows(); ++i) { | ||
| 847 | + | ||
| 848 | + // Get log10 of node energy and value. Make sure they are valid. | ||
| 849 | + double log10energy; | ||
| 850 | + double log10value; | ||
| 851 | + if (csv.real(i,0) > 0) { | ||
| 852 | + log10energy = std::log10(csv.real(i,0)); | ||
| 853 | + } | ||
| 854 | + else { | ||
| 855 | + throw GException::file_function_value(G_LOAD_NODES, filename.url(), | ||
| 856 | + csv.real(i,0), "Energy value must be positive."); | ||
| 857 | + } | ||
| 858 | + if (csv.real(i,1) > 0) { | ||
| 859 | + log10value = std::log10(csv.real(i,1)); | ||
| 860 | + } | ||
| 861 | + else { | ||
| 862 | + throw GException::file_function_value(G_LOAD_NODES, filename.url(), | ||
| 863 | + csv.real(i,1), "Intensity value must be positive."); | ||
| 864 | + } | ||
| 865 | + | ||
| 866 | + // Make sure that energies are increasing | ||
| 867 | + if (csv.real(i,0) <= last_energy) { | ||
| 868 | + throw GException::file_function_value(G_LOAD_NODES, filename.url(), | ||
| 869 | + csv.real(i,0), "Energy values must be monotonically increasing."); | ||
| 870 | + } | ||
| 871 | + | ||
| 872 | + // Append log10 of node energy and value | ||
| 873 | + m_lin_nodes.append(csv.real(i,0)); | ||
| 874 | + m_log_nodes.append(log10energy); | ||
| 875 | + m_lin_values.push_back(csv.real(i,1)); | ||
| 876 | + m_log_values.push_back(log10value); | ||
| 877 | + | ||
| 878 | + // Store last energy for monotonically increasing check | ||
| 879 | + last_energy = csv.real(i,0); | ||
| 874 | 880 | ||
| 875 | - // Store last energy for monotonically increasing check | ||
| 876 | - last_energy = csv.real(i,0); | 881 | + } // endfor: looped over nodes |
| 877 | 882 | ||
| 878 | - } // endfor: looped over nodes | 883 | + // Set pre-computation cache |
| 884 | + set_cache(); | ||
| 879 | 885 | ||
| 880 | - // Set pre-computation cache | ||
| 881 | - set_cache(); | 886 | + } // endif: filename was not empty |
| 882 | 887 | ||
| 883 | // Return | 888 | // Return |
| 884 | return; | 889 | return; |
src/model/GModelTemporalLightCurve.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelTemporalLightCurve.cpp - Temporal light curve model class * | 2 | * GModelTemporalLightCurve.cpp - Temporal light curve model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2017-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -601,86 +601,91 @@ void GModelTemporalLightCurve::load_nodes(const GFilename& filename) | @@ -601,86 +601,91 @@ void GModelTemporalLightCurve::load_nodes(const GFilename& filename) | ||
| 601 | // Set filename | 601 | // Set filename |
| 602 | m_filename = filename; | 602 | m_filename = filename; |
| 603 | 603 | ||
| 604 | - // Load FITS file | ||
| 605 | - GFits fits = GFits(filename); | 604 | + // Continue only if filename is not empty |
| 605 | + if (!filename.is_empty()) { | ||
| 606 | 606 | ||
| 607 | - // Extract binary table (so far always load extension 1 as table) | ||
| 608 | - GFitsTable* table = fits.table(1); | 607 | + // Load FITS file |
| 608 | + GFits fits = GFits(filename); | ||
| 609 | 609 | ||
| 610 | - // Read time reference from binary table | ||
| 611 | - m_timeref.read(*table); | 610 | + // Extract binary table (so far always load extension 1 as table) |
| 611 | + GFitsTable* table = fits.table(1); | ||
| 612 | 612 | ||
| 613 | - // Extract columns | ||
| 614 | - GFitsTableCol* time_col = (*table)["TIME"]; | ||
| 615 | - GFitsTableCol* norm_col = (*table)["NORM"]; | 613 | + // Read time reference from binary table |
| 614 | + m_timeref.read(*table); | ||
| 616 | 615 | ||
| 617 | - // Check that there are at least two nodes in table | ||
| 618 | - if (time_col->nrows() < 2) { | ||
| 619 | - std::string msg = "\"TIME\" column contains "+ | ||
| 620 | - gammalib::str(time_col->nrows())+" rows but at " | ||
| 621 | - "least two rows are required. Please specify a valid " | ||
| 622 | - "temporal file function."; | ||
| 623 | - throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 624 | - } | ||
| 625 | - | ||
| 626 | - // Check that both columns are consistent | ||
| 627 | - if (time_col->nrows() != norm_col->nrows()) { | ||
| 628 | - std::string msg = "\"TIME\" and \"NORM\" columns have inconsistent " | ||
| 629 | - "number of rows ("+ | ||
| 630 | - gammalib::str(time_col->nrows())+", "+ | ||
| 631 | - gammalib::str(norm_col->nrows())+"). Please " | ||
| 632 | - "specify a valid temporal file function."; | ||
| 633 | - throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 634 | - } | 616 | + // Extract columns |
| 617 | + GFitsTableCol* time_col = (*table)["TIME"]; | ||
| 618 | + GFitsTableCol* norm_col = (*table)["NORM"]; | ||
| 635 | 619 | ||
| 636 | - // Set number of nodes | ||
| 637 | - int nodes = time_col->nrows(); | ||
| 638 | - | ||
| 639 | - // Check that time values are in ascending order and that no node is | ||
| 640 | - // larger than 1 | ||
| 641 | - double last_time = -1.0; | ||
| 642 | - for (int i = 0; i < nodes; ++i) { | ||
| 643 | - | ||
| 644 | - // Check if time has increased | ||
| 645 | - if (last_time >= 0.0 && time_col->real(i) <= last_time) { | ||
| 646 | - std::string msg = "Time "+gammalib::str(time_col->real(i))+ | ||
| 647 | - " in row "+gammalib::str(i+1)+" of \"TIME\" " | ||
| 648 | - "column is equal to or smaller than preceeding " | ||
| 649 | - "value. Please provide a light curve file with " | ||
| 650 | - "monotonically increasing times."; | 620 | + // Check that there are at least two nodes in table |
| 621 | + if (time_col->nrows() < 2) { | ||
| 622 | + std::string msg = "\"TIME\" column contains "+ | ||
| 623 | + gammalib::str(time_col->nrows())+" rows but at " | ||
| 624 | + "least two rows are required. Please specify a valid " | ||
| 625 | + "temporal file function."; | ||
| 651 | throw GException::invalid_value(G_LOAD_NODES, msg); | 626 | throw GException::invalid_value(G_LOAD_NODES, msg); |
| 652 | } | 627 | } |
| 653 | 628 | ||
| 654 | - // Check if value is smaller than maximum allowed normalisation | ||
| 655 | - if (norm_col->real(i) > max_norm) { | ||
| 656 | - std::string msg = "Value "+gammalib::str(norm_col->real(i))+" at " | ||
| 657 | - "time "+gammalib::str(time_col->real(i))+" is " | ||
| 658 | - "larger than 1. Please provide a light curve file " | ||
| 659 | - "with normalizations not exceeding 1."; | 629 | + // Check that both columns are consistent |
| 630 | + if (time_col->nrows() != norm_col->nrows()) { | ||
| 631 | + std::string msg = "\"TIME\" and \"NORM\" columns have inconsistent " | ||
| 632 | + "number of rows ("+ | ||
| 633 | + gammalib::str(time_col->nrows())+", "+ | ||
| 634 | + gammalib::str(norm_col->nrows())+"). Please " | ||
| 635 | + "specify a valid temporal file function."; | ||
| 660 | throw GException::invalid_value(G_LOAD_NODES, msg); | 636 | throw GException::invalid_value(G_LOAD_NODES, msg); |
| 661 | } | 637 | } |
| 638 | + | ||
| 639 | + // Set number of nodes | ||
| 640 | + int nodes = time_col->nrows(); | ||
| 641 | + | ||
| 642 | + // Check that time values are in ascending order and that no node is | ||
| 643 | + // larger than 1 | ||
| 644 | + double last_time = -1.0; | ||
| 645 | + for (int i = 0; i < nodes; ++i) { | ||
| 646 | + | ||
| 647 | + // Check if time has increased | ||
| 648 | + if (last_time >= 0.0 && time_col->real(i) <= last_time) { | ||
| 649 | + std::string msg = "Time "+gammalib::str(time_col->real(i))+ | ||
| 650 | + " in row "+gammalib::str(i+1)+" of \"TIME\" " | ||
| 651 | + "column is equal to or smaller than preceeding " | ||
| 652 | + "value. Please provide a light curve file with " | ||
| 653 | + "monotonically increasing times."; | ||
| 654 | + throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 655 | + } | ||
| 656 | + | ||
| 657 | + // Check if value is smaller than maximum allowed normalisation | ||
| 658 | + if (norm_col->real(i) > max_norm) { | ||
| 659 | + std::string msg = "Value "+gammalib::str(norm_col->real(i))+" at " | ||
| 660 | + "time "+gammalib::str(time_col->real(i))+" is " | ||
| 661 | + "larger than 1. Please provide a light curve file " | ||
| 662 | + "with normalizations not exceeding 1."; | ||
| 663 | + throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 664 | + } | ||
| 662 | 665 | ||
| 663 | - } // endfor: looped over nodes | 666 | + } // endfor: looped over nodes |
| 664 | 667 | ||
| 665 | - // Extract nodes | ||
| 666 | - for (int i = 0; i < nodes; ++i) { | ||
| 667 | - m_nodes.append(time_col->real(i)); | ||
| 668 | - m_values.push_back(norm_col->real(i)); | ||
| 669 | - } | 668 | + // Extract nodes |
| 669 | + for (int i = 0; i < nodes; ++i) { | ||
| 670 | + m_nodes.append(time_col->real(i)); | ||
| 671 | + m_values.push_back(norm_col->real(i)); | ||
| 672 | + } | ||
| 670 | 673 | ||
| 671 | - // Make sure that no node exceeds 1 | ||
| 672 | - for (int i = 0; i < m_values.size(); ++i) { | ||
| 673 | - if (m_values[i] > 1.0) { | ||
| 674 | - m_values[i] = 1.0; | 674 | + // Make sure that no node exceeds 1 |
| 675 | + for (int i = 0; i < m_values.size(); ++i) { | ||
| 676 | + if (m_values[i] > 1.0) { | ||
| 677 | + m_values[i] = 1.0; | ||
| 678 | + } | ||
| 675 | } | 679 | } |
| 676 | - } | ||
| 677 | 680 | ||
| 678 | - // Set minimum and maximum times (assumes that times are ordered) | ||
| 679 | - m_tmin.set(time_col->real(0), m_timeref); | ||
| 680 | - m_tmax.set(time_col->real(time_col->nrows()-1), m_timeref); | 681 | + // Set minimum and maximum times (assumes that times are ordered) |
| 682 | + m_tmin.set(time_col->real(0), m_timeref); | ||
| 683 | + m_tmax.set(time_col->real(time_col->nrows()-1), m_timeref); | ||
| 684 | + | ||
| 685 | + // Close FITS file | ||
| 686 | + fits.close(); | ||
| 681 | 687 | ||
| 682 | - // Close FITS file | ||
| 683 | - fits.close(); | 688 | + } // endif: filename was not empty |
| 684 | 689 | ||
| 685 | // Return | 690 | // Return |
| 686 | return; | 691 | return; |
src/model/GModelTemporalPhaseCurve.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModelTemporalPhaseCurve.cpp - Temporal phase curve model class * | 2 | * GModelTemporalPhaseCurve.cpp - Temporal phase curve model class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2017 by Juergen Knoedlseder * | 4 | + * copyright (C) 2017-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -764,109 +764,114 @@ void GModelTemporalPhaseCurve::load_nodes(const GFilename& filename) | @@ -764,109 +764,114 @@ void GModelTemporalPhaseCurve::load_nodes(const GFilename& filename) | ||
| 764 | // Set filename | 764 | // Set filename |
| 765 | m_filename = filename; | 765 | m_filename = filename; |
| 766 | 766 | ||
| 767 | - // Load FITS file | ||
| 768 | - GFits fits = GFits(filename); | 767 | + // Continue only if filename is not empty |
| 768 | + if (!filename.is_empty()) { | ||
| 769 | 769 | ||
| 770 | - // Extract binary table (so far always load extension 1 as table) | ||
| 771 | - GFitsTable* table = fits.table(1); | 770 | + // Load FITS file |
| 771 | + GFits fits = GFits(filename); | ||
| 772 | 772 | ||
| 773 | - // Extract columns | ||
| 774 | - GFitsTableCol* phase_col = (*table)["PHASE"]; | ||
| 775 | - GFitsTableCol* norm_col = (*table)["NORM"]; | 773 | + // Extract binary table (so far always load extension 1 as table) |
| 774 | + GFitsTable* table = fits.table(1); | ||
| 776 | 775 | ||
| 777 | - // Check that there are at least two nodes in table | ||
| 778 | - if (phase_col->nrows() < 2) { | ||
| 779 | - std::string msg = "\"PHASE\" column contains "+ | ||
| 780 | - gammalib::str(phase_col->nrows())+" rows but at " | ||
| 781 | - "least two rows are required. Please specify a valid " | ||
| 782 | - "phase curve file."; | ||
| 783 | - throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 784 | - } | ||
| 785 | - | ||
| 786 | - // Check that both columns are consistent | ||
| 787 | - if (phase_col->nrows() != norm_col->nrows()) { | ||
| 788 | - std::string msg = "\"PHASE\" and \"NORM\" columns have inconsistent " | ||
| 789 | - "number of rows ("+ | ||
| 790 | - gammalib::str(phase_col->nrows())+", "+ | ||
| 791 | - gammalib::str(norm_col->nrows())+"). Please " | ||
| 792 | - "specify a valid phase curve file."; | ||
| 793 | - throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 794 | - } | 776 | + // Extract columns |
| 777 | + GFitsTableCol* phase_col = (*table)["PHASE"]; | ||
| 778 | + GFitsTableCol* norm_col = (*table)["NORM"]; | ||
| 795 | 779 | ||
| 796 | - // Set number of nodes | ||
| 797 | - int nodes = phase_col->nrows(); | ||
| 798 | - | ||
| 799 | - // Check that phase values are in ascending order and comprised between | ||
| 800 | - // 0 and 1, and that no node is larger than 1 | ||
| 801 | - double last_phase = -1.0; | ||
| 802 | - for (int i = 0; i < nodes; ++i) { | ||
| 803 | - | ||
| 804 | - // Check if phase has increased | ||
| 805 | - if (last_phase >= 0.0 && phase_col->real(i) <= last_phase) { | ||
| 806 | - std::string msg = "Phase value "+gammalib::str(phase_col->real(i))+ | ||
| 807 | - " in row "+gammalib::str(i+1)+" of \"PHASE\" " | ||
| 808 | - "column is equal to or smaller than preceeding " | ||
| 809 | - "value. Please provide a phase curve file with " | ||
| 810 | - "monotonically increasing phase values."; | 780 | + // Check that there are at least two nodes in table |
| 781 | + if (phase_col->nrows() < 2) { | ||
| 782 | + std::string msg = "\"PHASE\" column contains "+ | ||
| 783 | + gammalib::str(phase_col->nrows())+" rows but at " | ||
| 784 | + "least two rows are required. Please specify a valid " | ||
| 785 | + "phase curve file."; | ||
| 811 | throw GException::invalid_value(G_LOAD_NODES, msg); | 786 | throw GException::invalid_value(G_LOAD_NODES, msg); |
| 812 | } | 787 | } |
| 813 | 788 | ||
| 814 | - // Check if phase is within [0,1] | ||
| 815 | - if (phase_col->real(i) < 0.0 || phase_col->real(i) > 1.0) { | ||
| 816 | - std::string msg = "Phase value "+gammalib::str(phase_col->real(i))+ | ||
| 817 | - " outside range [0,1]. Please provide a phase " | ||
| 818 | - "curve file with phase values comprised in the " | ||
| 819 | - "interval [0,1]."; | 789 | + // Check that both columns are consistent |
| 790 | + if (phase_col->nrows() != norm_col->nrows()) { | ||
| 791 | + std::string msg = "\"PHASE\" and \"NORM\" columns have inconsistent " | ||
| 792 | + "number of rows ("+ | ||
| 793 | + gammalib::str(phase_col->nrows())+", "+ | ||
| 794 | + gammalib::str(norm_col->nrows())+"). Please " | ||
| 795 | + "specify a valid phase curve file."; | ||
| 820 | throw GException::invalid_value(G_LOAD_NODES, msg); | 796 | throw GException::invalid_value(G_LOAD_NODES, msg); |
| 821 | } | 797 | } |
| 822 | 798 | ||
| 823 | - // Check if value is smaller than maximum allowed normalisation | ||
| 824 | - if (norm_col->real(i) > max_norm) { | ||
| 825 | - std::string msg = "Value "+gammalib::str(norm_col->real(i))+" at " | ||
| 826 | - "phase "+gammalib::str(phase_col->real(i))+" is " | ||
| 827 | - "larger than 1. Please provide a phase curve file " | ||
| 828 | - "with normalizations not exceeding 1."; | ||
| 829 | - throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 830 | - } | 799 | + // Set number of nodes |
| 800 | + int nodes = phase_col->nrows(); | ||
| 801 | + | ||
| 802 | + // Check that phase values are in ascending order and comprised between | ||
| 803 | + // 0 and 1, and that no node is larger than 1 | ||
| 804 | + double last_phase = -1.0; | ||
| 805 | + for (int i = 0; i < nodes; ++i) { | ||
| 806 | + | ||
| 807 | + // Check if phase has increased | ||
| 808 | + if (last_phase >= 0.0 && phase_col->real(i) <= last_phase) { | ||
| 809 | + std::string msg = "Phase value "+gammalib::str(phase_col->real(i))+ | ||
| 810 | + " in row "+gammalib::str(i+1)+" of \"PHASE\" " | ||
| 811 | + "column is equal to or smaller than preceeding " | ||
| 812 | + "value. Please provide a phase curve file with " | ||
| 813 | + "monotonically increasing phase values."; | ||
| 814 | + throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 815 | + } | ||
| 816 | + | ||
| 817 | + // Check if phase is within [0,1] | ||
| 818 | + if (phase_col->real(i) < 0.0 || phase_col->real(i) > 1.0) { | ||
| 819 | + std::string msg = "Phase value "+gammalib::str(phase_col->real(i))+ | ||
| 820 | + " outside range [0,1]. Please provide a phase " | ||
| 821 | + "curve file with phase values comprised in the " | ||
| 822 | + "interval [0,1]."; | ||
| 823 | + throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 824 | + } | ||
| 825 | + | ||
| 826 | + // Check if value is smaller than maximum allowed normalisation | ||
| 827 | + if (norm_col->real(i) > max_norm) { | ||
| 828 | + std::string msg = "Value "+gammalib::str(norm_col->real(i))+" at " | ||
| 829 | + "phase "+gammalib::str(phase_col->real(i))+" is " | ||
| 830 | + "larger than 1. Please provide a phase curve file " | ||
| 831 | + "with normalizations not exceeding 1."; | ||
| 832 | + throw GException::invalid_value(G_LOAD_NODES, msg); | ||
| 833 | + } | ||
| 831 | 834 | ||
| 832 | - } // endfor: looped over nodes | ||
| 833 | - | ||
| 834 | - // If first phase is larger than zero then add last node with phase-1 as | ||
| 835 | - // first node. This makes sure that a valid normalization exists for | ||
| 836 | - // phase=0. | ||
| 837 | - if (phase_col->real(0) > 0.0) { | ||
| 838 | - m_nodes.append(phase_col->real(nodes-1)-1.0); | ||
| 839 | - m_values.push_back(norm_col->real(nodes-1)); | ||
| 840 | - } | 835 | + } // endfor: looped over nodes |
| 836 | + | ||
| 837 | + // If first phase is larger than zero then add last node with phase-1 as | ||
| 838 | + // first node. This makes sure that a valid normalization exists for | ||
| 839 | + // phase=0. | ||
| 840 | + if (phase_col->real(0) > 0.0) { | ||
| 841 | + m_nodes.append(phase_col->real(nodes-1)-1.0); | ||
| 842 | + m_values.push_back(norm_col->real(nodes-1)); | ||
| 843 | + } | ||
| 841 | 844 | ||
| 842 | - // Extract nodes | ||
| 843 | - for (int i = 0; i < nodes; ++i) { | ||
| 844 | - m_nodes.append(phase_col->real(i)); | ||
| 845 | - m_values.push_back(norm_col->real(i)); | ||
| 846 | - } | 845 | + // Extract nodes |
| 846 | + for (int i = 0; i < nodes; ++i) { | ||
| 847 | + m_nodes.append(phase_col->real(i)); | ||
| 848 | + m_values.push_back(norm_col->real(i)); | ||
| 849 | + } | ||
| 847 | 850 | ||
| 848 | - // If last node is smaller than one then add first node with phase+1 as | ||
| 849 | - // last node. This makes sure that a valid normalization exists for | ||
| 850 | - // phase=1. | ||
| 851 | - if (phase_col->real(nodes-1) < 1.0) { | ||
| 852 | - m_nodes.append(phase_col->real(0)+1.0); | ||
| 853 | - m_values.push_back(norm_col->real(0)); | ||
| 854 | - } | 851 | + // If last node is smaller than one then add first node with phase+1 as |
| 852 | + // last node. This makes sure that a valid normalization exists for | ||
| 853 | + // phase=1. | ||
| 854 | + if (phase_col->real(nodes-1) < 1.0) { | ||
| 855 | + m_nodes.append(phase_col->real(0)+1.0); | ||
| 856 | + m_values.push_back(norm_col->real(0)); | ||
| 857 | + } | ||
| 855 | 858 | ||
| 856 | - // Make sure that no node exceeds 1 | ||
| 857 | - for (int i = 0; i < m_values.size(); ++i) { | ||
| 858 | - if (m_values[i] > 1.0) { | ||
| 859 | - m_values[i] = 1.0; | 859 | + // Make sure that no node exceeds 1 |
| 860 | + for (int i = 0; i < m_values.size(); ++i) { | ||
| 861 | + if (m_values[i] > 1.0) { | ||
| 862 | + m_values[i] = 1.0; | ||
| 863 | + } | ||
| 860 | } | 864 | } |
| 861 | - } | ||
| 862 | 865 | ||
| 863 | - // Close FITS file | ||
| 864 | - fits.close(); | 866 | + // Close FITS file |
| 867 | + fits.close(); | ||
| 865 | 868 | ||
| 866 | - // Optionally normalize nodes | ||
| 867 | - if (m_normalize) { | ||
| 868 | - normalize_nodes(); | ||
| 869 | - } | 869 | + // Optionally normalize nodes |
| 870 | + if (m_normalize) { | ||
| 871 | + normalize_nodes(); | ||
| 872 | + } | ||
| 873 | + | ||
| 874 | + } // endif: filename was not empty | ||
| 870 | 875 | ||
| 871 | // Return | 876 | // Return |
| 872 | return; | 877 | return; |
src/model/GModels.cpp
| @@ -416,8 +416,8 @@ GModel* GModels::append(const GModel& model) | @@ -416,8 +416,8 @@ GModel* GModels::append(const GModel& model) | ||
| 416 | std::string msg = | 416 | std::string msg = |
| 417 | "Attempt to append model with name \""+model.name()+"\" to model" | 417 | "Attempt to append model with name \""+model.name()+"\" to model" |
| 418 | " container, but a model with the same name exists already at" | 418 | " container, but a model with the same name exists already at" |
| 419 | - " index "+gammalib::str(inx)+" in the container.\n" | ||
| 420 | - "Every model in the model container needs a unique name."; | 419 | + " index "+gammalib::str(inx)+" in the container." |
| 420 | + " Every model in the model container needs a unique name."; | ||
| 421 | throw GException::invalid_value(G_APPEND, msg); | 421 | throw GException::invalid_value(G_APPEND, msg); |
| 422 | } | 422 | } |
| 423 | 423 |
src/obs/GSource.cpp
| @@ -203,7 +203,12 @@ std::string GSource::print(const GChatter& chatter) const | @@ -203,7 +203,12 @@ std::string GSource::print(const GChatter& chatter) const | ||
| 203 | // Build photon string | 203 | // Build photon string |
| 204 | result.append("GSource("); | 204 | result.append("GSource("); |
| 205 | result.append(m_name); | 205 | result.append(m_name); |
| 206 | - result.append(", "+m_model->type()); | 206 | + if (m_model != NULL) { |
| 207 | + result.append(", "+m_model->type()); | ||
| 208 | + } | ||
| 209 | + else { | ||
| 210 | + result.append(", None"); | ||
| 211 | + } | ||
| 207 | result.append(", E="+m_energy.print(chatter)); | 212 | result.append(", E="+m_energy.print(chatter)); |
| 208 | result.append(", MET="+m_time.print(chatter)); | 213 | result.append(", MET="+m_time.print(chatter)); |
| 209 | result.append(")"); | 214 | result.append(")"); |
src/obs/GTimeReference.cpp
| @@ -672,7 +672,7 @@ void GTimeReference::init_members(void) | @@ -672,7 +672,7 @@ void GTimeReference::init_members(void) | ||
| 672 | m_mjdref = 0.0; | 672 | m_mjdref = 0.0; |
| 673 | m_timeunit = "secs"; | 673 | m_timeunit = "secs"; |
| 674 | m_timesys = "TT"; | 674 | m_timesys = "TT"; |
| 675 | - m_timeref = "local"; | 675 | + m_timeref = "LOCAL"; |
| 676 | m_unit_sec = true; | 676 | m_unit_sec = true; |
| 677 | 677 | ||
| 678 | // Return | 678 | // Return |
src/xml/GXml.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXml.cpp - XML class * | 2 | * GXml.cpp - XML class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -123,6 +123,24 @@ GXml::GXml(const std::string& xml) | @@ -123,6 +123,24 @@ GXml::GXml(const std::string& xml) | ||
| 123 | 123 | ||
| 124 | 124 | ||
| 125 | /***********************************************************************//** | 125 | /***********************************************************************//** |
| 126 | + * @brief Document constructor | ||
| 127 | + * | ||
| 128 | + * @param[in] root Root document. | ||
| 129 | + ***************************************************************************/ | ||
| 130 | +GXml::GXml(const GXmlDocument& root) | ||
| 131 | +{ | ||
| 132 | + // Initialise members | ||
| 133 | + init_members(); | ||
| 134 | + | ||
| 135 | + // Set document root | ||
| 136 | + this->root(root); | ||
| 137 | + | ||
| 138 | + // Return | ||
| 139 | + return; | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | + | ||
| 143 | +/***********************************************************************//** | ||
| 126 | * @brief Destructor | 144 | * @brief Destructor |
| 127 | ***************************************************************************/ | 145 | ***************************************************************************/ |
| 128 | GXml::~GXml(void) | 146 | GXml::~GXml(void) |
src/xml/GXmlDocument.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlDocument.cpp - XML document node class implementation * | 2 | * GXmlDocument.cpp - XML document node class implementation * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -51,7 +51,7 @@ | @@ -51,7 +51,7 @@ | ||
| 51 | ***************************************************************************/ | 51 | ***************************************************************************/ |
| 52 | GXmlDocument::GXmlDocument(void) : GXmlNode() | 52 | GXmlDocument::GXmlDocument(void) : GXmlNode() |
| 53 | { | 53 | { |
| 54 | - // Initialise private members for clean destruction | 54 | + // Initialise private members |
| 55 | init_members(); | 55 | init_members(); |
| 56 | 56 | ||
| 57 | // Return | 57 | // Return |
| @@ -60,6 +60,33 @@ GXmlDocument::GXmlDocument(void) : GXmlNode() | @@ -60,6 +60,33 @@ GXmlDocument::GXmlDocument(void) : GXmlNode() | ||
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | /***********************************************************************//** | 62 | /***********************************************************************//** |
| 63 | + * @brief Constructor | ||
| 64 | + * | ||
| 65 | + * @param[in] filename Filename. | ||
| 66 | + * @param[in] version Version string. | ||
| 67 | + * @param[in] encoding Encoding string. | ||
| 68 | + * @param[in] standalone Standalone string. | ||
| 69 | + ***************************************************************************/ | ||
| 70 | +GXmlDocument::GXmlDocument(const GFilename& filename, | ||
| 71 | + const std::string& version, | ||
| 72 | + const std::string& encoding, | ||
| 73 | + const std::string& standalone) : GXmlNode() | ||
| 74 | +{ | ||
| 75 | + // Initialise private members | ||
| 76 | + init_members(); | ||
| 77 | + | ||
| 78 | + // Set members | ||
| 79 | + this->filename(filename); | ||
| 80 | + this->version(version); | ||
| 81 | + this->encoding(encoding); | ||
| 82 | + this->standalone(standalone); | ||
| 83 | + | ||
| 84 | + // Return | ||
| 85 | + return; | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | + | ||
| 89 | +/***********************************************************************//** | ||
| 63 | * @brief Copy constructor | 90 | * @brief Copy constructor |
| 64 | * | 91 | * |
| 65 | * @param[in] node XML document. | 92 | * @param[in] node XML document. |
src/xml/GXmlElement.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GXmlElement.cpp - XML element node class implementation * | 2 | * GXmlElement.cpp - XML element node class implementation * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -35,6 +35,7 @@ | @@ -35,6 +35,7 @@ | ||
| 35 | #include "GXmlElement.hpp" | 35 | #include "GXmlElement.hpp" |
| 36 | 36 | ||
| 37 | /* __ Method name definitions ____________________________________________ */ | 37 | /* __ Method name definitions ____________________________________________ */ |
| 38 | +#define G_ATTRIBUTE "GXmlElement::attribute(int&)" | ||
| 38 | #define G_PARSE_START "GXmlElement::parse_start(std::string&)" | 39 | #define G_PARSE_START "GXmlElement::parse_start(std::string&)" |
| 39 | #define G_PARSE_STOP "GXmlElement::parse_stop(std::string&)" | 40 | #define G_PARSE_STOP "GXmlElement::parse_stop(std::string&)" |
| 40 | #define G_PARSE_ATTRIBUTE "GXmlElement::parse_attribute(size_t*, "\ | 41 | #define G_PARSE_ATTRIBUTE "GXmlElement::parse_attribute(size_t*, "\ |
| @@ -197,6 +198,26 @@ GXmlElement* GXmlElement::clone(void) const | @@ -197,6 +198,26 @@ GXmlElement* GXmlElement::clone(void) const | ||
| 197 | 198 | ||
| 198 | 199 | ||
| 199 | /***********************************************************************//** | 200 | /***********************************************************************//** |
| 201 | + * @brief Return attribute | ||
| 202 | + * | ||
| 203 | + * @param[in] index Attribute index. | ||
| 204 | + * @return Pointer to attribute. | ||
| 205 | + ***************************************************************************/ | ||
| 206 | +const GXmlAttribute* GXmlElement::attribute(const int& index) const | ||
| 207 | +{ | ||
| 208 | + // Compile option: raise exception if index is out of range | ||
| 209 | + #if defined(G_RANGE_CHECK) | ||
| 210 | + if (index < 0 || index >= attributes()) { | ||
| 211 | + throw GException::out_of_range(G_ATTRIBUTE, index, attributes()); | ||
| 212 | + } | ||
| 213 | + #endif | ||
| 214 | + | ||
| 215 | + // Return pointer to attribute | ||
| 216 | + return (m_attr[index]); | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | + | ||
| 220 | +/***********************************************************************//** | ||
| 200 | * @brief Return attribute value | 221 | * @brief Return attribute value |
| 201 | * | 222 | * |
| 202 | * @param[in] name Attribute name. | 223 | * @param[in] name Attribute name. |
test/test_GModel.py
| 1 | # ========================================================================== | 1 | # ========================================================================== |
| 2 | # This module performs unit tests for the GammaLib model module | 2 | # This module performs unit tests for the GammaLib model module |
| 3 | # | 3 | # |
| 4 | -# Copyright (C) 2012-2017 Juergen Knoedlseder | 4 | +# Copyright (C) 2012-2018 Juergen Knoedlseder |
| 5 | # | 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by | 7 | # it under the terms of the GNU General Public License as published by |
| @@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | # | 18 | # |
| 19 | # ========================================================================== | 19 | # ========================================================================== |
| 20 | +import os | ||
| 20 | import gammalib | 21 | import gammalib |
| 21 | import test_support | 22 | import test_support |
| 22 | 23 | ||
| @@ -106,6 +107,110 @@ class Test(gammalib.GPythonTestSuite): | @@ -106,6 +107,110 @@ class Test(gammalib.GPythonTestSuite): | ||
| 106 | # Return | 107 | # Return |
| 107 | return | 108 | return |
| 108 | 109 | ||
| 110 | + # Test class pickeling | ||
| 111 | + def _test_pickeling(self): | ||
| 112 | + """ | ||
| 113 | + Test class pickeling | ||
| 114 | + """ | ||
| 115 | + # Perform pickeling tests of empty classes | ||
| 116 | + test_support._pickeling(self, gammalib.GModelPar()) | ||
| 117 | + test_support._pickeling(self, gammalib.GModels()) | ||
| 118 | + test_support._pickeling(self, gammalib.GModelSky()) | ||
| 119 | + test_support._pickeling(self, gammalib.GModelSpatialComposite()) | ||
| 120 | + #test_support._pickeling(self, gammalib.GModelSpatialDiffuseConst()) | ||
| 121 | + #test_support._pickeling(self, gammalib.GModelSpatialDiffuseCube()) | ||
| 122 | + #test_support._pickeling(self, gammalib.GModelSpatialDiffuseMap()) | ||
| 123 | + #test_support._pickeling(self, gammalib.GModelSpatialEllipticalDisk()) | ||
| 124 | + #test_support._pickeling(self, gammalib.GModelSpatialEllipticalGauss()) | ||
| 125 | + test_support._pickeling(self, gammalib.GModelSpatialPointSource()) | ||
| 126 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialDisk()) | ||
| 127 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialGauss()) | ||
| 128 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMBurkert()) | ||
| 129 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMEinasto()) | ||
| 130 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMZhao()) | ||
| 131 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileGauss()) | ||
| 132 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialShell()) | ||
| 133 | + test_support._pickeling(self, gammalib.GModelSpectralBrokenPlaw()) | ||
| 134 | + test_support._pickeling(self, gammalib.GModelSpectralComposite()) | ||
| 135 | + test_support._pickeling(self, gammalib.GModelSpectralConst()) | ||
| 136 | + test_support._pickeling(self, gammalib.GModelSpectralExpInvPlaw()) | ||
| 137 | + test_support._pickeling(self, gammalib.GModelSpectralExpPlaw()) | ||
| 138 | + test_support._pickeling(self, gammalib.GModelSpectralFunc()) | ||
| 139 | + test_support._pickeling(self, gammalib.GModelSpectralGauss()) | ||
| 140 | + test_support._pickeling(self, gammalib.GModelSpectralLogParabola()) | ||
| 141 | + test_support._pickeling(self, gammalib.GModelSpectralMultiplicative()) | ||
| 142 | + test_support._pickeling(self, gammalib.GModelSpectralNodes()) | ||
| 143 | + test_support._pickeling(self, gammalib.GModelSpectralPlaw()) | ||
| 144 | + test_support._pickeling(self, gammalib.GModelSpectralPlawEnergyFlux()) | ||
| 145 | + test_support._pickeling(self, gammalib.GModelSpectralPlawPhotonFlux()) | ||
| 146 | + test_support._pickeling(self, gammalib.GModelSpectralSmoothBrokenPlaw()) | ||
| 147 | + test_support._pickeling(self, gammalib.GModelSpectralSuperExpPlaw()) | ||
| 148 | + test_support._pickeling(self, gammalib.GModelTemporalConst()) | ||
| 149 | + test_support._pickeling(self, gammalib.GModelTemporalLightCurve()) | ||
| 150 | + test_support._pickeling(self, gammalib.GModelTemporalPhaseCurve()) | ||
| 151 | + | ||
| 152 | + # Setup for tests | ||
| 153 | + time = gammalib.GTime(1.0,'sec') | ||
| 154 | + pivot = gammalib.GEnergy(1.0,'TeV') | ||
| 155 | + ptsrc = gammalib.GModelSpatialPointSource(1.0,2.0) | ||
| 156 | + plaw = gammalib.GModelSpectralPlaw(1.0,-2.0,pivot) | ||
| 157 | + cnst = gammalib.GModelTemporalConst(3.0) | ||
| 158 | + sky = gammalib.GModelSky(ptsrc, plaw, cnst) | ||
| 159 | + engs = gammalib.GEnergies(10,pivot,gammalib.GEnergy(10.0,'TeV')) | ||
| 160 | + spacom = gammalib.GModelSpatialComposite() | ||
| 161 | + spacom.append(ptsrc, 'Src1') | ||
| 162 | + spacom.append(ptsrc, 'Src2') | ||
| 163 | + specom = gammalib.GModelSpectralComposite() | ||
| 164 | + specom.append(plaw, 'Src1') | ||
| 165 | + specom.append(plaw, 'Src2') | ||
| 166 | + spemul = gammalib.GModelSpectralMultiplicative() | ||
| 167 | + spemul.append(plaw, 'Src1') | ||
| 168 | + spemul.append(plaw, 'Src2') | ||
| 169 | + nodes = gammalib.GModelSpectralNodes(plaw, engs) | ||
| 170 | + fct = gammalib.GFilename(os.environ['TEST_DATA']+'/filefunction.txt') | ||
| 171 | + lcrv = gammalib.GFilename(os.environ['TEST_DATA']+'/model_temporal_lightcurve.fits') | ||
| 172 | + pcrv = gammalib.GFilename(os.environ['TEST_DATA']+'/model_temporal_phasecurve.fits') | ||
| 173 | + | ||
| 174 | + # Perform pickeling tests of filled classes | ||
| 175 | + test_support._pickeling(self, gammalib.GModelPar('Par',2.0,5.0)) | ||
| 176 | + test_support._pickeling(self, gammalib.GModels(self._setup_models())) | ||
| 177 | + test_support._pickeling(self, gammalib.GModelSky(sky)) | ||
| 178 | + test_support._pickeling(self, gammalib.GModelSpatialComposite(spacom)) | ||
| 179 | + #test_support._pickeling(self, gammalib.GModelSpatialDiffuseConst()) | ||
| 180 | + #test_support._pickeling(self, gammalib.GModelSpatialDiffuseCube()) | ||
| 181 | + #test_support._pickeling(self, gammalib.GModelSpatialDiffuseMap()) | ||
| 182 | + #test_support._pickeling(self, gammalib.GModelSpatialEllipticalDisk()) | ||
| 183 | + #test_support._pickeling(self, gammalib.GModelSpatialEllipticalGauss()) | ||
| 184 | + test_support._pickeling(self, gammalib.GModelSpatialPointSource(ptsrc)) | ||
| 185 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialDisk()) | ||
| 186 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialGauss()) | ||
| 187 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMBurkert()) | ||
| 188 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMEinasto()) | ||
| 189 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMZhao()) | ||
| 190 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileGauss()) | ||
| 191 | + #test_support._pickeling(self, gammalib.GModelSpatialRadialShell()) | ||
| 192 | + test_support._pickeling(self, gammalib.GModelSpectralBrokenPlaw(1.0,-2.0,pivot,-2.1)) | ||
| 193 | + test_support._pickeling(self, gammalib.GModelSpectralComposite(specom)) | ||
| 194 | + test_support._pickeling(self, gammalib.GModelSpectralConst(3.0)) | ||
| 195 | + test_support._pickeling(self, gammalib.GModelSpectralExpInvPlaw(1.0,-2.0,pivot,0.9)) | ||
| 196 | + test_support._pickeling(self, gammalib.GModelSpectralExpPlaw(1.0,-2.0,pivot,pivot)) | ||
| 197 | + test_support._pickeling(self, gammalib.GModelSpectralFunc(fct, 2.0)) | ||
| 198 | + test_support._pickeling(self, gammalib.GModelSpectralGauss(1.0,pivot,pivot)) | ||
| 199 | + test_support._pickeling(self, gammalib.GModelSpectralLogParabola(1.0,-2.0,pivot,0.9)) | ||
| 200 | + test_support._pickeling(self, gammalib.GModelSpectralMultiplicative(spemul)) | ||
| 201 | + test_support._pickeling(self, gammalib.GModelSpectralNodes(nodes)) | ||
| 202 | + test_support._pickeling(self, gammalib.GModelSpectralPlaw(plaw)) | ||
| 203 | + test_support._pickeling(self, gammalib.GModelSpectralPlawEnergyFlux(1.0,-2.0,pivot,pivot)) | ||
| 204 | + test_support._pickeling(self, gammalib.GModelSpectralPlawPhotonFlux(1.0,-2.0,pivot,pivot)) | ||
| 205 | + test_support._pickeling(self, gammalib.GModelSpectralSmoothBrokenPlaw(1.0,-2.0,pivot,-2.1,pivot,0.9)) | ||
| 206 | + test_support._pickeling(self, gammalib.GModelSpectralSuperExpPlaw(1.0,-2.0,pivot,pivot,0.9)) | ||
| 207 | + test_support._pickeling(self, gammalib.GModelTemporalConst(cnst)) | ||
| 208 | + test_support._pickeling(self, gammalib.GModelTemporalLightCurve(lcrv, 2.0)) | ||
| 209 | + test_support._pickeling(self, gammalib.GModelTemporalPhaseCurve(pcrv, time, 0.5, 1.0, 1.0, 1.0, 2.0)) | ||
| 210 | + | ||
| 211 | + # Return | ||
| 212 | + return | ||
| 213 | + | ||
| 109 | # Set test functions | 214 | # Set test functions |
| 110 | def set(self): | 215 | def set(self): |
| 111 | """ | 216 | """ |
| @@ -117,6 +222,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -117,6 +222,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 117 | # Append tests | 222 | # Append tests |
| 118 | self.append(self._test_models_access, 'Test GModels model access') | 223 | self.append(self._test_models_access, 'Test GModels model access') |
| 119 | self.append(self._test_models_slicing, 'Test GModels slicing') | 224 | self.append(self._test_models_slicing, 'Test GModels slicing') |
| 225 | + self.append(self._test_pickeling, 'Test pickeling of "model" classes') | ||
| 120 | 226 | ||
| 121 | # Return | 227 | # Return |
| 122 | return | 228 | return |
test/test_GObservation.py
| 1 | # ========================================================================== | 1 | # ========================================================================== |
| 2 | # This module performs unit tests for the GammaLib observation module. | 2 | # This module performs unit tests for the GammaLib observation module. |
| 3 | # | 3 | # |
| 4 | -# Copyright (C) 2012-2017 Juergen Knoedlseder | 4 | +# Copyright (C) 2012-2018 Juergen Knoedlseder |
| 5 | # | 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by | 7 | # it under the terms of the GNU General Public License as published by |
| @@ -729,6 +729,58 @@ class Test(gammalib.GPythonTestSuite): | @@ -729,6 +729,58 @@ class Test(gammalib.GPythonTestSuite): | ||
| 729 | # Return | 729 | # Return |
| 730 | return | 730 | return |
| 731 | 731 | ||
| 732 | + # Test class pickeling | ||
| 733 | + def _test_pickeling(self): | ||
| 734 | + """ | ||
| 735 | + Test class pickeling | ||
| 736 | + """ | ||
| 737 | + # Perform pickeling tests of empty classes | ||
| 738 | + #test_support._pickeling(self, gammalib.GCaldb()) | ||
| 739 | + test_support._pickeling(self, gammalib.GEbounds()) | ||
| 740 | + test_support._pickeling(self, gammalib.GEnergy()) | ||
| 741 | + test_support._pickeling(self, gammalib.GEnergies()) | ||
| 742 | + test_support._pickeling(self, gammalib.GGti()) | ||
| 743 | + test_support._pickeling(self, gammalib.GObservations()) | ||
| 744 | + test_support._pickeling(self, gammalib.GPhases()) | ||
| 745 | + test_support._pickeling(self, gammalib.GPhoton()) | ||
| 746 | + test_support._pickeling(self, gammalib.GPhotons()) | ||
| 747 | + test_support._pickeling(self, gammalib.GSource()) | ||
| 748 | + test_support._pickeling(self, gammalib.GTime()) | ||
| 749 | + test_support._pickeling(self, gammalib.GTimes()) | ||
| 750 | + test_support._pickeling(self, gammalib.GTimeReference()) | ||
| 751 | + | ||
| 752 | + # Setup for tests | ||
| 753 | + dir = gammalib.GSkyDir() | ||
| 754 | + emin = gammalib.GEnergy(1.0,'TeV') | ||
| 755 | + emax = gammalib.GEnergy(100.0,'TeV') | ||
| 756 | + tmin = gammalib.GTime(1.0,'sec') | ||
| 757 | + tmax = gammalib.GTime(10.0,'sec') | ||
| 758 | + model = gammalib.GModelSpatialPointSource() | ||
| 759 | + photons = gammalib.GPhotons() | ||
| 760 | + photons.append(gammalib.GPhoton()) | ||
| 761 | + photons.append(gammalib.GPhoton()) | ||
| 762 | + times = gammalib.GTimes() | ||
| 763 | + times.append(tmin) | ||
| 764 | + times.append(tmax) | ||
| 765 | + | ||
| 766 | + # Perform pickeling tests of filled classes | ||
| 767 | + #test_support._pickeling(self, gammalib.GCaldb()) | ||
| 768 | + test_support._pickeling(self, gammalib.GEbounds(10, emin, emax)) | ||
| 769 | + test_support._pickeling(self, gammalib.GEnergy(emin)) | ||
| 770 | + test_support._pickeling(self, gammalib.GEnergies(10, emin, emax)) | ||
| 771 | + test_support._pickeling(self, gammalib.GGti(tmin, tmax)) | ||
| 772 | + test_support._pickeling(self, gammalib.GObservations(self._setup_obs())) | ||
| 773 | + test_support._pickeling(self, gammalib.GPhases(0.3, 0.7)) | ||
| 774 | + test_support._pickeling(self, gammalib.GPhoton(dir, emin, tmin)) | ||
| 775 | + test_support._pickeling(self, gammalib.GPhotons(photons)) | ||
| 776 | + test_support._pickeling(self, gammalib.GSource('Crab', model, emin, tmin)) | ||
| 777 | + test_support._pickeling(self, gammalib.GTime(tmin)) | ||
| 778 | + test_support._pickeling(self, gammalib.GTimes(times)) | ||
| 779 | + test_support._pickeling(self, gammalib.GTimeReference(12.345,'sec','utc','local')) | ||
| 780 | + | ||
| 781 | + # Return | ||
| 782 | + return | ||
| 783 | + | ||
| 732 | # Set test functions | 784 | # Set test functions |
| 733 | def set(self): | 785 | def set(self): |
| 734 | """ | 786 | """ |
| @@ -751,6 +803,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -751,6 +803,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 751 | self.append(self._test_times_slicing, 'Test GTimes slicing') | 803 | self.append(self._test_times_slicing, 'Test GTimes slicing') |
| 752 | self.append(self._test_photons_slicing, 'Test GPhotons slicing') | 804 | self.append(self._test_photons_slicing, 'Test GPhotons slicing') |
| 753 | self.append(self._test_observations_slicing, 'Test GObservations slicing') | 805 | self.append(self._test_observations_slicing, 'Test GObservations slicing') |
| 806 | + self.append(self._test_pickeling, 'Test pickeling of "obs" classes') | ||
| 754 | 807 | ||
| 755 | # Return | 808 | # Return |
| 756 | return | 809 | return |
test/test_GOptimizer.py
| 1 | # ========================================================================== | 1 | # ========================================================================== |
| 2 | # This module performs unit tests for the GammaLib optimizer module. | 2 | # This module performs unit tests for the GammaLib optimizer module. |
| 3 | # | 3 | # |
| 4 | -# Copyright (C) 2012-2017 Juergen Knoedlseder | 4 | +# Copyright (C) 2012-2018 Juergen Knoedlseder |
| 5 | # | 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by | 7 | # it under the terms of the GNU General Public License as published by |
| @@ -98,17 +98,31 @@ class Test(gammalib.GPythonTestSuite): | @@ -98,17 +98,31 @@ class Test(gammalib.GPythonTestSuite): | ||
| 98 | # Return | 98 | # Return |
| 99 | return | 99 | return |
| 100 | 100 | ||
| 101 | + # Test class pickeling | ||
| 102 | + def _test_pickeling(self): | ||
| 103 | + """ | ||
| 104 | + Test class pickeling | ||
| 105 | + """ | ||
| 106 | + # Perform pickeling tests | ||
| 107 | + #test_support._pickeling(self, gammalib.GOptimizerLM()) | ||
| 108 | + test_support._pickeling(self, gammalib.GOptimizerPar()) | ||
| 109 | + #test_support._pickeling(self, gammalib.GOptimizerPars()) | ||
| 110 | + | ||
| 111 | + # Return | ||
| 112 | + return | ||
| 113 | + | ||
| 101 | # Set test functions | 114 | # Set test functions |
| 102 | def set(self): | 115 | def set(self): |
| 103 | """ | 116 | """ |
| 104 | - Set all test functions. | 117 | + Set all test functions |
| 105 | """ | 118 | """ |
| 106 | # Set test name | 119 | # Set test name |
| 107 | self.name('opt') | 120 | self.name('opt') |
| 108 | 121 | ||
| 109 | # Append tests | 122 | # Append tests |
| 110 | - self.append(self._test_pars_access, "Test GOptimizerPars parameter access") | ||
| 111 | - self.append(self._test_pars_slicing, "Test GOptimizerPars slicing") | 123 | + self.append(self._test_pars_access, 'Test GOptimizerPars parameter access') |
| 124 | + self.append(self._test_pars_slicing, 'Test GOptimizerPars slicing') | ||
| 125 | + self.append(self._test_pickeling, 'Test pickeling of "opt" classes') | ||
| 112 | 126 | ||
| 113 | # Return | 127 | # Return |
| 114 | return | 128 | return |
test/test_GSky.py
| 1 | # ========================================================================== | 1 | # ========================================================================== |
| 2 | # This module performs unit tests for the GammaLib sky module. | 2 | # This module performs unit tests for the GammaLib sky module. |
| 3 | # | 3 | # |
| 4 | -# Copyright (C) 2012-2017 Juergen Knoedlseder | 4 | +# Copyright (C) 2012-2018 Juergen Knoedlseder |
| 5 | # | 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by | 7 | # it under the terms of the GNU General Public License as published by |
| @@ -550,30 +550,49 @@ class Test(gammalib.GPythonTestSuite): | @@ -550,30 +550,49 @@ class Test(gammalib.GPythonTestSuite): | ||
| 550 | # Return | 550 | # Return |
| 551 | return | 551 | return |
| 552 | 552 | ||
| 553 | + # Test class pickeling | ||
| 554 | + def _test_pickeling(self): | ||
| 555 | + """ | ||
| 556 | + Test class pickeling | ||
| 557 | + """ | ||
| 558 | + # Perform pickeling tests of empty classes | ||
| 559 | + test_support._pickeling(self, gammalib.GSkyDir()) | ||
| 560 | + | ||
| 561 | + # Setup test | ||
| 562 | + dir = gammalib.GSkyDir() | ||
| 563 | + dir.lb_deg(1.0, 2.0) | ||
| 564 | + | ||
| 565 | + # Perform pickeling tests of filled classes | ||
| 566 | + test_support._pickeling(self, gammalib.GSkyDir(dir)) | ||
| 567 | + | ||
| 568 | + # Return | ||
| 569 | + return | ||
| 570 | + | ||
| 553 | def set(self): | 571 | def set(self): |
| 554 | """ | 572 | """ |
| 555 | Set all test functions. | 573 | Set all test functions. |
| 556 | """ | 574 | """ |
| 557 | # Set test name | 575 | # Set test name |
| 558 | - self.name("sky") | 576 | + self.name('sky') |
| 559 | 577 | ||
| 560 | # Append tests | 578 | # Append tests |
| 561 | - self.append(self._test_methods, "Test sky map methods") | ||
| 562 | - self.append(self._test_friend_methods, "Test sky map friend methods") | ||
| 563 | - self.append(self._test_operators, "Test sky map operators") | ||
| 564 | - self.append(self._test_skymap_healpix, "Test HEALPix map") | ||
| 565 | - self.append(self._test_skymap_ait, "Test AIT projection map") | ||
| 566 | - self.append(self._test_skymap_azp, "Test AZP projection map") | ||
| 567 | - self.append(self._test_skymap_car, "Test CAR projection map") | ||
| 568 | - self.append(self._test_skymap_gls, "Test GLS projection map") | ||
| 569 | - self.append(self._test_skymap_mer, "Test MER projection map") | ||
| 570 | - self.append(self._test_skymap_mol, "Test MOL projection map") | ||
| 571 | - self.append(self._test_skymap_sfl, "Test SFL projection map") | ||
| 572 | - self.append(self._test_skymap_sin, "Test SIN projection map") | ||
| 573 | - self.append(self._test_skymap_stg, "Test STG projection map") | ||
| 574 | - self.append(self._test_skymap_tan, "Test TAN projection map") | ||
| 575 | - self.append(self._test_regions_access, "Test GSkyRegions region access") | ||
| 576 | - self.append(self._test_regions_slicing, "Test GSkyRegions slicing") | 579 | + self.append(self._test_methods, 'Test sky map methods') |
| 580 | + self.append(self._test_friend_methods, 'Test sky map friend methods') | ||
| 581 | + self.append(self._test_operators, 'Test sky map operators') | ||
| 582 | + self.append(self._test_skymap_healpix, 'Test HEALPix map') | ||
| 583 | + self.append(self._test_skymap_ait, 'Test AIT projection map') | ||
| 584 | + self.append(self._test_skymap_azp, 'Test AZP projection map') | ||
| 585 | + self.append(self._test_skymap_car, 'Test CAR projection map') | ||
| 586 | + self.append(self._test_skymap_gls, 'Test GLS projection map') | ||
| 587 | + self.append(self._test_skymap_mer, 'Test MER projection map') | ||
| 588 | + self.append(self._test_skymap_mol, 'Test MOL projection map') | ||
| 589 | + self.append(self._test_skymap_sfl, 'Test SFL projection map') | ||
| 590 | + self.append(self._test_skymap_sin, 'Test SIN projection map') | ||
| 591 | + self.append(self._test_skymap_stg, 'Test STG projection map') | ||
| 592 | + self.append(self._test_skymap_tan, 'Test TAN projection map') | ||
| 593 | + self.append(self._test_regions_access, 'Test GSkyRegions region access') | ||
| 594 | + self.append(self._test_regions_slicing, 'Test GSkyRegions slicing') | ||
| 595 | + self.append(self._test_pickeling, 'Test pickeling of "sky" classes') | ||
| 577 | 596 | ||
| 578 | # Return | 597 | # Return |
| 579 | return | 598 | return |
test/test_GSupport.py
| 1 | # ========================================================================== | 1 | # ========================================================================== |
| 2 | # This module performs unit tests for the GammaLib support module. | 2 | # This module performs unit tests for the GammaLib support module. |
| 3 | # | 3 | # |
| 4 | -# Copyright (C) 2012-2017 Juergen Knoedlseder | 4 | +# Copyright (C) 2012-2018 Juergen Knoedlseder |
| 5 | # | 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by | 7 | # it under the terms of the GNU General Public License as published by |
| @@ -19,6 +19,7 @@ | @@ -19,6 +19,7 @@ | ||
| 19 | # ========================================================================== | 19 | # ========================================================================== |
| 20 | import gammalib | 20 | import gammalib |
| 21 | import math | 21 | import math |
| 22 | +import test_support | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | # =============================== # | 25 | # =============================== # |
| @@ -279,6 +280,34 @@ class Test(gammalib.GPythonTestSuite): | @@ -279,6 +280,34 @@ class Test(gammalib.GPythonTestSuite): | ||
| 279 | # Return | 280 | # Return |
| 280 | return | 281 | return |
| 281 | 282 | ||
| 283 | + # Test class pickeling | ||
| 284 | + def _test_pickeling(self): | ||
| 285 | + """ | ||
| 286 | + Test class pickeling | ||
| 287 | + """ | ||
| 288 | + # Perform pickeling tests of empty classes | ||
| 289 | + #test_support._pickeling(self, gammalib.GBilinear()) | ||
| 290 | + #test_support._pickeling(self, gammalib.GCsv()) | ||
| 291 | + test_support._pickeling(self, gammalib.GFilename()) | ||
| 292 | + #test_support._pickeling(self, gammalib.GNodeArray()) | ||
| 293 | + #test_support._pickeling(self, gammalib.GRan()) | ||
| 294 | + #test_support._pickeling(self, gammalib.GUrl()) | ||
| 295 | + #test_support._pickeling(self, gammalib.GUrlFile()) | ||
| 296 | + #test_support._pickeling(self, gammalib.GUrlString()) | ||
| 297 | + | ||
| 298 | + # Perform pickeling tests of filled classes | ||
| 299 | + #test_support._pickeling(self, gammalib.GBilinear()) | ||
| 300 | + #test_support._pickeling(self, gammalib.GCsv()) | ||
| 301 | + test_support._pickeling(self, gammalib.GFilename('test.fits[URL]')) | ||
| 302 | + #test_support._pickeling(self, gammalib.GNodeArray()) | ||
| 303 | + #test_support._pickeling(self, gammalib.GRan()) | ||
| 304 | + #test_support._pickeling(self, gammalib.GUrl()) | ||
| 305 | + #test_support._pickeling(self, gammalib.GUrlFile()) | ||
| 306 | + #test_support._pickeling(self, gammalib.GUrlString()) | ||
| 307 | + | ||
| 308 | + # Return | ||
| 309 | + return | ||
| 310 | + | ||
| 282 | # Set all test functions | 311 | # Set all test functions |
| 283 | def set(self): | 312 | def set(self): |
| 284 | """ | 313 | """ |
| @@ -295,6 +324,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -295,6 +324,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 295 | self.append(self._test_url_string, 'Test GUrlString') | 324 | self.append(self._test_url_string, 'Test GUrlString') |
| 296 | self.append(self._test_filename, 'Test GFilename') | 325 | self.append(self._test_filename, 'Test GFilename') |
| 297 | self.append(self._test_csv, 'Test GCsv') | 326 | self.append(self._test_csv, 'Test GCsv') |
| 327 | + self.append(self._test_pickeling, 'Test pickeling of "support" classes') | ||
| 298 | 328 | ||
| 299 | # Return | 329 | # Return |
| 300 | return | 330 | return |
test/test_GXml.py
| 1 | # ========================================================================== | 1 | # ========================================================================== |
| 2 | # This module performs unit tests for the GammaLib xml module. | 2 | # This module performs unit tests for the GammaLib xml module. |
| 3 | # | 3 | # |
| 4 | -# Copyright (C) 2012-2017 Juergen Knoedlseder | 4 | +# Copyright (C) 2012-2018 Juergen Knoedlseder |
| 5 | # | 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by | 7 | # it under the terms of the GNU General Public License as published by |
| @@ -157,6 +157,32 @@ class Test(gammalib.GPythonTestSuite): | @@ -157,6 +157,32 @@ class Test(gammalib.GPythonTestSuite): | ||
| 157 | # Return | 157 | # Return |
| 158 | return | 158 | return |
| 159 | 159 | ||
| 160 | + # Test class pickeling | ||
| 161 | + def _test_pickeling(self): | ||
| 162 | + """ | ||
| 163 | + Test class pickeling | ||
| 164 | + """ | ||
| 165 | + # Perform pickeling tests of empty classes | ||
| 166 | + test_support._pickeling(self, gammalib.GXml()) | ||
| 167 | + test_support._pickeling(self, gammalib.GXmlAttribute()) | ||
| 168 | + test_support._pickeling(self, gammalib.GXmlComment()) | ||
| 169 | + test_support._pickeling(self, gammalib.GXmlDocument()) | ||
| 170 | + test_support._pickeling(self, gammalib.GXmlElement()) | ||
| 171 | + test_support._pickeling(self, gammalib.GXmlPI()) | ||
| 172 | + test_support._pickeling(self, gammalib.GXmlText()) | ||
| 173 | + | ||
| 174 | + # Perform pickeling tests of filled classes | ||
| 175 | + test_support._pickeling(self, gammalib.GXml('<?xml version="1.0" standalone="no"?><a>Text</a>')) | ||
| 176 | + test_support._pickeling(self, gammalib.GXmlAttribute('name','value')) | ||
| 177 | + test_support._pickeling(self, gammalib.GXmlComment('comment')) | ||
| 178 | + test_support._pickeling(self, gammalib.GXmlDocument('test.xml','a','b','c')) | ||
| 179 | + test_support._pickeling(self, gammalib.GXmlElement('a file="x"')) | ||
| 180 | + test_support._pickeling(self, gammalib.GXmlPI('<?PI?>')) | ||
| 181 | + test_support._pickeling(self, gammalib.GXmlText('Text')) | ||
| 182 | + | ||
| 183 | + # Return | ||
| 184 | + return | ||
| 185 | + | ||
| 160 | # Set test functions | 186 | # Set test functions |
| 161 | def set(self): | 187 | def set(self): |
| 162 | """ | 188 | """ |
| @@ -170,6 +196,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -170,6 +196,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 170 | self.append(self._test_xml_slicing, 'Test GXml slicing') | 196 | self.append(self._test_xml_slicing, 'Test GXml slicing') |
| 171 | self.append(self._test_elements_access, 'Test GXmlElement parameter access') | 197 | self.append(self._test_elements_access, 'Test GXmlElement parameter access') |
| 172 | self.append(self._test_elements_slicing, 'Test GXmlElement slicing') | 198 | self.append(self._test_elements_slicing, 'Test GXmlElement slicing') |
| 199 | + self.append(self._test_pickeling, 'Test pickeling of "xml" classes') | ||
| 173 | 200 | ||
| 174 | # Return | 201 | # Return |
| 175 | return | 202 | return |
test/test_support.py
| 1 | # ========================================================================== | 1 | # ========================================================================== |
| 2 | # This module provides support functions for the Python unit tests | 2 | # This module provides support functions for the Python unit tests |
| 3 | # | 3 | # |
| 4 | -# Copyright (C) 2017 Juergen Knoedlseder | 4 | +# Copyright (C) 2017-2018 Juergen Knoedlseder |
| 5 | # | 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by | 7 | # it under the terms of the GNU General Public License as published by |
| @@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | # | 18 | # |
| 19 | # ========================================================================== | 19 | # ========================================================================== |
| 20 | +import pickle | ||
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | # ============================== # | 23 | # ============================== # |
| @@ -235,3 +236,40 @@ def _energy_container_slicing(testsuite, container): | @@ -235,3 +236,40 @@ def _energy_container_slicing(testsuite, container): | ||
| 235 | 236 | ||
| 236 | # Return | 237 | # Return |
| 237 | return | 238 | return |
| 239 | + | ||
| 240 | + | ||
| 241 | +# ============== # | ||
| 242 | +# Test pickeling # | ||
| 243 | +# ============== # | ||
| 244 | +def _pickeling(testsuite, object): | ||
| 245 | + """ | ||
| 246 | + Test class pickeling | ||
| 247 | + | ||
| 248 | + Parameters | ||
| 249 | + ---------- | ||
| 250 | + testsuite : `~gammalib.GPythonTestSuite` | ||
| 251 | + Test suite class | ||
| 252 | + container : `~gammalib.GBase` | ||
| 253 | + GammaLib class | ||
| 254 | + """ | ||
| 255 | + # Get class name | ||
| 256 | + name = object.classname() | ||
| 257 | + | ||
| 258 | + # Start exception catching | ||
| 259 | + testsuite.test_try('Test pickeling of "%s" class.' % name) | ||
| 260 | + | ||
| 261 | + # Test if pickling results in an exception | ||
| 262 | + try: | ||
| 263 | + dump = pickle.dumps(object) | ||
| 264 | + obj = pickle.loads(dump) | ||
| 265 | + dump_again = pickle.dumps(obj) | ||
| 266 | + testsuite.test_assert(dump == dump_again, | ||
| 267 | + 'Check pickled dump of "%s\n%s\n%s"' % | ||
| 268 | + (name, str(object), str(obj))) | ||
| 269 | + testsuite.test_try_success() | ||
| 270 | + except Exception as e: | ||
| 271 | + testsuite.test_try_failure('Error in pickeling "%s" (%s).' % | ||
| 272 | + (name, str(e))) | ||
| 273 | + | ||
| 274 | + # Return | ||
| 275 | + return |