Skip to content

Commit 0241c70

Browse files
authored
Merge pull request #566 from astrorama/fix/head_files
Add logging to processing of .head files
2 parents 90010ad + 1ed593c commit 0241c70

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

SEFramework/src/lib/FITS/FitsFile.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@
3636
#include <boost/regex.hpp>
3737

3838
#include "ElementsKernel/Exception.h"
39+
#include "ElementsKernel/Logging.h"
40+
3941
#include "SEFramework/FITS/FitsFile.h"
4042

4143
namespace SourceXtractor {
4244

45+
static Elements::Logging logger = Elements::Logging::getLogger("FitsFile");
46+
4347
/**
4448
* Cast a string to a C++ type depending on the format of the content.
4549
* - if only digits are present, it will be casted to int64_t
@@ -69,7 +73,8 @@ static typename MetadataEntry::value_t valueAutoCast(const std::string& value) {
6973
// We used to use boost::io::quoted here, but it seems that starting with 1.73 it
7074
// does not work well when the escape code and the delimiter are the same
7175
std::string unquoted;
72-
bool escape = false;
76+
bool escape = false;
77+
7378
unquoted.reserve(value.size());
7479
for (auto i = value.begin(); i != value.end(); ++i) {
7580
if (*i == '\'' && !escape) {
@@ -264,7 +269,7 @@ void FitsFile::loadHeadFile() {
264269
return;
265270
}
266271

267-
auto hdu_iter = m_image_hdus.begin();
272+
auto hdu_iter = m_image_hdus.begin();
268273
std::ifstream file;
269274

270275
// open the file and check
@@ -273,6 +278,11 @@ void FitsFile::loadHeadFile() {
273278
throw Elements::Exception() << "Cannot load ascii header file: " << head_filename;
274279
}
275280

281+
logger.info() << "Loading .head file: " << head_filename << " for fits: " << m_path;
282+
283+
int headers_nb = 0;
284+
int hdu_nb = 0;
285+
bool is_new_hdu = true;
276286
while (file.good() && hdu_iter != m_image_hdus.end()) {
277287
int current_hdu = *hdu_iter;
278288

@@ -287,6 +297,7 @@ void FitsFile::loadHeadFile() {
287297

288298
if (boost::to_upper_copy(line) == "END") {
289299
current_hdu = *(++hdu_iter);
300+
is_new_hdu = true;
290301
} else {
291302
static boost::regex regex("([^=]{1,8})=([^\\/]*)(\\/ (.*))?");
292303
boost::smatch sub_matches;
@@ -298,10 +309,17 @@ void FitsFile::loadHeadFile() {
298309
boost::trim(value);
299310
boost::trim(comment);
300311
m_headers.at(current_hdu - 1)[keyword] = MetadataEntry{valueAutoCast(value), {{"comment", comment}}};
301-
;
312+
headers_nb++;
313+
if (is_new_hdu) {
314+
hdu_nb++;
315+
is_new_hdu = false;
316+
}
302317
}
303318
}
304319
}
320+
if (headers_nb > 0) {
321+
logger.info() << "Headers overriden: " << headers_nb << " in " << hdu_nb << " hdu(s)";
322+
}
305323
}
306324

307325
std::vector<int> FitsFile::getDimensions(int hdu) const {

0 commit comments

Comments
 (0)