EleFits  5.3.1
A modern C++ API on top of CFITSIO
Loading...
Searching...
No Matches
Enumerations | Classes
File-level strategies

Detailed Description

Register actions to be performed automatically according to some criteria.

Action!

Often, when reading or writing MEF files, the same actions have to be performed for all or some of the HDUs. For example, each time an HDU is accessed for the first time, the checksums can be validated. And before closing the file, the checksums of the edited HDUs can be updated if present.

Instead of doing so manually, e.g.:

MefFile f(filename, FileMode::Edit);
const auto& p = f.primary();
p.verify_checksums();
... // Do something with Primary
for (const auto& image : f.filter<ImageRaster>()) {
... // Do something with extension
}
for (const auto& h : f.filter<Header>(HduCategory::Edited)) {
if (h.has("CHECKSUM") || h.has("DATASUM")) {
h.update_checksums();
}
}
static const HduCategory Edited
Metadata or data was written.
Definition: HduCategory.h:254
@ Edit
Open an existing file with write permission.

... Actions can be registered in the MefFile and performed automatically:

MefFile f(filename, FileMode::Edit, VerifyChecksums());
const auto& p = f.primary();
... // Do something with Primary
for (const auto& image : f.filter<ImageRaster>(HduCategory::Ext)) {
... // Do something with extensions
}
static const HduCategory Ext
Extension.
Definition: HduCategory.h:230

This removes boilerplate and noise in the code, and guarantees nothing is forgotten. Moreover, HDUs are guaranteed to be visited only once whatever the action count.

Interfaces

Acions are classes which inherit Action and override at least one of its methods, like accessed() or closing(). Each time an action-related event occurs (an HDU is accessed for the first time or the file is being closed), all of the registered actions which override the corresponding method are executed.

The list of actions registered in the MefFile constitutes the so-called strategy.

A specific part of the strategy relates to internal compression: it is possible to specify which compression algorithm to use when creating a new image HDU according to predefined criteria. For more details, refer to Image compression.

Actions (or complete strategies) can be registered at construction, like in the introductory example, or using MefFile::strategy() methods and/or its Strategy instance.

Predefined actions, provided with the library, are listed below.

Enumerations

enum class  UpdateChecksums {
  None ,
  Outdated ,
  EditedHdu ,
  AnyHdu
}
 Checksum update policy of VerifyChecksums. More...
 

Classes

class  Action
 Base class for strategy actions. More...
 
class  CiteEleFits
 An action which cites EleFits in the Primary header as a HISTORY record. More...
 
class  Strategy
 MEF file strategy. More...
 
class  VerifyChecksums
 An action which verifies and possibly updates existing checksums. More...