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;
222void Foam::fileOperations::uncollatedFileOperation::init(
bool verbose)
252 const bool distributedRoots,
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
455 return Foam::mv(src, dst, followLink);
463 const bool checkGlobal,
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
483 <<
" filePath :" << objPath <<
endl <<
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
510 <<
" dirPath :" << objPath <<
endl <<
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
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;
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()
669 <<
"could not detect processor number"
670 <<
" from objectPath:" <<
io.objectPath()
671 <<
" fName:" << fName
684 proci -=
group.start();
696 const bool masterOnly,
707 Pout<<
"uncollatedFileOperation::read :"
708 <<
" Reading object " <<
io.objectPath()
709 <<
" from file " <<
endl;
713 const bool oldGlobal =
io.globalObject(masterOnly);
733 io.globalObject(oldGlobal);
739 Pout<<
"uncollatedFileOperation::read :"
740 <<
" Done reading object " <<
io.objectPath()
741 <<
" from file " <<
endl;
752 os <<
io.headerClassName() <<
io.note();
753 bool okWrite =
io.writeData(
os);
760 is >>
io.headerClassName() >>
io.note();
761 ok =
io.readData(is);
784 const bool writeOnProc
797 const bool writeOnProc
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
fileName objectPath() const
The complete path + object name.
A simple container for options an IOstream can normally have.
streamFormat
Data format (ascii | binary | coherent).
atomicType
Atomic operations (output).
Input inter-processor communications stream using MPI broadcast.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Output inter-processor communications stream using MPI broadcast.
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...
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
const T1 & first() const noexcept
Access the first element.
const T2 & second() const noexcept
Access the second element.
static constexpr int commSelf() noexcept
Communicator within the current rank only.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
static label newCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Create new communicator with sub-ranks on the parent communicator.
static void freeCommunicator(const label communicator, const bool withComponents=true)
Free a previously allocated communicator.
static bool & parRun() noexcept
Test if this a parallel run.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
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.
static autoPtr< ISstream > New()
Return a dummyISstream.
A class for handling file names.
Type
Enumerations to handle directory entry types.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
An encapsulation of filesystem-related operations.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile).
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
static label getManagedComm(const label communicator)
Construction helper: check for locally allocated communicator.
Tuple2< fileName, Tuple2< pathType, int > > dirIndex
Augment fileName with pathType and local offset.
refPtr< dirIndexList > lookupAndCacheProcessorsPath(const fileName &objectPath, const bool syncPar) const
Lookup name of processorsDDD using cache.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
fileName processorsPath(const IOobject &io, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
static label detectProcessorPath(const fileName &objPath)
Detect processor number from '/aa/bb/processorDDD/cc'.
label comm_
Communicator to use.
static labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
fileOperation(const label comm, const labelUList &ioRanks=labelUList::null(), const bool distributedRoots=false)
Construct from communicator, optionally with specified io-ranks and/or distributed roots.
UPstream::rangeType procRangeType
For addressing a range of processors (an int range).
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
A fileOperation initialiser for unthreaded file handlers.
fileOperation that assumes file operations are local.
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const bool search) const
Search for an object.
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Generate an OSstream that writes a file.
virtual ~uncollatedFileOperation()
Destructor.
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
Remove a directory and its contents.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool readOnProc=true) const
Reads header for regIOobject and returns an ISstream to read the contents.
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 readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
Top-level read.
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory.
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of 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?
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
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?
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
virtual fileName filePath(const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
Search for an object.
uncollatedFileOperation(bool verbose=false)
Default construct.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Registry of regIOobjects.
const Time & time() const noexcept
Return time registry.
A class for managing references or pointers (no reference counting).
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
static bool masterOnlyReading
To flag master-only reading of objects.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define InfoInFunction
Report an information message using Foam::Info.
constexpr const char *const group
Group name for atomic constants.
Namespace for handling debugging switches.
Namespace for implementations of a fileOperation.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
time_t lastModified(const fileName &name, const bool followLink=true)
Return time of last file modification (normally follows symbolic links).
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?
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
List< fileName > fileNameList
List of fileName.
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
bool chMod(const fileName &name, const mode_t mode)
Set the file/directory mode, return true on success.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
int infoDetailLevel
Global for selective suppression of Info output.
bool mvBak(const fileName &src, const std::string &ext="bak")
Rename to a corresponding backup file.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static Tuple2< label, labelList > getCommPattern()
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Ostream & flush(Ostream &os)
Flush stream.
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
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.
word format(conversionProperties.get< word >("format"))