Skip to content

Commit d43dc5d

Browse files
authored
Merge pull request #327 from astrorama/feature/new_file_pool
Use Alexandria's FilePool
2 parents e8d8248 + 514d9cd commit d43dc5d

12 files changed

Lines changed: 257 additions & 481 deletions

File tree

SEBenchmarks/src/program/BenchBackgroundModel.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ class BenchBackgroundModel : public Elements::Program {
195195
std::cout << "Elapsed: " << timer.elapsed().wall << std::endl;
196196

197197
TileManager::getInstance()->saveAllTiles();
198-
FitsFileManager::getInstance()->closeAllFiles();
199198

200199
return Elements::ExitCode::OK;
201200
}

SEFramework/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ elements_subdir(SEFramework)
1616
elements_depends_on_subdirs(ElementsKernel)
1717
elements_depends_on_subdirs(Configuration) # From Alexandria
1818
elements_depends_on_subdirs(MathUtils) # From Alexandria
19+
elements_depends_on_subdirs(FilePool) # From Alexandria
1920
elements_depends_on_subdirs(Table)
2021
elements_depends_on_subdirs(SEUtils)
2122
elements_depends_on_subdirs(ModelFitting)
@@ -56,8 +57,9 @@ elements_add_library(SEFramework
5657
src/lib/FITS/*.cpp
5758
src/lib/Frame/*.cpp
5859
src/lib/CoordinateSystem/*.cpp
59-
LINK_LIBRARIES ElementsKernel SEUtils Table Configuration MathUtils WCSLIB
60-
${CCFITS_LIBRARIES} ${FFTW_LIBRARIES}
60+
LINK_LIBRARIES
61+
ElementsKernel SEUtils Table Configuration MathUtils FilePool
62+
WCSLIB ${CCFITS_LIBRARIES} ${FFTW_LIBRARIES}
6163
INCLUDE_DIRS SEUtils ${CCFITS_INCLUDE_DIRS} ${BoostDLL_INCLUDE_DIRS} ${FFTW_INCLUDE_DIRS}
6264
PUBLIC_HEADERS SEFramework)
6365

SEFramework/SEFramework/FITS/FitsFile.h

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
#ifndef _SEFRAMEWORK_FITS_FITSFILE_H_
2626
#define _SEFRAMEWORK_FITS_FITSFILE_H_
2727

28+
#include <boost/filesystem/path.hpp>
29+
#include <fitsio.h>
30+
#include <map>
2831
#include <string>
2932
#include <vector>
30-
#include <map>
31-
32-
#include <fitsio.h>
3333

3434
#include "SEFramework/Image/ImageSourceWithMetadata.h"
35-
#include "SEFramework/FITS/FitsFileManager.h"
3635

3736
namespace SourceXtractor {
3837

@@ -42,57 +41,31 @@ namespace SourceXtractor {
4241
*
4342
*/
4443
class FitsFile {
45-
protected:
46-
FitsFile(const std::string& filename, bool writeable, std::shared_ptr<FitsFileManager> manager);
47-
4844
public:
45+
FitsFile(const boost::filesystem::path& path, bool writeable);
4946

50-
virtual ~FitsFile();
51-
52-
fitsfile* getFitsFilePtr() {
53-
if (!m_is_file_opened) {
54-
open();
55-
}
56-
return m_file_pointer;
57-
}
47+
FitsFile(FitsFile&&) = default;
5848

59-
const std::vector<int>& getImageHdus() const {
60-
return m_image_hdus;
61-
}
49+
virtual ~FitsFile();
6250

63-
std::map<std::string, MetadataEntry>& getHDUHeaders(int hdu) {
64-
return m_headers.at(hdu-1);
65-
}
51+
fitsfile* getFitsFilePtr();
6652

67-
void setWriteMode();
68-
69-
void open();
70-
void close();
53+
const std::vector<int>& getImageHdus() const;
7154

55+
std::map<std::string, MetadataEntry>& getHDUHeaders(int hdu);
7256

7357
private:
74-
void openFirstTime();
75-
void reopen();
76-
77-
void reloadHeaders();
78-
std::map<std::string, MetadataEntry> loadFitsHeader(fitsfile *fptr);
79-
void loadHeadFile();
80-
81-
std::string m_filename;
82-
fitsfile* m_file_pointer;
83-
bool m_is_file_opened;
84-
bool m_is_writeable;
85-
bool m_was_opened_before;
86-
87-
std::vector<int> m_image_hdus;
88-
58+
boost::filesystem::path m_path;
59+
bool m_is_writeable;
60+
std::unique_ptr<fitsfile, void (*)(fitsfile*)> m_fits_ptr;
61+
std::vector<int> m_image_hdus;
8962
std::vector<std::map<std::string, MetadataEntry>> m_headers;
9063

91-
std::shared_ptr<FitsFileManager> m_manager;
92-
93-
friend class FitsFileManager;
64+
void open();
65+
void loadFitsHeader();
66+
void loadHeadFile();
9467
};
9568

96-
}
69+
} // namespace SourceXtractor
9770

