Commit 452c7462fbd4ca7128461ca18a7c9a8c9df6151a

Authored by Jürgen Knödlseder
1 parent 0383e8da

Use GFilename for filename arguments in GEbounds and GGti.

... ... @@ -24,6 +24,14 @@ The following methods have been renamed:
24 24 - GCTAResponseTable::tables(), was formerly GCTAResponseTable::size()
25 25 - GCTAResponseTable::axis_bins(), was formerly GCTAResponseTable::axis()
26 26  
  27 +The following methods now take a GFilename argument instead of std::string:
  28 +- GEbounds(const GFilename&)
  29 +- GEbounds::load()
  30 +- GEbounds::save()
  31 +- GGti(const GFilename&)
  32 +- GGti::load()
  33 +- GGti::save()
  34 +
27 35 The return value has been changed for the following methods:
28 36 - GFits::filename() returns now GFilename instead of std::string
29 37 - GCTAObservation::eventtype() returns now std::string instead of const std::string&
... ...
include/GEbounds.hpp
1 1 /***************************************************************************
2 2 * GEbounds.hpp - Energy boundaries class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2009-2015 by Juergen Knoedlseder *
  4 + * copyright (C) 2009-2016 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -36,6 +36,7 @@
36 36 class GXmlElement;
37 37 class GFits;
38 38 class GFitsTable;
  39 +class GFilename;
39 40  
40 41  
41 42 /***********************************************************************//**
... ... @@ -55,7 +56,7 @@ class GEbounds : public GContainer {
55 56 public:
56 57 // Constructors and destructors
57 58 GEbounds(void);
58   - explicit GEbounds(const std::string& filename);
  59 + explicit GEbounds(const GFilename& filename);
59 60 explicit GEbounds(const GXmlElement& xml);
60 61 GEbounds(const GEbounds& ebds);
61 62 GEbounds(const GEnergy& emin, const GEnergy& emax);
... ... @@ -81,8 +82,8 @@ public:
81 82 void extend(const GEbounds& ebds);
82 83 void set_lin(const int& num, const GEnergy& emin, const GEnergy& emax);
83 84 void set_log(const int& num, const GEnergy& emin, const GEnergy& emax);
84   - void load(const std::string& filename);
85   - void save(const std::string& filename,
  85 + void load(const GFilename& filename);
  86 + void save(const GFilename& filename,
86 87 const bool& clobber = false,
87 88 const std::string& unit = "keV") const;
88 89 void read(const GFitsTable& table);
... ...
include/GGti.hpp
... ... @@ -32,6 +32,7 @@
32 32 #include "GContainer.hpp"
33 33 #include "GTime.hpp"
34 34 #include "GTimeReference.hpp"
  35 +#include "GFilename.hpp"
35 36  
36 37 /* __ Forward declarations _______________________________________________ */
37 38 class GXmlElement;
... ... @@ -58,7 +59,7 @@ class GGti : public GContainer {
58 59 public:
59 60 // Constructors and destructors
60 61 GGti(void);
61   - explicit GGti(const std::string& filename);
  62 + explicit GGti(const GFilename& filename);
62 63 GGti(const GGti& gti);
63 64 GGti(const GTime& tstart, const GTime& tstop);
64 65 explicit GGti(const GXmlElement& xml);
... ... @@ -82,8 +83,8 @@ public:
82 83 void remove(const int& index);
83 84 void reserve(const int& num);
84 85 void extend(const GGti& gti);
85   - void load(const std::string& filename);
86   - void save(const std::string& filename,
  86 + void load(const GFilename& filename);
  87 + void save(const GFilename& filename,
87 88 const bool& clobber = false) const;
88 89 void read(const GFitsTable& table);
89 90 void write(GFits& fits,
... ... @@ -118,7 +119,7 @@ protected:
118 119 GTime *m_start; //!< Array of start times
119 120 GTime *m_stop; //!< Array of stop times
120 121 GTimeReference m_reference; //!< Time reference
121   - std::string m_xml_filename; //!< XML filename
  122 + GFilename m_xml_filename; //!< XML filename
122 123 };
123 124  
124 125  
... ...
pyext/GEbounds.i
1 1 /***************************************************************************
2 2 * GEbounds.i - Energy boundaries class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2015 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2016 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -39,7 +39,7 @@ class GEbounds : public GContainer {
39 39 public:
40 40 // Constructors and destructors
41 41 GEbounds(void);
42   - explicit GEbounds(const std::string& filename);
  42 + explicit GEbounds(const GFilename& filename);
43 43 explicit GEbounds(const GXmlElement& xml);
44 44 GEbounds(const GEbounds& ebds);
45 45 GEbounds(const GEnergy& emin, const GEnergy& emax);
... ... @@ -62,8 +62,8 @@ public:
62 62 void extend(const GEbounds& ebds);
63 63 void set_lin(const int& num, const GEnergy& emin, const GEnergy& emax);
64 64 void set_log(const int& num, const GEnergy& emin, const GEnergy& emax);
65   - void load(const std::string& filename);
66   - void save(const std::string& filename,
  65 + void load(const GFilename& filename);
  66 + void save(const GFilename& filename,
67 67 const bool& clobber = false,
68 68 const std::string& unit = "keV") const;
69 69 void read(const GFitsTable& table);
... ...
pyext/GGti.i
... ... @@ -40,7 +40,7 @@ class GGti : public GBase {
40 40 public:
41 41 // Constructors and destructors
42 42 GGti(void);
43   - explicit GGti(const std::string& filename);
  43 + explicit GGti(const GFilename& filename);
44 44 GGti(const GGti& gti);
45 45 GGti(const GTime& tstart, const GTime& tstop);
46 46 explicit GGti(const GXmlElement& xml);
... ... @@ -61,8 +61,8 @@ public:
61 61 void remove(const int& index);
62 62 void reserve(const int& num);
63 63 void extend(const GGti& gti);
64   - void load(const std::string& filename);
65   - void save(const std::string& filename,
  64 + void load(const GFilename& filename);
  65 + void save(const GFilename& filename,
66 66 const bool& clobber = false) const;
67 67 void read(const GFitsTable& table);
68 68 void write(GFits& fits,
... ...
src/obs/GEbounds.cpp
... ... @@ -83,7 +83,7 @@ GEbounds::GEbounds(void)
83 83 *
84 84 * Constructs energy boundaries from a FITS file.
85 85 ***************************************************************************/
86   -GEbounds::GEbounds(const std::string& filename)
  86 +GEbounds::GEbounds(const GFilename& filename)
87 87 {
88 88 // Initialise members
89 89 init_members();
... ... @@ -576,19 +576,16 @@ void GEbounds::set_log(const int&amp; num, const GEnergy&amp; emin, const GEnergy&amp; emax)
576 576 * If no extension name is provided, the energy boundaries are loaded from
577 577 * the "EBOUNDS" extension.
578 578 ***************************************************************************/
579   -void GEbounds::load(const std::string& filename)
  579 +void GEbounds::load(const GFilename& filename)
580 580 {
581   - // Create file name
582   - GFilename fname(filename);
583   -
584 581 // Allocate FITS file
585 582 GFits file;
586 583  
587 584 // Open FITS file
588   - file.open(fname.filename());
  585 + file.open(filename.filename());
589 586  
590 587 // Get energy boundary table
591   - const GFitsTable& table = *file.table(fname.extname("EBOUNDS"));
  588 + const GFitsTable& table = *file.table(filename.extname("EBOUNDS"));
592 589  
593 590 // Read energy boundaries from table
594 591 read(table);
... ... @@ -613,21 +610,18 @@ void GEbounds::load(const std::string&amp; filename)
613 610 * If no extension name is provided, the energy boundaries are saved into
614 611 * an "EBOUNDS" extension.
615 612 ***************************************************************************/
616   -void GEbounds::save(const std::string& filename,
  613 +void GEbounds::save(const GFilename& filename,
617 614 const bool& clobber,
618 615 const std::string& unit) const
619 616 {
620   - // Create file name
621   - GFilename fname(filename);
622   -
623 617 // Allocate FITS file
624 618 GFits file;
625 619  
626 620 // Write energy boundaries to FITS file
627   - write(file, fname.extname("EBOUNDS"), unit);
  621 + write(file, filename.extname("EBOUNDS"), unit);
628 622  
629 623 // Save to file
630   - file.saveto(fname.filename(), clobber);
  624 + file.saveto(filename.filename(), clobber);
631 625  
632 626 // Return
633 627 return;
... ...
src/obs/GGti.cpp
... ... @@ -62,6 +62,8 @@
62 62  
63 63 /***********************************************************************//**
64 64 * @brief Void constructor
  65 + *
  66 + * Constructs empty Good Time Intervals.
65 67 ***************************************************************************/
66 68 GGti::GGti(void)
67 69 {
... ... @@ -80,7 +82,7 @@ GGti::GGti(void)
80 82 *
81 83 * Constructs Good Time Intervals from a FITS file.
82 84 ***************************************************************************/
83   -GGti::GGti(const std::string& filename)
  85 +GGti::GGti(const GFilename& filename)
84 86 {
85 87 // Initialise members
86 88 init_members();
... ... @@ -97,6 +99,8 @@ GGti::GGti(const std::string&amp; filename)
97 99 * @brief Copy constructor
98 100 *
99 101 * @param[in] gti Good Time Intervals.
  102 + *
  103 + * Constructs Good Time Intervals by coping other Good Time Intervals.
100 104 ***************************************************************************/
101 105 GGti::GGti(const GGti& gti)
102 106 {
... ... @@ -578,19 +582,16 @@ void GGti::extend(const GGti&amp; gti)
578 582 * If no extension name is provided in the @p filename, the Good Time
579 583 * Intervals are loaded from the "GTI" extension.
580 584 ***************************************************************************/
581   -void GGti::load(const std::string& filename)
  585 +void GGti::load(const GFilename& filename)
582 586 {
583   - // Create file name
584   - GFilename fname(filename);
585   -
586 587 // Allocate FITS file
587 588 GFits file;
588 589  
589 590 // Open FITS file
590   - file.open(fname.filename());
  591 + file.open(filename.filename());
591 592  
592 593 // Get GTI table
593   - const GFitsTable& table = *file.table(fname.extname("GTI"));
  594 + const GFitsTable& table = *file.table(filename.extname("GTI"));
594 595  
595 596 // Read GTI from table
596 597 read(table);
... ... @@ -619,16 +620,13 @@ void GGti::load(const std::string&amp; filename)
619 620 * An existing file will only be modified if the @p clobber flag is set to
620 621 * true.
621 622 ***************************************************************************/
622   -void GGti::save(const std::string& filename, const bool& clobber) const
  623 +void GGti::save(const GFilename& filename, const bool& clobber) const
623 624 {
624   - // Create file name
625   - GFilename fname(filename);
626   -
627 625 // Open or create FITS file
628   - GFits fits(fname.filename(), true);
  626 + GFits fits(filename.filename(), true);
629 627  
630 628 // Write GTI to FITS object
631   - write(fits, fname.extname("GTI"));
  629 + write(fits, filename.extname("GTI"));
632 630  
633 631 // Save to file
634 632 fits.save(clobber);
... ... @@ -835,7 +833,7 @@ void GGti::write(GXmlElement&amp; xml) const
835 833 if (!m_xml_filename.empty()) {
836 834  
837 835 // Write "file" attribute
838   - par->attribute("file", m_xml_filename);
  836 + par->attribute("file", m_xml_filename.fullname());
839 837  
840 838 // Write GTI file
841 839 save(m_xml_filename, true);
... ... @@ -1064,7 +1062,7 @@ std::string GGti::print(const GChatter&amp; chatter) const
1064 1062 // Optionally append XML filename
1065 1063 if (!m_xml_filename.empty()) {
1066 1064 result.append("\n"+gammalib::parformat("File name"));
1067   - result.append(m_xml_filename);
  1065 + result.append(m_xml_filename.fullname());
1068 1066 }
1069 1067  
1070 1068 } // endif: chatter was not silent
... ...