uncollatedFileOperation.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenFOAM Foundation
9  Copyright (C) 2020-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "Time.H"
32 #include "Fstream.H"
34 #include "decomposedBlockData.H"
35 #include "dummyISstream.H"
36 
37 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
38 
39 namespace Foam
40 {
41 namespace fileOperations
42 {
43  defineTypeNameAndDebug(uncollatedFileOperation, 0);
45  (
46  fileOperation,
47  uncollatedFileOperation,
48  word
49  );
51  (
52  fileOperation,
53  uncollatedFileOperation,
54  comm
55  );
56 
57  // Threaded MPI: not required
59  (
60  fileOperationInitialise,
61  fileOperationInitialise_unthreaded,
62  word,
63  uncollated
64  );
65 }
66 }
67 
68 
69 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70 
72 (
73  const bool checkGlobal,
74  const bool isFile,
75  const IOobject& io,
76  const bool search
77 ) const
78 {
79  if (io.instance().isAbsolute())
80  {
81  fileName objectPath(io.instance()/io.name());
82 
84  {
85  return objectPath;
86  }
87  }
88  else
89  {
90  fileName path(io.path());
91  fileName objectPath(path/io.name());
92 
94  {
95  return objectPath;
96  }
97  else
98  {
99  if
100  (
101  checkGlobal
102  && io.time().processorCase()
103  && (
104  io.instance() == io.time().system()
105  || io.instance() == io.time().constant()
106  )
107  )
108  {
109  // Constant & system can come from global case
110 
111  fileName parentObjectPath =
112  io.rootPath()/io.time().globalCaseName()
113  /io.instance()/io.db().dbDir()/io.local()/io.name();
114 
115  if (isFileOrDir(isFile, parentObjectPath))
116  {
117  return parentObjectPath;
118  }
119  }
120 
121  // Check if parallel "procesors" directory
122  if (io.time().processorCase())
123  {
124  const refPtr<dirIndexList> pDirs
125  (
127  (
128  io.objectPath()
129  )
130  );
131 
132  for (const dirIndex& dirIdx : pDirs())
133  {
134  const fileName& pDir = dirIdx.first();
135  fileName objPath =
136  processorsPath(io, io.instance(), pDir)
137  /io.name();
138  if (objPath != objectPath && isFileOrDir(isFile, objPath))
139  {
140  return objPath;
141  }
142  }
143  }
144 
145 
146  // Check for approximately same time. E.g. if time = 1e-2 and
147  // directory is 0.01 (due to different time formats)
148  if (search && !Foam::isDir(path))
149  {
150  word newInstancePath = io.time().findInstancePath
151  (
152  instant(io.instance())
153  );
154 
155  if (newInstancePath.size())
156  {
157  fileName fName
158  (
159  io.rootPath()/io.caseName()
160  /newInstancePath/io.db().dbDir()/io.local()/io.name()
161  );
162 
163  if (isFileOrDir(isFile, fName))
164  {
165  return fName;
166  }
167  }
168  }
169  }
170  }
172  return fileName();
173 }
174 
175 
178 (
179  const fileName& fName
180 ) const
181 {
182  // No additional parallel synchronisation
183  return fileOperation::lookupAndCacheProcessorsPath(fName, false);
184 }
185 
187 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
188 
189 namespace Foam
190 {
191 
192 // Construction helper: self/world/local communicator and IO ranks
194 {
195  // Default is COMM_SELF (only involves itself)
196  Tuple2<label, labelList> commAndIORanks
197  (
200  );
201 
202  if (UPstream::parRun() && commAndIORanks.second().size() > 1)
203  {
204  // Multiple masters: ranks for my IO range
205  commAndIORanks.first() = UPstream::allocateCommunicator
206  (
208  fileOperation::subRanks(commAndIORanks.second())
209  );
210  }
211 
212  return commAndIORanks;
213 }
214 
215 } // End namespace Foam
216 
217 
218 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
219 
220 void Foam::fileOperations::uncollatedFileOperation::init(bool verbose)
221 {
222  verbose = (verbose && Foam::infoDetailLevel > 0);
223 
224  if (verbose)
225  {
227  << "I/O : " << typeName << endl;
228  }
229 }
230 
231 
233 (
234  bool verbose
235 )
236 :
238  (
240  ),
241  managedComm_(getManagedComm(comm_)) // Possibly locally allocated
242 {
243  init(verbose);
244 }
245 
246 
248 (
249  const Tuple2<label, labelList>& commAndIORanks,
250  const bool distributedRoots,
251  bool verbose
252 )
253 :
254  fileOperation(commAndIORanks, distributedRoots),
255  managedComm_(-1) // Externally managed
256 {
257  init(verbose);
258 }
259 
260 
262 {
263  // From externally -> locally managed
264  managedComm_ = getManagedComm(comm_);
265 }
266 
267 
268 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
269 
271 {
272  // Wait for any outstanding file operations
273  flush();
274 
276 }
277 
278 
279 // * * * * * * * * * * * * * Filesystem Operations * * * * * * * * * * * * * //
280 
282 (
283  const fileName& dir,
284  mode_t mode
285 ) const
286 {
287  return Foam::mkDir(dir, mode);
288 }
289 
290 
292 (
293  const fileName& fName,
294  mode_t mode
295 ) const
296 {
297  return Foam::chMod(fName, mode);
298 }
299 
300 
302 (
303  const fileName& fName,
304  const bool followLink
305 ) const
306 {
307  return Foam::mode(fName, followLink);
308 }
309 
310 
312 (
313  const fileName& fName,
314  const bool followLink
315 ) const
316 {
317  return Foam::type(fName, followLink);
318 }
319 
320 
322 (
323  const fileName& fName,
324  const bool checkGzip,
325  const bool followLink
326 ) const
327 {
328  return Foam::exists(fName, checkGzip, followLink);
329 }
330 
331 
333 (
334  const fileName& fName,
335  const bool followLink
336 ) const
337 {
338  return Foam::isDir(fName, followLink);
339 }
340 
341 
343 (
344  const fileName& fName,
345  const bool checkGzip,
346  const bool followLink
347 ) const
348 {
349  return Foam::isFile(fName, checkGzip, followLink);
350 }
351 
352 
354 (
355  const fileName& fName,
356  const bool followLink
357 ) const
358 {
359  return Foam::fileSize(fName, followLink);
360 }
361 
362 
364 (
365  const fileName& fName,
366  const bool followLink
367 ) const
368 {
369  return Foam::lastModified(fName, followLink);
370 }
371 
372 
374 (
375  const fileName& fName,
376  const bool followLink
377 ) const
378 {
379  return Foam::highResLastModified(fName, followLink);
380 }
381 
382 
384 (
385  const fileName& fName,
386  const std::string& ext
387 ) const
388 {
389  return Foam::mvBak(fName, ext);
390 }
391 
392 
394 (
395  const fileName& fName
396 ) const
397 {
398  return Foam::rm(fName);
399 }
400 
401 
403 (
404  const fileName& dir,
405  const bool silent,
406  const bool emptyOnly
407 ) const
408 {
409  return Foam::rmDir(dir, silent, emptyOnly);
410 }
411 
412 
414 (
415  const fileName& dir,
416  const fileName::Type type,
417  const bool filtergz,
418  const bool followLink
419 ) const
420 {
421  return Foam::readDir(dir, type, filtergz, followLink);
422 }
423 
424 
426 (
427  const fileName& src,
428  const fileName& dst,
429  const bool followLink
430 ) const
431 {
432  return Foam::cp(src, dst, followLink);
433 }
434 
435 
437 (
438  const fileName& src,
439  const fileName& dst
440 ) const
441 {
442  return Foam::ln(src, dst);
443 }
444 
445 
447 (
448  const fileName& src,
449  const fileName& dst,
450  const bool followLink
451 ) const
452 {
453  return Foam::mv(src, dst, followLink);
454 }
455 
456 
457 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
458 
460 (
461  const bool checkGlobal,
462  const IOobject& io,
463  const word& typeName,
464  const bool search
465 ) const
466 {
467  if (debug)
468  {
469  Pout<< "uncollatedFileOperation::filePath :"
470  << " objectPath:" << io.objectPath()
471  << " checkGlobal:" << checkGlobal << endl;
472  }
473 
474  fileName objPath(filePathInfo(checkGlobal, true, io, search));
475 
476  if (debug)
477  {
478  Pout<< "uncollatedFileOperation::filePath :"
479  << " Returning from file searching:" << endl
480  << " objectPath:" << io.objectPath() << endl
481  << " filePath :" << objPath << endl << endl;
482  }
483  return objPath;
484 }
485 
486 
488 (
489  const bool checkGlobal,
490  const IOobject& io,
491  const bool search
492 ) const
493 {
494  if (debug)
495  {
496  Pout<< "uncollatedFileOperation::dirPath :"
497  << " objectPath:" << io.objectPath()
498  << " checkGlobal:" << checkGlobal << endl;
499  }
500 
501  fileName objPath(filePathInfo(checkGlobal, false, io, search));
502 
503  if (debug)
504  {
505  Pout<< "uncollatedFileOperation::dirPath :"
506  << " Returning from directory searching:" << endl
507  << " objectPath:" << io.objectPath() << endl
508  << " dirPath :" << objPath << endl << endl;
509  }
510  return objPath;
511 }
512 
513 
515 (
516  const objectRegistry& db,
517  const fileName& instance,
518  const fileName& local,
519  word& newInstance
520 ) const
521 {
522  if (debug)
523  {
524  Pout<< "uncollatedFileOperation::readObjects :"
525  << " db:" << db.objectPath()
526  << " instance:" << instance << endl;
527  }
528 
529  //- Use non-time searching version
530  fileNameList objectNames
531  (
532  fileOperation::readObjects(db, instance, local, newInstance)
533  );
534 
535  if (newInstance.empty())
536  {
537  // Find similar time
538  fileName newInst = db.time().findInstancePath(instant(instance));
539  if (!newInst.empty() && newInst != instance)
540  {
541  // Try with new time
542  objectNames = fileOperation::readObjects
543  (
544  db,
545  newInst,
546  local,
547  newInstance
548  );
549  }
550  }
551 
552  if (debug)
553  {
554  Pout<< "uncollatedFileOperation::readObjects :"
555  << " newInstance:" << newInstance
556  << " objectNames:" << objectNames << endl;
557  }
558 
559  return objectNames;
560 }
561 
562 
564 (
565  IOobject& io,
566  const fileName& fName,
567  const word& typeName
568 ) const
569 {
570  if (debug)
571  {
572  Pout<< "uncollatedFileOperation::readHeader :"
573  << " fName:" << fName
574  << " typeName:" << typeName << endl;
575  }
576  if (fName.empty())
577  {
578  if (IOobject::debug)
579  {
581  << "file " << io.objectPath() << " could not be opened"
582  << endl;
583  }
584 
585  return false;
586  }
587 
588  autoPtr<ISstream> isPtr(NewIFstream(fName));
589 
590  if (!isPtr || !isPtr->good())
591  {
592  return false;
593  }
594 
595  // Regular header or from decomposed data
596  bool ok = decomposedBlockData::readHeader(io, *isPtr);
597 
598  if (debug)
599  {
600  Pout<< "uncollatedFileOperation::readHeader :"
601  << " for fName:" << fName
602  << " ok:" << ok
603  << " headerClassName:" << io.headerClassName() << endl;
604  }
605 
606  return ok;
607 }
608 
609 
612 (
613  regIOobject& io,
614  const fileName& fName,
615  const word& typeName,
616  const bool readOnProc
617 ) const
618 {
619  if (!readOnProc)
620  {
621  return autoPtr<ISstream>(new dummyISstream());
622  }
623 
624  if (fName.empty())
625  {
627  << "cannot find file " << io.objectPath()
628  << exit(FatalError);
629  }
630 
631  autoPtr<ISstream> isPtr = NewIFstream(fName);
632 
633  if (!isPtr || !isPtr->good())
634  {
636  (
637  "uncollatedFileOperation::readStream()",
638  __FILE__,
639  __LINE__,
640  fName,
641  0
642  ) << "cannot open file"
643  << exit(FatalIOError);
644  }
645  else if (!io.readHeader(*isPtr))
646  {
647  FatalIOErrorInFunction(*isPtr)
648  << "problem while reading header for object " << io.name()
649  << exit(FatalIOError);
650  }
651 
653  {
654  // Short circuit: non-collated format.
655  return isPtr;
656  }
657  else
658  {
659  // Analyse the objectpath to find out the processor we're trying
660  // to access
661  label proci = detectProcessorPath(io.objectPath());
662 
663  if (proci == -1)
664  {
665  FatalIOErrorInFunction(*isPtr)
666  << "could not detect processor number"
667  << " from objectPath:" << io.objectPath()
668  << " fName:" << fName
669  << exit(FatalIOError);
670  }
671 
672  // Analyse the fileName for any processor subset. Note: this
673  // should really be part of filePath() which should return
674  // both file and index in file.
675  fileName path, procDir, local;
676  procRangeType group;
677  label nProcs;
678  splitProcessorPath(fName, path, procDir, local, group, nProcs);
679 
680  // The local rank (offset)
681  if (!group.empty())
682  {
683  proci = proci - group.start();
684  }
685 
686  // Read data and return as stream
687  return decomposedBlockData::readBlock(proci, *isPtr, io);
688  }
689 }
690 
691 
693 (
694  regIOobject& io,
695  const bool masterOnly,
697  const word& typeName
698 ) const
699 {
700  bool ok = false;
701 
702  if (!masterOnly || Pstream::master(UPstream::worldComm))
703  {
704  if (debug)
705  {
706  Pout<< "uncollatedFileOperation::read :"
707  << " Reading object " << io.objectPath()
708  << " from file " << endl;
709  }
710 
711  // Set flag for e.g. codeStream
712  const bool oldGlobal = io.globalObject(masterOnly);
713 
714  // If codeStream originates from dictionary which is
715  // not IOdictionary we have a problem so use global
716  const bool oldMasterOnly = regIOobject::masterOnlyReading;
717  regIOobject::masterOnlyReading = masterOnly;
718 
719  // Read file
720  ok = io.readData(io.readStream(typeName));
721  io.close();
722 
723  // Restore flags
724  io.globalObject(oldGlobal);
725  regIOobject::masterOnlyReading = oldMasterOnly;
726 
727  if (debug)
728  {
729  Pout<< "uncollatedFileOperation::read :"
730  << " Done reading object " << io.objectPath()
731  << " from file " << endl;
732  }
733  }
734 
735  if (masterOnly && Pstream::parRun())
736  {
738  (
740  io.headerClassName(),
741  io.note()
742  );
743 
745  {
746  OPBstream toAll
747  (
750  format
751  );
752  bool okWrite = io.writeData(toAll);
753  ok = ok && okWrite;
754  }
755  else
756  {
757  IPBstream fromMaster
758  (
761  format
762  );
763  ok = io.readData(fromMaster);
764  }
765  }
766 
767  return ok;
768 }
769 
770 
773 (
774  const fileName& filePath
775 ) const
776 {
777  return autoPtr<ISstream>(new IFstream(filePath));
778 }
779 
780 
783 (
784  const fileName& pathName,
785  IOstreamOption streamOpt,
786  const bool writeOnProc
787 ) const
788 {
789  return autoPtr<OSstream>(new OFstream(pathName, streamOpt));
790 }
791 
792 
795 (
797  const fileName& pathName,
798  IOstreamOption streamOpt,
799  const bool writeOnProc
800 ) const
801 {
802  return autoPtr<OSstream>(new OFstream(atomic, pathName, streamOpt));
803 }
804 
805 
806 // ************************************************************************* //
bool mvBak(const fileName &src, const std::string &ext="bak")
Rename to a corresponding backup file.
Definition: POSIX.C:1357
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.
Definition: POSIX.C:1324
A class for handling file names.
Definition: fileName.H:72
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
Definition: POSIX.C:905
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; 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.
Definition: error.H:598
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
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.
Definition: UPstream.C:565
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.
Definition: OFstream.H:49
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.
Definition: Ostream.H:531
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
Definition: POSIX.C:1063
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.
Definition: UPstream.H:1049
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.
Definition: UPstream.H:424
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.
Definition: UPstream.H:409
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
An encapsulation of filesystem-related operations.
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:284
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?
Definition: POSIX.C:860
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.
Definition: POSIX.C:799
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.
Definition: POSIX.C:614
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.
Definition: word.H:63
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.
Definition: UPstream.H:1059
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).
Definition: POSIX.C:930
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?
Definition: POSIX.C:835
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
bool local
Definition: EEqn.H:20
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.
#define DetailInfo
Definition: evalEntry.C:30
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.
Definition: POSIX.C:1237
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
Definition: POSIX.C:1433
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.
Definition: IFstream.H:49
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.
Definition: POSIX.C:757
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.
Definition: regIOobject.H:84
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:877
word findInstancePath(const fileName &directory, const instant &t) const
Search the case for the time directory path corresponding to the given instance.
Definition: Time.C:749
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:521
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.
Definition: error.H:627
const T2 & second() const noexcept
Access the second element.
Definition: Tuple2.H:142
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1082
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...
Definition: regIOobject.H:66
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:642
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.
Definition: Tuple2.H:132
List< fileName > fileNameList
List of fileName.
Definition: fileNameList.H:32
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.
Definition: POSIX.C:963
Dummy input stream, which can be used as a placeholder for interfaces taking an Istream or ISstream...
Definition: dummyISstream.H:52
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Definition: POSIX.C:773
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.
Definition: fileName.H:81
static label allocateCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Allocate new communicator with contiguous sub-ranks on the parent communicator.
Definition: UPstream.C:258
Namespace for OpenFOAM.
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
Definition: POSIX.C:946
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.
Definition: POSIX.C:1404
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
#define InfoInFunction
Report an information message using Foam::Info.