41 namespace fileOperations
47 uncollatedFileOperation,
53 uncollatedFileOperation,
60 fileOperationInitialise,
61 fileOperationInitialise_unthreaded,
73 const bool checkGlobal,
79 if (
io.instance().isAbsolute())
102 &&
io.time().processorCase()
104 io.instance() ==
io.time().system()
105 ||
io.instance() ==
io.time().constant()
111 fileName parentPath =
113 io.rootPath()/
io.globalCaseName()
114 /
io.instance()/
io.db().dbDir()/
io.local()/
io.name()
124 if (
io.time().processorCase())
126 const refPtr<dirIndexList> pDirs
134 for (
const dirIndex& dirIdx : pDirs())
136 const fileName& pDir = dirIdx.first();
152 word newInstancePath =
io.time().findInstancePath
154 instant(
io.instance())
157 if (newInstancePath.size())
161 io.rootPath()/
io.caseName()
162 /newInstancePath/
io.db().dbDir()/
io.local()/
io.name()
214 return commAndIORanks;
222 void Foam::fileOperations::uncollatedFileOperation::init(
bool verbose)
229 <<
"I/O : " << typeName <<
endl;
243 managedComm_(getManagedComm(comm_))
252 const bool distributedRoots,
266 managedComm_ = getManagedComm(comm_);
306 const bool followLink
316 const bool followLink
326 const bool checkGzip,
327 const bool followLink
337 const bool followLink
347 const bool checkGzip,
348 const bool followLink
358 const bool followLink
368 const bool followLink
378 const bool followLink
388 const std::string& ext
420 const bool followLink
431 const bool followLink
434 return Foam::cp(src, dst, followLink);
452 const bool followLink
463 const bool checkGlobal,
465 const word& typeName,
471 Pout<<
"uncollatedFileOperation::filePath :" 472 <<
" objectPath:" <<
io.objectPath()
473 <<
" checkGlobal:" << checkGlobal <<
endl;
480 Pout<<
"uncollatedFileOperation::filePath :" 481 <<
" Returning from file searching:" <<
endl 482 <<
" objectPath:" <<
io.objectPath() <<
endl 491 const bool checkGlobal,
498 Pout<<
"uncollatedFileOperation::dirPath :" 499 <<
" objectPath:" <<
io.objectPath()
500 <<
" checkGlobal:" << checkGlobal <<
endl;
503 fileName objPath(filePathInfo(checkGlobal,
false,
io,
search));
507 Pout<<
"uncollatedFileOperation::dirPath :" 508 <<
" Returning from directory searching:" <<
endl 509 <<
" objectPath:" <<
io.objectPath() <<
endl 526 Pout<<
"uncollatedFileOperation::readObjects :" 528 <<
" instance:" << instance <<
endl;
537 if (newInstance.empty())
542 if (!newInst.empty() && newInst != instance)
557 Pout<<
"uncollatedFileOperation::readObjects :" 558 <<
" newInstance:" << newInstance
559 <<
" objectNames:" << objectNames <<
endl;
575 Pout<<
"uncollatedFileOperation::readHeader :" 576 <<
" fName:" << fName
577 <<
" typeName:" << typeName <<
endl;
584 <<
"file " <<
io.objectPath() <<
" could not be opened" 591 autoPtr<ISstream> isPtr(NewIFstream(fName));
593 if (!isPtr || !isPtr->good())
603 Pout<<
"uncollatedFileOperation::readHeader :" 604 <<
" for fName:" << fName
606 <<
" headerClassName:" <<
io.headerClassName() <<
endl;
618 const word& typeName,
619 const bool readOnProc
630 <<
"cannot find file " <<
io.objectPath()
634 autoPtr<ISstream> isPtr = NewIFstream(fName);
636 if (!isPtr || !isPtr->good())
640 "uncollatedFileOperation::readStream()",
645 ) <<
"cannot open file" 648 else if (!
io.readHeader(*isPtr))
651 <<
"problem while reading header for object " <<
io.name()
664 label proci = detectProcessorPath(
io.objectPath());
669 <<
"could not detect processor number" 670 <<
" from objectPath:" <<
io.objectPath()
671 <<
" fName:" << fName
686 proci = proci -
group.start();
698 const bool masterOnly,
709 Pout<<
"uncollatedFileOperation::read :" 710 <<
" Reading object " <<
io.objectPath()
711 <<
" from file " <<
endl;
715 const bool oldGlobal =
io.globalObject(masterOnly);
731 ok =
io.readData(
io.readStream(typeName));
735 io.globalObject(oldGlobal);
741 Pout<<
"uncollatedFileOperation::read :" 742 <<
" Done reading object " <<
io.objectPath()
743 <<
" from file " <<
endl;
754 os <<
io.headerClassName() <<
io.note();
755 bool okWrite =
io.writeData(
os);
762 is >>
io.headerClassName() >>
io.note();
763 ok =
io.readData(is);
786 const bool writeOnProc
799 const bool writeOnProc
bool mvBak(const fileName &src, const std::string &ext="bak")
Rename to a corresponding backup file.
virtual bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist (as DIRECTORY or FILE) in the file system?
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
A class for handling file names.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
fileName processorsPath(const IOobject &io, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static void freeCommunicator(const label communicator, const bool withComponents=true)
Free a previously allocated communicator.
virtual fileName filePath(const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
Search for an object. checkGlobal : also check undecomposed case.
Output to file stream as an OSstream, normally using std::ofstream for the actual output...
int infoDetailLevel
Global for selective suppression of Info output.
uncollatedFileOperation(bool verbose=false)
Default construct.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
Top-level read.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const bool search) const
Search for an object.
static bool & parRun() noexcept
Test if this a parallel run.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
Remove a directory and its contents.
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
static constexpr label commSelf() noexcept
Communicator within the current rank only.
A simple container for options an IOstream can normally have.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
A class for managing references or pointers (no reference counting)
An encapsulation of filesystem-related operations.
fileName objectPath() const
The complete path + object name.
Macros for easy insertion into run-time selection tables.
virtual bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
refPtr< dirIndexList > lookupAndCacheProcessorsPath(const fileName &objectPath, const bool syncPar) const
Lookup name of processorsDDD using cache.
constexpr const char *const group
Group name for atomic constants.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Tuple2< fileName, Tuple2< pathType, int > > dirIndex
Augment fileName with pathType and local offset.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
atomicType
Atomic operations (output)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
virtual fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true, const bool followLink=true) const
Read a directory and return the entries as a string list.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
A class for handling words, derived from Foam::string.
const Time & time() const noexcept
Return time registry.
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
time_t lastModified(const fileName &name, const bool followLink=true)
Return time of last file modification (normally follows symbolic links).
addNamedToRunTimeSelectionTable(fileOperationInitialise, fileOperationInitialise_collated, word, collated)
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
static word findInstancePath(const UList< instant > &timeDirs, const instant &t)
Search instantList for matching time value, return the instance name or word::null if nothing is equa...
static bool readHeader(IOobject &io, Istream &is)
Read header as per IOobject with additional handling of decomposedBlockData.
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Input from file stream as an ISstream, normally using std::ifstream for the actual input...
static Tuple2< label, labelList > getCommPattern()
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
bool chMod(const fileName &name, const mode_t mode)
Set the file/directory mode, return true on success.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile)
word format(conversionProperties.get< word >("format"))
static bool masterOnlyReading
To flag master-only reading of objects.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
virtual ~uncollatedFileOperation()
Destructor.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
Ostream & flush(Ostream &os)
Flush stream.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const T2 & second() const noexcept
Access the second element.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
streamFormat
Data format (ascii | binary)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Generate an OSstream that writes a file.
static labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
defineTypeNameAndDebug(collatedFileOperation, 0)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Registry of regIOobjects.
const T1 & first() const noexcept
Access the first element.
List< fileName > fileNameList
List of fileName.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Dummy input stream, which can be used as a placeholder for interfaces taking an Istream or ISstream...
Defines the attributes of an object for which implicit objectRegistry management is supported...
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Type
Enumerations to handle directory entry types.
static label allocateCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Allocate new communicator with contiguous sub-ranks on the parent communicator.
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool readOnProc=true) const
Reads header for regIOobject and returns an ISstream.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
#define InfoInFunction
Report an information message using Foam::Info.