73#ifndef Foam_fileOperation_H
74#define Foam_fileOperation_H
157 static int nProcsFilter_;
203 const word& constantName,
234 bool isIOrank(
const label proci)
const;
303 const bool distributedRoots =
false
310 const bool distributedRoots =
false
334 const bool distributedRoots,
337 (commAndIORanks, distributedRoots, verbose)
347 const word& handlerType,
355 const word& handlerType,
357 const bool distributedRoots,
466 return nProcsFilter_;
473 int old(nProcsFilter_);
474 nProcsFilter_ = level;
483 const word& constantName =
"constant"
505 label
comm(label communicator)
const noexcept
508 if (communicator >= 0)
comm_ = communicator;
533 InfoProxy<fileOperation>
info() const
noexcept {
return *
this; }
540 virtual bool good()
const {
return true; }
559 const bool followLink =
true
566 const bool followLink =
true
574 const bool checkGzip =
true,
575 const bool followLink =
true
582 const bool followLink =
true
590 const bool checkGzip =
true,
591 const bool followLink =
true
598 const bool followLink =
true
605 const bool followLink =
true
612 const bool followLink =
true
620 const bool filtergz=
true,
621 const bool followLink =
true
629 const bool followLink =
true
641 const bool followLink =
false
650 const std::string& ext =
"bak"
663 const bool silent =
false,
664 const bool emptyOnly =
false
678 const bool writeOnProc,
699 const bool checkGlobal,
710 const bool checkGlobal,
739 const bool readOnProc =
true
746 const bool masterOnly,
762 const bool writeOnProc =
true
773 const bool checkGzip =
true,
774 const bool followLink =
true
785 const bool writeOnProc =
true
794 const bool writeOnProc =
true
822 const bool masterOnly,
857 label
nProcs(
const label numProcs)
noexcept
871 const label wantedNProcs = 0
880 const word& constantName =
"constant"
896 const scalar startValue,
898 const word& stopInstance =
"",
900 const bool constant_fallback =
true
908 virtual void flush()
const;
926 const word& instance,
966 label* numProcs =
nullptr
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
A HashTable similar to std::unordered_map.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
A simple container for options an IOstream can normally have.
streamFormat
Data format (ascii | binary | coherent).
atomicType
Atomic operations (output).
A helper class for outputting values to Ostream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
static const UList< label > & null() noexcept
static label commWorld() noexcept
Communicator for all ranks (respecting any local worlds).
static constexpr int commSelf() noexcept
Communicator within the current rank only.
IntRange< int > rangeType
Int ranges are used for MPI ranks (processes).
static constexpr int commGlobal() noexcept
Communicator for all ranks, irrespective of any local worlds.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Checking for changes to files.
fileState
Enumeration defining the file state.
A class for handling file names.
Type
Enumerations to handle directory entry types.
An encapsulation of filesystem-related operations.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile).
static const fileOperation & fileHandler()
Return the current file handler. Will create the default file handler if necessary.
static refPtr< fileOperation > fileHandlerPtr_
The currently active file handler. Avoid accessing directly.
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
bool distributed(bool on) const noexcept
Set distributed roots on/off [mutable].
virtual bool chMod(const fileName &, const mode_t) const =0
Set the file mode.
std::unique_ptr< fileMonitor > monitorPtr_
File-change monitor for all registered files.
static int nProcsFilter(int level) noexcept
Set collated 'processorsDDD' filtering (0 = off).
static label getManagedComm(const label communicator)
Construction helper: check for locally allocated communicator.
virtual mode_t mode(const fileName &, const bool followLink=true) const =0
Return the file mode.
virtual bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true) const =0
Does the name exist as a FILE in the file system?
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const =0
Generate an OSstream that writes a file.
bool distributed() const noexcept
Distributed roots (parallel run).
TypeName("fileOperation")
Runtime type information.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const =0
Rename to a corresponding backup file.
virtual instantList findTimes(const fileName &directory, const word &constantName="constant") const
Get sorted list of times.
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
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.
static instantList sortTimes(const fileNameList &dirEntries, const word &constantName="constant")
Sort directory entries according to time value,.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const =0
Generate an ISstream that reads a file.
virtual double highResLastModified(const fileName &, const bool followLink=true) const =0
Return time of last file modification.
virtual autoPtr< OSstream > NewOFstream(IOstreamOption::atomicType atomic, const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const =0
Generate an OSstream that writes a file.
virtual bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true) const =0
Does the name exist (as DIRECTORY or FILE) in the file system?
virtual bool rm(const fileName &) const =0
Remove a file, returning true if successful otherwise false.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
const labelList ioRanks_
The list of IO ranks (global ranks).
virtual bool removeWatch(const label) const
Remove watch on a file (using handle).
bool exists(IOobject &io) const
Does IOobject exist? Is either a directory (empty name()) or a 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 broadcastCopy(const label comm, const bool writeOnProc, const fileName &src, const fileName &dst) const
Read dir/file (recursively if necessary) on master of the communicator, send and write contents to al...
virtual off_t fileSize(const fileName &, const bool followLink=true) const =0
Return size of file.
static word defaultFileHandler
Name of the default fileHandler.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
static void mergeTimes(const UList< instant > &extraTimes, const word &constantName, instantList ×)
Merge two times.
label nProcs() const noexcept
Overall number of processors, from UPstream::nProcs() or detected from directories/results.
fileName processorsPath(const IOobject &io, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const =0
Copy, recursively if necessary, the source to the destination.
label setNProcs(label numProcs)
Same as nProcs.
virtual fileName::Type type(const fileName &, const bool followLink=true) const =0
Return the file type: DIRECTORY, FILE or SYMLINK.
static refPtr< fileOperation > null()
Reference to a dummy file handler.
virtual bool ln(const fileName &src, const fileName &dst) const =0
Create a softlink. dst should not exist. Returns true if.
fileName processorsCasePath(const IOobject &io, const word &procDir) const
Generate path (like io.path) from root+casename with any.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const =0
Top-level read.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
label nProcs_
Overall number of processors.
const labelList & ioRanks() const noexcept
The list of IO ranks (global ranks).
virtual bool good() const
True if the fileOperation can be considered valid. At the moment, primarily used to detect the dummy ...
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const =0
Read object header from supplied file.
List< dirIndex > dirIndexList
static label splitProcessorPath(const fileName &objectPath, fileName &path, fileName &procDir, fileName &local, procRangeType &group, label &nProcs)
Split objectPath into part before 'processor' and part after.
static autoPtr< fileOperation > NewUncollated()
The commonly used uncollatedFileOperation.
virtual word processorsDir(const IOobject &io) const
Actual name of processors dir (for use in mode PROCOBJECT, PROCINSTANCE).
HashTable< dirIndexList > procsDirs_
Detected processors directories.
static label detectProcessorPath(const fileName &objPath)
Detect processor number from '/aa/bb/processorDDD/cc'.
virtual void storeComm() const =0
Transfer ownership of communicator to this fileOperation. Use with caution.
virtual void setTime(const Time &) const
Callback for time change.
pathType
Enumeration for the location of an IOobject.
@ PROCUNCOLLATEDINSTANCE
as PROCUNCOLLATED but with instance
@ WRITEOBJECT
write path exists
@ OBJECT
io.objectPath() exists
@ PROCINSTANCE
as PROCOBJECT but with instance
@ FINDINSTANCE
file found in time directory
@ PROCUNCOLLATED
objectPath exists in 'processorN'
@ ABSOLUTE
instance is absolute directory
@ PROCBASEINSTANCE
as PROCBASEOBJECT but with instance
@ PARENTOBJECT
parent of object path
@ PROCOBJECT
objectPath exists in 'processorsNN_first-last'
@ PROCBASEOBJECT
objectPath exists in 'processorsNN'
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const =0
Remove a directory and its contents.
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const =0
Rename src to dst.
bool isIOrank(const label proci) const
Is proci a master rank in the communicator (in parallel) or a master rank in the IO ranks (non-parall...
static int cacheLevel_
Cache level (eg, for caching time directories). Default: 1.
label comm_
Communicator to use.
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle).
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
static labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
label comm() const noexcept
Communicator to use.
InfoProxy< fileOperation > info() const noexcept
Return info proxy, used to print information to a stream.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
static int cacheLevel(int level) noexcept
Set cache level (0 = off).
static bool uniformFile(const fileNameList &names)
True if the file names are identical. False on an empty list.
virtual time_t lastModified(const fileName &, const bool followLink=true) const =0
Return time of last file modification.
void printRanks() const
Helper: output which ranks are IO.
static int cacheLevel() noexcept
Return cache level.
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance="", const bool constant_fallback=true) const
Find time instance where IOobject is located. The name of the IOobject can be empty,...
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.
static const Enum< pathType > pathTypeNames_
declareRunTimeSelectionTable(autoPtr, fileOperation, comm,(const Tuple2< label, labelList > &commAndIORanks, const bool distributedRoots, bool verbose),(commAndIORanks, distributedRoots, verbose))
virtual void sync()
Forcibly parallel sync.
label nProcs(const label numProcs) noexcept
Set number of processor directories/results.
bool distributed_
Distributed roots (parallel run).
fileMonitor & monitor() const
Get or create fileMonitor singleton.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search=true) const =0
Search for a directory.
virtual ~fileOperation()=default
Destructor.
virtual bool isDir(const fileName &, const bool followLink=true) const =0
Does the name exist as a DIRECTORY in the file system?
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Writes a regIOobject (so header, contents and divider).
virtual word processorsDir(const fileName &) const
Actual name of processors dir (for use in mode PROCOBJECT, PROCINSTANCE).
label comm(label communicator) const noexcept
Set communicator to use [mutable]. Negative values are a no-op.
virtual fileName filePath(const bool checkGlobal, const IOobject &, const word &typeName, const bool search=true) const =0
Search for an object.
static word processorsBaseDir
Return the processors directory name (usually "processors").
virtual bool mkDir(const fileName &, mode_t=0777) const =0
Make directory.
UPstream::rangeType procRangeType
For addressing a range of processors (an int range).
declareRunTimeSelectionTable(autoPtr, fileOperation, word,(bool verbose),(verbose))
static labelList getGlobalHostIORanks()
Get list of global IO master ranks based on the hostname. It is assumed that each host range is conti...
static autoPtr< fileOperation > New(const word &handlerType, bool verbose=false)
Select fileHandler-type. Uses defaultFileHandler if the handlerType is empty.
virtual fileName getFile(const label) const
Get name of file being watched (using handle).
static int nProcsFilter() noexcept
Return collated 'processorsDDD' filtering.
virtual fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true, const bool followLink=true) const =0
Read a directory and return the entries as a string list.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool readOnProc=true) const =0
Reads header for regIOobject and returns an ISstream.
A range or interval of labels defined by a start and a size.
Registry of regIOobjects.
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...
A class for handling words, derived from Foam::string.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
OBJstream os(runTime.globalPath()/outputName)
List< label > labelList
A List of labels.
List< fileName > fileNameList
List of fileName.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
List< instant > instantList
List of instants.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Istream & operator>>(Istream &, directionInfo &)
UList< bool > boolUList
A UList of bools.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
UList< label > labelUList
A UList of labels.
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
word format(conversionProperties.get< word >("format"))
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
const volScalarField & cp
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.