![]() |
MAOS
Multithreaded Adaptive Optics Simulator
|
Data Structures | |
| struct | header_t |
Macros | |
| #define | swap2bytes(data) |
| #define | swap4bytes(data) |
| #define | swap8bytes(data) |
| #define | M_INT M_INT32 |
| #define | M_STR M_INT8 |
| #define | M_SPINT M_INT |
| #define | M_DSP M_DSP32 |
| #define | M_CSP M_CSP32 |
| #define | M_SSP M_SSP32 |
| #define | M_ZSP M_ZSP32 |
| #define | IS_SHM(name) |
Typedefs | |
| typedef uint32_t | M_ID |
| typedef int | spint |
Functions | |
| int | zfexist (const char *format,...) |
| void | zftouch (const char *format,...) |
| int | zfeof (file_t *fp) |
| long | zfpos (file_t *fp) |
| long | zfseek (file_t *fp, long offset, int whence) |
| void | zfrewind (file_t *fp) |
| long | zflen (file_t *fp) |
| file_t * | zfopen (const char *fn, const char *mod) |
| file_t * | zfdopen (int fd) |
| file_t * | zfdopen_as (int fd, const char *mod, const char *suffix) |
| const char * | zfname (file_t *fp) |
| int | zfisfits (file_t *fp) |
| void | zfclose (file_t *fp) |
| int | zfwrite (const void *ptr, const size_t size, const size_t nmemb, file_t *fp) |
| int | zfread (void *ptr, const size_t size, const size_t nmemb, file_t *fp) |
| int | zferrno (file_t *fp) |
| uint64_t | bytes_header (const char *keywords) |
| void | write_timestamp (file_t *fp) |
| void | write_header (const header_t *header, file_t *fp) |
| int | read_header (header_t *header, file_t *fp) |
| long | writearr (const void *fpn, const int isfile, const size_t size, const uint32_t magic, const char *keywords, const void *p, const uint64_t nx, const uint64_t ny) |
| struct mem_t * | mem_new (void *p) __attribute__((warn_unused_result)) |
| unsigned int | mem_unref (mem_t **in) |
| mem_t * | mem_ref (mem_t *in) __attribute__((warn_unused_result)) |
| void | mem_replace (mem_t *in, void *p) |
| int | mem_nref (const mem_t *in) |
| void * | mem_p (const mem_t *in) |
| mem_t * | mmap_open (const char *fn, size_t msize, int rw) |
| void | mmap_write_header (char **p0, uint32_t magic, long nx, long ny, const char *keywords) |
| void | mmap_read_header (char **p0, uint32_t *magic, long *nx, long *ny, const char **pkeywords) |
| async_t * | async_init (file_t *fp, const size_t size, const uint32_t magic, const char *str, const void *p, const uint64_t nx, const uint64_t ny) |
| int | async_write (async_t *async, long offset, int wait) |
| void | async_free (async_t *async) |
Defines our custom file format .bin that may be gzipped and the basic IO functions. All file read/write operators are through functions in this file. The routines can also operate on .fits files.
| struct header_t |
| #define swap2bytes | ( | data | ) |
| #define swap4bytes | ( | data | ) |
| #define swap8bytes | ( | data | ) |
| #define IS_SHM | ( | name | ) |
| int zfexist | ( | const char * | format, |
| ... ) |
Test whether a bin file exist.
| [in] | format | printf style format of the file name, followed by its arguments. |
| void zftouch | ( | const char * | format, |
| ... ) |
Update the modification time of a bin file.
| [in] | format | printf style format of the file name, followed by its arguments. |
| int zfeof | ( | file_t * | fp | ) |
Return 1 if end of file is reached.
| [in] | fp | File handle. |
| long zfpos | ( | file_t * | fp | ) |
Tell position pointer in file.
| [in] | fp | File handle. |
Move the current position pointer, like fseek
| [in,out] | fp | File handle. |
| [in] | offset | Offset in bytes. |
| [in] | whence | SEEK_SET, SEEK_CUR, or SEEK_END. |
| void zfrewind | ( | file_t * | fp | ) |
Move the file position pointer to the beginning and clear the error on success.
| [in,out] | fp | File handle. |
| long zflen | ( | file_t * | fp | ) |
Return file length. The current file position is preserved.
| [in] | fp | File handle. |
| file_t * zfopen | ( | const char * | fni, |
| const char * | mod ) |
Open a bin file for read/write access.
Whether the file is gzipped or not is automatically determined when open for reading. When open for writing, the file is compressed with gzip or zstd if the name ends with .gz or .zst. If the file has no recognized suffix, .bin is appended to the file name. Files opened for writing are locked.
| [in] | fni | File name. |
| [in] | mod | Access mode: r for read, w for write (truncate), a for append. |
| file_t * zfdopen | ( | int | fd | ) |
convert a socket or fd into file_t.
| [in] | fd | File or socket descriptor. Closed by zfclose(). |
| file_t * zfdopen_as | ( | int | fd, |
| const char * | mod, | ||
| const char * | suffix ) |
convert a file descriptor, socket, or pipe into file_t with the format implied by suffix.
Unlike zfopen(), the format is not detected from the content, so the descriptor does not need to be seekable.
| [in] | fd | File, socket, or pipe descriptor. Closed by zfclose(). |
| [in] | mod | Access mode: r for read, w for write. |
| [in] | suffix | File name suffix that sets the format: .bin, .fits, with optional .gz or .zst appended. NULL is .bin. |
| const char * zfname | ( | file_t * | fp | ) |
Open a bin file or socket for read/write access.
Whether the file is gzipped or not is automatically determined when open for reading. When open for writing, if the file name ends with .bin or .fits, will not be gzipped. If the file has no suffix, the file will be gzipped and .bin is appened to file name. Return the underlining filename
| [in] | fp | File handle. |
| int zfisfits | ( | file_t * | fp | ) |
Return 1 when it is a fits file.
| [in] | fp | File handle. |
| void zfclose | ( | file_t * | fp | ) |
Close the file.
| [in] | fp | File handle; freed. May be NULL. |
| int zfwrite | ( | const void * | ptr, |
| const size_t | size, | ||
| const size_t | nmemb, | ||
| file_t * | fp ) |
Handles byteswapping in fits file format then call zfwrite_do to do the actual writing. For fits files, each call writes one complete data unit padded to a full FITS block. Complex numbers must be written with size of each real component and twice the number of elements so that the real and imaginary parts are byte swapped separately (see writearr()).
| [in] | ptr | Data to write. |
| [in] | size | Size of each element in bytes. |
| [in] | nmemb | Number of elements. |
| [in,out] | fp | File handle; its error field is set on failure. |
| int zfread | ( | void * | ptr, |
| const size_t | size, | ||
| const size_t | nmemb, | ||
| file_t * | fp ) |
Handles byteswapping in fits file format then call zfread_do to do the actual reading. For fits files, each call reads one complete data unit: the padding to a full FITS block (2880 bytes) after the data is skipped for all element sizes. Complex numbers must be read with size of each real component and twice the number of elements (see readvec()).
| [out] | ptr | Buffer to read into. |
| [in] | size | Size of each element in bytes. |
| [in] | nmemb | Number of elements. |
| [in,out] | fp | File handle; its error field is set on failure. |
| int zferrno | ( | file_t * | fp | ) |
Return the error number
| [in] | fp | File handle. |
| uint64_t bytes_header | ( | const char * | keywords | ) |
Get the length of mem to storge the header and its dimension, rounded to multiple of 8.
| [in] | keywords | Header string. May be NULL. |
| void write_header | ( | const header_t * | header, |
| file_t * | fp ) |
A unified header writing routine for .bin and .fits files. It write the array information and string header if any.
| [in] | header | Header with magic number, dimension, and optional string. For fits files, magic MCC_ANY saves the string as the global keyword. |
| [in,out] | fp | File handle to write to. |
| int read_header | ( | header_t * | header, |
| file_t * | fp ) |
A unified header reading routine for .bin and .fits files. It read the array information and string header if any.
| [out] | header | Header to fill. header->str is newly allocated; the caller frees it. |
| [in,out] | fp | File handle, read from its current position. |
| long writearr | ( | const void * | fpn, |
| const int | isfn, | ||
| const size_t | size, | ||
| const uint32_t | magic, | ||
| const char * | str, | ||
| const void * | p, | ||
| const uint64_t | nx, | ||
| const uint64_t | ny ) |
Write the time stamp as header into current location in the file. Write an 1-d or 2-d array into the file. First write a magic number that represents the data type. Then write two numbers representing the dimension. Finally write the data itself.
| [in] | fpn | The file name (if isfn) or the opened file_t pointer. |
| [in] | isfn | Is this a filename or already opened file. |
| [in] | size | Size of each element. |
| [in] | magic | The magic number. see bin.h. |
| [in] | str | The header as string. |
| [in] | p | The data of the array. |
| [in] | nx | Number of rows. this index changes fastest. |
| [in] | ny | Number of columns. 1 for vector. |
| struct mem_t * mem_new | ( | void * | p | ) |
Create a mem_t object.
Notice that nref is set to 0 by design: each user (e.g., X(new_do)) takes its own reference with mem_ref() and releases it with mem_unref(), which frees the object when the last reference is released. Default is set to reference heap memory.
| [in] | p | Memory to manage; owned by the returned mem_t. |
| unsigned int mem_unref | ( | mem_t ** | pin | ) |
Unreference the mmaped memory. When the reference drops to zero free or unmap it.
| [in,out] | pin | Pointer to the mem_t; set to NULL. |
| mem_t * mem_ref | ( | mem_t * | in | ) |
Add a reference to a mem_t.
| [in,out] | in | The mem_t. May be NULL. |
| void mem_replace | ( | mem_t * | in, |
| void * | p ) |
Replace internal vector. Use with care. Errors if the memory is mmaped or referenced more than once.
| [in,out] | in | The mem_t. |
| [in] | p | New memory pointer; the old one is not freed. |
| int mem_nref | ( | const mem_t * | in | ) |
Check whether it is a referenced data.
| [in] | in | The mem_t. May be NULL. |
| void * mem_p | ( | const mem_t * | in | ) |
Return internal pointer
| [in] | in | The mem_t. May be NULL. |
| mem_t * mmap_open | ( | const char * | fn, |
| size_t | msize, | ||
| int | rw ) |
Open a file for write with mmmap. We don't provide an access control here for generic usage of the function. Lock on a special dummy file for access control.
| [in] | fn | File name (.bin only), or a shared memory name. May be NULL for writing. |
| [in] | msize | Size in bytes to map. For reading, 0 means the file length. |
| [in] | rw | 1 to open for read/write (the file is created and resized), 0 for read only. |
Initialize the header in the mmaped file. Upon exit, p0 points to the location of data p.
| [in,out] | p0 | Pointer to the header location in the mmaped memory; advanced past the header. |
| [in] | magic | Magic number of the data type. |
| [in] | nx | Number of rows. |
| [in] | ny | Number of columns. |
| [in] | keywords | Header string. May be NULL. |
| void mmap_read_header | ( | char ** | p0, |
| uint32_t * | magic, | ||
| long * | nx, | ||
| long * | ny, | ||
| const char ** | pkeywords ) |
Initialize the dimension from the header in the mmaped file.
| [in,out] | p0 | Pointer to the header location in the mmaped memory; advanced to the data. |
| [out] | magic | Magic number of the data type. |
| [out] | nx | Number of rows. |
| [out] | ny | Number of columns. |
| [out] | pkeywords | Reference to the header string in the mapped memory; do not free. NULL if there is none. May be NULL. |
| async_t * async_init | ( | file_t * | fp, |
| const size_t | size, | ||
| const uint32_t | magic, | ||
| const char * | str, | ||
| const void * | p, | ||
| const uint64_t | nx, | ||
| const uint64_t | ny ) |
Allocates space in fp for our block of data by writing header first and skip to the end of data offset. It has the same interface as writearr except only fp is allowed Use aio_* api if USE_ASYNC is set, otherwise use pwrite() aio_* api launches threads for async writing. pwrite is much simpler for our usecase. There is no impact on simulation step timing. we don't use mmap to write to file as it causes excessive traffic to NFS file system.
| [in,out] | fp | File handle opened for writing. |
| [in] | size | Size of each element. |
| [in] | magic | The magic number. see bin.h. |
| [in] | str | The header as string. |
| [in] | p | The data of the array. Must stay valid until async_free(). |
| [in] | nx | Number of rows. |
| [in] | ny | Number of columns. |
| int async_write | ( | async_t * | async, |
| long | offset, | ||
| int | wait ) |
Write to file asynchronously.
| [in,out] | async | The async writing state. May be NULL. |
| [in] | offset | The end (in bytes from the start of the data) of the block that is ready to write. |
| [in] | wait | Wait for the previous write to finish (only with USE_ASYNC). |
| void async_free | ( | async_t * | async | ) |
Wait for pending asynchronous writes to finish and free async.
| [in] | async | The async writing state; freed. May be NULL. |