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 parentObjectPath =
112 io.rootPath()/
io.time().globalCaseName()
113 /
io.instance()/
io.db().dbDir()/
io.local()/
io.name();
117 return parentObjectPath;
122 if (
io.time().processorCase())
124 const refPtr<dirIndexList> pDirs
132 for (
const dirIndex& dirIdx : pDirs())
134 const fileName& pDir = dirIdx.first();
150 word newInstancePath =
io.time().findInstancePath
152 instant(
io.instance())
155 if (newInstancePath.size())
159 io.rootPath()/
io.caseName()
160 /newInstancePath/
io.db().dbDir()/
io.local()/
io.name()
212 return commAndIORanks;
220 void Foam::fileOperations::uncollatedFileOperation::init(
bool verbose)
227 <<
"I/O : " << typeName <<
endl;
241 managedComm_(getManagedComm(comm_))
250 const bool distributedRoots,
264 managedComm_ = getManagedComm(comm_);
304 const bool followLink
314 const bool followLink
324 const bool checkGzip,
325 const bool followLink
335 const bool followLink
345 const bool checkGzip,
346 const bool followLink
356 const bool followLink
366 const bool followLink
376 const bool followLink
386 const std::string& ext
418 const bool followLink
429 const bool followLink
432 return Foam::cp(src, dst, followLink);
450 const bool followLink
461 const bool checkGlobal,
463 const word& typeName,
469 Pout<<
"uncollatedFileOperation::filePath :" 470 <<
" objectPath:" <<
io.objectPath()
471 <<
" checkGlobal:" << checkGlobal <<
endl;
478 Pout<<
"uncollatedFileOperation::filePath :" 479 <<
" Returning from file searching:" <<
endl 480 <<
" objectPath:" <<
io.objectPath() <<
endl 489 const bool checkGlobal,
496 Pout<<
"uncollatedFileOperation::dirPath :" 497 <<
" objectPath:" <<
io.objectPath()
498 <<
" checkGlobal:" << checkGlobal <<
endl;
501 fileName objPath(filePathInfo(checkGlobal,
false,
io,
search));
505 Pout<<
"uncollatedFileOperation::dirPath :" 506 <<
" Returning from directory searching:" <<
endl 507 <<
" objectPath:" <<
io.objectPath() <<
endl 524 Pout<<
"uncollatedFileOperation::readObjects :" 526 <<
" instance:" << instance <<
endl;
535 if (newInstance.empty())
539 if (!newInst.empty() && newInst != instance)
554 Pout<<
"uncollatedFileOperation::readObjects :" 555 <<
" newInstance:" << newInstance
556 <<
" objectNames:" << objectNames <<
endl;
572 Pout<<
"uncollatedFileOperation::readHeader :" 573 <<
" fName:" << fName
574 <<
" typeName:" << typeName <<
endl;
581 <<
"file " <<
io.objectPath() <<
" could not be opened" 588 autoPtr<ISstream> isPtr(NewIFstream(fName));
590 if (!isPtr || !isPtr->good())
600 Pout<<
"uncollatedFileOperation::readHeader :" 601 <<
" for fName:" << fName
603 <<
" headerClassName:" <<
io.headerClassName() <<
endl;
615 const word& typeName,
616 const bool readOnProc
627 <<
"cannot find file " <<
io.objectPath()
631 autoPtr<ISstream> isPtr = NewIFstream(fName);
633 if (!isPtr || !isPtr->good())
637 "uncollatedFileOperation::readStream()",
642 ) <<
"cannot open file" 645 else if (!
io.readHeader(*isPtr))
648 <<
"problem while reading header for object " <<
io.name()
661 label proci = detectProcessorPath(
io.objectPath());
666 <<
"could not detect processor number" 667 <<
" from objectPath:" <<
io.objectPath()
668 <<
" fName:" << fName
683 proci = proci -
group.start();
695 const bool masterOnly,
706 Pout<<
"uncollatedFileOperation::read :" 707 <<
" Reading object " <<
io.objectPath()
708 <<
" from file " <<
endl;
712 const bool oldGlobal =
io.globalObject(masterOnly);
720 ok =
io.readData(
io.readStream(typeName));
724 io.globalObject(oldGlobal);
729 Pout<<
"uncollatedFileOperation::read :" 730 <<
" Done reading object " <<
io.objectPath()
731 <<
" from file " <<
endl;
740 io.headerClassName(),
752 bool okWrite =
io.writeData(toAll);
763 ok =
io.readData(fromMaster);
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, using an OSstream.
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.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
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 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.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Input from file stream, using an ISstream.
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 void broadcasts(const label comm, Type &arg1, Args &&... args)
Broadcast multiple items to all communicator ranks. Does nothing in non-parallel. ...
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.
word findInstancePath(const fileName &directory, const instant &t) const
Search the case for the time directory path corresponding to the given instance.
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.