42 namespace fileOperations
48 masterUncollatedFileOperation,
58 "maxMasterFileBufferSize",
83 if (t.
equal(timeDirs[i].value()))
85 return timeDirs[i].name();
95 const bool checkGlobal,
108 if (isFileOrDir(isFile, objectPath))
125 if (isFileOrDir(isFile, objectPath))
135 if (isFileOrDir(isFile, localObjectPath))
138 return localObjectPath;
159 if (isFileOrDir(isFile, parentObjectPath))
162 return parentObjectPath;
175 if (pathFnd != times_.end())
177 newInstancePath = findInstancePath
183 if (newInstancePath.size())
188 processorsPath(io, newInstancePath)
190 if (isFileOrDir(isFile, fName))
200 if (isFileOrDir(isFile, fName))
235 processorsCasePath(io)
254 return dir.
path()/processorsDir;
273 if (pos == string::npos)
281 local = objectPath.substr(pos+9);
283 else if (objectPath[pos-1] !=
'/')
289 path = objectPath.substr(0, pos-1);
290 local = objectPath.substr(pos+9);
293 pos = local.find(
'/');
294 if (pos == string::npos)
305 string procName(local.substr(0, pos));
309 local = local.substr(pos+1);
320 const word& instancePath
363 return processorsPath(io, instancePath)/io.
name();
387 const fileName& object0 = filePaths[0];
389 for (
label i = 1; i < filePaths.
size(); i++)
391 if (filePaths[i] != object0)
408 if (cmp == IOstream::compressionType::COMPRESSED)
412 Pout<<
"masterUncollatedFileOperation::readAndSend:" 413 <<
" opening compressed " << filePath <<
endl;
416 IFstream is(filePath, IOstream::streamFormat::BINARY);
418 std::ostringstream stringStr;
420 string buf(stringStr.str());
425 os.
write(&buf[0], buf.size());
431 IFstream is(filePath, IOstream::streamFormat::BINARY);
435 Pout<<
"masterUncollatedFileOperation::readStream:" 436 <<
" From " << filePath <<
" reading " <<
label(count)
461 Info<<
"I/O : " << typeName
462 <<
" (maxMasterFileBufferSize " << maxMasterFileBufferSize <<
')' 471 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
484 <<
"Resetting fileModificationChecking to inotify" 507 return masterOp<mode_t, mkDirOp>(dir,
mkDirOp(mode));
517 return masterOp<mode_t, chModOp>(fName,
chModOp(mode));
524 const bool followLink
527 return masterOp<mode_t, modeOp>(fName,
modeOp(followLink));
534 const bool followLink
544 const bool checkGzip,
545 const bool followLink
548 return masterOp<bool, existsOp>(fName,
existsOp(checkGzip, followLink));
555 const bool followLink
558 return masterOp<bool, isDirOp>(fName,
isDirOp(followLink));
565 const bool checkGzip,
566 const bool followLink
569 return masterOp<bool, isFileOp>(fName,
isFileOp(checkGzip, followLink));
576 const bool followLink
579 return masterOp<off_t, fileSizeOp>(fName,
fileSizeOp(followLink));
586 const bool followLink
589 return masterOp<time_t, lastModifiedOp>
600 const bool followLink
603 return masterOp<double, lastModifiedHROp>
614 const std::string& ext
617 return masterOp<bool, mvBakOp>(fName,
mvBakOp(ext));
626 return masterOp<bool, rmOp>(fName,
rmOp());
635 return masterOp<bool, rmDirOp>(dir,
rmDirOp());
644 const bool followLink
647 return masterOp<fileNameList, readDirOp>
659 const bool followLink
662 return masterOp<bool, cpOp>(src, dst,
cpOp(followLink));
672 return masterOp<bool, lnOp>(src, dst,
lnOp());
680 const bool followLink
683 return masterOp<bool, mvOp>(src, dst,
mvOp(followLink));
689 const bool checkGlobal,
696 Pout<<
"masterUncollatedFileOperation::filePath :" 698 <<
" checkGlobal:" << checkGlobal <<
endl;
708 word newInstancePath;
712 objPath = filePathInfo
723 label masterType(searchType);
742 objPath = objectPath(io, searchType, newInstancePath);
751 objPath = masterOp<fileName, fileOrNullOp>
762 Pout<<
"masterUncollatedFileOperation::filePath :" 763 <<
" Returning from file searching:" <<
endl 765 <<
" filePath :" << objPath <<
endl <<
endl;
773 const bool checkGlobal,
779 Pout<<
"masterUncollatedFileOperation::dirPath :" 781 <<
" checkGlobal:" << checkGlobal <<
endl;
788 word newInstancePath;
792 objPath = filePathInfo
803 label masterType(searchType);
821 objPath = objectPath(io, searchType, newInstancePath);
830 objPath = masterOp<fileName, fileOrNullOp>
841 Pout<<
"masterUncollatedFileOperation::dirPath :" 842 <<
" Returning from file searching:" <<
endl 844 <<
" filePath :" << objPath <<
endl <<
endl;
861 Pout<<
"masterUncollatedFileOperation::readObjects :" 863 <<
" instance:" << instance <<
endl;
880 if (newInstance.empty())
899 if (t.
equal(timeDirs[i].value()))
919 Pout<<
"masterUncollatedFileOperation::readObjects :" 920 <<
" newInstance:" << newInstance
921 <<
" objectNames:" << objectNames <<
endl;
939 Pout<<
"masterUncollatedFileOperation::readHeader:" <<
endl 941 <<
" fName :" << fName <<
endl;
948 bool uniform = uniformFile(filePaths);
984 if (!filePaths[proci].empty())
992 note[proci] = io.
note();
997 == decomposedBlockData::typeName
1001 <<
"Unexpected decomposedBlockData container" 1002 <<
" for processor " << proci
1003 <<
" file:" << filePaths[proci]
1004 <<
". A decomposedBlockData container should" 1005 <<
" produce the same file name on all" 1012 ok = scatterList(result);
1014 io.
note() = scatterList(note);
1019 Pout<<
"masterUncollatedFileOperation::readHeader:" <<
" ok:" << ok
1031 const word& typeName,
1037 Pout<<
"masterUncollatedFileOperation::readStream:" 1038 <<
" object : " << io.
name()
1039 <<
" fName : " << fName <<
" valid:" << valid <<
endl;
1044 bool isCollated =
false;
1083 Pout<<
"masterUncollatedFileOperation::readStream:" 1084 <<
" for object : " << io.
name()
1085 <<
" starting collating input from " << fName <<
endl;
1106 <<
"Could not detect processor number" 1126 sz > off_t(maxMasterFileBufferSize)
1137 Pout<<
"masterUncollatedFileOperation::readStream:" 1138 <<
" for object : " << io.
name()
1139 <<
" starting separated input from " << fName <<
endl;
1171 <<
"problem while reading header for object " 1185 Pout<<
"masterUncollatedFileOperation::readStream:" 1186 <<
" For processor " << proci
1187 <<
" opening " << filePaths[proci] <<
endl;
1190 if (procValid[proci] && !filePaths[proci].empty())
1200 IOstream::compressionType::COMPRESSED,
1210 IOstream::compressionType::UNCOMPRESSED,
1249 Pout<<
"masterUncollatedFileOperation::readStream:" 1250 <<
" Done reading " << buf.size() <<
" bytes" <<
endl;
1257 <<
"problem while reading header for object " 1275 const bool masterOnly,
1277 const word& typeName
1286 Pout<<
"masterUncollatedFileOperation::read:" 1287 <<
"reading global object " << io.
name() <<
endl;
1297 ok = io.
readData(io.readStream(typeName));
1320 if (myComm.
above() != -1)
1340 myComm.
below()[belowI],
1354 Pout<<
"masterUncollatedFileOperation::read:" 1355 <<
"reading local object " << io.
name() <<
endl;
1358 ok = io.
readData(io.readStream(typeName));
1379 Pout<<
"masterUncollatedFileOperation::writeObject:" 1380 <<
" io:" << pathName <<
" valid:" << valid <<
endl;
1425 const word& constantName
1430 Pout<<
"masterUncollatedFileOperation::findTimes:" 1431 <<
" Finding times in directory " << directory <<
endl;
1435 if (iter != times_.end())
1439 Pout<<
"masterUncollatedFileOperation::findTimes:" 1440 <<
" Found cached times:" << *iter() <<
endl;
1455 times_.insert(directory, tPtr);
1459 Pout<<
"masterUncollatedFileOperation::findTimes:" 1460 <<
" Caching times:" << *tPtr <<
endl;
1473 if (iter != times_.end())
1477 Pout<<
"masterUncollatedFileOperation::setTime:" 1478 <<
" Caching time " << tm.
timeName()
1479 <<
" for case:" << tm.
path() <<
endl;
1485 if (times.
size() > 0 && times[0].name() == tm.
constant())
1536 const bool uniform = uniformFile(filePaths);
1542 Pout<<
"masterUncollatedFileOperation::NewIFstream:" 1543 <<
" Opening global file " << filePath <<
endl;
1549 ? IOstream::compressionType::COMPRESSED
1550 : IOstream::compressionType::UNCOMPRESSED
1556 procs[proci-1] = proci;
1559 readAndSend(filePath, cmp, procs, pBufs);
1568 ? IOstream::compressionType::COMPRESSED
1569 : IOstream::compressionType::UNCOMPRESSED
1599 Pout<<
"masterUncollatedFileOperation::NewIFstream:" 1600 <<
" Reading " << filePath
1610 Pout<<
"masterUncollatedFileOperation::NewIFstream:" 1611 <<
" Done reading " << buf.size() <<
" bytes" <<
endl;
1661 watchFd = monitor().addWatch(fName);
1670 const label watchIndex
1676 ok = monitor().removeWatch(watchIndex);
1695 if (monitor().getFile(watchIndices[i]) == fName)
1721 label index = findWatch(watchIndices, f);
1725 newWatchIndices.
append(addWatch(f));
1730 newWatchIndices.
append(watchIndices[index]);
1731 removedWatches.
erase(index);
1738 removeWatch(watchIndices[iter.key()]);
1747 const label watchIndex
1753 fName = monitor().getFile(watchIndex);
1762 const bool masterOnly,
1768 monitor().updateStates(
true,
false);
1782 state = monitor().getState(watchFd);
1796 monitor().setUnmodified(watchFd);
pathType
Enumeration for the location of an IOobject.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
static word findInstancePath(const instantList &timeDirs, const instant &t)
Equivalent of Time::findInstance.
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 fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
List< instant > instantList
List of instants.
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &data, const UPstream::commsTypes commsType)
Read data into *this. ISstream is only valid on master.
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.
const labelList & below() const
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
label findSortedIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element in sorted list and return index,.
#define forAll(list, i)
Loop across all elements in list.
bool processorCase() const
Return true if this is a processor case.
fileName path() const
Return path.
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.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static int masterNo()
Process index of the master.
const word & name() const
Return name.
A class for handling file names.
masterUncollatedFileOperation(const bool verbose)
Construct null.
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
An STL-conforming const_iterator.
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
float floatOptimisationSwitch(const char *name, const float defaultValue=0)
Lookup optimisation switch or add default value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
virtual autoPtr< Ostream > NewOFstream(const fileName &pathname, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool valid=true) const
Generate an Ostream that writes a file.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
off_t fileSize(const fileName &, const bool followLink=true)
Return size of file.
fileState
Enumeration defining the file state.
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
void size(const label)
Override size to be inconsistent with allocated storage.
static const fileName null
An empty fileName.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool valid=true) const
Reads header for regIOobject and returns an ISstream.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
virtual istream & stdStream()
Access to underlying std::istream.
virtual bool rmDir(const fileName &) const
Remove a dirctory and its contents.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool master(const label communicator=0)
Am I the master process.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
const labelList & watchIndices() const
Return file-monitoring handles.
word format(conversionProperties.lookup("format"))
static int & msgType()
Message tag of standard messages.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
T * ptr()
Return object pointer for reuse.
static label worldComm
Default communicator (all processors)
static const List< commsStruct > & linearCommunication(const label communicator=0)
Communication schedule for linear all-to-master (proc 0)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool good() const
Return true if next operation might succeed.
static fileName objectPath(const IOobject &, const pathType &, const word &)
Construct filePath.
Macros for easy insertion into run-time selection tables.
fileName path() const
Return complete path.
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
Input inter-processor communications stream.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
void clear()
Delete object (if the pointer is valid) and set pointer to.
Input inter-processor communications stream operating on external buffer.
bool readHeader(Istream &)
Read header.
dimensionedScalar pos(const dimensionedScalar &ds)
string & note()
Return non-constant access to the optional note.
A List obtained as a section of another List.
bool read(const char *, int32_t &)
virtual bool writeObject(const regIOobject &, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
void reset(T *=0)
If object pointer already set, delete object and set to given.
static label splitProcessorPath(const fileName &, fileName &path, fileName &local)
Split fileName into part before processor and part after.
fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &, pathType &, word &) const
Search for object; return info on how it was found.
static instantList timeDirs
static float maxMasterFileBufferSize
Max size of parallel communications. Switches from non-blocking.
void close()
Close Istream.
bool isAbsolute() const
Return true if file name is absolute.
A class for handling words, derived from string.
bool & globalObject()
Is object same for all processors.
Master-only drop-in replacement for OFstream.
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
void append(const T &)
Append an element at the end of the list.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
const fileName & local() const
iterator begin()
Return an iterator to begin traversing the UList.
const word & constant() const
Return constant name.
word name() const
Return file name (part beyond last /)
static void readAndSend(const fileName &filePath, const IOstream::compressionType cmp, const labelUList &procs, PstreamBuffers &pBufs)
Read file contents and send to processors.
const Type & value() const
Return const reference to value.
streamFormat
Enumeration for the format of data in the stream.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
static const word null
An empty word.
static const List< commsStruct > & treeCommunication(const label communicator=0)
Communication schedule for tree all-to-master (proc 0)
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?
List< label > labelList
A List of labels.
graph_traits< Graph >::vertices_size_type size_type
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Structure for communicating between processors.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
const word & system() const
Return system name.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
compressionType
Enumeration for the format of data in the stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Output inter-processor communications stream operating on external buffer.
virtual fileName filePath(const bool checkGlobal, const IOobject &, const word &typeName) const
Search for an object. checkGlobal : also check undecomposed case.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Read into given buffer from given processor and return the.
const fileName & globalCaseName() const
Return global case name.
const Time & time() const
Return time.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Database for solution data, solver performance and other reduced data.
static bool write(const commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Write given buffer to given processor.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Output inter-processor communications stream.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
word name(const complex &)
Return a string representation of a complex.
virtual ~masterUncollatedFileOperation()
Destructor.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
const fileName & rootPath() const
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
An instant of time. Contains the time value and name.
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static bool uniformFile(const fileNameList &)
Same file?
static bool & parRun()
Is this a parallel run?
const fileName & instance() const
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
virtual bool readData(Istream &)
Virtual readData function.
virtual void setTime(const Time &) const
Callback for time change.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const Time & time() const
Return time.
Input from memory buffer stream.
prefixOSstream Pout(cout, "Pout")
static fileName processorsPath(const IOobject &, const word &)
Like io.path with provided instance and any 'processorXXX'.
virtual bool read(regIOobject &, const bool masterOnly, const IOstream::streamFormat format, const word &typeName) const
Top-level read.
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
registerOptSwitch("maxThreadFileBufferSize", float, collatedFileOperation::maxThreadFileBufferSize)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
bool writeHeader(Ostream &) const
Write header.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or LINK.
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
fileName path() const
Return directory path name (part before last /)
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
defineTypeNameAndDebug(collatedFileOperation, 0)
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Registry of regIOobjects.
virtual bool writeData(Ostream &) const =0
Pure virtual writaData function.
const objectRegistry & db() const
Return the local objectRegistry.
virtual void setTime(const Time &) const
Callback for time change.
void stableSort(UList< T > &)
virtual fileName dirPath(const bool checkGlobal, const IOobject &) const
Search for a directory. checkGlobal : also check undecomposed.
Dummy stream for input. Aborts at any attempt to read from it.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
const word & headerClassName() const
Return name of the class name read from header.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
const fileName & caseName() const
fileName objectPath() const
Return complete path + object name.
static fileName processorsCasePath(const IOobject &)
root+casename with any 'processorXXX' replaced by 'processsors'
bool equal(const scalar) const
Comparison used for instants to be equal.
bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Type
Enumerations to handle file types and modes.