Psi4
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
psi::PSIO Class Reference

#include <psio.hpp>

Public Member Functions

 PSIO ()
 
 ~PSIO ()
 
int state ()
 return 1 if activated More...
 
void filecfg_kwd (const char *kwdgrp, const char *kwd, int unit, const char *kwdval)
 
const std::string & filecfg_kwd (const char *kwdgrp, const char *kwd, int unit)
 returns the keyword value. If not defined, returns empty string. More...
 
void rename_file (size_t old_unit, size_t new_unit)
 moves a file from old_unit to new_unit More...
 
bool exists (size_t unit)
 check if a psi unit already exists or not More...
 
void open (size_t unit, int status)
 open unit. status can be PSIO_OPEN_OLD (if existing file is to be opened) or PSIO_OPEN_NEW if new file should be open More...
 
void close (size_t unit, int keep)
 close unit. if keep == 0, will remove the file, else keep it More...
 
std::string getpid (void)
 lookup process id More...
 
void rehash (size_t unit)
 sync up the object to the file on disk by closing and opening the file, if necessary More...
 
int open_check (size_t unit)
 return 1 if unit is open More...
 
void read (size_t unit, const char *key, char *buffer, size_t size, psio_address start, psio_address *end)
 
void write (size_t unit, const char *key, char *buffer, size_t size, psio_address start, psio_address *end)
 
void read_entry (size_t unit, const char *key, char *buffer, size_t size)
 
void write_entry (size_t unit, const char *key, char *buffer, size_t size)
 
void zero_disk (size_t unit, const char *key, size_t rows, size_t cols)
 
void rw (size_t unit, char *buffer, psio_address address, size_t size, int wrt)
 
void tocclean (size_t unit, const char *key)
 Delete all TOC entries after the given key. If a blank key is given, the entire TOC will be wiped. More...
 
void tocprint (size_t unit)
 Print the table of contents for the given unit. More...
 
psio_tocentrytocscan (size_t unit, const char *key)
 Scans the TOC for a particular keyword and returns either a pointer to the entry or nullptr to the caller. More...
 
bool tocentry_exists (size_t unit, const char *key)
 Checks the TOC to see if a particular keyword exists there or not. More...
 
void tocwrite (size_t unit)
 Write the table of contents for file number 'unit'. NB: This function should NOT call psio_error because the latter calls it! More...
 
size_t rd_toclen (size_t unit)
 
void get_filename (size_t unit, char **name, bool remove_namespace=false)
 grab the filename of unit and strdup into name. More...
 
bool tocdel (size_t unit, const char *key)
 delete a specific TOC entry (only deletes entry, not data) More...
 
void set_pid (const std::string &pid)
 

Static Public Member Functions

static void set_default_namespace (const std::string &_ns)
 Set the current namespace (for PREFIX.NAMESPACE.UNIT file numbering) More...
 
static std::string get_default_namespace ()
 Get the default namespace (for PREFIX.NAMESPACE.UNIT file numbering) More...
 
static void change_file_namespace (size_t fileno, const std::string &ns1, const std::string &ns2)
 Change file FILENO from NS1 to NS2. More...
 
static std::shared_ptr< PSIOshared_object ()
 Return the global shared object. More...
 

Static Public Attributes

static int _error_exit_code_ = 1
 Upon catastrophic failure, the library will exit() with this code. The default is 1, but can be overridden. More...
 

Private Types

typedef std::map< std::string,
std::string > 
KWDMap
 

Private Member Functions

size_t get_numvols (size_t unit)
 return the number of volumes over which unit will be striped More...
 
void get_volpath (size_t unit, size_t volume, char **path)
 grab the path to volume of unit and strdup into path. More...
 
psio_tocentrytoclast (size_t unit)
 return the last TOC entry More...
 
size_t toclen (size_t unit)
 Compute the length of the TOC for a given unit using the in-core TOC list. More...
 
void wt_toclen (size_t unit, size_t toclen)
 
void tocread (size_t unit)
 Read the table of contents for file number 'unit'. More...
 

Private Attributes

psio_udpsio_unit
 vector of units More...
 
std::string pid_
 Process ID. More...
 
KWDMap files_keywords_
 library configuration is described by a set of keywords More...
 
int state_
 Library state variable. More...
 

