nidas  v1.2-1520
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
nidas::util::FileSet Class Reference

A description of a set of output files, consisting of a directory name and a file name format containing UNIX strftime conversion specifiers, like Y, m, etc. More...

#include <FileSet.h>

Public Member Functions

 FileSet ()
 constructor More...
 
 FileSet (const FileSet &x)
 Copy constructor. More...
 
FileSetoperator= (const FileSet &x)
 Assignment operator. More...
 
virtual FileSetclone () const
 Virtual constructor. More...
 
virtual ~FileSet ()
 Destructor. More...
 
virtual void setDir (const std::string &val)
 Set directory portion of file path. More...
 
virtual const std::string & getDir ()
 
int getFd () const
 
bool isNewFile () const
 
virtual void setFileName (const std::string &val)
 Set file name portion of file path. More...
 
virtual const std::string & getFileName ()
 
virtual const std::string & getPath ()
 Get the full path, the concatenation of getDir() and getFileName(). More...
 
virtual void addFileName (const std::string &val)
 
void setFileLengthSecs (int val)
 Set/get the file length in seconds. More...
 
int getFileLengthSecs () const
 
virtual UTime createFile (UTime tfile, bool exact) throw (IOException)
 Create a new file, with a name formed from a time. More...
 
void setStartTime (const UTime &val)
 
UTime getStartTime () const
 
void setEndTime (const UTime &val)
 
UTime getEndTime () const
 
const std::string & getCurrentName () const
 Get name of current file. More...
 
virtual void closeFile () throw (IOException)
 Closes any file currently open. More...
 
virtual void openFileForWriting (const std::string &filename) throw (IOException)
 Open a new file for writing. More...
 
void openNextFile () throw (IOException)
 Open the next file to be read. More...
 
virtual size_t read (void *buf, size_t count) throw (IOException)
 Read from current file. More...
 
virtual size_t write (const void *buf, size_t count) throw (IOException)
 Write to current file. More...
 
virtual size_t write (const struct iovec *iov, int iovcnt) throw (IOException)
 
void checkPathFormat (const UTime &t1, const UTime &t2) throw (IOException)
 Check that any date or time descriptors, e.g. More...
 
std::list< std::string > matchFiles (const UTime &t1, const UTime &t2) throw (IOException)
 
long long getFileSize () const throw (IOException)
 
int getLastErrno () const
 Get last error value. More...
 
void setKeepOpening (bool keepopening)
 Set whether the FileSet should keep going to the next file when an error happens opening a file. More...
 
bool keepOpening ()
 

Static Public Member Functions

static void createDirectory (const std::string &name, mode_t mode)
 
static std::string getDirPortion (const std::string &path)
 Utility function to return the directory portion of a file path. More...
 
static std::string getFilePortion (const std::string &path)
 Utility function to return the file portion of a file path. More...
 
static std::string makePath (const std::string &dir, const std::string &file)
 Utility function to create a full path name from a directory and file portion. More...
 

Static Public Attributes

static const char pathSeparator = '/'
 

Protected Member Functions

std::string formatName (const UTime &t1)
 

Static Protected Member Functions

static void replaceChars (std::string &in, const std::string &pat, const std::string &rep)
 

Protected Attributes

const std::time_put< char > & _timeputter
 
bool _newFile
 
int _lastErrno
 This value can get set by getFileSize() which is a const method. More...
 
int _fd
 
bool _keepopening
 

Private Member Functions

void initialize ()
 

Private Attributes

std::string _dir
 
std::string _filename
 
std::string _currname
 
std::string _fullpath
 
UTime _startTime
 
UTime _endTime
 
std::list< std::string > _fileset
 
std::list< std::string >::iterator _fileiter
 
bool _initialized
 
long long _fileLength
 File length, in microseconds. More...
 

Detailed Description

A description of a set of output files, consisting of a directory name and a file name format containing UNIX strftime conversion specifiers, like Y, m, etc.

Typically this class is used by an archive method.

Constructor & Destructor Documentation

FileSet::FileSet ( )

constructor

Referenced by clone().

FileSet::FileSet ( const FileSet x)

Copy constructor.

Only permissable before it is opened.

FileSet::~FileSet ( )
virtual

Destructor.

