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

More...

#include <Aipsrc.h>

Static Public Member Functions

static Bool find (String &value, const String &keyword)
 
static Bool findNoHome (String &value, const String &keyword)
 
static Bool find (uInt &value, const String &keyword, Int Nname, const String tname[])
 These finds check a (possible) value of the keyword against a list of coded values provided, and return an index into the list (N if not found). More...
 
static Bool find (uInt &value, const String &keyword, const Vector< String > &tname)
 
static Bool find (String &value, const String &keyword, const String &deflt)
 This find usually saves you some lines of code, since you can supply the default you want to use when no such keyword is defined. More...
 
static Bool findNoHome (String &value, const String &keyword, const String &deflt)
 
static Bool find (uInt &value, const String &keyword, Int Nname, const String tname[], const String &deflt)
 
static Bool find (uInt &value, const String &keyword, const Vector< String > &tname, const String &deflt)
 
static Bool findDir (String &foundDir, const String &lastPart="", const Vector< String > &prepends=Vector< String >(), const Vector< String > &appends=Vector< String >(), Bool useStds=True)
 Sets foundDir to the first /firstPart/lastPart path that it finds present on the system, where /firstPart comes from, in order, this list: contents of prepends. More...
 
static uInt registerRC (const String &keyword, const String &deflt)
 Functions to register keywords for later use in get() and set(). More...
 
static uInt registerRC (const String &keyword, Int Nname, const String tname[], const String &deflt)
 
static uInt registerRC (const String &keyword, const Vector< String > &tname, const String &deflt)
 
static const Stringget (uInt keyword)
 Gets are like find, but using registered integers rather than names. More...
 
static const uIntget (uInt &code, uInt keyword)
 get for code More...
 
static void set (uInt keyword, const String &deflt)
 Sets allow registered values to be set. More...
 
static void set (uInt keyword, Int Nname, const String tname[], const String &deflt)
 
static void set (uInt keyword, const Vector< String > &tname, const String &deflt)
 
static void save (uInt keyword)
 Save a registered keyword value to $HOME/.aipsrc More...
 
static void save (uInt keyword, const String tname[])
 
static void save (uInt keyword, const Vector< String > &tname)
 
static void setAipsPath (const String &path=String())
 Set an AIPSPATH that should be used in stead of a global AIPSPATH. More...
 
static const StringaipsRoot ()
 Returns the appropriate Casacore or system variable values. More...
 
static const StringaipsArch ()
 
static const StringaipsSite ()
 
static const StringaipsHost ()
 
static const StringaipsHome ()
 Returns: ~/aips++ More...
 
static void reRead ()
 The reRead() function will reinitialise the static maps and read the aipsrc files again. More...
 
static Double lastRead ()
 
static const Block< String > & values ()
 The following functions return the full lists of available data. More...
 
static const Block< String > & patterns ()
 
static void show (ostream &oStream)
 The following show() function, useful for debugging, outputs all keyword/value pairs found. More...
 
static void show ()
 Prints all info on cout. More...
 
static uInt genRestore (Vector< String > &namlst, Vector< String > &vallst, const String &fileList)
 The following set is a general set of functions. More...
 
static void genSave (Vector< String > &namlst, Vector< String > &vallst, const String &fnam)
 Save the names/values in file. More...
 
static void genSet (Vector< String > &namlst, Vector< String > &vallst, const String &nam, const String &val)
 Set (new or overwrite) keyword/value pair. More...
 
static Bool genUnSet (Vector< String > &namlst, Vector< String > &vallst, const String &nam)
 Remove a keyword from list (False if not in list) More...
 
static Bool genGet (String &val, Vector< String > &namlst, Vector< String > &vallst, const String &nam)
 Get the value of a keyword. More...
 

Static Protected Member Functions

static Bool find (String &value, const String &keyword, uInt start)
 Actual find function. More...
 
static Bool findNoParse (String &value, const String &keyword, uInt start)
 Actual find function to use during parse() without recursing into parse() More...
 
static uInt registerRC (const String &keyword, Block< String > &nlst)
 The registration function. More...
 
static void save (const String keyword, const String val)
 Actual saving. More...
 

Static Private Member Functions

static void parse ()
 Read in the aipsrc files. More...
 
static void doParse (String &fileList)
 
static uInt genParse (Block< String > &keywordPattern, Block< String > &keywordValue, uInt &fileEnd, const String &fileList)
 The following parse function can be used for any list of files. More...
 
