masterUncollatedFileOperation.H
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) 2019-2021 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 Class
28  Foam::fileOperations::masterUncollatedFileOperation
29 
30 Description
31  fileOperations that performs all file operations on the master processor.
32  Requires the calls to be parallel synchronised!
33 
34  Limitations
35  - no /processor in filename
36  - no /uniform/ in the filename
37 
38  The main logic is in ::filePath which returns a
39  - same path on all processors. This can either be a global file
40  (system/controlDict, processorXXX/0/uniform/) or a collated file
41  (processors/0/p)
42  - same path on all processors of the local communicator
43  (processors4_0-1/0/p)
44  - different path on all processors (processor0/0/p)
45 
46  system/controlDict:
47  filePath worldmaster: <globalRoot>/system/controlDict
48  localmaster: ,,
49  slave : ,,
50 
51  processor0/uniform/time
52  filePath worldmaster: <globalRoot>/processorXXX/uniform/time
53  localmaster: ,,
54  slave : ,,
55 
56  processors0/0/p
57  processors10/0/p
58  processors10_2-4/0/p
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef fileOperations_masterUncollatedFileOperation_H
63 #define fileOperations_masterUncollatedFileOperation_H
64 
65 #include "fileOperation.H"
66 #include "OSspecific.H"
67 #include "HashPtrTable.H"
68 #include "List.H"
69 #include "unthreadedInitialise.H"
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 namespace Foam
74 {
75 
76 class PstreamBuffers;
77 
78 namespace fileOperations
79 {
80 
81 /*---------------------------------------------------------------------------*\
82  Class masterUncollatedFileOperation Declaration
83 \*---------------------------------------------------------------------------*/
84 
86 :
87  public fileOperation
88 {
89 protected:
90 
91  // Protected Data
92 
93  //- Any communicator allocated by me
94  const label myComm_;
95 
96  //- Cached times for a given directory
98 
99 
100  // Protected Classes
101 
102  class mkDirOp
103  {
104  const mode_t mode_;
105  public:
106  mkDirOp(const mode_t mode)
107  :
108  mode_(mode)
109  {}
110 
111  bool operator()(const fileName& fName) const
112  {
113  return Foam::mkDir(fName, mode_);
114  }
115  };
116 
117  class chModOp
118  {
119  const mode_t mode_;
120  public:
121  chModOp(const mode_t mode)
122  :
123  mode_(mode)
124  {}
125 
126  bool operator()(const fileName& fName) const
127  {
128  return Foam::chMod(fName, mode_);
129  }
130  };
131 
132  class modeOp
133  {
134  const bool followLink_;
135  public:
136  modeOp(const bool followLink)
137  :
138  followLink_(followLink)
139  {}
140 
141  mode_t operator()(const fileName& fName) const
142  {
143  return Foam::mode(fName, followLink_);
144  }
145  };
146 
147  class typeOp
148  {
149  const bool followLink_;
150  public:
151  typeOp(const bool followLink)
152  :
153  followLink_(followLink)
154  {}
155 
156  label operator()(const fileName& fName) const
157  {
158  return Foam::type(fName, followLink_);
159  }
160  };
161 
162  class existsOp
163  {
164  const bool checkGzip_;
165  const bool followLink_;
166  public:
167  existsOp(const bool checkGzip, const bool followLink)
168  :
169  checkGzip_(checkGzip),
170  followLink_(followLink)
171  {}
172 
173  bool operator()(const fileName& fName) const
174  {
175  return Foam::exists(fName, checkGzip_, followLink_);
176  }
177  };
178 
179  class isDirOp
180  {
181  const bool followLink_;
182  public:
183  isDirOp(const bool followLink)
184  :
185  followLink_(followLink)
186  {}
187 
188  public:
189  bool operator()(const fileName& fName) const
190  {
191  return Foam::isDir(fName, followLink_);
192  }
193  };
194 
195  class isFileOp
196  {
197  const bool checkGzip_;
198  const bool followLink_;
199  public:
200  isFileOp(const bool checkGzip, const bool followLink)
201  :
202  checkGzip_(checkGzip),
203  followLink_(followLink)
204  {}
205  public:
206  bool operator()(const fileName& fName) const
207  {
208  return Foam::isFile(fName, checkGzip_, followLink_);
209  }
210  };
211 
212  class fileSizeOp
213  {
214  const bool followLink_;
215  public:
216  fileSizeOp(const bool followLink)
217  :
218  followLink_(followLink)
219  {}
220 
221  public:
222  off_t operator()(const fileName& fName) const
223  {
224  return Foam::fileSize(fName, followLink_);
225  }
226  };
227 
228  class lastModifiedOp
229  {
230  const bool followLink_;
231  public:
232  lastModifiedOp(const bool followLink)
233  :
234  followLink_(followLink)
235  {}
236 
237  public:
238  time_t operator()(const fileName& fName) const
239  {
240  return Foam::lastModified(fName, followLink_);
241  }
242  };
243 
244  class lastModifiedHROp
245  {
246  const bool followLink_;
247  public:
248  lastModifiedHROp(const bool followLink)
249  :
250  followLink_(followLink)
251  {}
252 
253  public:
254  double operator()(const fileName& fName) const
255  {
256  return Foam::highResLastModified(fName, followLink_);
257  }
258  };
259 
260  class mvBakOp
261  {
262  std::string ext_;
263  public:
264  mvBakOp(const std::string& ext)
265  :
266  ext_(ext)
267  {}
268 
269  bool operator()(const fileName& fName) const
270  {
271  return Foam::mvBak(fName, ext_);
272  }
273  };
274 
275  class rmOp
276  {
277  public:
278  bool operator()(const fileName& fName) const
279  {
280  return Foam::rm(fName);
281  }
282  };
283 
284  class rmDirOp
285  {
286  bool silent_;
287  public:
288  rmDirOp()
289  :
290  silent_(false)
291  {}
292  rmDirOp(const bool silent)
293  :
294  silent_(silent)
295  {}
296  bool operator()(const fileName& fName) const
297  {
298  return Foam::rmDir(fName, silent_);
299  }
300  };
301 
302  class cpOp
303  {
304  const bool followLink_;
305  public:
306  cpOp(const bool followLink)
307  :
308  followLink_(followLink)
309  {}
310 
311  public:
312  bool operator()(const fileName& src, const fileName& dest) const
313  {
314  return Foam::cp(src, dest, followLink_);
315  }
316  };
317 
318  class lnOp
319  {
320  public:
321  bool operator()(const fileName& src, const fileName& dest) const
322  {
323  return Foam::ln(src, dest);
324  }
325  };
326 
327  class mvOp
328  {
329  const bool followLink_;
330  public:
331  mvOp(const bool followLink)
332  :
333  followLink_(followLink)
334  {}
335 
336  public:
337  bool operator()(const fileName& src, const fileName& dest) const
338  {
339  return Foam::mv(src, dest, followLink_);
340  }
341  };
342 
343  class fileOrNullOp
344  {
345  const bool isFile_;
346  public:
347  fileOrNullOp(const bool isFile)
348  :
349  isFile_(isFile)
350  {}
351 
352  fileName operator()(const fileName& fName) const
353  {
354  return
355  (
356  (isFile_ && Foam::isFile(fName))
357  || (!isFile_ && Foam::isDir(fName))
358  ? fName
360  );
361  }
362  };
363 
364  class readDirOp
365  {
366  const fileName::Type type_;
367  const bool filtergz_;
368  const bool followLink_;
369  public:
371  (
372  const fileName::Type type,
373  const bool filtergz,
374  const bool followLink
375  )
376  :
377  type_(type),
378  filtergz_(filtergz),
379  followLink_(followLink)
380  {}
381 
382  fileNameList operator()(const fileName& fName) const
383  {
384  return Foam::readDir(fName, type_, filtergz_, followLink_);
385  }
386  };
387 
388 
389  // Private Member Functions
390 
391  //- Get the list of processors that are part of this communicator
392  static labelList subRanks(const label n);
393 
394  template<class Type>
395  Type scatterList(const UList<Type>&, const int, const label comm) const;
396 
397  template<class Type, class fileOp>
398  Type masterOp
399  (
400  const fileName&,
401  const fileOp& fop,
402  const int tag,
403  const label comm
404  ) const;
405 
406  template<class Type, class fileOp>
407  Type masterOp
408  (
409  const fileName&,
410  const fileName&,
411  const fileOp& fop,
412  const int tag,
413  const label comm
414  ) const;
415 
416  //- Equivalent of Time::findInstance
417  static word findInstancePath
418  (
419  const instantList& timeDirs,
420  const instant& t
421  );
422 
423  //- Search (locally!) for object; return info on how it was found.
424  // Does not do any parallel communication.
425  // checkGlobal : also check undecomposed case
426  // isFile : true:check for file false:check for directory
427  // searchType : how was found
428  // processorsDir : name of processor directory
429  // instance : instance
430  virtual fileName filePathInfo
431  (
432  const bool checkGlobal,
433  const bool isFile,
434  const IOobject&,
435  const bool search,
436  pathType& searchType,
438  word& instance
439  ) const;
440 
441  //- Construct filePath
443  (
444  const IOobject&,
445  const pathType& searchType,
446  const word& processorsDir,
447  const word& instancePath
448  ) const;
449 
450  //- Read file contents and send to processors.
451  // Handles compressed or uncompressed files
452  static void readAndSend
453  (
454  const fileName& filePath,
455  const labelUList& procs,
456  PstreamBuffers& pBufs
457  );
458 
459  //- Read files on comms master
460  static autoPtr<ISstream> read
461  (
462  IOobject& io,
463  const label comm,
464  const bool uniform, // on comms master only
465  const fileNameList& filePaths, // on comms master only
466  const boolList& procValid // on comms master only
467  );
468 
469  //- Helper: check IO for local existence. Like filePathInfo but
470  // without parent searchign and instance searching
471  bool exists(const dirIndexList&, IOobject& io) const;
472 
473 
474 public:
475 
476  //- Runtime type information
477  TypeName("masterUncollated");
478 
479 
480  // Static Data
481 
482  //- Max size of parallel communications. Switches from non-blocking
483  // to scheduled when reading/writing files. Read as float to enable
484  // easy specification of large sizes.
485  static float maxMasterFileBufferSize;
486 
487 
488  // Constructors
489 
490  //- Default construct
491  explicit masterUncollatedFileOperation(bool verbose);
492 
493  //- Construct from communicator
494  masterUncollatedFileOperation(const label comm, bool verbose);
495 
496 
497  //- Destructor
499 
500 
501  // Member Functions
502 
503  // OSSpecific equivalents
504 
505  //- Make directory
506  virtual bool mkDir(const fileName&, mode_t=0777) const;
507 
508  //- Set the file mode
509  virtual bool chMod(const fileName&, const mode_t) const;
510 
511  //- Return the file mode
512  virtual mode_t mode
513  (
514  const fileName&,
515  const bool followLink = true
516  ) const;
517 
518  //- Return the file type: DIRECTORY, FILE or LINK
519  virtual fileName::Type type
520  (
521  const fileName&,
522  const bool followLink = true
523  ) const;
524 
525  //- Does the name exist (as DIRECTORY or FILE) in the file system?
526  // Optionally enable/disable check for gzip file.
527  virtual bool exists
528  (
529  const fileName&,
530  const bool checkGzip=true,
531  const bool followLink = true
532  ) const;
533 
534  //- Does the name exist as a DIRECTORY in the file system?
535  virtual bool isDir
536  (
537  const fileName&,
538  const bool followLink = true
539  ) const;
540 
541  //- Does the name exist as a FILE in the file system?
542  // Optionally enable/disable check for gzip file.
543  virtual bool isFile
544  (
545  const fileName&,
546  const bool checkGzip=true,
547  const bool followLink = true
548  ) const;
549 
550  //- Return size of file
551  virtual off_t fileSize
552  (
553  const fileName&,
554  const bool followLink = true
555  ) const;
556 
557  //- Return time of last file modification
558  virtual time_t lastModified
559  (
560  const fileName&,
561  const bool followLink = true
562  ) const;
563 
564  //- Return time of last file modification
565  virtual double highResLastModified
566  (
567  const fileName&,
568  const bool followLink = true
569  ) const;
570 
571  //- Read a directory and return the entries as a string list
572  virtual fileNameList readDir
573  (
574  const fileName&,
576  const bool filtergz=true,
577  const bool followLink = true
578  ) const;
579 
580  //- Copy, recursively if necessary, the source to the destination
581  virtual bool cp
582  (
583  const fileName& src,
584  const fileName& dst,
585  const bool followLink = true
586  ) const;
587 
588  //- Create a softlink. dst should not exist. Returns true if
589  // successful.
590  virtual bool ln(const fileName& src, const fileName& dst) const;
591 
592  //- Rename src to dst
593  virtual bool mv
594  (
595  const fileName& src,
596  const fileName& dst,
597  const bool followLink = false
598  ) const;
599 
600  //- Rename to a corresponding backup file
601  // If the backup file already exists, attempt with
602  // "01" .. "99" suffix
603  virtual bool mvBak
604  (
605  const fileName&,
606  const std::string& ext = "bak"
607  ) const;
608 
609  //- Remove a file, returning true if successful otherwise false
610  virtual bool rm(const fileName&) const;
611 
612  //- Remove a directory and its contents
613  // \param silent do not report missing directory
614  virtual bool rmDir
615  (
616  const fileName& dir,
617  const bool silent = false
618  ) const;
619 
620 // //- Open a shared library. Return handle to library. Print error
621 // // message if library cannot be loaded (check = true)
622 // virtual void* dlOpen
623 // (
624 // const fileName& lib,
625 // const bool check = true
626 // ) const;
627 
628 
629  // (reg)IOobject functinality
630 
631  //- Search for an object. checkGlobal : also check undecomposed case
632  virtual fileName filePath
633  (
634  const bool checkGlobal,
635  const IOobject& io,
636  const word& typeName,
637  const bool search
638  ) const;
639 
640  //- Search for a directory. checkGlobal : also check undecomposed
641  // case
642  virtual fileName dirPath
643  (
644  const bool checkGlobal,
645  const IOobject& io,
646  const bool search
647  ) const;
648 
649  //- Search directory for objects. Used in IOobjectList.
650  virtual fileNameList readObjects
651  (
652  const objectRegistry& db,
653  const fileName& instance,
654  const fileName& local,
655  word& newInstance
656  ) const;
657 
658  //- Read object header from supplied file
659  virtual bool readHeader
660  (
661  IOobject&,
662  const fileName&,
663  const word& typeName
664  ) const;
665 
666  //- Reads header for regIOobject and returns an ISstream
667  // to read the contents.
669  (
670  regIOobject&,
671  const fileName&,
672  const word& typeName,
673  const bool valid = true
674  ) const;
675 
676  //- Top-level read
677  virtual bool read
678  (
679  regIOobject&,
680  const bool masterOnly,
682  const word& typeName
683  ) const;
684 
685  //- Writes a regIOobject (so header, contents and divider).
686  // Returns success state.
687  virtual bool writeObject
688  (
689  const regIOobject& io,
690  IOstreamOption streamOpt = IOstreamOption(),
691  const bool valid = true
692  ) const;
693 
694  //- Generate an ISstream that reads a file
695  virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
696 
697  //- Generate an OSstream that writes a file
699  (
700  const fileName& pathname,
701  IOstreamOption streamOpt = IOstreamOption(),
702  const bool valid = true
703  ) const;
704 
705 
706  // File modification checking
707 
708  //- Add watching of a file. Returns handle
709  virtual label addWatch(const fileName&) const;
710 
711  //- Remove watch on a file (using handle)
712  virtual bool removeWatch(const label) const;
713 
714  //- Find index (or -1) of file in list of handles
715  virtual label findWatch
716  (
717  const labelList& watchIndices,
718  const fileName&
719  ) const;
720 
721  //- Helper: add watches for list of regIOobjects
722  virtual void addWatches(regIOobject&, const fileNameList&) const;
723 
724  //- Get name of file being watched (using handle)
725  virtual fileName getFile(const label) const;
726 
727  //- Update state of all files
728  virtual void updateStates
729  (
730  const bool masterOnly,
731  const bool syncPar
732  ) const;
733 
734  //- Get current state of file (using handle)
735  virtual fileMonitor::fileState getState(const label) const;
736 
737  //- Set current state of file (using handle) to unmodified
738  virtual void setUnmodified(const label) const;
739 
740 
741  // Other
742 
743  //- Same file?
744  static bool uniformFile(const fileNameList&);
745 
746  //- Get sorted list of times
747  virtual instantList findTimes(const fileName&, const word&) const;
748 
749  //- Find instance where IOobject is. Fails if cannot be found
750  // and readOpt() is MUST_READ/MUST_READ_IF_MODIFIED. Otherwise
751  // returns stopInstance.
752  virtual IOobject findInstance
753  (
754  const IOobject& io,
755  const scalar startValue,
756  const word& stopInstance
757  ) const;
758 
759  //- Callback for time change
760  virtual void setTime(const Time&) const;
761 
762  //- Forcibly wait until all output done. Flush any cached data
763  virtual void flush() const;
764 
765  //- Return cached times
766  const HashPtrTable<instantList>& times() const
767  {
768  return times_;
769  }
770 };
771 
772 
773 /*---------------------------------------------------------------------------*\
774  Class masterUncollatedFileOperationInitialise Declaration
775 \*---------------------------------------------------------------------------*/
776 
778 :
779  public unthreadedInitialise
780 {
781 public:
782 
783  // Constructors
784 
785  //- Construct from components
786  masterUncollatedFileOperationInitialise(int& argc, char**& argv)
787  :
788  unthreadedInitialise(argc, argv)
789  {}
790 
791 
792  //- Destructor
793  virtual ~masterUncollatedFileOperationInitialise() = default;
794 };
795 
796 
797 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
798 
799 } // End namespace fileOperations
800 } // End namespace Foam
801 
802 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
803 
804 #ifdef NoRepository
806 #endif
807 
808 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
809 
810 #endif
811 
812 // ************************************************************************* //
Foam::fileOperations::masterUncollatedFileOperation::setUnmodified
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
Definition: masterUncollatedFileOperation.C:2560
Foam::fileOperations::masterUncollatedFileOperation::type
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or LINK.
Definition: masterUncollatedFileOperation.C:875
Foam::fileOperations::masterUncollatedFileOperation::getFile
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
Definition: masterUncollatedFileOperation.C:2516
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::fileOperations::masterUncollatedFileOperation::fileOrNullOp::operator()
fileName operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:351
Foam::fileOperations::masterUncollatedFileOperation::cp
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
Definition: masterUncollatedFileOperation.C:1057
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::fileOperations::masterUncollatedFileOperation::setTime
virtual void setTime(const Time &) const
Callback for time change.
Definition: masterUncollatedFileOperation.C:2232
Foam::fileOperations::masterUncollatedFileOperation::readAndSend
static void readAndSend(const fileName &filePath, const labelUList &procs, PstreamBuffers &pBufs)
Read file contents and send to processors.
Definition: masterUncollatedFileOperation.C:496
Foam::fileOperations::masterUncollatedFileOperation::mkDirOp::mkDirOp
mkDirOp(const mode_t mode)
Definition: masterUncollatedFileOperation.H:105
Foam::exists
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: MSwindows.C:625
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::fileName::FILE
A file.
Definition: fileName.H:83
List.H
Foam::fileOperations::masterUncollatedFileOperation::dirPath
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
Definition: masterUncollatedFileOperation.C:1259
Foam::fileOperations::masterUncollatedFileOperation::lastModifiedOp
Definition: masterUncollatedFileOperation.H:227
Foam::fileOperations::masterUncollatedFileOperation::chModOp::chModOp
chModOp(const mode_t mode)
Definition: masterUncollatedFileOperation.H:120
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileOperation
An encapsulation of filesystem-related operations.
Definition: fileOperation.H:68
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::fileOperations::masterUncollatedFileOperation::mvBakOp
Definition: masterUncollatedFileOperation.H:259
Foam::chMod
bool chMod(const fileName &name, const mode_t mode)
Set the file/directory mode, return true on success.
Definition: MSwindows.C:557
Foam::fileOperations::masterUncollatedFileOperation::uniformFile
static bool uniformFile(const fileNameList &)
Same file?
Definition: masterUncollatedFileOperation.C:478
Foam::fileOperations::masterUncollatedFileOperation::readDir
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.
Definition: masterUncollatedFileOperation.C:1039
Foam::fileOperation::processorsDir
virtual word processorsDir(const IOobject &io) const
Actual name of processors dir (for use in mode PROCOBJECT,.
Definition: fileOperation.H:510
Foam::fileOperations::masterUncollatedFileOperation::times_
HashPtrTable< instantList > times_
Cached times for a given directory.
Definition: masterUncollatedFileOperation.H:96
Foam::fileOperations::masterUncollatedFileOperation::rmDirOp
Definition: masterUncollatedFileOperation.H:283
Foam::fileOperations::masterUncollatedFileOperation::lastModifiedHROp
Definition: masterUncollatedFileOperation.H:243
Foam::fileOperations::masterUncollatedFileOperation::existsOp::existsOp
existsOp(const bool checkGzip, const bool followLink)
Definition: masterUncollatedFileOperation.H:166
Foam::fileOperations::masterUncollatedFileOperation::rmOp::operator()
bool operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:277
Foam::fileOperations::masterUncollatedFileOperation::mode
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
Definition: masterUncollatedFileOperation.C:859
Foam::fileOperations::masterUncollatedFileOperation::existsOp::operator()
bool operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:172
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:88
Foam::fileOperations::masterUncollatedFileOperation::fileSizeOp::operator()
off_t operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:221
Foam::fileOperations::masterUncollatedFileOperation::isFile
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?
Definition: masterUncollatedFileOperation.C:927
Foam::fileOperations::masterUncollatedFileOperation::isDirOp::operator()
bool operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:188
Foam::fileOperations::masterUncollatedFileOperation::readDirOp::readDirOp
readDirOp(const fileName::Type type, const bool filtergz, const bool followLink)
Definition: masterUncollatedFileOperation.H:370
Foam::fileOperations::masterUncollatedFileOperation::fileSize
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
Definition: masterUncollatedFileOperation.C:944
Foam::fileName::Type
Type
Enumerations to handle directory entry types.
Definition: fileName.H:80
Foam::fileOperations::masterUncollatedFileOperation::fileOrNullOp::fileOrNullOp
fileOrNullOp(const bool isFile)
Definition: masterUncollatedFileOperation.H:346
Foam::fileMonitor::fileState
fileState
Enumeration defining the file state.
Definition: fileMonitor.H:73
Foam::isFile
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: MSwindows.C:658
Foam::rm
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition: MSwindows.C:1004
Foam::fileOperations::masterUncollatedFileOperation::mv
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
Definition: masterUncollatedFileOperation.C:1092
Foam::fileOperations::masterUncollatedFileOperation::readDirOp::operator()
fileNameList operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:381
Foam::fileOperations::masterUncollatedFileOperation::chModOp::operator()
bool operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:125
Foam::fileOperations::masterUncollatedFileOperation::maxMasterFileBufferSize
static float maxMasterFileBufferSize
Max size of parallel communications. Switches from non-blocking.
Definition: masterUncollatedFileOperation.H:484
Foam::fileOperations::masterUncollatedFileOperation::chMod
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
Definition: masterUncollatedFileOperation.C:843
Foam::fileOperations::masterUncollatedFileOperation::fileSizeOp::fileSizeOp
fileSizeOp(const bool followLink)
Definition: masterUncollatedFileOperation.H:215
masterUncollatedFileOperationTemplates.C
Foam::fileOperations::masterUncollatedFileOperationInitialise::masterUncollatedFileOperationInitialise
masterUncollatedFileOperationInitialise(int &argc, char **&argv)
Construct from components.
Definition: masterUncollatedFileOperation.H:785
Foam::fileOperations::masterUncollatedFileOperation::isDirOp
Definition: masterUncollatedFileOperation.H:178
Foam::fileOperations::masterUncollatedFileOperation::~masterUncollatedFileOperation
virtual ~masterUncollatedFileOperation()
Destructor.
Definition: masterUncollatedFileOperation.C:815
Foam::fileOperations::masterUncollatedFileOperation::fileOrNullOp
Definition: masterUncollatedFileOperation.H:342
Foam::fileOperations::masterUncollatedFileOperation::typeOp
Definition: masterUncollatedFileOperation.H:146
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::mode
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Definition: MSwindows.C:564
Foam::fileOperations::masterUncollatedFileOperation::readStream
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool valid=true) const
Reads header for regIOobject and returns an ISstream.
Definition: masterUncollatedFileOperation.C:1834
Foam::fileOperations::masterUncollatedFileOperation::modeOp
Definition: masterUncollatedFileOperation.H:131
Foam::uniform
Definition: uniform.H:50
n
label n
Definition: TABSMDCalcMethod2.H:31
format
word format(conversionProperties.get< word >("format"))
Foam::fileOperations::masterUncollatedFileOperation::read
static autoPtr< ISstream > read(IOobject &io, const label comm, const bool uniform, const fileNameList &filePaths, const boolList &procValid)
Read files on comms master.
Definition: masterUncollatedFileOperation.C:569
Foam::fileSize
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
Definition: MSwindows.C:676
Foam::fileOperations::masterUncollatedFileOperation::filePath
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.
Definition: masterUncollatedFileOperation.C:1110
Foam::fileOperations::masterUncollatedFileOperation::rmDirOp::rmDirOp
rmDirOp()
Definition: masterUncollatedFileOperation.H:287
Foam::fileOperations::masterUncollatedFileOperation::myComm_
const label myComm_
Any communicator allocated by me.
Definition: masterUncollatedFileOperation.H:93
Foam::fileOperations::masterUncollatedFileOperation::rmDirOp::operator()
bool operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:295
Foam::fileOperations::masterUncollatedFileOperation::fileSizeOp
Definition: masterUncollatedFileOperation.H:211
Foam::fileOperations::masterUncollatedFileOperation::rmOp
Definition: masterUncollatedFileOperation.H:274
Foam::fileOperations::masterUncollatedFileOperation::lastModified
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
Definition: masterUncollatedFileOperation.C:960
Foam::fileOperations::masterUncollatedFileOperation::rmDirOp::rmDirOp
rmDirOp(const bool silent)
Definition: masterUncollatedFileOperation.H:291
Foam::fileOperations::masterUncollatedFileOperation::writeObject
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
Definition: masterUncollatedFileOperation.C:2142
Foam::fileOperations::masterUncollatedFileOperation::isDirOp::isDirOp
isDirOp(const bool followLink)
Definition: masterUncollatedFileOperation.H:182
Foam::fileOperations::masterUncollatedFileOperation::findWatch
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
Definition: masterUncollatedFileOperation.C:2455
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::fileOperations::masterUncollatedFileOperation::exists
bool exists(const dirIndexList &, IOobject &io) const
Helper: check IO for local existence. Like filePathInfo but.
Definition: masterUncollatedFileOperation.C:1387
Foam::highResLastModified
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
Definition: MSwindows.C:699
Foam::fileOperations::masterUncollatedFileOperation::existsOp
Definition: masterUncollatedFileOperation.H:161
Foam::fileOperations::masterUncollatedFileOperation::mvBakOp::mvBakOp
mvBakOp(const std::string &ext)
Definition: masterUncollatedFileOperation.H:263
Foam::fileOperations::masterUncollatedFileOperation::cpOp
Definition: masterUncollatedFileOperation.H:301
Foam::fileOperations::masterUncollatedFileOperation::isFileOp::isFileOp
isFileOp(const bool checkGzip, const bool followLink)
Definition: masterUncollatedFileOperation.H:199
Foam::fileOperations::masterUncollatedFileOperation::mvOp::operator()
bool operator()(const fileName &src, const fileName &dest) const
Definition: masterUncollatedFileOperation.H:336
Foam::fileOperations::masterUncollatedFileOperation::highResLastModified
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
Definition: masterUncollatedFileOperation.C:976
Foam::fileOperations::masterUncollatedFileOperation::removeWatch
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
Definition: masterUncollatedFileOperation.C:2440
Foam::fileOperations::unthreadedInitialise
Definition: unthreadedInitialise.H:49
Foam::fileOperations::masterUncollatedFileOperation::modeOp::operator()
mode_t operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:140
Foam::fileOperations::masterUncollatedFileOperation::masterUncollatedFileOperation
masterUncollatedFileOperation(bool verbose)
Default construct.
Definition: masterUncollatedFileOperation.C:724
Foam::fileOperations::masterUncollatedFileOperation::TypeName
TypeName("masterUncollated")
Runtime type information.
Foam::fileOperations::masterUncollatedFileOperation::lastModifiedHROp::operator()
double operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:253
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::mv
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
Definition: MSwindows.C:939
Foam::fileOperations::masterUncollatedFileOperation::updateStates
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
Definition: masterUncollatedFileOperation.C:2531
Foam::fileOperations::masterUncollatedFileOperation::mvBakOp::operator()
bool operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:268
fileOperation.H
Foam::fileOperations::masterUncollatedFileOperation::isFileOp
Definition: masterUncollatedFileOperation.H:194
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fileOperations::masterUncollatedFileOperation::masterOp
Type masterOp(const fileName &, const fileOp &fop, const int tag, const label comm) const
Definition: masterUncollatedFileOperationTemplates.C:71
Foam::fileOperations::masterUncollatedFileOperation::modeOp::modeOp
modeOp(const bool followLink)
Definition: masterUncollatedFileOperation.H:135
Foam::fileOperations::masterUncollatedFileOperation::rmDir
virtual bool rmDir(const fileName &dir, const bool silent=false) const
Remove a directory and its contents.
Definition: masterUncollatedFileOperation.C:1023
Foam::fileOperations::masterUncollatedFileOperation::mvBak
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
Definition: masterUncollatedFileOperation.C:992
Foam::fileOperations::masterUncollatedFileOperation::times
const HashPtrTable< instantList > & times() const
Return cached times.
Definition: masterUncollatedFileOperation.H:765
Foam::fileOperations::masterUncollatedFileOperation::readObjects
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Definition: masterUncollatedFileOperation.C:1641
Foam::fileOperations::masterUncollatedFileOperation::lastModifiedOp::operator()
time_t operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:237
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:101
Foam::fileOperations::masterUncollatedFileOperation::filePathInfo
virtual fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &, const bool search, pathType &searchType, word &processorsDir, word &instance) const
Search (locally!) for object; return info on how it was found.
Definition: masterUncollatedFileOperation.C:159
Foam::fileOperations::masterUncollatedFileOperation::scatterList
Type scatterList(const UList< Type > &, const int, const label comm) const
Definition: masterUncollatedFileOperationTemplates.C:36
Foam::fileOperations::masterUncollatedFileOperation::findInstancePath
static word findInstancePath(const instantList &timeDirs, const instant &t)
Equivalent of Time::findInstance.
Definition: masterUncollatedFileOperation.C:134
Foam::fileOperations::masterUncollatedFileOperation::mkDir
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
Definition: masterUncollatedFileOperation.C:827
Foam::fileOperations::masterUncollatedFileOperation::getState
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
Definition: masterUncollatedFileOperation.C:2545
unthreadedInitialise.H
Foam::mvBak
bool mvBak(const fileName &src, const std::string &ext="bak")
Rename to a corresponding backup file.
Definition: MSwindows.C:968
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::fileOperations::masterUncollatedFileOperation::chModOp
Definition: masterUncollatedFileOperation.H:116
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::fileOperations::masterUncollatedFileOperation::mvOp::mvOp
mvOp(const bool followLink)
Definition: masterUncollatedFileOperation.H:330
Foam::fileOperations::masterUncollatedFileOperation::flush
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Definition: masterUncollatedFileOperation.C:2417
Foam::fileOperations::masterUncollatedFileOperation
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
Definition: masterUncollatedFileOperation.H:84
Foam::cp
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
Definition: MSwindows.C:802
Foam::fileOperations::masterUncollatedFileOperation::addWatch
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
Definition: masterUncollatedFileOperation.C:2425
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:54
Foam::fileOperations::masterUncollatedFileOperation::rm
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
Definition: masterUncollatedFileOperation.C:1008
Foam::rmDir
bool rmDir(const fileName &directory, const bool silent=false)
Remove a directory and its contents (optionally silencing warnings)
Definition: MSwindows.C:1028
Foam::fileOperations::masterUncollatedFileOperation::cpOp::operator()
bool operator()(const fileName &src, const fileName &dest) const
Definition: masterUncollatedFileOperation.H:311
Foam::List< fileName >
Foam::fileOperations::masterUncollatedFileOperation::lastModifiedOp::lastModifiedOp
lastModifiedOp(const bool followLink)
Definition: masterUncollatedFileOperation.H:231
Foam::fileOperations::masterUncollatedFileOperation::typeOp::typeOp
typeOp(const bool followLink)
Definition: masterUncollatedFileOperation.H:150
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::fileOperations::masterUncollatedFileOperation::NewIFstream
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
Definition: masterUncollatedFileOperation.C:2292
Foam::UList< Type >
HashPtrTable.H
Foam::fileOperation::dirIndexList
List< dirIndex > dirIndexList
Definition: fileOperation.H:99
Foam::search
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:571
Foam::fileOperations::masterUncollatedFileOperation::mkDirOp::operator()
bool operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:110
Foam::fileOperations::masterUncollatedFileOperation::readHeader
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
Definition: masterUncollatedFileOperation.C:1727
Foam::fileOperations::masterUncollatedFileOperationInitialise::~masterUncollatedFileOperationInitialise
virtual ~masterUncollatedFileOperationInitialise()=default
Destructor.
Foam::fileOperations::masterUncollatedFileOperation::isDir
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
Definition: masterUncollatedFileOperation.C:911
Foam::fileOperations::masterUncollatedFileOperation::lnOp
Definition: masterUncollatedFileOperation.H:317
Foam::fileOperations::masterUncollatedFileOperation::localObjectPath
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
Definition: masterUncollatedFileOperation.C:336
Foam::fileOperations::masterUncollatedFileOperation::readDirOp
Definition: masterUncollatedFileOperation.H:363
Foam::ln
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: MSwindows.C:925
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
Foam::fileOperations::masterUncollatedFileOperation::NewOFstream
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Generate an OSstream that writes a file.
Definition: masterUncollatedFileOperation.C:2398
Foam::fileOperations::masterUncollatedFileOperationInitialise
Definition: masterUncollatedFileOperation.H:776
Foam::fileOperations::masterUncollatedFileOperation::findTimes
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
Definition: masterUncollatedFileOperation.C:2184
Foam::fileOperations::masterUncollatedFileOperation::lastModifiedHROp::lastModifiedHROp
lastModifiedHROp(const bool followLink)
Definition: masterUncollatedFileOperation.H:247
Foam::fileOperations::masterUncollatedFileOperation::ln
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
Definition: masterUncollatedFileOperation.C:1075
Foam::mkDir
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: MSwindows.C:507
Foam::fileOperations::masterUncollatedFileOperation::addWatches
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
Definition: masterUncollatedFileOperation.C:2479
Foam::readDir
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Definition: MSwindows.C:707
Foam::fileOperations::masterUncollatedFileOperation::mkDirOp
Definition: masterUncollatedFileOperation.H:101
Foam::fileOperations::masterUncollatedFileOperation::subRanks
static labelList subRanks(const label n)
Get the list of processors that are part of this communicator.
Definition: masterUncollatedFileOperation.C:84
Foam::fileOperation::pathType
pathType
Enumeration for the location of an IOobject.
Definition: fileOperation.H:73
Foam::fileOperations::masterUncollatedFileOperation::cpOp::cpOp
cpOp(const bool followLink)
Definition: masterUncollatedFileOperation.H:305
Foam::fileOperations::masterUncollatedFileOperation::isFileOp::operator()
bool operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:205
Foam::lastModified
time_t lastModified(const fileName &name, const bool followLink=true)
Return time of last file modification (normally follows symbolic links).
Definition: MSwindows.C:692
Foam::fileOperations::masterUncollatedFileOperation::lnOp::operator()
bool operator()(const fileName &src, const fileName &dest) const
Definition: masterUncollatedFileOperation.H:320
Foam::fileOperations::masterUncollatedFileOperation::mvOp
Definition: masterUncollatedFileOperation.H:326
Foam::isDir
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:643
Foam::fileOperations::masterUncollatedFileOperation::findInstance
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance) const
Find instance where IOobject is. Fails if cannot be found.
Definition: masterUncollatedFileOperation.C:1436
Foam::fileOperations::masterUncollatedFileOperation::typeOp::operator()
label operator()(const fileName &fName) const
Definition: masterUncollatedFileOperation.H:155