Closes current file, ignoring possible IOException if the file isn't open.

References closeFile().

Member Function Documentation

virtual void nidas::util::FileSet::addFileName ( const std::string &  val)
inlinevirtual

References _fileset.

Referenced by nidas::core::FileSet::addFileName().

void FileSet::checkPathFormat ( const UTime t1,
const UTime t2 
)
throw (IOException
)

Check that any date or time descriptors, e.g.

"%y", "%m", in the full file path string are in the correct order, so that a default lexical sort will sort the file path names in time order. The descriptors in the path must be in decreasing time-interval order, e.g. year before month, month before day, etc.

References USECS_PER_DAY.

FileSet * FileSet::clone ( ) const
virtual

Virtual constructor.

Only permissable before *this is opened.

References FileSet().

void FileSet::closeFile ( )
throw (IOException
)
virtual

Closes any file currently open.

The base implementation closes the file descriptor. Subclasses override this method to close alternate resources.

References _currname, _fd, DLOG, and fd.

Referenced by nidas::core::FileSet::close(), openNextFile(), operator=(), and ~FileSet().

void FileSet::createDirectory ( const std::string &  name,
mode_t  mode 
)
static
UTime FileSet::createFile ( UTime  tfile,
bool  exact 
)
throw (IOException
)
virtual

Create a new file, with a name formed from a time.

Create a file using a time to create the name.

Parameters
tfileTime to use when creating file name.
exactUse exact time when creating file name, else the time is truncated by getFileLengthSecs.
Returns
Start time of next file, i.e. when to create next file.

Return the time of the next file.

References DLOG, nidas::util::UTime::format(), ftime(), nidas::util::Exception::getErrno(), ILOG, nidas::util::UTime::toUsecs(), USECS_PER_SEC, nidas::util::Exception::what(), and WLOG.

string FileSet::formatName ( const UTime t1)
protected

References _fullpath, and nidas::util::UTime::format().

Referenced by initialize().

const std::string& nidas::util::FileSet::getCurrentName ( ) const
inline

Get name of current file.

References _currname.

Referenced by nidas::core::FileSet::getCurrentName().

virtual const std::string& nidas::util::FileSet::getDir ( )
inlinevirtual

References _dir.

Referenced by setFileName().

string FileSet::getDirPortion ( const std::string &  path)
static

Utility function to return the directory portion of a file path.

If the directory portion is empty, returns ".". Uses pathSeparator to determine directory and file portion.

References pathSeparator.

Referenced by nidas::core::NidasApp::checkPidFile(), and createDirectory().

UTime nidas::util::FileSet::getEndTime ( ) const
inline

References _endTime.

int nidas::util::FileSet::getFd ( ) const
inline

References _fd.

Referenced by nidas::core::FileSet::getFd().

int nidas::util::FileSet::getFileLengthSecs ( ) const
inline
virtual const std::string& nidas::util::FileSet::getFileName ( )
inlinevirtual

References _filename.

Referenced by setDir().

string FileSet::getFilePortion ( const std::string &  path)
static

Utility function to return the file portion of a file path.

Uses pathSeparator to determine directory and file portion.

References pathSeparator.

long long FileSet::getFileSize ( ) const
throw (IOException
)

References _currname, _fd, and _lastErrno.

Referenced by nidas::core::FileSet::getFileSize().

int nidas::util::FileSet::getLastErrno ( ) const
inline

Get last error value.

Should be 0. Currently only supported for an output file, to be queried by a system status thread.

References _lastErrno.

Referenced by nidas::core::FileSet::getLastErrno().

virtual const std::string& nidas::util::FileSet::getPath ( )
inlinevirtual

Get the full path, the concatenation of getDir() and getFileName().

References _fullpath.

Referenced by nidas::core::FileSet::setDir(), and nidas::core::FileSet::setFileName().

UTime nidas::util::FileSet::getStartTime ( ) const
inline
void FileSet::initialize ( )
private
bool nidas::util::FileSet::isNewFile ( ) const
inline

References _newFile.

Referenced by nidas::core::FileSet::isNewInput().

bool nidas::util::FileSet::keepOpening ( )
inline
string FileSet::makePath ( const std::string &  dir,
const std::string &  file 
)
static

Utility function to create a full path name from a directory and file portion.

