nidas
v1.2-1520
|
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... | |
FileSet & | operator= (const FileSet &x) |
Assignment operator. More... | |
virtual FileSet * | clone () 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... | |
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.
FileSet::FileSet | ( | ) |
constructor
Referenced by clone().
FileSet::FileSet | ( | const FileSet & | x | ) |
Copy constructor.
Only permissable before it is opened.
|
virtual |
Destructor.
Closes current file, ignoring possible IOException if the file isn't open.
References closeFile().
|
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.
|
virtual |
|
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().
|
static |
References DLOG, getDirPortion(), and ILOG.
Referenced by nidas::core::NidasApp::checkPidFile(), and nidas::core::FsMount::mount().
|
virtual |
Create a new file, with a name formed from a time.
Create a file using a time to create the name.
tfile | Time to use when creating file name. |
exact | Use exact time when creating file name, else the time is truncated by getFileLengthSecs. |
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.
|
protected |
References _fullpath, and nidas::util::UTime::format().
Referenced by initialize().
|
inline |
Get name of current file.
References _currname.
Referenced by nidas::core::FileSet::getCurrentName().
|
inlinevirtual |
References _dir.
Referenced by setFileName().
|
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().
|
inline |
References _fd.
Referenced by nidas::core::FileSet::getFd().
|
inline |
References _fileLength, and USECS_PER_SEC.
Referenced by nidas::core::FileSet::getFileLengthSecs().
|
inlinevirtual |
|
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().
|
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().
|
inlinevirtual |
Get the full path, the concatenation of getDir() and getFileName().
References _fullpath.
Referenced by nidas::core::FileSet::setDir(), and nidas::core::FileSet::setFileName().
|
inline |
References _startTime.
Referenced by nidas::core::FileSet::getEndTime(), and nidas::core::FileSet::getStartTime().
|
private |
References _endTime, _fileiter, _fileLength, _fileset, _fullpath, _initialized, _startTime, DLOG, formatName(), matchFiles(), nidas::util::UTime::toUsecs(), and USECS_PER_DAY.
Referenced by openNextFile().
|
inline |
References _newFile.
Referenced by nidas::core::FileSet::isNewInput().
|
inline |
References _keepopening.
Referenced by nidas::core::FileSet::keepOpening().
|
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 | |
) |
References DLOG, ftime(), nidas::util::replaceChars(), USECS_PER_DAY, and USECS_PER_HOUR.
Referenced by initialize().
|
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 | ||
) |
Open the next file to be read.
References _currname, _fd, _fileiter, _fileset, _initialized, _keepopening, _newFile, closeFile(), DLOG, ELOG, ILOG, initialize(), and nidas::util::Exception::what().
Assignment operator.
Only permissable before it is opened.
References _currname, _dir, _endTime, _fileiter, _fileLength, _filename, _fileset, _fullpath, _initialized, _keepopening, _lastErrno, _newFile, _startTime, and closeFile().
|
virtual |
Read from current file.
Referenced by nidas::core::FileSet::read().
|
staticprotected |
|
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().
|
inline |
References _endTime.
Referenced by nidas::core::FileSet::setEndTime().
|
inline |
Set/get the file length in seconds.
0 means unlimited.
References _fileLength, and USECS_PER_SEC.
Referenced by nidas::core::FileSet::setFileLengthSecs().
|
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().
|
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().
|
inline |
References _startTime.
Referenced by nidas::core::FileSet::setStartTime().
|
virtual |
Write to current file.
Referenced by nidas::core::FileSet::write().
|
virtual |
|
private |
Referenced by closeFile(), getCurrentName(), getFileSize(), openNextFile(), and operator=().
|
private |
Referenced by getDir(), operator=(), and setDir().
|
private |
Referenced by getEndTime(), initialize(), operator=(), and setEndTime().
|
protected |
Referenced by closeFile(), getFd(), getFileSize(), and openNextFile().
|
private |
Referenced by initialize(), openNextFile(), and operator=().
|
private |
File length, in microseconds.
Referenced by getFileLengthSecs(), initialize(), operator=(), and setFileLengthSecs().
|
private |
Referenced by getFileName(), operator=(), and setFileName().
|
private |
Referenced by addFileName(), initialize(), openNextFile(), and operator=().
|
private |
Referenced by formatName(), getPath(), initialize(), operator=(), setDir(), and setFileName().
|
private |
Referenced by initialize(), openNextFile(), and operator=().
|
protected |
Referenced by keepOpening(), openNextFile(), operator=(), and setKeepOpening().
|
mutableprotected |
This value can get set by getFileSize() which is a const method.
Referenced by getFileSize(), getLastErrno(), and operator=().
|
protected |
Referenced by isNewFile(), openNextFile(), and operator=().
|
private |
Referenced by getStartTime(), initialize(), operator=(), and setStartTime().
|
protected |
|
static |
Referenced by getDirPortion(), getFilePortion(), and makePath().