Static Private Attributes

static std::string default_namespace_
 Current default namespace (for PREFIX.NAMESPACE.UNIT numbering) More...
 

Friends

class AIO_Handler
 

Detailed Description

PSIO is an instance of libpsio library. Multiple instances of PSIO are supported.

Each instance can be configured using filecfg_kwd(). The following example best demonstrates how to configure a PSIO instance Lib: Lib->filecfg_kwd("DEFAULT","NAME",-1,"newwfn") // all modules will set filename prefix to newwfn for all units Lib->filecfg_kwd("DEFAULT","NVOLUME",34,"2") // all modules will stripe unit 34 over 2 volumes Lib->filecfg_kwd("CINTS","VOLUME1",-1,"/scratch1/") // module CINTS will access volume 1 of all units under /scratch etc.

Member Typedef Documentation

typedef std::map<std::string,std::string> psi::PSIO::KWDMap
private

Constructor & Destructor Documentation

psi::PSIO::PSIO ( )
psi::PSIO::~PSIO ( )

Member Function Documentation

void psi::PSIO::change_file_namespace ( size_t  fileno,
const std::string &  ns1,
const std::string &  ns2 
)
static

Change file FILENO from NS1 to NS2.

void psi::PSIO::close ( size_t  unit,
int  keep 
)

close unit. if keep == 0, will remove the file, else keep it

bool psi::PSIO::exists ( size_t  unit)

check if a psi unit already exists or not

void psi::PSIO::filecfg_kwd ( const char *  kwdgrp,
const char *  kwd,
int  unit,
const char *  kwdval 
)

set keyword kwd describing some aspect of configuration of PSIO file unit to value kwdval. kwdgrp specifies the keyword group (useful values are: "DEFAULT", "PSI", and the name of the current executable). If unit is set to -1, this keyword will set the default for all units (this keyword can be further overridden for some units). To specify a keyword that works for a specific unit, set unit to the appropriate number between 0 to PSIO_MAXUNIT.

PSIO understands the following keywords: "name" (specifies the prefix for the filename, i.e. if name is set to "psi" then unit 35 will be named "psi.35"), "nvolume" (number of files over which to stripe this unit, cannot be greater than PSIO_MAXVOL), "volumeX", where X is a positive integer less than or equal to the value of "nvolume".

const std::string & psi::PSIO::filecfg_kwd ( const char *  kwdgrp,
const char *  kwd,
int  unit 
)

returns the keyword value. If not defined, returns empty string.

static std::string psi::PSIO::get_default_namespace ( )
inlinestatic

Get the default namespace (for PREFIX.NAMESPACE.UNIT file numbering)

void psi::PSIO::get_filename ( size_t  unit,
char **  name,
bool  remove_namespace = false 
)

grab the filename of unit and strdup into name.

size_t psi::PSIO::get_numvols ( size_t  unit)
private

return the number of volumes over which unit will be striped

void psi::PSIO::get_volpath ( size_t  unit,
size_t  volume,
char **  path 
)
private

grab the path to volume of unit and strdup into path.

std::string psi::PSIO::getpid ( void  )

lookup process id

void psi::PSIO::open ( size_t  unit,
int  status 
)

open unit. status can be PSIO_OPEN_OLD (if existing file is to be opened) or PSIO_OPEN_NEW if new file should be open

int psi::PSIO::open_check ( size_t  unit)

return 1 if unit is open

size_t psi::PSIO::rd_toclen ( size_t  unit)

Read the length of the TOC for a given unit directly from the file.

Parameters
unit= PSI unit number from which to read the toclen.

NB: Note that we do not exit if the read request of the toclen from the file fails. This is because the request may be to an new file for which the toclen has not yet been written. (We allow the user to open files with status PSIO_OPEN_OLD even if they don't exist, because sometimes you can't know this in advance.)

void psi::PSIO::read ( size_t  unit,
const char *  key,
char *  buffer,
size_t  size,
psio_address  start,
psio_address end 
)

Reads data from within a TOC entry from a PSI file.

Parameters
unit= The PSI unit number used to identify the file to all read and write functions.
key= The TOC keyword identifying the desired entry.
buffer= The buffer to store the data as it is read.
size= The number of bytes to read.
start= The entry-relative starting page/offset of the desired data.
end= A pointer to the entry-relative page/offset for the next byte after the end of the read request.
void psi::PSIO::read_entry ( size_t  unit,
const char *  key,
char *  buffer,
size_t  size 
)
void psi::PSIO::rehash ( size_t  unit)

