CASToR  1.1
Tomographic Reconstruction (PET/SPECT)
 All Classes Files Functions Variables Typedefs Macros Groups Pages
Macros | Functions
gOptions.hh File Reference

This file is used for all kind of different functions designed for options parsing and ASCII file reading.
All functions included here are not class members. More...

Go to the source code of this file.

Macros

#define KEYWORD_MANDATORY   true
 
#define KEYWORD_OPTIONAL   false
 
#define KEYWORD_MANDATORY_NOT_FOUND   1
 
#define KEYWORD_OPTIONAL_NOT_FOUND   2
 

Functions

template<typename T >
int ReadStringOption (const string &a_input, T *ap_return, int a_nbElts, const string &sep, const string &a_option)
 Parse the 'a_input' string corresponding to the 'a_option' into 'a_nbElts' elements, using the 'sep' separator.
The results are returned in the templated 'ap_return' dynamic templated array.
Call "ConvertFromString()" to perform the correct conversion depending on the type of the data to convert. More...
 
template<typename T >
int ReadDataASCIIFile (const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag)
 Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter
and return the corresponding value(s) in the "ap_return" templated array.
This function expect the data to recover to be written on one line after the key. More...
 
template<typename T >
int ReadDataASCIIFile (const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag)
 Look for "a_nbLines" lines of "a_nbElts" elts in the 'a_file' file matching the "a_keyword" string
passed as parameter and return the corresponding value(s) in the "ap_return" templated 1D array.
This function expects the following parsing :
KEY :
line1 : elt1,elt2,...,eltN
line2 : elt1,elt2,...,eltN
(...)
lineN : elt1,elt2,...,eltN. More...
 
template<typename T >
int ReadDataASCIIFile (const string &a_file, const string &a_keyword, T **a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag)
 Look for "a_nbLines" lines of "a_nbElts" elts in the 'a_file' file matching the "a_keyword" string
passed as parameter and return the corresponding value(s) in the "a2p_return" 2D array.
The first and second dimensions of "a2p_return" correspond to the line and elements respectively
This function expects the following parsing :
KEY :
line1 : elt1,elt2,...,eltN
line2 : elt1,elt2,...,eltN
(...)
lineN : elt1,elt2,...,eltN. More...
 
template<typename T >
int ReadDataASCIIFile (const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag, string a_firstTag, string a_lastTag)
 Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter
and return the corresponding value(s) in the "ap_return" templated array.
Additionnal two parameters allow to search within two specific tags
This function expects the following parsing :
FIRST_TAG
(...)
KEY : elt1,elt2,...,eltN
(...)
LAST_TAG. More...
 
template<typename T >
int ReadDataASCIIFile (const string &a_file, const string &a_keyword, T **a2p_return, int a_nbElts, int a_nbLines, bool a_mandatoryFlag, string a_firstTag, string a_lastTag)
 Look for "a_nbLines" lines of "a_nbElts" elts in the "a_file" file matching the "a_keyword" string
passed as parameter and return the corresponding value(s) in the "a2p_return" templated 2D array.
The first and second dimensions of "a2p_return" correspond to the line and elements respectively
Additionnal two parameters allow to search within two specific tags
This function expects the following parsing :
KEY :
FIRST_TAG
(...)
line1 : elt1,elt2,...,eltN
line2 : elt1,elt2,...,eltN
(...)
lineN : elt1,elt2,...,eltN
(...)
LAST_TAG. More...
 
int ConvertFromString (const string &a_str, string *a_result)
 Copy the 'a_str' string in the position pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, float *a_result)
 Convert the 'a_str' string in float and copy the result in the variable pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, double *a_result)
 Convert the 'a_str' string in double and copy the result in the position pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, long double *a_result)
 Convert the 'a_str' string in long double and copy the result in the position pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, int *a_result)
 Convert the 'a_str' string in int and copy the result in the position pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, int64_t *a_result)
 Convert the 'a_str' string in long int and copy the result in the position pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, uint8_t *a_result)
 Convert the 'a_str' string in uint16_t and copy the result in the position pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, uint16_t *a_result)
 Convert the 'a_str' string in uint16_t and copy the result in the position pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, uint32_t *a_result)
 Convert the 'a_str' string in uint32_t and copy the result in the position pointed by 'a_result'. More...
 
int ConvertFromString (const string &a_str, bool *a_result)
 Convert the 'a_str' string in bool and copy the result in the position pointed by 'a_result'. More...
 
bool FLTNBIsEqual (FLTNB a, FLTNB b, FLTNB a_eps)
 Comparison of FLTNB numbers. More...
 
string GetFileFromPath (const string &a_pathToFile)
 Simply return the file from a path string passed in parameter. More...
 
string GetPathOfFile (const string &a_pathToFile)
 Simply return the path to the directory of a file path string passed in parameter. More...
 
string ConvertAllSlashOccurrencesToBackSlash (const string &a_path)
 

Detailed Description

This file is used for all kind of different functions designed for options parsing and ASCII file reading.
All functions included here are not class members.

Definition in file gOptions.hh.

Function Documentation

string ConvertAllSlashOccurrencesToBackSlash ( const string &  a_path)

Definition at line 1164 of file gOptions.cc.

Here is the caller graph for this function:

int ConvertFromString ( const string &  a_str,
string *  a_result 
)

Copy the 'a_str' string in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

The only purposes of this function is to have an unified templated conversion function for each type

Returns
0 if success, and positive value otherwise

Definition at line 749 of file gOptions.cc.

Here is the caller graph for this function:

int ConvertFromString ( const string &  a_str,
float *  a_result 
)

Convert the 'a_str' string in float and copy the result in the variable pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtod to check errors with str to float conversion
(implementation similar to c++11 std::stof() ).

Returns
0 if success, and positive value otherwise

Definition at line 771 of file gOptions.cc.

int ConvertFromString ( const string &  a_str,
double *  a_result 
)

Convert the 'a_str' string in double and copy the result in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtod to check errors with str to double conversion
(implementation similar to c++11 std::stod() ).

Returns
0 if success, and positive value otherwise

Definition at line 810 of file gOptions.cc.

int ConvertFromString ( const string &  a_str,
long double *  a_result 
)

Convert the 'a_str' string in long double and copy the result in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtod to check errors with str to ldouble conversion
(implementation similar to c++11 std::stod() ).

Returns
0 if success, and positive value otherwise

Definition at line 849 of file gOptions.cc.

int ConvertFromString ( const string &  a_str,
int *  a_result 
)

Convert the 'a_str' string in int and copy the result in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtol to check errors with str to int conversion
(implementation similar to c++11 std::stoi() ).

Returns
0 if success, and positive value otherwise

Definition at line 888 of file gOptions.cc.

int ConvertFromString ( const string &  a_str,
int64_t *  a_result 
)

Convert the 'a_str' string in long int and copy the result in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtol to check errors with str to int64_t (8 bytes int) conversion
(implementation similar to c++11 std::stol() ).

Returns
0 if success, and positive value otherwise

Definition at line 927 of file gOptions.cc.

int ConvertFromString ( const string &  a_str,
uint8_t *  a_result 
)

Convert the 'a_str' string in uint16_t and copy the result in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtol to check errors with str to uint8 conversion
(implementation similar to c++11 std::stoi() ).

Returns
0 if success, and positive value otherwise

Definition at line 966 of file gOptions.cc.

int ConvertFromString ( const string &  a_str,
uint16_t *  a_result 
)

Convert the 'a_str' string in uint16_t and copy the result in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtol to check errors with str to uint16 conversion
(implementation similar to c++11 std::stoi() ).

Returns
0 if success, and positive value otherwise

Definition at line 1005 of file gOptions.cc.

int ConvertFromString ( const string &  a_str,
uint32_t *  a_result 
)

Convert the 'a_str' string in uint32_t and copy the result in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtol to check errors with str to uint32 conversion
(implementation similar to c++11 std::stoi() ).

Returns
0 if success, and positive value otherwise

Definition at line 1044 of file gOptions.cc.

int ConvertFromString ( const string &  a_str,
bool *  a_result 
)

Convert the 'a_str' string in bool and copy the result in the position pointed by 'a_result'.

Parameters
a_str: string to convert
a_result: variable which will recover the result

Uses strtol to check errors with str to bool conversion
(implementation similar to c++11 std::stoi() ).

Returns
0 if success, and positive value otherwise