If the directory portion is an empty string, or ".", then the result path will have no directory portion.

References pathSeparator.

Referenced by setDir(), and setFileName().

list< string > FileSet::matchFiles ( const UTime t1,
const UTime t2 
)
throw (IOException
)
void FileSet::openFileForWriting ( const std::string &  filename)
throw (IOException
)
virtual

Open a new file for writing.

The filename is the path for the new file as generated from the filename template and a time. The base implementation calls open64() and sets the file descriptor.

void FileSet::openNextFile ( )
throw (IOException
)
FileSet & FileSet::operator= ( const FileSet x)

Assignment operator.

Only permissable before it is opened.

References _currname, _dir, _endTime, _fileiter, _fileLength, _filename, _fileset, _fullpath, _initialized, _keepopening, _lastErrno, _newFile, _startTime, and closeFile().

size_t FileSet::read ( void *  buf,
size_t  count 
)
throw (IOException
)
virtual

Read from current file.

Referenced by nidas::core::FileSet::read().

void FileSet::replaceChars ( std::string &  in,
const std::string &  pat,
const std::string &  rep 
)
staticprotected
void FileSet::setDir ( const std::string &  val)
virtual

Set directory portion of file path.

This may contain strftime conversion specifiers, like Y in order to put a year in the directory name.

References _dir, _fullpath, getFileName(), and makePath().

Referenced by nidas::core::FileSet::setDir().

void nidas::util::FileSet::setEndTime ( const UTime val)
inline

References _endTime.

Referenced by nidas::core::FileSet::setEndTime().

void nidas::util::FileSet::setFileLengthSecs ( int  val)
inline

Set/get the file length in seconds.

0 means unlimited.

References _fileLength, and USECS_PER_SEC.

Referenced by nidas::core::FileSet::setFileLengthSecs().

void FileSet::setFileName ( const std::string &  val)
virtual

Set file name portion of file path.

This can contain strftime conversion specifiers. FileSet inserts the pathSeparator between the directory and the file name when creating the full file path string. Otherwise there is no distinction between the directory and file portion.

References _filename, _fullpath, getDir(), and makePath().

Referenced by nidas::core::FileSet::setFileName().

void nidas::util::FileSet::setKeepOpening ( bool  keepopening)
inline

Set whether the FileSet should keep going to the next file when an error happens opening a file.

References _keepopening.

Referenced by nidas::core::FileSet::setKeepOpening().

void nidas::util::FileSet::setStartTime ( const UTime val)
inline
size_t FileSet::write ( const void *  buf,
size_t  count 
)
throw (IOException
)
virtual

Write to current file.

Referenced by nidas::core::FileSet::write().

size_t FileSet::write ( const struct iovec *  iov,
int  iovcnt 
)
throw (IOException
)
virtual

Member Data Documentation

std::string nidas::util::FileSet::_currname
private
std::string nidas::util::FileSet::_dir
private

Referenced by getDir(), operator=(), and setDir().

UTime nidas::util::FileSet::_endTime
private
int nidas::util::FileSet::_fd
protected
std::list<std::string>::iterator nidas::util::FileSet::_fileiter
private

Referenced by initialize(), openNextFile(), and operator=().

long long nidas::util::FileSet::_fileLength
private

File length, in microseconds.

Referenced by getFileLengthSecs(), initialize(), operator=(), and setFileLengthSecs().

std::string nidas::util::FileSet::_filename
private

Referenced by getFileName(), operator=(), and setFileName().

std::list<std::string> nidas::util::FileSet::_fileset
private
std::string nidas::util::FileSet::_fullpath
private
bool nidas::util::FileSet::_initialized
private

Referenced by initialize(), openNextFile(), and operator=().

bool nidas::util::FileSet::_keepopening
protected
int nidas::util::FileSet::_lastErrno
mutableprotected

This value can get set by getFileSize() which is a const method.

Referenced by getFileSize(), getLastErrno(), and operator=().

bool nidas::util::FileSet::_newFile
protected

Referenced by isNewFile(), openNextFile(), and operator=().

UTime nidas::util::FileSet::_startTime
private
const std::time_put<char>& nidas::util::FileSet::_timeputter
protected
const char FileSet::pathSeparator = '/'
static

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