static Bool matchKeyword (uInt &where, const String &keyword, uInt start)
 Locate the right keyword in the static maps. More...
 
static void fillAips ()
 Fill in root, arch, site, host and home. More...
 

Static Private Attributes

static std::once_flag theirCallOnceFlag
 Object to ensure safe multi-threaded lazy single initialization. More...
 
static Double lastParse
 Last time data was (re)read. More...
 
static Block< StringkeywordValue
 List of values belonging to keywords found. More...
 
static Block< StringkeywordPattern
 List of patterns deducted from names. More...
 
static uInt fileEnd
 The start of the non-home values. More...
 
static String extAipsPath
 The possibly set external AIPSPATH. More...
 
static String root
 AIPSROOT. More...
 
static String arch
 AIPSARCH. More...
 
static String site
 AIPSSITE. More...
 
static String host
 AIPSHOST. More...
 
static String home
 AIPSHOME. More...
 
static String uhome
 HOME. More...
 
static Bool filled
 Indicate above filled. More...
 
static Block< Stringstrlst
 String register list. More...
 
static Block< Stringnstrlst
 
static Block< uIntcodlst
 
static Block< Stringncodlst
 

Detailed Description

Class to read the casa general resource files

Intended use:

Public interface

Review Status

Reviewed By:
wyoung
Date Reviewed:
1996/11/25
Test programs:
tAipsrc

Prerequisite

Etymology

A class for getting values from the casa resource files

Synopsis

The static Aipsrc class can get information from the casa resource files. It has the same functionality as getrc (c program used for Casacore installation scripts).
In addition it acts as a central clearing house between system and software by providing functionality to obtain Casacore system parameters (like AIPSPATH elements), and the possibility of storing system wide information provided by a class for reference by other classes.
The format of a line in a resource file is:

# Line starting with an # in column 1 is a comment (as is an empty line)
keyword: value
keyword: value
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.

The keyword (starting at first non-blank) consists in general of keyword fields separated by periods:

printer.ps.page
measures.precession.d_interval
measures.nutation.d_interval

and, by preference, in lower case (but search is case sensitive) with an _ as word-parts separator.
The keyword and value are separated by a :. The value is the string from the first non-whitespace character after the separator to the end of the line. Interpretation of the string is in general the program's responsibility, but special find() calls (see below) exist to aid.
Any part of the keyword string can be replaced by a wildcard * to indicate all values with that structure (e.g. *.d_interval would indicate in the example above both the precession and the nutation d_interval.
A match between a keyword to be found and a keyword in the resource files will be the first match (taking wildcards into account) encountered in the search through the resource files. The resource files to be looked at can be defined in the environment variable CASARCFILES. If undefined, the resource files searched are (in the given order):

~/.casarc
~/.casa/rc
~/.aipsrc
$AIPSROOT/.aipsrc
$AIPSHOST/aipsrc
$AIPSSITE/aipsrc
$AIPSARCH/aipsrc

It is not an error for any of the aipsrc files to be absent or empty. However, it is an error if HOME has not been set: an exception will occur. AIPSPATH will in general be read from the global environment variables, but can, before any other Aipsrc related call, be set with the setAipsPath() call.
If AIPSPATH is not set in either way, it is set to the home directory.

The basic interaction with the class is with the static keyword match function

Bool Aipsrc::find(String &result, const String &keyword)
static Bool find(String &value, const String &keyword)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42

A set of

Bool AipsrcValue::find(Type &result, const String &keyword,...)
static Bool find(T &value, const String &keyword)
The find() functions will, given a keyword, return the value of a matched keyword found in the files.

are available to interpret the string value found. (see AipsrcValue).
All the find functions have the ability to set a default if there is no match, while also unit conversion is possible.
The Bool return indicates if the keyword was found, and, in the case of the interpretative finds, if an 'important' format error was found (e.g. '+12a' will be accepted as a Double, with a result of '12', since the standard double conversion in >> will produce this result.)
Caution: The search keyword (unlike the file keyword) has no wildcards; The real name should, of course, be looked for;
To aid in other places, the following (static) methods are available to get the requested information (derived from HOME and AIPSPATH, computer system information and/or aipsrc keywords):

Other, numeric, system information can be found in AipsrcValue.

Given an AIPSPATH of

/epp/aips++ sun4sol_gnu epping norma

aipsSite will return

/epp/aips++/sun4sol_gnu/epping

.

The basic find above reacts with the aipsrc files available. If regular access is necessary (e.g. a lot of routines have to check independently a certain integration time limit), keywords can be registered to enable:


Tip: The registered value is never equal to zero, hence a zero value can be used to check if registration is done; Also, registering the same keyword twice is safe, and will produce the same value;
When saving a keyword/value pair in $HOME/.aipsrc, the old version is saved in $HOME/.aipsrc.old, before the keyword/value pair is prepended to the file. A limited number of edits of the same keyword is preserved only (default 5, changeable with the user.aipsrc.edit.keep keyword.

Example

String printerPage; // result of keyword find
if(!Aipsrc::find(printerPage, "printer.ps.page")) { // look for keyword match
printerPage = "notSet";
};

A more convenient way of accomplishing the same result is:

Aipsrc::find(printerPage, "printer.ps.page", "notSet");

Here the final argument is the default to use if the keyword is not found at all.
If you often want to know, dynamically, the current 'printer.ps.page' value, you could do something like:

static uInt pp = Aipsrc::registerRC("printer.ps.page", "noSet");
String printerPage = Aipsrc::get(pp);
// Processing, and maybe somewhere else:
Aipsrc::set(pp, "nowSet");
//..\.
printerPage = Aipsrc::get(pp);
// and save it to the <tt>$HOME/.aipsrc</tt> list
static void set(uInt keyword, const String &deflt)
Sets allow registered values to be set.
static void save(uInt keyword)
Save a registered keyword value to $HOME/.aipsrc
static const String & get(uInt keyword)
Gets are like find, but using registered integers rather than names.
static uInt registerRC(const String &keyword, const String &deflt)
Functions to register keywords for later use in get() and set().
unsigned int uInt
Definition: aipstype.h:51

Motivation

Programs need a way to interact with the aipsrc files.

Thrown Exceptions

Definition at line 219 of file Aipsrc.h.

Member Function Documentation

◆ aipsArch()

static const String& casacore::Aipsrc::aipsArch ( )
static

◆ aipsHome()

static const String& casacore::Aipsrc::aipsHome ( )
static

Returns: ~/aips++

◆ aipsHost()

static const String& casacore::Aipsrc::aipsHost ( )
static

◆ aipsRoot()

static const String& casacore::Aipsrc::aipsRoot ( )
static

Returns the appropriate Casacore or system variable values.

◆ aipsSite()

static const String& casacore::Aipsrc::aipsSite ( )
static

◆ doParse()

static void casacore::Aipsrc::doParse ( String fileList)
staticprivate

◆ fillAips()

static void casacore::Aipsrc::fillAips ( )
staticprivate

Fill in root, arch, site, host and home.

◆ find() [1/7]

static Bool casacore::Aipsrc::find ( String value,
const String keyword 
)
static

Thrown Exceptions

  • AipsError if HOME environment variable not set

The find() functions will, given a keyword, return the value with a matched keyword found in the files. If no match found the function will be False. The findNoHome() emulates the -i switch of getrc by bypassing the ~/.aipsrc file.

◆ find() [2/7]

static Bool casacore::Aipsrc::find ( String value,
const String keyword,
const String deflt 
)
static

This find usually saves you some lines of code, since you can supply the default you want to use when no such keyword is defined.

If the return value is False, the keyword was not found and the default was used.

◆ find() [3/7]

static Bool casacore::Aipsrc::find ( String value,
const String keyword,
uInt  start 
)
staticprotected

Actual find function.

◆ find() [4/7]

static Bool casacore::Aipsrc::find ( uInt value,
const String keyword,
const Vector< String > &  tname 
)
static

◆ find() [5/7]

static Bool casacore::Aipsrc::find ( uInt value,
const String keyword,
const Vector< String > &  tname,
const String deflt 
)
static

◆ find() [6/7]

static Bool casacore::Aipsrc::find ( uInt value,
const String keyword,
Int  Nname,
const String  tname[] 
)
static

These finds check a (possible) value of the keyword against a list of coded values provided, and return an index into the list (N if not found).

Matching is minimax, case insensitive. Always better to use the one with default. return is False if no keyword or no match.

◆ find() [7/7]

static Bool casacore::Aipsrc::find ( uInt value,
const String keyword,
Int  Nname,
const String  tname[],
const String deflt 
)
static

◆ findDir()

static Bool casacore::Aipsrc::findDir ( String foundDir,
const String lastPart = "",
const Vector< String > &  prepends = VectorString >(),
const Vector< String > &  appends = VectorString >(),
Bool  useStds = True 
)
static

Sets foundDir to the first /firstPart/lastPart path that it finds present on the system, where /firstPart comes from, in order, this list: contents of prepends.

◆ findNoHome() [1/2]

static Bool casacore::Aipsrc::findNoHome ( String value,
const String keyword 
)
static

◆ findNoHome() [2/2]

static Bool casacore::Aipsrc::findNoHome ( String value,
const String keyword,
const String deflt 
)
static

◆ findNoParse()

static Bool casacore::Aipsrc::findNoParse ( String value,
const String keyword,
uInt  start 
)
staticprotected

Actual find function to use during parse() without recursing into parse()

◆ genGet()

static Bool casacore::Aipsrc::genGet ( String val,
Vector< String > &  namlst,
Vector< String > &  vallst,
const String nam 
)
static

Get the value of a keyword.

◆ genParse()

static uInt casacore::Aipsrc::genParse ( Block< String > &  keywordPattern,
Block< String > &  keywordValue,
uInt fileEnd,
const String fileList 
)
staticprivate

The following parse function can be used for any list of files.

It will return the list of Patterns and values found, and the last keyword number of first file in list.

◆ genRestore()

static uInt casacore::Aipsrc::genRestore ( Vector< String > &  namlst,
Vector< String > &  vallst,
const String fileList 
)
static

The following set is a general set of functions.

Read aipsrc type files (without wildcards), and return the unique names and values in the Vector arguments. The return value is number of names.

◆ genSave()

static void casacore::Aipsrc::genSave ( Vector< String > &  namlst,
Vector< String > &  vallst,
const String fnam 
)
static

Save the names/values in file.

◆ genSet()

static void casacore::Aipsrc::genSet ( Vector< String > &  namlst,
Vector< String > &  vallst,
const String nam,
const String val 
)
static

Set (new or overwrite) keyword/value pair.

◆ genUnSet()

static Bool casacore::Aipsrc::genUnSet ( Vector< String > &  namlst,
Vector< String > &  vallst,
const String nam 
)
static

Remove a keyword from list (False if not in list)

◆ get() [1/2]

static const uInt& casacore::Aipsrc::get ( uInt code,
uInt  keyword 
)
static

get for code

◆ get() [2/2]

static const String& casacore::Aipsrc::get ( uInt  keyword)
static

Gets are like find, but using registered integers rather than names.

◆ lastRead()

static Double casacore::Aipsrc::lastRead ( )
static

◆ matchKeyword()

static Bool casacore::Aipsrc::matchKeyword ( uInt where,
const String keyword,
uInt  start 
)
staticprivate

Locate the right keyword in the static maps.

◆ parse()

static void casacore::Aipsrc::parse ( )
staticprivate

Read in the aipsrc files.

Always called using theirCallOnce (except for reRead()).

◆ patterns()

static const Block<String>& casacore::Aipsrc::patterns ( )
static

◆ registerRC() [1/4]

static uInt casacore::Aipsrc::registerRC ( const String keyword,
Block< String > &  nlst 
)
staticprotected

The registration function.

◆ registerRC() [2/4]

static uInt casacore::Aipsrc::registerRC ( const String keyword,
const String deflt 
)
static

Functions to register keywords for later use in get() and set().

The returned value is the index for get() and set().

◆ registerRC() [3/4]

static uInt casacore::Aipsrc::registerRC ( const String keyword,
const Vector< String > &  tname,
const String deflt 
)
static

◆ registerRC() [4/4]

static uInt casacore::Aipsrc::registerRC ( const String keyword,
Int  Nname,
const String  tname[],
const String deflt 
)
static

◆ reRead()

static void casacore::Aipsrc::reRead ( )
static

The reRead() function will reinitialise the static maps and read the aipsrc files again.

It could be useful in some interactive circumstances. Note: Calling reRead() while using the static maps is not (thread-)safe. (Getting it right is a lot of work, but why apply settings while processing?) Note: casa_measures MeasTable.cc reads its iau2000_reg and iau2000a_reg upon first uses. Those cached values are not re-read, but only influence what useIAU2000() and useIAU2000A() return.

lastRead() returns the time last reRead.

◆ save() [1/4]

static void casacore::Aipsrc::save ( const String  keyword,
const String  val 
)
staticprotected

Actual saving.

◆ save() [2/4]

static void casacore::Aipsrc::save ( uInt  keyword)
static

Save a registered keyword value to $HOME/.aipsrc

◆ save() [3/4]

static void casacore::Aipsrc::save ( uInt  keyword,
const String  tname[] 
)
static

◆ save() [4/4]

static void casacore::Aipsrc::save ( uInt  keyword,
const Vector< String > &  tname 
)
static

◆ set() [1/3]

static void casacore::Aipsrc::set ( uInt  keyword,
const String deflt 
)
static

Sets allow registered values to be set.

◆ set() [2/3]

static void casacore::Aipsrc::set ( uInt  keyword,
const Vector< String > &  tname,
const String deflt 
)
static

◆ set() [3/3]

static void casacore::Aipsrc::set ( uInt  keyword,
Int  Nname,
const String  tname[],
const String deflt 
)
static

◆ setAipsPath()

static void casacore::Aipsrc::setAipsPath ( const String path = String())
static

Set an AIPSPATH that should be used in stead of a global AIPSPATH.

This call should be made before any Aipsrc related call. The AIPSPATH will have up to 4 fields (which can all be empty) giving the root, host, site and arch directory that will be searched for possible [.]aipsrc files.

◆ show() [1/2]

static void casacore::Aipsrc::show ( )
static

Prints all info on cout.

◆ show() [2/2]

static void casacore::Aipsrc::show ( ostream &  oStream)
static

The following show() function, useful for debugging, outputs all keyword/value pairs found.

◆ values()

static const Block<String>& casacore::Aipsrc::values ( )
static

The following functions return the full lists of available data.

They could be useful for debugging purposes.

Member Data Documentation

◆ arch

String casacore::Aipsrc::arch
staticprivate

AIPSARCH.

Definition at line 402 of file Aipsrc.h.

◆ codlst

Block<uInt> casacore::Aipsrc::codlst
staticprivate

Definition at line 417 of file Aipsrc.h.

◆ extAipsPath

String casacore::Aipsrc::extAipsPath
staticprivate

The possibly set external AIPSPATH.

Definition at line 398 of file Aipsrc.h.

◆ fileEnd

uInt casacore::Aipsrc::fileEnd
staticprivate

The start of the non-home values.

Definition at line 396 of file Aipsrc.h.

◆ filled

Bool casacore::Aipsrc::filled
staticprivate

Indicate above filled.

Definition at line 412 of file Aipsrc.h.

◆ home

String casacore::Aipsrc::home
staticprivate

AIPSHOME.

Definition at line 408 of file Aipsrc.h.

◆ host

String casacore::Aipsrc::host
staticprivate

AIPSHOST.

Definition at line 406 of file Aipsrc.h.

◆ keywordPattern

Block<String> casacore::Aipsrc::keywordPattern
staticprivate

List of patterns deducted from names.

Definition at line 394 of file Aipsrc.h.

◆ keywordValue

Block<String> casacore::Aipsrc::keywordValue
staticprivate

List of values belonging to keywords found.

Definition at line 392 of file Aipsrc.h.

◆ lastParse

Double casacore::Aipsrc::lastParse
staticprivate

Last time data was (re)read.

Definition at line 390 of file Aipsrc.h.

◆ ncodlst

Block<String> casacore::Aipsrc::ncodlst
staticprivate

Definition at line 418 of file Aipsrc.h.

◆ nstrlst

Block<String> casacore::Aipsrc::nstrlst
staticprivate

Definition at line 416 of file Aipsrc.h.

◆ root

String casacore::Aipsrc::root
staticprivate

AIPSROOT.

Definition at line 400 of file Aipsrc.h.

◆ site

String casacore::Aipsrc::site
staticprivate

AIPSSITE.

Definition at line 404 of file Aipsrc.h.

◆ strlst

Block<String> casacore::Aipsrc::strlst
staticprivate

String register list.

Definition at line 415 of file Aipsrc.h.

◆ theirCallOnceFlag

std::once_flag casacore::Aipsrc::theirCallOnceFlag
staticprivate

Object to ensure safe multi-threaded lazy single initialization.

Definition at line 388 of file Aipsrc.h.

◆ uhome

String casacore::Aipsrc::uhome
staticprivate

HOME.

Definition at line 410 of file Aipsrc.h.


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