Definition at line 1083 of file gOptions.cc.

bool FLTNBIsEqual ( FLTNB  a,
FLTNB  b,
FLTNB  a_eps 
)

Comparison of FLTNB numbers.

Parameters
a: 1st FLTNB nb to compare
b: 2nd FLTNB nb to compare
a_eps: epsilon for comparison
Returns
true if equal according to the provided epsilon, false otherwise

Definition at line 1184 of file gOptions.cc.

Here is the caller graph for this function:

string GetFileFromPath ( const string &  a_pathToFile)

Simply return the file from a path string passed in parameter.

Parameters
a_pathToFile
Returns
The path.

Definition at line 1119 of file gOptions.cc.

Here is the caller graph for this function:

string GetPathOfFile ( const string &  a_pathToFile)

Simply return the path to the directory of a file path string passed in parameter.

Parameters
a_pathToFile
Returns
The path.

Definition at line 1144 of file gOptions.cc.

Here is the caller graph for this function:

template<typename T >
int ReadDataASCIIFile ( const string &  a_file,
const string &  a_keyword,
T *  ap_return,
int  a_nbElts,
bool  a_mandatoryFlag 
)

Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter
and return the corresponding value(s) in the "ap_return" templated array.
This function expect the data to recover to be written on one line after the key.

Parameters
a_file: string containing the path to the ASCII file
a_keyword: key related to the data we want to recover
ap_return: templated array in which the data will be returned the recovered data will be converted to its type its size should be equal to the number of elts to recover
a_nbElts: number of elements to recover
a_mandatoryFlag: boolean indicating the data to recover is
mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)

This function assumes the following separators :
":" is used as separator between the keyworld and the value
"#" is used for comment. Every following characters will be discarded
"," is used to separate elements if more than one are required

Returns
0 if success, and positive value otherwise (1 if error, 2 if tag not found).

Definition at line 111 of file gOptions.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
int ReadDataASCIIFile ( const string &  a_file,
const string &  a_keyword,
T *  ap_return,
int  a_nbElts,
int  a_nbLines,
bool  a_mandatoryFlag 
)

Look for "a_nbLines" lines of "a_nbElts" elts in the 'a_file' file matching the "a_keyword" string
passed as parameter and return the corresponding value(s) in the "ap_return" templated 1D array.
This function expects the following parsing :
KEY :
line1 : elt1,elt2,...,eltN
line2 : elt1,elt2,...,eltN
(...)
lineN : elt1,elt2,...,eltN.

Parameters
a_file: string containing the path to the ASCII file
a_keyword: key related to the data we want to recover
ap_return: templated array in which the data will be returned
the recovered data will be converted to its type
its size should be equal to the nb of lines*nb of elts to recover
a_nbElts: number of elements to recover (on each line)
a_nbLines: number of lines to recover
a_mandatoryFlag: boolean indicating the data to recover is
mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)

This function assumes the following separators :
":" is used as separator between the keyworld and the value
"#" is used for comment. Every following characters will be discarded
"," is used to separate elements if more than one are required

Returns
0 if success, and positive value otherwise (1 if error, 2 if tag not found).

Definition at line 236 of file gOptions.cc.

Here is the call graph for this function:

template<typename T >
int ReadDataASCIIFile ( const string &  a_file,
const string &  a_keyword,
T **  a2p_return,
int  a_nbElts,
int  a_nbLines,
bool  a_mandatoryFlag 
)

Look for "a_nbLines" lines of "a_nbElts" elts in the 'a_file' file matching the "a_keyword" string
passed as parameter and return the corresponding value(s) in the "a2p_return" 2D array.
The first and second dimensions of "a2p_return" correspond to the line and elements respectively
This function expects the following parsing :
KEY :
line1 : elt1,elt2,...,eltN
line2 : elt1,elt2,...,eltN
(...)
lineN : elt1,elt2,...,eltN.

Parameters
a_file: string containing the path to the ASCII file
a_keyword: key related to the data we want to recover
a2p_return: 2D templated array in which the data will be returned
the recovered data will be converted to its type
its size should be equal [nb of lines][nb of elts to recover]
a_nbElts: number of elements to recover (on each line)
a_nbLines: number of lines to recover
a_mandatoryFlag: boolean indicating the data to recover is
mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)