9871
#endif /* _SEFRAMEWORK_FITS_FITSFILE_H_ */

SEFramework/SEFramework/FITS/FitsFileManager.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

SEFramework/SEFramework/FITS/FitsImageSource.h

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@
3030

3131
#include <boost/lexical_cast.hpp>
3232

33+
#include "FilePool/FileManager.h"
3334
#include "SEFramework/CoordinateSystem/CoordinateSystem.h"
3435
#include "SEFramework/Image/ImageSourceWithMetadata.h"
35-
#include "SEFramework/FITS/FitsFileManager.h"
3636
#include "SEFramework/FITS/FitsFile.h"
3737
#include "SEUtils/VariantCast.h"
3838

3939

4040
namespace SourceXtractor {
4141

42-
class FitsImageSource : public ImageSource, public std::enable_shared_from_this<ImageSource> {
42+
using Euclid::FilePool::FileManager;
43+
using Euclid::FilePool::FileHandler;
44+
45+
class FitsImageSource : public ImageSource, public std::enable_shared_from_this<ImageSource> {
4346
public:
4447

4548

@@ -51,12 +54,16 @@ class FitsImageSource : public ImageSource, public std::enable_shared_from_this<
5154
* HDU number. If <= 0, the constructor will use the first HDU containing an image
5255
* @param manager
5356
*/
54-
FitsImageSource(const std::string &filename, int hdu_number = 0, ImageTile::ImageType image_type = ImageTile::AutoType,
55-
std::shared_ptr<FitsFileManager> manager = FitsFileManager::getInstance());
57+
FitsImageSource(const std::string& filename, int hdu_number = 0,
58+
ImageTile::ImageType image_type = ImageTile::AutoType,
59+
std::shared_ptr<FileManager> manager = FileManager::getDefault());
5660

57-
FitsImageSource(const std::string &filename, int width, int height, ImageTile::ImageType image_type,
58-
const std::shared_ptr<CoordinateSystem> coord_system = nullptr, bool append=false,
59-
bool empty_primary=false, std::shared_ptr<FitsFileManager> manager = FitsFileManager::getInstance());
61+
FitsImageSource(const std::string& filename, int width, int height,
62+
ImageTile::ImageType image_type,
63+
const std::shared_ptr<CoordinateSystem> coord_system = nullptr,
64+
bool append = false,
65+
bool empty_primary = false,
66+
std::shared_ptr<FileManager> manager = FileManager::getDefault());
6067

6168
virtual ~FitsImageSource() = default;
6269

@@ -70,15 +77,15 @@ class FitsImageSource : public ImageSource, public std::enable_shared_from_this<
7077
}
7178

7279
/// Returns the height of the image in pixels
73-
int getHeight() const override {
80+
int getHeight() const override {
7481
return m_height;
7582
}
7683

7784
std::shared_ptr<ImageTile> getImageTile(int x, int y, int width, int height) const override;
7885

7986
void saveTile(ImageTile& tile) override;
8087

81-
template <typename TT>
88+
template<typename TT>
8289
bool readFitsKeyword(const std::string& header_keyword, TT& out_value) const {
8390
auto& headers = getMetadata();
8491
auto i = headers.find(header_keyword);
@@ -99,21 +106,19 @@ class FitsImageSource : public ImageSource, public std::enable_shared_from_this<
99106

100107
std::unique_ptr<std::vector<char>> getFitsHeaders(int& number_of_records) const;
101108

102-
const std::map<std::string, MetadataEntry> getMetadata() const override {
103-
return m_fits_file->getHDUHeaders(m_hdu_number);
104-
}
109+
const std::map<std::string, MetadataEntry> getMetadata() const override;
105110

106111
void setMetadata(std::string key, MetadataEntry value) override;
107112

108113
private:
109-
void switchHdu(fitsfile* fptr, int hdu_number) const;
114+
void switchHdu(fitsfile *fptr, int hdu_number) const;
110115

111116
int getDataType() const;
117+
112118
int getImageType() const;
113119

114120
std::string m_filename;
115-
std::shared_ptr<FitsFile> m_fits_file;
116-
std::shared_ptr<FitsFileManager> m_manager;
121+
std::shared_ptr<FileHandler> m_handler;
117122

118123
int m_hdu_number;
119124

SEFramework/SEFramework/Image/ImageSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ImageSource {
7676
*/
7777
virtual const std::map<std::string, MetadataEntry> getMetadata() const { return {}; };
7878

79-
virtual void setMetadata(std::string /* key */, MetadataEntry /* value */) {}
79+
virtual void setMetadata(std::string /*key*/, MetadataEntry /*value*/) {}
8080

8181
private:
8282

0 commit comments

Comments
 (0)