SourceXtractorPlusPlus  0.12
Please provide a description of the project.
FitsFileManager.cpp
Go to the documentation of this file.
1 
17 /*
18  * FitsFileManager.cpp
19  *
20  * Created on: Sep 19, 2019
21  * Author: mschefer
22  */
23 
24 #include <iostream>
25 #include <assert.h>
26 
28 
30 
32 
33 namespace SourceXtractor {
34 
36 
37 FitsFileManager::FitsFileManager(unsigned int max_open_files) : m_max_open_files(max_open_files) {
38 }
39 
41  closeAllFiles();
42 }
43 
45  for (auto& file : m_fits_files) {
46  file.second->close();
47  }
48 }
49 
51  if (m_fits_files.find(filename) != m_fits_files.end()) {
52  auto fits_file = m_fits_files.at(filename);
53  if (writeable) {
54  fits_file->setWriteMode();
55  }
56 
57  return fits_file;
58  } else {
59  auto new_fits_file = std::shared_ptr<FitsFile>(new FitsFile(filename, writeable, shared_from_this()));
60  m_fits_files[filename] = new_fits_file;
61  return new_fits_file;
62  }
63 }
64 
65 
67  while (m_open_files.size() > m_max_open_files) {
68  auto& file_to_close = m_fits_files[m_open_files.back()];
69  file_to_close->close();
71  }
72 }
73 
74 }
std::shared_ptr< FitsFile > getFitsFile(const std::string &filename, bool writeable=false)
static std::shared_ptr< FitsFileManager > s_instance
STL class.
string filename
Definition: conf.py:63
T pop_back(T... args)
represents access to a whole FITS file and handles loading and caching FITS headers ...
Definition: FitsFile.h:44
std::list< std::string > m_open_files
T size(T... args)
T back(T... args)
FitsFileManager(unsigned int max_open_files=500)
std::unordered_map< std::string, std::shared_ptr< FitsFile > > m_fits_files