73 #ifndef Foam_fileOperation_H 74 #define Foam_fileOperation_H 100 Ostream& operator<<(Ostream& os, const InfoProxy<fileOperation>& info);
158 static int nProcsFilter_;
203 const word& constantName,
233 bool isIOrank(
const label proci)
const;
302 const bool distributedRoots =
false 309 const bool distributedRoots =
false 333 const bool distributedRoots,
336 (commAndIORanks, distributedRoots, verbose)
346 const word& handlerType,
354 const word& handlerType,
356 const bool distributedRoots,
465 return nProcsFilter_;
472 int old(nProcsFilter_);
473 nProcsFilter_ = level;
482 const word& constantName =
"constant" 507 if (communicator >= 0)
comm_ = communicator;
532 InfoProxy<fileOperation>
info() const
noexcept {
return *
this; }
539 virtual bool good()
const {
return true; }
558 const bool followLink =
true 565 const bool followLink =
true 573 const bool checkGzip =
true,
574 const bool followLink =
true 581 const bool followLink =
true 589 const bool checkGzip =
true,
590 const bool followLink =
true 597 const bool followLink =
true 604 const bool followLink =
true 611 const bool followLink =
true 619 const bool filtergz=
true,
620 const bool followLink =
true 628 const bool followLink =
true 640 const bool followLink =
false 649 const std::string& ext =
"bak" 662 const bool silent =
false,
663 const bool emptyOnly =
false 677 const bool writeOnProc,
698 const bool checkGlobal,
700 const word& typeName,
708 const bool checkGlobal,
736 const word& typeName,
737 const bool readOnProc =
true 744 const bool masterOnly,
758 const bool writeOnProc =
true 769 const bool checkGzip =
true,
770 const bool followLink =
true 781 const bool writeOnProc =
true 790 const bool writeOnProc =
true 818 const bool masterOnly,
865 const fileName&
local =
"",
867 const label wantedNProcs = 0
886 const scalar startValue,
888 const word& stopInstance,
890 const bool constant_fallback =
true 894 virtual void setTime(
const Time&)
const 898 virtual void flush()
const;
916 const word& instance,
921 fileName
processorsPath(
const fileName&,
const word& procDir)
const;
979 os << static_cast<int>(
b);
996 inline refPtr<fileOperation>
fileHandler(std::nullptr_t)
1003 autoPtr<fileOperation>
fileHandler(autoPtr<fileOperation>&& newHandler);
virtual bool rm(const fileName &) const =0
Remove a file, returning true if successful otherwise false.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool readOnProc=true) const =0
Reads header for regIOobject and returns an ISstream.
static const Enum< pathType > pathTypeNames_
static label detectProcessorPath(const fileName &objPath)
Detect processor number from '/aa/bb/processorDDD/cc'.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
static refPtr< fileOperation > fileHandlerPtr_
The currently active file handler. Avoid accessing directly.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search=true) const =0
Search for a directory. checkGlobal : also check undecomposed.
List< dirIndex > dirIndexList
virtual double highResLastModified(const fileName &, const bool followLink=true) const =0
Return time of last file modification.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
A class for handling file names.
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, in which case only the IOobject::local() is checked. Does not search beyond stopInstance (if set) or constant.
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
static int nProcsFilter() noexcept
Return collated 'processorsDDD' filtering.
as PROCUNCOLLATED but with instance
virtual bool chMod(const fileName &, const mode_t) const =0
Set the file mode.
Checking for changes to files.
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.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
label nProcs() const noexcept
Overall number of processors, from UPstream::nProcs() or detected from directories/results.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
static labelList getGlobalHostIORanks()
Get list of global IO master ranks based on the hostname. It is assumed that each host range is conti...
fileName processorsPath(const IOobject &io, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const =0
Rename to a corresponding backup file.
An interval of (signed) integers defined by a start and a size.
fileState
Enumeration defining the file state.
virtual off_t fileSize(const fileName &, const bool followLink=true) const =0
Return size of file.
pathType
Enumeration for the location of an IOobject.
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
virtual bool mkDir(const fileName &, mode_t=0777) const =0
Make directory.
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 void storeComm() const =0
Transfer ownership of communicator to this fileOperation. Use with caution.
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const =0
Rename src to dst.
file found in time directory
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
static constexpr label commSelf() noexcept
Communicator within the current rank only.
A simple container for options an IOstream can normally have.
static refPtr< fileOperation > null()
Reference to a dummy file handler.
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?
static word processorsBaseDir
Return the processors directory name (usually "processors")
A class for managing references or pointers (no reference counting)
An encapsulation of filesystem-related operations.
as PROCOBJECT but with instance
UList< label > labelUList
A UList of labels.
virtual mode_t mode(const fileName &, const bool followLink=true) const =0
Return the file mode.
label nProcs_
Overall number of processors.
IntRange< int > procRangeType
For addressing a range of processors, identical to UPstream::rangeType.
virtual fileName::Type type(const fileName &, const bool followLink=true) const =0
Return the file type: DIRECTORY, FILE or SYMLINK.
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.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
Tuple2< fileName, Tuple2< pathType, int > > dirIndex
Augment fileName with pathType and local offset.
atomicType
Atomic operations (output)
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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
instance is absolute directory
virtual fileName filePath(const bool checkGlobal, const IOobject &, const word &typeName, const bool search=true) const =0
Search for an object. checkGlobal : also check undecomposed case.
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 ~fileOperation()=default
Destructor.
virtual bool ln(const fileName &src, const fileName &dst) const =0
Create a softlink. dst should not exist. Returns true if.
objectPath exists in 'processorsNN'
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
A class for handling words, derived from Foam::string.
objectPath exists in 'processorN'
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
Istream & operator>>(Istream &, directionInfo &)
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Writes a regIOobject (so header, contents and divider).
virtual autoPtr< ISstream > NewIFstream(const fileName &) const =0
Generate an ISstream that reads a file.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static instantList sortTimes(const fileNameList &dirEntries, const word &constantName="constant")
Sort directory entries according to time value,.
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
as PROCBASEOBJECT but with instance
objectPath exists in 'processorsNN_first-last'
A HashTable similar to std::unordered_map.
virtual bool good() const
True if the fileOperation can be considered valid. At the moment, primarily used to detect the dummy ...
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const =0
Copy, recursively if necessary, the source to the destination.
static void mergeTimes(const instantList &extraTimes, const word &constantName, instantList ×)
Merge two times.
static label getManagedComm(const label communicator)
Construction helper: check for locally allocated communicator.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
virtual void sync()
Forcibly parallel sync.
static int cacheLevel() noexcept
Return cache level.
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
fileMonitor & monitor() const
Get or create fileMonitor singleton.
HashTable< dirIndexList > procsDirs_
Detected processors directories.
static autoPtr< fileOperation > New(const word &handlerType, bool verbose=false)
Select fileHandler-type. Uses defaultFileHandler if the handlerType is empty.
fileName processorsCasePath(const IOobject &io, const word &procDir) const
Generate path (like io.path) from root+casename with any.
static bool uniformFile(const fileNameList &names)
True if the file names are identical. False on an empty list.
static label commWorld() noexcept
Communicator for all ranks (respecting any local worlds)
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const =0
Remove a directory and its contents.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile)
word format(conversionProperties.get< word >("format"))
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
void printRanks() const
Helper: output which ranks are IO.
virtual void setTime(const Time &) const
Callback for time change.
static word defaultFileHandler
Name of the default fileHandler.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
virtual bool isDir(const fileName &, const bool followLink=true) const =0
Does the name exist as a DIRECTORY in the file system?
label comm() const noexcept
Communicator to use.
InfoProxy< fileOperation > info() const noexcept
Return info proxy, used to print information to a stream.
static int cacheLevel_
Cache level (eg, for caching time directories). Default: 1.
virtual time_t lastModified(const fileName &, const bool followLink=true) const =0
Return time of last file modification.
const labelList ioRanks_
The list of IO ranks (global ranks)
static const UList< label > & null() noexcept
Return a null UList (reference to a nullObject). Behaves like an empty UList.
bool distributed() const noexcept
Distributed roots (parallel run)
streamFormat
Data format (ascii | binary)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
std::unique_ptr< fileMonitor > monitorPtr_
File-change monitor for all registered files.
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
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...
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const =0
Generate an OSstream that writes a file.
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 labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
static const fileOperation & fileHandler()
Return the current file handler. Will create the default file handler if necessary.
List< label > labelList
A List of labels.
TypeName("fileOperation")
Runtime type information.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
List< instant > instantList
List of instants.
Registry of regIOobjects.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
List< fileName > fileNameList
List of fileName.
const labelList & ioRanks() const noexcept
The list of IO ranks (global ranks)
Defines the attributes of an object for which implicit objectRegistry management is supported...
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
declareRunTimeSelectionTable(autoPtr, fileOperation, word,(bool verbose),(verbose))
bool distributed_
Distributed roots (parallel run)
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const =0
Read object header from supplied file.
Type
Enumerations to handle directory entry types.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const =0
Top-level read.
virtual word processorsDir(const IOobject &io) const
Actual name of processors dir (for use in mode PROCOBJECT, PROCINSTANCE)
label comm_
Communicator to use.
label setNProcs(label numProcs)
Same as nProcs.
static autoPtr< fileOperation > NewUncollated()
The commonly used uncollatedFileOperation.
static constexpr label commGlobal() noexcept
Communicator for all ranks, irrespective of any local worlds.