casacore
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::TapeIO Class Reference

More...

#include <TapeIO.h>

Public Member Functions

 TapeIO ()
 Default constructor. More...
 
 TapeIO (int fd)
 Construct from the given file descriptor. More...
 
 TapeIO (const Path &device, Bool writable=False)
 Construct from the given device. More...
 
virtual ~TapeIO ()
 The destructor will only close the file if the appropriate constructor, or attach function, was used. More...
 
void attach (int fd)
 Attach to the given file descriptor. More...
 
void attach (const Path &device, Bool writable=False)
 Attach to the given tape device. More...
 
virtual void write (Int64 size, const void *buf)
 Write the specified number of bytes. More...
 
virtual Int64 read (Int64 size, void *buf, Bool throwException=True)
 Read size bytes from the tape. More...
 
virtual void rewind ()
 Rewind the tape device to the beginning. More...
 
virtual void skip (uInt howMany=1)
 skip the specified number of files (ie tape marks) on the tape. More...
 
virtual void mark (uInt howMany=1)
 write the specified number of filemarks. More...
 
Bool fixedBlocks () const
 returns True if the tape device is configured to use a fixed block size More...
 
uInt fixedBlockSize () const
 returns the block size in bytes. More...
 
void setFixedBlockSize (uInt sizeInBytes)
 Configure the tape device to use fixed length blocks of the specified size. More...
 
void setVariableBlockSize ()
 Configure the tape device to use variable length blocks. More...
 
virtual Int64 length ()
 Get the length of the tape device. More...
 
virtual Bool isReadable () const
 Is the tape device readable? More...
 
virtual Bool isWritable () const
 Is the tape device writable? More...
 
virtual Bool isSeekable () const
 Is the tape device seekable? More...
 
virtual String fileName () const
 Get the name of the attached device or return a zero length string if it cannot be determined. More...
 
- Public Member Functions inherited from casacore::ByteIO
 ByteIO ()
 The constructor does nothing. More...
 
virtual ~ByteIO ()
 
virtual void pwrite (Int64 size, Int64 offset, const void *buf)
 Write size bytes to the byte stream at offset. More...
 
virtual Int64 pread (Int64 size, Int64 offset, void *buf, Bool throwException=True)
 Like read but reads from offset of start of the file The file offset is not changed. More...
 
virtual void reopenRW ()
 Reopen the underlying IO stream for read/write access. More...
 
Int64 seek (Int offset, ByteIO::SeekOption=ByteIO::Begin)
 This function sets the position on the given offset. More...
 
Int64 seek (Int64 offset, ByteIO::SeekOption=ByteIO::Begin)
 
virtual void flush ()
 Flush the data to the file. More...
 
virtual void fsync ()
 Fsync the file (i.e. More...
 
virtual void resync ()
 Resync the file (i.e. More...
 

Static Public Member Functions

static int open (const Path &device, Bool writable=False)
 Some static convenience functions for file descriptor opening & closing. More...
 
static void close (int fd)
 

Protected Member Functions

void detach ()
 Detach the FILE. More...
 
void fillRWFlags ()
 Determine if the file is readable and/or writable. More...
 
void fillSeekable ()
 Determine if the file is seekable. More...
 
virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption)
 Reset the position pointer to the given value. More...
 
- Protected Member Functions inherited from casacore::ByteIO
 ByteIO (const ByteIO &byteIO)
 Make copy constructor and assignment protected, so a user cannot use them (but a derived class can). More...
 
ByteIOoperator= (const ByteIO &byteIO)
 

Private Member Functions

 TapeIO (const TapeIO &that)
 The following functions are made private so that the compiler does not generate default ones. More...
 
TapeIOoperator= (const TapeIO &that)
 
void setBlockSize (uInt sizeInBytes)
 
uInt getBlockSize () const
 

Private Attributes

int itsDevice
 
Bool itsOwner
 
Bool itsReadable
 
Bool itsWritable
 
Bool itsSeekable
 
String itsDeviceName
 

Additional Inherited Members

- Public Types inherited from casacore::ByteIO
enum  OpenOption {
  Old ,
  Update ,
  Append ,
  New ,
  NewNoReplace ,
  Scratch ,
  Delete
}
 Define the possible ByteIO open options. More...
 
enum  SeekOption {
  Begin ,
  Current ,
  End
}
 Define the possible seek options. More...
 

Detailed Description

Class for IO on a tape device

Intended use:

Public interface

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Synopsis

This class is a specialization of class ByteIO. It uses a file descriptor to read/write data.

The file associated with the file descriptor has to be opened before hand. The constructor will determine automatically if the file is readable, writable and seekable. Note that on destruction the file descriptor is NOT closed.

Example

This example shows how FiledesIO can be used with an fd. It uses the fd for a regular file, which could be done in an easier way using class RegularFileIO. However, when using pipes or sockets, this would be the only way.

// Get a file descriptor for the file.
int fd = open ("file.name");
// Use that as the source of AipsIO (which will also use CanonicalIO).
FiledesIO fio (fd);
AipsIO stream (&fio);
// Read the data.
Int vali;
Bool valb;
stream >> vali >> valb;
static int open(const Path &device, Bool writable=False)
Some static convenience functions for file descriptor opening & closing.
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42

Motivation

Make it possible to use the Casacore IO functionality on any file. In this way any device can be hooked to the IO framework.

Definition at line 87 of file TapeIO.h.

Constructor & Destructor Documentation

◆ TapeIO() [1/4]

casacore::TapeIO::TapeIO ( )

Default constructor.

A stream can be attached using the attach function.

◆ TapeIO() [2/4]

casacore::TapeIO::TapeIO ( int  fd)
explicit

Construct from the given file descriptor.

The file descriptor must have been obtained using the TapeIO::open static function. When constructed this way the class will not take over the file descriptor and hence not close the Tape device when this class is destroyed.

◆ TapeIO() [3/4]

casacore::TapeIO::TapeIO ( const Path device,
Bool  writable = False 
)

Construct from the given device.

The device must point to a tape device and if requested it is checked if the device is writeable. Throws an exception if the device could not be opened correctly. When constructed this way the class will close the Tape device when this class is destroyed or the TapeIO object is attached to a new file descriptor.

◆ ~TapeIO()

virtual casacore::TapeIO::~TapeIO ( )
virtual

The destructor will only close the file if the appropriate constructor, or attach function, was used.

◆ TapeIO() [4/4]

casacore::TapeIO::TapeIO ( const TapeIO that)
private

The following functions are made private so that the compiler does not generate default ones.

They cannot be used and are not defined.

Member Function Documentation

◆ attach() [1/2]

void casacore::TapeIO::attach ( const Path device,
Bool  writable = False 
)

Attach to the given tape device.

The tape will be closed when this class is destroyed or the TapeIO object is attached to a new descriptor.

◆ attach() [2/2]

void casacore::TapeIO::attach ( int  fd)

Attach to the given file descriptor.

The file descriptor will not be closed when this class is destroyed.

◆ close()

static void casacore::TapeIO::close ( int  fd)
static

◆ detach()

void casacore::TapeIO::detach ( )
protected

Detach the FILE.

Close it when it is owned.

◆ doSeek()

virtual Int64 casacore::TapeIO::doSeek ( Int64  offset,
ByteIO::SeekOption   
)
protectedvirtual

Reset the position pointer to the given value.

It returns the new position. May not work on all Tape devices use the isSeekable(0 member function to see if this function is usuable. Otherwise an Exception (AipsError) is thrown.

Implements casacore::ByteIO.

◆ fileName()

virtual String casacore::TapeIO::fileName ( ) const
virtual

Get the name of the attached device or return a zero length string if it cannot be determined.

Reimplemented from casacore::ByteIO.

◆ fillRWFlags()

void casacore::TapeIO::fillRWFlags ( )
protected

Determine if the file is readable and/or writable.

◆ fillSeekable()

void casacore::TapeIO::fillSeekable ( )
protected

Determine if the file is seekable.

◆ fixedBlocks()

Bool casacore::TapeIO::fixedBlocks ( ) const

returns True if the tape device is configured to use a fixed block size

◆ fixedBlockSize()

uInt casacore::TapeIO::fixedBlockSize ( ) const

returns the block size in bytes.

Returns zero if the device is configured to use variable length blocks.

◆ getBlockSize()

uInt casacore::TapeIO::getBlockSize ( ) const
private

◆ isReadable()

virtual Bool casacore::TapeIO::isReadable ( ) const
virtual

Is the tape device readable?

Implements casacore::ByteIO.

◆ isSeekable()

virtual Bool casacore::TapeIO::isSeekable ( ) const
virtual

Is the tape device seekable?

Implements casacore::ByteIO.

◆ isWritable()

virtual Bool casacore::TapeIO::isWritable ( ) const
virtual

Is the tape device writable?

Implements casacore::ByteIO.

◆ length()

virtual Int64 casacore::TapeIO::length ( )
virtual

Get the length of the tape device.

Not a meaningful function for this class and this function always returns -1.

Implements casacore::ByteIO.

◆ mark()

virtual void casacore::TapeIO::mark ( uInt  howMany = 1)
virtual

write the specified number of filemarks.

◆ open()

static int casacore::TapeIO::open ( const Path device,
Bool  writable = False 
)
static

Some static convenience functions for file descriptor opening & closing.

The open function returns a file descriptor and the close function requires a file descriptor as an argument.

◆ operator=()

TapeIO& casacore::TapeIO::operator= ( const TapeIO that)
private

◆ read()

virtual Int64 casacore::TapeIO::read ( Int64  size,
void *  buf,
Bool  throwException = True 
)
virtual

Read size bytes from the tape.

Returns the number of bytes actually read or a negative number if an error occured. Will throw an exception (AipsError) if the requested number of bytes could not be read, or an error occured, unless throwException is set to False. Will always throw an exception if the tape is not readable or the system call returns an undocumented value. Returns zero if the tape is at the end of the current file (and size is non-zero and throwException is False).

Implements casacore::ByteIO.

◆ rewind()

virtual void casacore::TapeIO::rewind ( )
virtual

Rewind the tape device to the beginning.

◆ setBlockSize()

void casacore::TapeIO::setBlockSize ( uInt  sizeInBytes)
private

◆ setFixedBlockSize()

void casacore::TapeIO::setFixedBlockSize ( uInt  sizeInBytes)

Configure the tape device to use fixed length blocks of the specified size.

The size must be bigger than zero (dugh!). Values bigger than 64k may cause problems on some systems. Currently this function only does anything under Solaris and Linux systems.

◆ setVariableBlockSize()

void casacore::TapeIO::setVariableBlockSize ( )

Configure the tape device to use variable length blocks.

Currently this function only does anything under Solaris and Linux systems.

◆ skip()

virtual void casacore::TapeIO::skip ( uInt  howMany = 1)
virtual

skip the specified number of files (ie tape marks) on the tape.

Throws an exception if you try to skip past the last filemark.

◆ write()

virtual void casacore::TapeIO::write ( Int64  size,
const void *  buf 
)
virtual

Write the specified number of bytes.

Implements casacore::ByteIO.

Member Data Documentation

◆ itsDevice

int casacore::TapeIO::itsDevice
private

Definition at line 208 of file TapeIO.h.

◆ itsDeviceName

String casacore::TapeIO::itsDeviceName
private

Definition at line 213 of file TapeIO.h.

◆ itsOwner

Bool casacore::TapeIO::itsOwner
private

Definition at line 209 of file TapeIO.h.

◆ itsReadable

Bool casacore::TapeIO::itsReadable
private

Definition at line 210 of file TapeIO.h.

◆ itsSeekable

Bool casacore::TapeIO::itsSeekable
private

Definition at line 212 of file TapeIO.h.

◆ itsWritable

Bool casacore::TapeIO::itsWritable
private

Definition at line 211 of file TapeIO.h.


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