LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
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. More...
 
 ~HduMoveGuard ()
 
void disable ()
 Disable the guard, leaving the HDU at its current state at destruction. More...
 

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 724 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 1683 of file fits.cc.

1683  :
1684  _fits(fits),
1685  _oldHdu(_fits.getHdu()),
1686  _enabled(true)
1687 {
1688  _fits.setHdu(hdu, relative);
1689 }
Fits * fits
Definition: FitsWriter.cc:90
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Definition: fits.cc:512
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
Definition: fits.cc:506

◆ ~HduMoveGuard()

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

Definition at line 1691 of file fits.cc.

1691  {
1692  if (!_enabled) {
1693  return;
1694  }
1695  int status = 0;
1696  std::swap(status, _fits.status); // unset error indicator, but remember the old status
1697  try {
1698  _fits.setHdu(_oldHdu);
1699  } catch (...) {
1700  LOGL_WARN(
1701  "afw.fits",
1702  makeErrorMessage(_fits.fptr, _fits.status, "Failed to move back to HDU %d").c_str(),
1703  _oldHdu
1704  );
1705  }
1706  std::swap(status, _fits.status); // reset the old status
1707 }
T swap(T... args)
#define LOGL_WARN(logger, message...)
Log a warn-level message using a varargs/printf style interface.
Definition: Log.h:536
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Definition: fits.cc:512
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:425

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 751 of file fits.h.

751 { _enabled = false; }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

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