sync up the object to the file on disk by closing and opening the file, if necessary

void psi::PSIO::rename_file ( size_t  old_unit,
size_t  new_unit 
)

moves a file from old_unit to new_unit

void psi::PSIO::rw ( size_t  unit,
char *  buffer,
psio_address  address,
size_t  size,
int  wrt 
)

Central function for all reads and writes on a PSIO unit.

Parameters
unit= The PSI unit number.
buffer= The buffer containing the bytes for the read/write event.
address= the PSIO global address for the start of the read/write.
size= The number of bytes to read/write.
wrt= Indicates if the call is to read (0) or write (0) the input data.
static void psi::PSIO::set_default_namespace ( const std::string &  _ns)
inlinestatic

Set the current namespace (for PREFIX.NAMESPACE.UNIT file numbering)

void psi::PSIO::set_pid ( const std::string &  pid)
inline
std::shared_ptr< PSIO > psi::PSIO::shared_object ( )
static

Return the global shared object.

int psi::PSIO::state ( )
inline

return 1 if activated

void psi::PSIO::tocclean ( size_t  unit,
const char *  key 
)

Delete all TOC entries after the given key. If a blank key is given, the entire TOC will be wiped.

bool psi::PSIO::tocdel ( size_t  unit,
const char *  key 
)

delete a specific TOC entry (only deletes entry, not data)

bool psi::PSIO::tocentry_exists ( size_t  unit,
const char *  key 
)

Checks the TOC to see if a particular keyword exists there or not.

psio_tocentry * psi::PSIO::toclast ( size_t  unit)
private

return the last TOC entry

size_t psi::PSIO::toclen ( size_t  unit)
private

Compute the length of the TOC for a given unit using the in-core TOC list.

void psi::PSIO::tocprint ( size_t  unit)

Print the table of contents for the given unit.

void psi::PSIO::tocread ( size_t  unit)
private

Read the table of contents for file number 'unit'.

psio_tocentry * psi::PSIO::tocscan ( size_t  unit,
const char *  key 
)

Scans the TOC for a particular keyword and returns either a pointer to the entry or nullptr to the caller.

void psi::PSIO::tocwrite ( size_t  unit)

Write the table of contents for file number 'unit'. NB: This function should NOT call psio_error because the latter calls it!

void psi::PSIO::write ( size_t  unit,
const char *  key,
char *  buffer,
size_t  size,
psio_address  start,
psio_address end 
)

Writes data to a TOC entry in a PSI file.

Parameters
unit= The PSI unit number used to identify the file to all read and write functions.
key= The TOC keyword identifying the desired entry.
buffer= The buffer from which the data is written.
size= The number of bytes to write.
start= The entry-relative starting page/offset to write the data.
end= A pointer to the entry-relative page/offset for the next byte after the end of the write request.
void psi::PSIO::write_entry ( size_t  unit,
const char *  key,
char *  buffer,
size_t  size 
)
void psi::PSIO::zero_disk ( size_t  unit,
const char *  key,
size_t  rows,
size_t  cols 
)

Zeros out a double precision array in a PSI file. Typically used before striping out a transposed array Total fill size is rows*cols*sizeof(double) Buffer memory of cols*sizeof(double) is used

Parameters
unit= The PSI unit number used to identify the file
key= The TOC keyword identifying the desired entry.
rows= The number of rows in the full array
cols= The number of columnss in the full array

Friends And Related Function Documentation

friend class AIO_Handler
friend

Member Data Documentation

int psi::PSIO::_error_exit_code_ = 1
static

Upon catastrophic failure, the library will exit() with this code. The default is 1, but can be overridden.

std::string psi::PSIO::default_namespace_
staticprivate

Current default namespace (for PREFIX.NAMESPACE.UNIT numbering)

KWDMap psi::PSIO::files_keywords_
private

library configuration is described by a set of keywords

std::string psi::PSIO::pid_
private

Process ID.

psio_ud* psi::PSIO::psio_unit
private

vector of units

int psi::PSIO::state_
private

Library state variable.


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