LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+b2075782a9,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g3ddfee87b4+a60788ef87,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+a60788ef87,g591dd9f2cf+ba8caea58f,g5ec818987f+864ee9cddb,g858d7b2824+9ee1ab4172,g876c692160+a40945ebb7,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+5e309b7bc6,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+aa12a14d27,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+d0da15e3be,gba4ed39666+1ac82b564f,gbb8dafda3b+5dfd9c994b,gbeb006f7da+97157f9740,gc28159a63d+c6dfa2ddaf,gc86a011abf+9ee1ab4172,gcf0d15dbbd+a60788ef87,gdaeeff99f8+1cafcb7cd4,gdc0c513512+9ee1ab4172,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,geb961e4c1e+f9439d1e6f,gee10cc3b42+90ebb246c7,gf1cff7945b+9ee1ab4172,w.2024.12
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | List of all members
lsst::afw::fits::HduMoveGuard Class Reference

RAII scoped guard for moving the HDU in a Fits object. More...

#include <fits.h>

Public Member Functions

 HduMoveGuard ()=delete
 
 HduMoveGuard (HduMoveGuard const &)=delete
 
 HduMoveGuard (HduMoveGuard &&)=delete
 
HduMoveGuardoperator= (HduMoveGuard const &)=delete
 
HduMoveGuardoperator= (HduMoveGuard &&)=delete
 
 HduMoveGuard (Fits &fits, int hdu, bool relative=false)
 Create a guard object and set the HDU of the given Fits object at the same time.
 
 ~HduMoveGuard ()
 
void disable ()
 Disable the guard, leaving the HDU at its current state at destruction.
 

Detailed Description

RAII scoped guard for moving the HDU in a Fits object.

This class attempts to ensure that the HDU state of a Fits object is restored when the guard class goes out of scope, even in the presence of exceptions. (In practice, resetting the HDU can only fail if the Fits object has become sufficiently corrupted that it's no longer usable at all).

Definition at line 782 of file fits.h.

Constructor & Destructor Documentation

◆ HduMoveGuard() [1/4]

lsst::afw::fits::HduMoveGuard::HduMoveGuard ( )
delete

◆ HduMoveGuard() [2/4]

lsst::afw::fits::HduMoveGuard::HduMoveGuard ( HduMoveGuard const & )
delete

◆ HduMoveGuard() [3/4]

lsst::afw::fits::HduMoveGuard::HduMoveGuard ( HduMoveGuard && )
delete

◆ HduMoveGuard() [4/4]

lsst::afw::fits::HduMoveGuard::HduMoveGuard ( Fits & fits,
int hdu,
bool relative = false )

Create a guard object and set the HDU of the given Fits object at the same time.

Parameters
[in,out]fitsFITS file pointer to manipulate.
[in]hduHDU index moved to within the lifetime of the guard object (0 is primary).
[in]relativeIf True, interpret hdu as relative to the current HDU rather than an absolute index.

Definition at line 1741 of file fits.cc.

1741 :
1742 _fits(fits),
1743 _oldHdu(_fits.getHdu()),
1744 _enabled(true)
1745{
1746 _fits.setHdu(hdu, relative);
1747}
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Definition fits.cc:524
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
Definition fits.cc:518

◆ ~HduMoveGuard()

lsst::afw::fits::HduMoveGuard::~HduMoveGuard ( )

Definition at line 1749 of file fits.cc.

1749 {
1750 if (!_enabled) {
1751 return;
1752 }
1753 int status = 0;
1754 std::swap(status, _fits.status); // unset error indicator, but remember the old status
1755 try {
1756 _fits.setHdu(_oldHdu);
1757 } catch (...) {
1758 LOGL_WARN(
1759 "afw.fits",
1760 makeErrorMessage(_fits.fptr, _fits.status, "Failed to move back to HDU %d").c_str(),
1761 _oldHdu
1762 );
1763 }
1764 std::swap(status, _fits.status); // reset the old status
1765}
#define LOGL_WARN(logger, message...)
Log a warn-level message using a varargs/printf style interface.
Definition Log.h:547
T c_str(T... args)
std::string makeErrorMessage(std::string const &fileName="", int status=0, std::string const &msg="")
Return an error message reflecting FITS I/O errors.
Definition fits.cc:431
T swap(T... args)

Member Function Documentation

◆ disable()

void lsst::afw::fits::HduMoveGuard::disable ( )
inline

Disable the guard, leaving the HDU at its current state at destruction.

Definition at line 809 of file fits.h.

809{ _enabled = false; }

◆ operator=() [1/2]

HduMoveGuard & lsst::afw::fits::HduMoveGuard::operator= ( HduMoveGuard && )
delete

◆ operator=() [2/2]

HduMoveGuard & lsst::afw::fits::HduMoveGuard::operator= ( HduMoveGuard const & )
delete

The documentation for this class was generated from the following files: