Loading...
Searching...
No Matches
casacore::BucketFile Class Reference
casa package (libcasa_casa) » IO_module » IO_module_internal_classes

More...

`#include <BucketFile.h>`

## Public Member Functions

| BucketFile (const String &fileName, uInt bufSizeFile=0, Bool mappedFile=False, const std::shared_ptr< MultiFileBase > &mfile=std::shared_ptr< MultiFileBase >())
| Create a BucketFile object for a new file.
| BucketFile (const String &fileName, Bool writable, uInt bufSizeFile=0, Bool mappedFile=False, const std::shared_ptr< MultiFileBase > &mfile=std::shared_ptr< MultiFileBase >())
| Create a BucketFile object for an existing file.
virtual | ~BucketFile ()
| The destructor closes the file (if open).
| BucketFile (const BucketFile &)=delete
| Forbid copy constructor.
BucketFile & | operator= (const BucketFile &)=delete
| Forbid assignment.
virtual std::shared_ptr< ByteIO > | makeFilebufIO (uInt bufferSize)
| Make a (temporary) buffered IO object for this file.
MMapfdIO * | mappedFile ()
| Get the mapped file object.
FilebufIO * | bufferedFile ()
| Get the buffered file object.
virtual void | open ()
| Open the file if not open yet.
virtual void | close ()
| Close the file (if open).
virtual void | remove ()
| Remove the file (and close it if needed).
virtual void | fsync ()
| Fsync the file (i.e.
virtual void | setRW ()
| Set the file to read/write access.
virtual const String & | name () const
| Get the file name.
Bool | isWritable () const
| Has the file logically been indicated as writable?
virtual uInt | read (void *buffer, uInt length)
| Read bytes from the file.
virtual uInt | write (const void *buffer, uInt length)
| Write bytes into the file.
virtual void | seek (Int64 offset)
| Seek in the file.
void | seek (Int offset)
virtual Int64 | fileSize () const
| Get the (physical) size of the file.
Bool | isCached () const
| Is the file cached, mapped, or buffered?
Bool | isMapped () const
Bool | isBuffered () const

## Private Member Functions

void | createMapBuf ()
| Create the mapped or buffered file object.
void | deleteMapBuf ()
| Delete the possible mapped or buffered file object.

## Private Attributes

String | name_p
| The file name.
Bool | isWritable_p
| The (logical) writability of the file.
Bool | isMapped_p
uInt | bufSize_p
int | fd_p
std::shared_ptr< ByteIO > | file_p
| The unbuffered file.
MMapfdIO * | mappedFile_p
| The optional mapped file.
FilebufIO * | bufferedFile_p
| The optional buffered file.
std::shared_ptr< MultiFileBase > | mfile_p
| The possibly used MultiFileBase.

## Detailed Description

File object for BucketCache.

### Intended use:

Internal

### Review Status

Reviewed By:
  UNKNOWN
Date Reviewed:
  before2004/08/25

### Etymology

BucketFile represents a data file for the BucketCache class.

### Synopsis

A BucketFile object represents a data file. Currently it is used by the Table system, but it can easily be turned into a more general storage manager file class.
Creation of a BucketFile object does not open the file yet. An explicit open call has to be given before the file can be used.

The file can be opened as an ordinary file (with a file descriptor) or as a file in a MultiFileBase object. An ordinary file can be accessed in 3 ways:

- In an unbuffered way, where the parent BucketCache class accesses a bucket at a time (and possibly keeps it in a cache).
- In a memory-mapped way, where the parent BucketMapped class does the access using the MMapfdIO member.
- In a buffered way, where the parent BucketBuffered class does the access using the FilebufIO member.

A MultiFileBase file can only be accessed in the unbuffered way.

### Motivation

Encapsulate the file creation and access into a single class to hide the file IO details.

### Example

// Create the file for the given storage manager.
BucketFile file ("file.name");
// Open the file and write into it.
file.open();
file.write (someBuffer, someLength);
// Get the length of the file.
uInt size = file.fileSize();
casacore::BucketFile::BucketFile
BucketFile(const String &fileName, uInt bufSizeFile=0, Bool mappedFile=False, const std::shared_ptr< MultiFileBase > &mfile=std::shared_ptr< MultiFileBase >())
Create a BucketFile object for a new file.
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::size
uInt size() const
Definition RecordInterface.h:224

### To Do

- Use the ByteIO classes when they are ready.

Definition at line 104 of file BucketFile.h.

## Constructor & Destructor Documentation

## BucketFile() [1/3]

casacore::BucketFile::BucketFile | ( | const String & | fileName,
|  | uInt | bufSizeFile = 0,
|  | Bool | mappedFile = False,
|  | const std::shared_ptr< MultiFileBase > & | mfile = std::shared_ptr< MultiFileBase >() )

explicit

Create a BucketFile object for a new file.

The file with the given name will be created as a normal file or as part of a MultiFileBase (if mfile != 0). It can be indicated if a MMapfdIO and/or FilebufIO object must be created for the file. If a MultiFileBase is used, memory-mapped IO cannot be used and mappedFile is ignored.

References casacore::False, and mappedFile().

Referenced by BucketFile(), and operator=().

## BucketFile() [2/3]

casacore::BucketFile::BucketFile | ( | const String & | fileName,
|  | Bool | writable,
|  | uInt | bufSizeFile = 0,
|  | Bool | mappedFile = False,
|  | const std::shared_ptr< MultiFileBase > & | mfile = std::shared_ptr< MultiFileBase >() )

Create a BucketFile object for an existing file.

The file should be opened by the open. Tell if the file must be opened writable. It can be indicated if a MMapfdIO and/or FilebufIO object must be created for the file. If a MultiFileBase is used, memory-mapped IO cannot be used and mappedFile is ignored.

References casacore::False, and mappedFile().

## ~BucketFile()

virtual casacore::BucketFile::~BucketFile | ( |  | ) |

virtual

The destructor closes the file (if open).

## BucketFile() [3/3]

casacore::BucketFile::BucketFile | ( | const BucketFile & |  | ) |

delete

Forbid copy constructor.

References BucketFile().

## Member Function Documentation

## bufferedFile()

FilebufIO * casacore::BucketFile::bufferedFile | ( |  | ) |

inline

Get the buffered file object.

Definition at line 145 of file BucketFile.h.

References bufferedFile_p.

## close()

virtual void casacore::BucketFile::close | ( |  | ) |

virtual

Close the file (if open).

## createMapBuf()

void casacore::BucketFile::createMapBuf | ( |  | ) |

private

Create the mapped or buffered file object.

## deleteMapBuf()

void casacore::BucketFile::deleteMapBuf | ( |  | ) |

private

Delete the possible mapped or buffered file object.

## fileSize()

virtual Int64 casacore::BucketFile::fileSize | ( |  | ) | const

virtual

Get the (physical) size of the file.

This is doing a seek and sets the file pointer to end-of-file.

## fsync()

virtual void casacore::BucketFile::fsync | ( |  | ) |

virtual

Fsync the file (i.e.

force the data to be physically written).

## isBuffered()

Bool casacore::BucketFile::isBuffered | ( |  | ) | const

inline

Definition at line 232 of file BucketFile.h.

References bufSize_p.

## isCached()

Bool casacore::BucketFile::isCached | ( |  | ) | const

inline

Is the file cached, mapped, or buffered?

Definition at line 228 of file BucketFile.h.

References bufSize_p, and isMapped_p.

## isMapped()

Bool casacore::BucketFile::isMapped | ( |  | ) | const

inline

Definition at line 230 of file BucketFile.h.

References isMapped_p.

## isWritable()

Bool casacore::BucketFile::isWritable | ( |  | ) | const

inline

Has the file logically been indicated as writable?

Definition at line 222 of file BucketFile.h.

References isWritable_p.

## makeFilebufIO()

virtual std::shared_ptr< ByteIO > casacore::BucketFile::makeFilebufIO | ( | uInt | bufferSize | ) |

virtual

Make a (temporary) buffered IO object for this file.

That object should not close the file.

## mappedFile()

MMapfdIO * casacore::BucketFile::mappedFile | ( |  | ) |

inline

Get the mapped file object.

Definition at line 141 of file BucketFile.h.

References mappedFile_p.

Referenced by BucketFile(), and BucketFile().

## name()

const String & casacore::BucketFile::name | ( |  | ) | const

inline virtual

Get the file name.

Definition at line 219 of file BucketFile.h.

References name_p.

## open()

virtual void casacore::BucketFile::open | ( |  | ) |

virtual

Open the file if not open yet.

## operator=()

BucketFile & casacore::BucketFile::operator= | ( | const BucketFile & |  | ) |

delete

Forbid assignment.

References BucketFile().

## read()

virtual uInt casacore::BucketFile::read | ( | void * | buffer,
|  | uInt | length )

virtual

Read bytes from the file.

References casacore::length().

## remove()

virtual void casacore::BucketFile::remove | ( |  | ) |

virtual

Remove the file (and close it if needed).

## seek() [1/2]

void casacore::BucketFile::seek | ( | Int | offset | ) |

inline

Definition at line 225 of file BucketFile.h.

References casacore::offset(), and seek().

## seek() [2/2]

virtual void casacore::BucketFile::seek | ( | Int64 | offset | ) |

virtual

Seek in the file.

References casacore::offset().

Referenced by seek().

## setRW()

virtual void casacore::BucketFile::setRW | ( |  | ) |

virtual

Set the file to read/write access.

It is reopened if not writable. It does nothing if the file is already writable.

## write()

virtual uInt casacore::BucketFile::write | ( | const void * | buffer,
|  | uInt | length )

virtual

Write bytes into the file.

References casacore::length().

## Member Data Documentation

## bufferedFile_p

FilebufIO* casacore::BucketFile::bufferedFile_p

private

The optional buffered file.

Definition at line 206 of file BucketFile.h.

Referenced by bufferedFile().

## bufSize_p

uInt casacore::BucketFile::bufSize_p

private

Definition at line 199 of file BucketFile.h.

Referenced by isBuffered(), and isCached().

## fd_p

int casacore::BucketFile::fd_p

private

Definition at line 200 of file BucketFile.h.

## file_p

std::shared_ptr<ByteIO> casacore::BucketFile::file_p

private

The unbuffered file.

Definition at line 202 of file BucketFile.h.

## isMapped_p

Bool casacore::BucketFile::isMapped_p

private

Definition at line 198 of file BucketFile.h.

Referenced by isCached(), and isMapped().

## isWritable_p

Bool casacore::BucketFile::isWritable_p

private

The (logical) writability of the file.

Definition at line 197 of file BucketFile.h.

Referenced by isWritable().

## mappedFile_p

MMapfdIO* casacore::BucketFile::mappedFile_p

private

The optional mapped file.

Definition at line 204 of file BucketFile.h.

Referenced by mappedFile().

## mfile_p

std::shared_ptr<MultiFileBase> casacore::BucketFile::mfile_p

private

The possibly used MultiFileBase.

Definition at line 208 of file BucketFile.h.

## name_p

String casacore::BucketFile::name_p

private

The file name.

Definition at line 195 of file BucketFile.h.

Referenced by name().

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

- casa/IO/BucketFile.h