This function assumes the following separators :
":" is used as separator between the keyworld and the value
"#" is used for comment. Every following characters will be discarded
"," is used to separate elements if more than one are required

Returns
0 if success, and positive value otherwise (1 if error, 2 if tag not found).

Definition at line 364 of file gOptions.cc.

Here is the call graph for this function:

template<typename T >
int ReadDataASCIIFile ( const string &  a_file,
const string &  a_keyword,
T *  ap_return,
int  a_nbElts,
bool  a_mandatoryFlag,
string  a_firstTag,
string  a_lastTag 
)

Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter
and return the corresponding value(s) in the "ap_return" templated array.
Additionnal two parameters allow to search within two specific tags
This function expects the following parsing :
FIRST_TAG
(...)
KEY : elt1,elt2,...,eltN
(...)
LAST_TAG.

Parameters
a_file: string containing the path to the ASCII file
a_keyword: key related to the data we want to recover
ap_return: templated array in which the data will be returned
the recovered data will be converted to its type
its size should be equal to the number of elts to recover
a_nbElts: number of elements to recover
a_mandatoryFlag: boolean indicating the data to recover is
mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)
a_firstTag: the requested key will be looked for after the first occurence of this string
a_lastTag: the requested key will be looked for before the first occurence of this string

This function assumes the following separators :
":" is used as separator between the keyworld and the value
"#" is used for comment. Every following characters will be discarded
"," is used to separate elements if more than one are required

Returns
0 if success, and positive value otherwise (1 if error, 2 if tag not found).

Definition at line 494 of file gOptions.cc.

Here is the call graph for this function:

template<typename T >
int ReadDataASCIIFile ( const string &  a_file,
const string &  a_keyword,
T **  a2p_return,
int  a_nbElts,
int  a_nbLines,
bool  a_mandatoryFlag,
string  a_firstTag,
string  a_lastTag 
)

Look for "a_nbLines" lines of "a_nbElts" elts in the "a_file" file matching the "a_keyword" string
passed as parameter and return the corresponding value(s) in the "a2p_return" templated 2D array.
The first and second dimensions of "a2p_return" correspond to the line and elements respectively
Additionnal two parameters allow to search within two specific tags
This function expects the following parsing :
KEY :
FIRST_TAG
(...)
line1 : elt1,elt2,...,eltN
line2 : elt1,elt2,...,eltN
(...)
lineN : elt1,elt2,...,eltN
(...)
LAST_TAG.

Parameters
a_file: string containing the path to the ASCII file
a_keyword: key related to the data we want to recover
a2p_return: 2D templated array in which the data will be returned
the recovered data will be converted to its type
its size should be equal [nb of lines][nb of elts to recover]
a_nbElts: number of elements to recover (on each line)
a_nbLines: number of lines to recover
a_mandatoryFlag: boolean indicating the data to recover is
mandatory (KEYWORD_MANDATORY) (error value (=1) will be returned if not found)
or optional (KEYWORD_OPTIONAL) (warning value (=2) will be returned if not found)
a_firstTag: the requested key will be looked for after the first occurence of this string
a_lastTag: the requested key will be looked for before the first occurence of this string

This function assumes the following separators :
":" is used as separator between the keyworld and the value
"#" is used for comment. Every following characters will be discarded
"," is used to separate elements if more than one are required

Returns
0 if success, and positive value otherwise (1 if error, 2 if tag not found).

Definition at line 637 of file gOptions.cc.

Here is the call graph for this function:

template<typename T >
int ReadStringOption ( const string &  a_input,
T *  ap_return,
int  a_nbElts,
const string &  sep,
const string &  a_option 
)

Parse the 'a_input' string corresponding to the 'a_option' into 'a_nbElts' elements, using the 'sep' separator.
The results are returned in the templated 'ap_return' dynamic templated array.
Call "ConvertFromString()" to perform the correct conversion depending on the type of the data to convert.

Parameters
a_input: string to parse
ap_return: (templated) array in which the parsed elements will be returned
a_nbElts: a number of elements to parse
sep: the separator (usually comma)
a_option: string indicating from where the function has been called
Returns
0 if success, and positive value otherwise.

Definition at line 50 of file gOptions.cc.

Here is the call graph for this function:

Here is the caller graph for this function: