lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
psalg::ArrayIO< T > Class Template Reference

Loads an array of T from a text file in the constructor. More...

#include <ArrayIO.hh>

Public Types

enum  STATUS { LOADED =0 , DEFAULT , UNREADABLE , UNDEFINED }
 Load status reported by status(). More...
 
typedef psalg::types::shape_t shape_t
 Alias for psalg::types::shape_t (uint32_t).
 
typedef psalg::types::size_t size_t
 Alias for psalg::types::size_t (uint32_t).
 

Public Member Functions

 ArrayIO (const std::string &fname, void *buf=0)
 Read fname right away.
 
 ~ArrayIO ()
 Destructor; only logs a trace message.
 
const STATUS status () const
 Return the load status.
 
const std::string str_status () const
 Return the status name ("LOADED", "DEFAULT", "UNREADABLE" or "UNDEFINED").
 
const std::string & dtype_name () const
 Return the DATATYPE value read from the file (empty if there was none).
 
NDArray< T > & ndarray ()
 Return the loaded array.
 

Public Attributes

std::string STRAUS [4] ={"LOADED", "DEFAULT", "UNREADABLE", "UNDEFINED"}
 Names of the STATUS values, used by str_status().
 

Detailed Description

template<typename T>
class psalg::ArrayIO< T >

Loads an array of T from a text file in the constructor.

Lines starting with '#' are metadata ("SHAPE (d0,d1,...)" sets the shape, "DATATYPE x" the type name); the first other non-empty line and everything after it are read as whitespace-separated values. Instantiated in ArrayIO.cc for int, unsigned, unsigned short and float.

Member Typedef Documentation

◆ shape_t

template<typename T >
typedef psalg::types::shape_t psalg::ArrayIO< T >::shape_t

Alias for psalg::types::shape_t (uint32_t).

◆ size_t

template<typename T >
typedef psalg::types::size_t psalg::ArrayIO< T >::size_t

Alias for psalg::types::size_t (uint32_t).

Member Enumeration Documentation

◆ STATUS

template<typename T >
enum psalg::ArrayIO::STATUS

Load status reported by status().

Enumerator
LOADED 

0: the file was read (also set when the value count differs from the shape size).

DEFAULT 

1: not set anywhere in ArrayIO.cc.

UNREADABLE 

2: the file could not be opened.

UNDEFINED 

3: initial value before loading.

Constructor & Destructor Documentation

◆ ArrayIO()

template<typename T >
psalg::ArrayIO< T >::ArrayIO ( const std::string &  fname,
void *  buf = 0 
)

Read fname right away.

Values go into buf if it is non-null, otherwise into a buffer the NDArray allocates. Logs a warning if the file cannot be opened (status UNREADABLE) or if the number of values differs from the shape size; extra values are still written past the end of the buffer.

◆ ~ArrayIO()

template<typename T >
psalg::ArrayIO< T >::~ArrayIO ( )

Destructor; only logs a trace message.

Member Function Documentation

◆ dtype_name()

template<typename T >
const std::string & psalg::ArrayIO< T >::dtype_name ( ) const
inline

Return the DATATYPE value read from the file (empty if there was none).

◆ ndarray()

template<typename T >
NDArray< T > & psalg::ArrayIO< T >::ndarray ( )
inline

Return the loaded array.

◆ status()

template<typename T >
const STATUS psalg::ArrayIO< T >::status ( ) const
inline

Return the load status.

◆ str_status()

template<typename T >
const std::string psalg::ArrayIO< T >::str_status ( ) const
inline

Return the status name ("LOADED", "DEFAULT", "UNREADABLE" or "UNDEFINED").

Member Data Documentation

◆ STRAUS

template<typename T >
std::string psalg::ArrayIO< T >::STRAUS[4] ={"LOADED", "DEFAULT", "UNREADABLE", "UNDEFINED"}

Names of the STATUS values, used by str_status().


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