casa
$Rev:20696$
|
SDDBlock handles the IO and value extraction from SDD records (blocks). More...
#include <SDDBlock.h>
Public Types | |
enum | { STANDARD_RECORD_SIZE } |
SDD files have traditionally been composed of 512 byte records, but they are not not really required to be. More... | |
Public Member Functions | |
SDDBlock (uInt n=1, uInt bytesPerRecord=STANDARD_RECORD_SIZE) | |
An SDDBlock with the indicated number of SDD records, each record having the indicated size in bytes, the whole thing filled with zeros. | |
SDDBlock (const SDDBlock &other) | |
copy constructor, this makes a true copy. | |
~SDDBlock () | |
SDDBlock & | operator= (const SDDBlock &other) |
assignment operator, this makes a true copy | |
uInt | nRecords () const |
return the size in SDD records | |
uInt | nbytes () const |
return the number of bytes | |
uInt | bytesPerRecord () const |
return the number of bytes per record | |
void | resize (uInt nRecords, Bool forceSmaller=False, Bool copyElements=False) |
resize this block to the indicated number of SDD records forceSmaller and copyElements work as with the Block class | |
void | reshape (uInt nRecords, uInt bytesPerRecord, Bool forceSmaller=False, Bool copyElements=False) |
reshape is like resize, except that the number of bytes per record can also change. | |
uInt | read (istream &in) |
read from istream and fill until this SDDBlock is full or istream is exhausted return the number of records actually read | |
uInt | read (istream &in, uInt nrecord, uInt startRecord=0) |
read nrecord records from istream, filling starting at the indicated record stop if istream is exhausted, return the number of records actually read | |
uInt | readBytes (istream &in, uInt nbytes, uInt startOffset=0) |
read the indicated number of bytes from in, starting at the optionally indicated starting bytes offset, returns the number of bytes actually read | |
uInt | write (ostream &out) const |
write the entire SDDBlock to ostream, return the number of records written | |
uInt | write (ostream &out, uInt nrecord, uInt startRecord=0) const |
write nrecord records to ostream, starting at the indicated record return the number of records written | |
uInt | writeBytes (ostream &out, uInt nbytes, uInt startOffset=0) const |
write the indicated number of bytes to out, starting at the optionally indicated starting byte offset, returns the number of bytes actually written | |
void | copy (SDDBlock &outBlock, uInt ncopy, uInt outStart=0, uInt inStart=0) const |
copy ncopy character to another SDDBlock starting at outStart (characters) offset into and starting at inStart (characters) offset into this blcck | |
Char & | operator[] (uInt index) |
index into the block | |
const Char & | operator[] (uInt index) const |
Short & | asShort (uInt index) |
Index into the block as Shorts (0-based) | |
const Short & | asShort (uInt index) const |
Int & | asInt (uInt location) |
Index into the block as Ints (0-based) | |
const Int & | asInt (uInt location) const |
float & | asfloat (uInt location) |
Index into the block as floats (0-based) | |
const float & | asfloat (uInt location) const |
double & | asdouble (uInt location) |
Index into the block as doubles (0-based) | |
const double & | asdouble (uInt location) const |
Private Member Functions | |
void | set_pointers () |
Private Attributes | |
Block< Char > * | cblk_p |
Short * | sarray |
Int * | iarray |
float * | farray |
double * | darray |
uInt | bytesPerRecord_p |
SDDBlock handles the IO and value extraction from SDD records (blocks).
Internal
SDD stands for Single Dish Data. It is the data format that UniPOPS understands. It is also the on-line data format at the NRAO 12m. SDD files are organized in records or blocks. This class handles the io to and from those blocks. it is used by the other SDD classes.
SDDBlock is used primarily to handle the IO to and from an SDD file in units of an SDD record size. The standard rccord size if 512 bytes although this class can handle arbitrarily sized records so long as the size is an integer multiple of 8 bytes (the size of and IEEE double precision floating point number). The total size of an SDDBlock is an integer multiple of the record size (i.e. no fractional records are allowed). This class also aids in extracting values of different types from the block. This is not likely to be immediately portable. However, by isolating that conversion here, it should make any future ports easier. Since SDD files will only ever be written on Suns, its unlikely that this issue will be a problem.
The IO only involves iostreams and not fstream. It is intended that the public SDD classes handle all of the fstream specific operations and that this class does not need to do any seeks.
An SDDBlock is always at least 1 SDD record in size.
This is a somewhat contrived example.
// This istream would be initialized appropriately istream in; // construct an SDDBlock of 1 SDD record using the standard record size SDDBlock block; block.read(in, 1); // Extract the 5th double from the record, which indicates the size // of the full record to read in bytes, convert that to SDD records // read it in. This would need some additional checks if partial // records might be indicated. double fullSize = block.asdouble(4); uInt nrecs = uInt(fullSize/block.bytesPerRecord()); // read the remaining records block.read(in, (nrecs-1));
SDD files are organized into units that are integer number of records (always of 512 bytes at this point in history, but they could theoretically be of a different size). It makes sense to have a class that the other SDD classes could use to deal with the data in those chunks.
Definition at line 121 of file SDDBlock.h.
anonymous enum |
SDD files have traditionally been composed of 512 byte records, but they are not not really required to be.
Definition at line 126 of file SDDBlock.h.
SDDBlock::SDDBlock | ( | uInt | n = 1 , |
uInt | bytesPerRecord = STANDARD_RECORD_SIZE |
||
) |
An SDDBlock with the indicated number of SDD records, each record having the indicated size in bytes, the whole thing filled with zeros.
SDDBlock::SDDBlock | ( | const SDDBlock & | other | ) |
copy constructor, this makes a true copy.
double & SDDBlock::asdouble | ( | uInt | location | ) | [inline] |
Index into the block as doubles (0-based)
Definition at line 284 of file SDDBlock.h.
const double & SDDBlock::asdouble | ( | uInt | location | ) | const [inline] |
Definition at line 296 of file SDDBlock.h.
float & SDDBlock::asfloat | ( | uInt | location | ) | [inline] |
Index into the block as floats (0-based)
Definition at line 260 of file SDDBlock.h.
const float & SDDBlock::asfloat | ( | uInt | location | ) | const [inline] |
Definition at line 272 of file SDDBlock.h.
Int & SDDBlock::asInt | ( | uInt | location | ) | [inline] |
Index into the block as Ints (0-based)
Definition at line 235 of file SDDBlock.h.
const Int & SDDBlock::asInt | ( | uInt | location | ) | const [inline] |
Definition at line 247 of file SDDBlock.h.
Short & SDDBlock::asShort | ( | uInt | index | ) | [inline] |
Index into the block as Shorts (0-based)
Definition at line 211 of file SDDBlock.h.
const Short & SDDBlock::asShort | ( | uInt | index | ) | const [inline] |
Definition at line 223 of file SDDBlock.h.
uInt SDDBlock::bytesPerRecord | ( | ) | const [inline] |
return the number of bytes per record
Definition at line 144 of file SDDBlock.h.
References bytesPerRecord_p.
void SDDBlock::copy | ( | SDDBlock & | outBlock, |
uInt | ncopy, | ||
uInt | outStart = 0 , |
||
uInt | inStart = 0 |
||
) | const [inline] |
copy ncopy character to another SDDBlock starting at outStart (characters) offset into and starting at inStart (characters) offset into this blcck
Definition at line 363 of file SDDBlock.h.
uInt SDDBlock::nbytes | ( | ) | const [inline] |
return the number of bytes
Definition at line 142 of file SDDBlock.h.
References cblk_p.
Referenced by copy(), and writeBytes().
uInt SDDBlock::nRecords | ( | ) | const [inline] |
return the size in SDD records
Definition at line 140 of file SDDBlock.h.
References bytesPerRecord_p, and cblk_p.
Char& SDDBlock::operator[] | ( | uInt | index | ) | [inline] |
const Char& SDDBlock::operator[] | ( | uInt | index | ) | const [inline] |
Definition at line 184 of file SDDBlock.h.
References cblk_p.
uInt SDDBlock::read | ( | istream & | in | ) | [inline] |
read from istream and fill until this SDDBlock is full or istream is exhausted return the number of records actually read
attempt to read from istream until Block is full
Definition at line 319 of file SDDBlock.h.
References bytesPerRecord_p, cblk_p, and readBytes().
uInt SDDBlock::read | ( | istream & | in, |
uInt | nrecord, | ||
uInt | startRecord = 0 |
||
) | [inline] |
read nrecord records from istream, filling starting at the indicated record stop if istream is exhausted, return the number of records actually read
Definition at line 329 of file SDDBlock.h.
References bytesPerRecord_p, and readBytes().
uInt SDDBlock::readBytes | ( | istream & | in, |
uInt | nbytes, | ||
uInt | startOffset = 0 |
||
) | [inline] |
read the indicated number of bytes from in, starting at the optionally indicated starting bytes offset, returns the number of bytes actually read
is a resize necessary, copy elements if it is necessary this may be wastefull, if so, use SDDBlock::resize() first without copying
Definition at line 308 of file SDDBlock.h.
References cblk_p, casa::False, resize(), and casa::True.
Referenced by read().
void SDDBlock::reshape | ( | uInt | nRecords, |
uInt | bytesPerRecord, | ||
Bool | forceSmaller = False , |
||
Bool | copyElements = False |
||
) |
reshape is like resize, except that the number of bytes per record can also change.
The number of bytesPerRecord must be a multiple of 8.
void SDDBlock::resize | ( | uInt | nRecords, |
Bool | forceSmaller = False , |
||
Bool | copyElements = False |
||
) |
resize this block to the indicated number of SDD records forceSmaller and copyElements work as with the Block class
Referenced by readBytes().
void SDDBlock::set_pointers | ( | ) | [private] |
uInt SDDBlock::write | ( | ostream & | out | ) | const [inline] |
write the entire SDDBlock to ostream, return the number of records written
write all of Block to ostream
Definition at line 351 of file SDDBlock.h.
References bytesPerRecord_p, cblk_p, and writeBytes().
uInt SDDBlock::write | ( | ostream & | out, |
uInt | nrecord, | ||
uInt | startRecord = 0 |
||
) | const [inline] |
write nrecord records to ostream, starting at the indicated record return the number of records written
Definition at line 357 of file SDDBlock.h.
References bytesPerRecord_p, and writeBytes().
uInt SDDBlock::writeBytes | ( | ostream & | out, |
uInt | nbytes, | ||
uInt | startOffset = 0 |
||
) | const [inline] |
write the indicated number of bytes to out, starting at the optionally indicated starting byte offset, returns the number of bytes actually written
make sure we have what has been requested
Definition at line 341 of file SDDBlock.h.
References cblk_p, and nbytes().
Referenced by write().
uInt SDDBlock::bytesPerRecord_p [private] |
Definition at line 206 of file SDDBlock.h.
Referenced by bytesPerRecord(), nRecords(), read(), and write().
Block<Char>* SDDBlock::cblk_p [private] |
Definition at line 200 of file SDDBlock.h.
Referenced by asdouble(), asfloat(), asInt(), asShort(), copy(), nbytes(), nRecords(), operator[](), read(), readBytes(), write(), and writeBytes().
double* SDDBlock::darray [private] |
Definition at line 204 of file SDDBlock.h.
Referenced by asdouble().
float* SDDBlock::farray [private] |
Definition at line 203 of file SDDBlock.h.
Referenced by asfloat().
Int* SDDBlock::iarray [private] |
Definition at line 202 of file SDDBlock.h.
Referenced by asInt().
Short* SDDBlock::sarray [private] |
Definition at line 201 of file SDDBlock.h.
Referenced by asShort().