masterUncollatedFileOperation.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 | Copyright (C) 2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "Pstream.H"
29 #include "Time.H"
30 #include "instant.H"
31 #include "IFstream.H"
32 #include "masterOFstream.H"
33 #include "decomposedBlockData.H"
34 #include "registerSwitch.H"
35 #include "dummyISstream.H"
36 #include "SubList.H"
37 
38 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
39 
40 namespace Foam
41 {
42 namespace fileOperations
43 {
44  defineTypeNameAndDebug(masterUncollatedFileOperation, 0);
46  (
47  fileOperation,
48  masterUncollatedFileOperation,
49  word
50  );
51 
53  (
54  Foam::debug::floatOptimisationSwitch("maxMasterFileBufferSize", 1e9)
55  );
57  (
58  "maxMasterFileBufferSize",
59  float,
61  );
62 }
63 }
64 
65 
66 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
67 
70 (
71  const instantList& timeDirs,
72  const instant& t
73 )
74 {
75  // Note:
76  // - times will include constant (with value 0) as first element.
77  // For backwards compatibility make sure to find 0 in preference
78  // to constant.
79  // - list is sorted so could use binary search
80 
81  forAllReverse(timeDirs, i)
82  {
83  if (t.equal(timeDirs[i].value()))
84  {
85  return timeDirs[i].name();
86  }
87  }
88 
89  return word::null;
90 }
91 
92 
94 (
95  const bool checkGlobal,
96  const bool isFile,
97  const IOobject& io,
98  pathType& searchType,
99  word& newInstancePath
100 ) const
101 {
102  newInstancePath = word::null;
103 
104  if (io.instance().isAbsolute())
105  {
106  fileName objectPath = io.instance()/io.name();
107 
108  if (isFileOrDir(isFile, objectPath))
109  {
110  searchType = fileOperation::ABSOLUTE;
111  return objectPath;
112  }
113  else
114  {
115  searchType = fileOperation::NOTFOUND;
116  return fileName::null;
117  }
118  }
119  else
120  {
121  // 1. Check processors/
122  if (io.time().processorCase())
123  {
124  fileName objectPath = processorsPath(io, io.instance())/io.name();
125  if (isFileOrDir(isFile, objectPath))
126  {
127  searchType = fileOperation::PROCESSORSOBJECT;
128  return objectPath;
129  }
130  }
131  {
132  // 2. Check local
133  fileName localObjectPath = io.objectPath();
134 
135  if (isFileOrDir(isFile, localObjectPath))
136  {
137  searchType = fileOperation::OBJECT;
138  return localObjectPath;
139  }
140  }
141 
142 
143 
144  // Any global checks
145  if
146  (
147  checkGlobal
148  && io.time().processorCase()
149  && (
150  io.instance() == io.time().system()
151  || io.instance() == io.time().constant()
152  )
153  )
154  {
155  fileName parentObjectPath =
156  io.rootPath()/io.time().globalCaseName()
157  /io.instance()/io.db().dbDir()/io.local()/io.name();
158 
159  if (isFileOrDir(isFile, parentObjectPath))
160  {
161  searchType = fileOperation::PARENTOBJECT;
162  return parentObjectPath;
163  }
164  }
165 
166  // Check for approximately same time. E.g. if time = 1e-2 and
167  // directory is 0.01 (due to different time formats)
169  (
170  times_.find
171  (
172  io.time().path()
173  )
174  );
175  if (pathFnd != times_.end())
176  {
177  newInstancePath = findInstancePath
178  (
179  *pathFnd(),
180  instant(io.instance())
181  );
182 
183  if (newInstancePath.size())
184  {
185  // 1. Try processors equivalent
186 
187  fileName fName =
188  processorsPath(io, newInstancePath)
189  /io.name();
190  if (isFileOrDir(isFile, fName))
191  {
193  return fName;
194  }
195 
196  fName =
197  io.rootPath()/io.caseName()
198  /newInstancePath/io.db().dbDir()/io.local()/io.name();
199 
200  if (isFileOrDir(isFile, fName))
201  {
202  searchType = fileOperation::FINDINSTANCE;
203  return fName;
204  }
205  }
206  }
207 
208  searchType = fileOperation::NOTFOUND;
209  return fileName::null;
210  }
211 }
212 
213 
216 (
217  const IOobject& io
218 )
219 {
220  return
221  io.rootPath()
222  /io.time().globalCaseName()
223  /processorsDir;
224 }
225 
226 
229 (
230  const IOobject& io,
231  const word& instance
232 )
233 {
234  return
235  processorsCasePath(io)
236  /instance
237  /io.db().dbDir()
238  /io.local();
239 }
240 
241 
244 (
245  const fileName& dir
246 )
247 {
248  // Check if directory is processorXXX
249  word caseName(dir.name());
250 
251  std::string::size_type pos = caseName.find("processor");
252  if (pos == 0)
253  {
254  return dir.path()/processorsDir;
255  }
256  else
257  {
258  return fileName::null;
259  }
260 }
261 
262 
265 (
266  const fileName& objectPath,
267  fileName& path,
268  fileName& local
269 )
270 {
271  // Search for processor at start of line or /processor
272  std::string::size_type pos = objectPath.find("processor");
273  if (pos == string::npos)
274  {
275  return -1;
276  }
277 
278  if (pos == 0)
279  {
280  path = "";
281  local = objectPath.substr(pos+9);
282  }
283  else if (objectPath[pos-1] != '/')
284  {
285  return -1;
286  }
287  else
288  {
289  path = objectPath.substr(0, pos-1);
290  local = objectPath.substr(pos+9);
291  }
292 
293  pos = local.find('/');
294  if (pos == string::npos)
295  {
296  // processorXXX without local
297  label proci;
298  if (Foam::read(local.c_str(), proci))
299  {
300  local.clear();
301  return proci;
302  }
303  return -1;
304  }
305  string procName(local.substr(0, pos));
306  label proci;
307  if (Foam::read(procName.c_str(), proci))
308  {
309  local = local.substr(pos+1);
310  return proci;
311  }
312  return -1;
313 }
314 
315 
317 (
318  const IOobject& io,
319  const pathType& searchType,
320  const word& instancePath
321 )
322 {
323  // Replacement for IOobject::objectPath()
324 
325  switch (searchType)
326  {
328  {
329  return io.instance()/io.name();
330  }
331  break;
332 
334  {
335  return io.path()/io.name();
336  }
337  break;
338 
340  {
341  return processorsPath(io, io.instance())/io.name();
342  }
343  break;
344 
346  {
347  return
348  io.rootPath()/io.time().globalCaseName()
349  /io.instance()/io.db().dbDir()/io.local()/io.name();
350  }
351  break;
352 
354  {
355  return
356  io.rootPath()/io.caseName()
357  /instancePath/io.db().dbDir()/io.local()/io.name();
358  }
359  break;
360 
362  {
363  return processorsPath(io, instancePath)/io.name();
364  }
365  break;
366 
368  {
369  return fileName::null;
370  }
371  break;
372 
373  default:
374  {
376  return fileName::null;
377  }
378  }
379 }
380 
381 
383 (
384  const fileNameList& filePaths
385 )
386 {
387  const fileName& object0 = filePaths[0];
388 
389  for (label i = 1; i < filePaths.size(); i++)
390  {
391  if (filePaths[i] != object0)
392  {
393  return false;
394  }
395  }
396  return true;
397 }
398 
399 
401 (
402  const fileName& filePath,
403  const IOstream::compressionType cmp,
404  const labelUList& procs,
405  PstreamBuffers& pBufs
406 )
407 {
408  if (cmp == IOstream::compressionType::COMPRESSED)
409  {
410  if (debug)
411  {
412  Pout<< "masterUncollatedFileOperation::readAndSend:"
413  << " opening compressed " << filePath << endl;
414  }
415 
416  IFstream is(filePath, IOstream::streamFormat::BINARY);
417 
418  std::ostringstream stringStr;
419  stringStr << is.stdStream().rdbuf();
420  string buf(stringStr.str());
421 
422  forAll(procs, i)
423  {
424  UOPstream os(procs[i], pBufs);
425  os.write(&buf[0], buf.size());
426  }
427  }
428  else
429  {
430  off_t count(Foam::fileSize(filePath));
431  IFstream is(filePath, IOstream::streamFormat::BINARY);
432 
433  if (debug)
434  {
435  Pout<< "masterUncollatedFileOperation::readStream:"
436  << " From " << filePath << " reading " << label(count)
437  << " bytes" << endl;
438  }
439  List<char> buf(static_cast<label>(count));
440  is.stdStream().read(buf.begin(), count);
441 
442  forAll(procs, i)
443  {
444  UOPstream os(procs[i], pBufs);
445  os.write(buf.begin(), count);
446  }
447  }
448 }
449 
450 
451 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
452 
455 (
456  const bool verbose
457 )
458 {
459  if (verbose)
460  {
461  Info<< "I/O : " << typeName
462  << " (maxMasterFileBufferSize " << maxMasterFileBufferSize << ')'
463  << endl;
464  }
465 
467  {
468  if (verbose)
469  {
471  << "Resetting fileModificationChecking to timeStamp" << endl;
472  }
474  }
475  else if
476  (
479  )
480  {
481  if (verbose)
482  {
484  << "Resetting fileModificationChecking to inotify"
485  << endl;
486  }
488  }
489 }
490 
491 
492 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
493 
496 {}
497 
498 
499 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
500 
502 (
503  const fileName& dir,
504  mode_t mode
505 ) const
506 {
507  return masterOp<mode_t, mkDirOp>(dir, mkDirOp(mode));
508 }
509 
510 
512 (
513  const fileName& fName,
514  mode_t mode
515 ) const
516 {
517  return masterOp<mode_t, chModOp>(fName, chModOp(mode));
518 }
519 
520 
522 (
523  const fileName& fName,
524  const bool followLink
525 ) const
526 {
527  return masterOp<mode_t, modeOp>(fName, modeOp(followLink));
528 }
529 
530 
532 (
533  const fileName& fName,
534  const bool followLink
535 ) const
536 {
537  return fileName::Type(masterOp<label, typeOp>(fName, typeOp(followLink)));
538 }
539 
540 
542 (
543  const fileName& fName,
544  const bool checkGzip,
545  const bool followLink
546 ) const
547 {
548  return masterOp<bool, existsOp>(fName, existsOp(checkGzip, followLink));
549 }
550 
551 
553 (
554  const fileName& fName,
555  const bool followLink
556 ) const
557 {
558  return masterOp<bool, isDirOp>(fName, isDirOp(followLink));
559 }
560 
561 
563 (
564  const fileName& fName,
565  const bool checkGzip,
566  const bool followLink
567 ) const
568 {
569  return masterOp<bool, isFileOp>(fName, isFileOp(checkGzip, followLink));
570 }
571 
572 
574 (
575  const fileName& fName,
576  const bool followLink
577 ) const
578 {
579  return masterOp<off_t, fileSizeOp>(fName, fileSizeOp(followLink));
580 }
581 
582 
584 (
585  const fileName& fName,
586  const bool followLink
587 ) const
588 {
589  return masterOp<time_t, lastModifiedOp>
590  (
591  fName,
592  lastModifiedOp(followLink)
593  );
594 }
595 
596 
598 (
599  const fileName& fName,
600  const bool followLink
601 ) const
602 {
603  return masterOp<double, lastModifiedHROp>
604  (
605  fName,
606  lastModifiedHROp(followLink)
607  );
608 }
609 
610 
612 (
613  const fileName& fName,
614  const std::string& ext
615 ) const
616 {
617  return masterOp<bool, mvBakOp>(fName, mvBakOp(ext));
618 }
619 
620 
622 (
623  const fileName& fName
624 ) const
625 {
626  return masterOp<bool, rmOp>(fName, rmOp());
627 }
628 
629 
631 (
632  const fileName& dir
633 ) const
634 {
635  return masterOp<bool, rmDirOp>(dir, rmDirOp());
636 }
637 
638 
640 (
641  const fileName& dir,
642  const fileName::Type type,
643  const bool filtergz,
644  const bool followLink
645 ) const
646 {
647  return masterOp<fileNameList, readDirOp>
648  (
649  dir,
650  readDirOp(type, filtergz, followLink)
651  );
652 }
653 
654 
656 (
657  const fileName& src,
658  const fileName& dst,
659  const bool followLink
660 ) const
661 {
662  return masterOp<bool, cpOp>(src, dst, cpOp(followLink));
663 }
664 
665 
667 (
668  const fileName& src,
669  const fileName& dst
670 ) const
671 {
672  return masterOp<bool, lnOp>(src, dst, lnOp());
673 }
674 
675 
677 (
678  const fileName& src,
679  const fileName& dst,
680  const bool followLink
681 ) const
682 {
683  return masterOp<bool, mvOp>(src, dst, mvOp(followLink));
684 }
685 
686 
688 (
689  const bool checkGlobal,
690  const IOobject& io,
691  const word& typeName
692 ) const
693 {
694  if (debug)
695  {
696  Pout<< "masterUncollatedFileOperation::filePath :"
697  << " objectPath:" << io.objectPath()
698  << " checkGlobal:" << checkGlobal << endl;
699  }
700 
701  // Trigger caching of times
702  (void)findTimes(io.time().path(), io.time().constant());
703 
704  // Determine master filePath and scatter
705 
706  fileName objPath;
707  pathType searchType = NOTFOUND;
708  word newInstancePath;
709 
710  if (Pstream::master())
711  {
712  objPath = filePathInfo
713  (
714  checkGlobal,
715  true,
716  io,
717  searchType,
718  newInstancePath
719  );
720  }
721 
722  {
723  label masterType(searchType);
724  Pstream::scatter(masterType);
725  searchType = pathType(masterType);
726  }
727 
728  Pstream::scatter(newInstancePath);
729 
730 
731  // Use the master type to determine if additional information is
732  // needed to construct the local equivalent
733  switch (searchType)
734  {
740  {
741  // Construct equivalent local path
742  objPath = objectPath(io, searchType, newInstancePath);
743  }
744  break;
745 
748  {
749  // Retest all processors separately since some processors might
750  // have the file and some not (e.g. lagrangian data)
751  objPath = masterOp<fileName, fileOrNullOp>
752  (
753  io.objectPath(),
754  fileOrNullOp(true)
755  );
756  }
757  break;
758  }
759 
760  if (debug)
761  {
762  Pout<< "masterUncollatedFileOperation::filePath :"
763  << " Returning from file searching:" << endl
764  << " objectPath:" << io.objectPath() << endl
765  << " filePath :" << objPath << endl << endl;
766  }
767  return objPath;
768 }
769 
770 
772 (
773  const bool checkGlobal,
774  const IOobject& io
775 ) const
776 {
777  if (debug)
778  {
779  Pout<< "masterUncollatedFileOperation::dirPath :"
780  << " objectPath:" << io.objectPath()
781  << " checkGlobal:" << checkGlobal << endl;
782  }
783 
784  // Determine master dirPath and scatter
785 
786  fileName objPath;
787  pathType searchType = NOTFOUND;
788  word newInstancePath;
789 
790  if (Pstream::master())
791  {
792  objPath = filePathInfo
793  (
794  checkGlobal,
795  false,
796  io,
797  searchType,
798  newInstancePath
799  );
800  }
801 
802  {
803  label masterType(searchType);
804  Pstream::scatter(masterType);
805  searchType = pathType(masterType);
806  }
807  Pstream::scatter(newInstancePath);
808 
809 
810  // Use the master type to determine if additional information is
811  // needed to construct the local equivalent
812  switch (searchType)
813  {
819  {
820  // Construct equivalent local path
821  objPath = objectPath(io, searchType, newInstancePath);
822  }
823  break;
824 
827  {
828  // Retest all processors separately since some processors might
829  // have the file and some not (e.g. lagrangian data)
830  objPath = masterOp<fileName, fileOrNullOp>
831  (
832  io.objectPath(),
833  fileOrNullOp(false)
834  );
835  }
836  break;
837  }
838 
839  if (debug)
840  {
841  Pout<< "masterUncollatedFileOperation::dirPath :"
842  << " Returning from file searching:" << endl
843  << " objectPath:" << io.objectPath() << endl
844  << " filePath :" << objPath << endl << endl;
845  }
846  return objPath;
847 }
848 
849 
852 (
853  const objectRegistry& db,
854  const fileName& instance,
855  const fileName& local,
856  word& newInstance
857 ) const
858 {
859  if (debug)
860  {
861  Pout<< "masterUncollatedFileOperation::readObjects :"
862  << " db:" << db.objectPath()
863  << " instance:" << instance << endl;
864  }
865 
866  fileNameList objectNames;
867  newInstance = word::null;
868 
869  if (Pstream::master())
870  {
871  //- Use non-time searching version
872  objectNames = fileOperation::readObjects
873  (
874  db,
875  instance,
876  local,
877  newInstance
878  );
879 
880  if (newInstance.empty())
881  {
882  // Find similar time
883 
884  // Copy of Time::findInstancePath. We want to avoid the
885  // parallel call to findTimes. Alternative is to have
886  // version of findInstancePath that takes instantList ...
887  const instantList timeDirs
888  (
890  (
891  db.time().path(),
892  db.time().constant()
893  )
894  );
895 
896  const instant t(instance);
897  forAllReverse(timeDirs, i)
898  {
899  if (t.equal(timeDirs[i].value()))
900  {
901  objectNames = fileOperation::readObjects
902  (
903  db,
904  timeDirs[i].name(), // newly found time
905  local,
906  newInstance
907  );
908  break;
909  }
910  }
911  }
912  }
913 
914  Pstream::scatter(newInstance);
915  Pstream::scatter(objectNames);
916 
917  if (debug)
918  {
919  Pout<< "masterUncollatedFileOperation::readObjects :"
920  << " newInstance:" << newInstance
921  << " objectNames:" << objectNames << endl;
922  }
923 
924  return objectNames;
925 }
926 
927 
929 (
930  IOobject& io,
931  const fileName& fName,
932  const word& typeName
933 ) const
934 {
935  bool ok = false;
936 
937  if (debug)
938  {
939  Pout<< "masterUncollatedFileOperation::readHeader:" << endl
940  << " objectPath:" << io.objectPath() << endl
941  << " fName :" << fName << endl;
942  }
943 
944  fileNameList filePaths(Pstream::nProcs());
945  filePaths[Pstream::myProcNo()] = fName;
946  Pstream::gatherList(filePaths);
947 
948  bool uniform = uniformFile(filePaths);
949  Pstream::scatter(uniform);
950 
951  if (uniform)
952  {
953  if (Pstream::master())
954  {
955  if (!fName.empty())
956  {
957  IFstream is(fName);
958 
959  if (is.good())
960  {
961  ok = io.readHeader(is);
962 
963  if (io.headerClassName() == decomposedBlockData::typeName)
964  {
965  // Read the header inside the container (master data)
967  }
968  }
969  }
970  }
971  Pstream::scatter(ok);
973  Pstream::scatter(io.note());
974  }
975  else
976  {
977  boolList result(Pstream::nProcs(), false);
978  wordList headerClassName(Pstream::nProcs());
979  stringList note(Pstream::nProcs());
980  if (Pstream::master())
981  {
982  forAll(filePaths, proci)
983  {
984  if (!filePaths[proci].empty())
985  {
986  IFstream is(filePaths[proci]);
987 
988  if (is.good())
989  {
990  result[proci] = io.readHeader(is);
991  headerClassName[proci] = io.headerClassName();
992  note[proci] = io.note();
993 
994  if
995  (
996  io.headerClassName()
997  == decomposedBlockData::typeName
998  )
999  {
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"
1006  << " processors" << exit(FatalError);
1007  }
1008  }
1009  }
1010  }
1011  }
1012  ok = scatterList(result);
1013  io.headerClassName() = scatterList(headerClassName);
1014  io.note() = scatterList(note);
1015  }
1016 
1017  if (debug)
1018  {
1019  Pout<< "masterUncollatedFileOperation::readHeader:" << " ok:" << ok
1020  << " class:" << io.headerClassName() << endl;
1021  }
1022  return ok;
1023 }
1024 
1025 
1029  regIOobject& io,
1030  const fileName& fName,
1031  const word& typeName,
1032  const bool valid
1033 ) const
1034 {
1035  if (debug)
1036  {
1037  Pout<< "masterUncollatedFileOperation::readStream:"
1038  << " object : " << io.name()
1039  << " fName : " << fName << " valid:" << valid << endl;
1040  }
1041 
1042 
1043  autoPtr<ISstream> isPtr;
1044  bool isCollated = false;
1045  if (UPstream::master())
1046  {
1047  if (!fName.empty())
1048  {
1049  // This can happen in lagrangian field reading some processors
1050  // have no file to read from. This will only happen when using
1051  // normal writing since then the fName for the valid processors is
1052  // processorDDD/<instance>/.. . In case of collocated writing
1053  // the fName is already rewritten to processors/.
1054 
1055  isPtr.reset(new IFstream(fName));
1056 
1057  if (isPtr().good())
1058  {
1059  // Read header data (on copy)
1060  IOobject headerIO(io);
1061  headerIO.readHeader(isPtr());
1062 
1063  if (headerIO.headerClassName() == decomposedBlockData::typeName)
1064  {
1065  isCollated = true;
1066  }
1067  }
1068 
1069  if (!isCollated)
1070  {
1071  // Close file. Reopened below.
1072  isPtr.clear();
1073  }
1074  }
1075  }
1076 
1077  Pstream::scatter(isCollated);
1078 
1079  if (isCollated)
1080  {
1081  if (debug)
1082  {
1083  Pout<< "masterUncollatedFileOperation::readStream:"
1084  << " for object : " << io.name()
1085  << " starting collating input from " << fName << endl;
1086  }
1087 
1088  List<char> data;
1089  if (!Pstream::parRun())
1090  {
1091  // Analyse the objectpath to find out the processor we're trying
1092  // to access
1093  fileName path;
1094  fileName local;
1097  (
1098  io.objectPath(),
1099  path,
1100  local
1101  );
1102 
1103  if (proci == -1)
1104  {
1105  FatalIOErrorInFunction(isPtr())
1106  << "Could not detect processor number"
1107  << " from objectPath:" << io.objectPath()
1108  << exit(FatalIOError);
1109  }
1110 
1111  return decomposedBlockData::readBlock(proci, isPtr(), io);
1112  }
1113  else
1114  {
1115  // Get size of file (on master, scatter to slaves)
1116  off_t sz = fileSize(fName);
1117 
1118  // Read my data
1120  (
1122  fName,
1123  isPtr,
1124  io,
1125  (
1126  sz > off_t(maxMasterFileBufferSize)
1129  )
1130  );
1131  }
1132  }
1133  else
1134  {
1135  if (debug)
1136  {
1137  Pout<< "masterUncollatedFileOperation::readStream:"
1138  << " for object : " << io.name()
1139  << " starting separated input from " << fName << endl;
1140  }
1141 
1142  fileNameList filePaths(Pstream::nProcs());
1143  filePaths[Pstream::myProcNo()] = fName;
1144  Pstream::gatherList(filePaths);
1145  boolList procValid(Pstream::nProcs());
1146  procValid[Pstream::myProcNo()] = valid;
1147  Pstream::gatherList(procValid);
1148 
1150 
1151  if (Pstream::master())
1152  {
1153  //const bool uniform = uniformFile(filePaths);
1154 
1155  if (valid)
1156  {
1157  if (fName.empty())
1158  {
1160  << "cannot find file " << io.objectPath()
1161  << exit(FatalError);
1162  }
1163  else
1164  {
1165  autoPtr<IFstream> ifsPtr(new IFstream(fName));
1166 
1167  // Read header
1168  if (!io.readHeader(ifsPtr()))
1169  {
1170  FatalIOErrorInFunction(ifsPtr())
1171  << "problem while reading header for object "
1172  << io.name() << exit(FatalIOError);
1173  }
1174 
1175  // Open master (steal from ifsPtr)
1176  isPtr.reset(ifsPtr.ptr());
1177  }
1178  }
1179 
1180  // Read slave files
1181  for (label proci = 1; proci < Pstream::nProcs(); proci++)
1182  {
1183  if (debug)
1184  {
1185  Pout<< "masterUncollatedFileOperation::readStream:"
1186  << " For processor " << proci
1187  << " opening " << filePaths[proci] << endl;
1188  }
1189 
1190  if (procValid[proci] && !filePaths[proci].empty())
1191  {
1192  // Note: handle compression ourselves since size cannot
1193  // be determined without actually uncompressing
1194 
1195  if (Foam::exists(filePaths[proci]+".gz", false))
1196  {
1197  readAndSend
1198  (
1199  filePaths[proci],
1200  IOstream::compressionType::COMPRESSED,
1201  labelList(1, proci),
1202  pBufs
1203  );
1204  }
1205  else
1206  {
1207  readAndSend
1208  (
1209  filePaths[proci],
1210  IOstream::compressionType::UNCOMPRESSED,
1211  labelList(1, proci),
1212  pBufs
1213  );
1214  }
1215  }
1216  }
1217  }
1218 
1219  labelList recvSizes;
1220  pBufs.finishedSends(recvSizes);
1221 
1222  // isPtr will be valid on master. Else the information is in the
1223  // PstreamBuffers
1224 
1225  if (Pstream::master())
1226  {
1227  if (!isPtr.valid())
1228  {
1229  return autoPtr<ISstream>(new dummyISstream());
1230  }
1231  else
1232  {
1233  return isPtr;
1234  }
1235  }
1236  else
1237  {
1238  if (valid)
1239  {
1240  UIPstream is(Pstream::masterNo(), pBufs);
1241  string buf(recvSizes[Pstream::masterNo()], '\0');
1242  if (recvSizes[Pstream::masterNo()] > 0)
1243  {
1244  is.read(&buf[0], recvSizes[Pstream::masterNo()]);
1245  }
1246 
1247  if (debug)
1248  {
1249  Pout<< "masterUncollatedFileOperation::readStream:"
1250  << " Done reading " << buf.size() << " bytes" << endl;
1251  }
1252  isPtr.reset(new IStringStream(fName, buf));
1253 
1254  if (!io.readHeader(isPtr()))
1255  {
1256  FatalIOErrorInFunction(isPtr())
1257  << "problem while reading header for object "
1258  << io.name() << exit(FatalIOError);
1259  }
1260 
1261  return isPtr;
1262  }
1263  else
1264  {
1265  return autoPtr<ISstream>(new dummyISstream());
1266  }
1267  }
1268  }
1269 }
1270 
1271 
1274  regIOobject& io,
1275  const bool masterOnly,
1276  const IOstream::streamFormat format,
1277  const word& typeName
1278 ) const
1279 {
1280  bool ok = true;
1281 
1282  if (io.globalObject())
1283  {
1284  if (debug)
1285  {
1286  Pout<< "masterUncollatedFileOperation::read:"
1287  << "reading global object " << io.name() << endl;
1288  }
1289 
1290  bool ok = false;
1291  if (Pstream::master())
1292  {
1293  // Do master-only reading always.
1294  bool oldParRun = UPstream::parRun();
1295  UPstream::parRun() = false;
1296 
1297  ok = io.readData(io.readStream(typeName));
1298  io.close();
1299 
1300  UPstream::parRun() = oldParRun;
1301  }
1302 
1303  Pstream::scatter(ok);
1305  Pstream::scatter(io.note());
1306 
1307 
1308  // scatter operation for regIOobjects
1309 
1310  // Get my communication order
1311  const List<Pstream::commsStruct>& comms =
1312  (
1316  );
1317  const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
1318 
1319  // Reveive from up
1320  if (myComm.above() != -1)
1321  {
1322  IPstream fromAbove
1323  (
1325  myComm.above(),
1326  0,
1327  Pstream::msgType(),
1329  format
1330  );
1331  ok = io.readData(fromAbove);
1332  }
1333 
1334  // Send to my downstairs neighbours
1335  forAll(myComm.below(), belowI)
1336  {
1337  OPstream toBelow
1338  (
1340  myComm.below()[belowI],
1341  0,
1342  Pstream::msgType(),
1344  format
1345  );
1346  bool okWrite = io.writeData(toBelow);
1347  ok = ok && okWrite;
1348  }
1349  }
1350  else
1351  {
1352  if (debug)
1353  {
1354  Pout<< "masterUncollatedFileOperation::read:"
1355  << "reading local object " << io.name() << endl;
1356  }
1357 
1358  ok = io.readData(io.readStream(typeName));
1359  io.close();
1360  }
1361 
1362  return ok;
1363 }
1364 
1365 
1368  const regIOobject& io,
1372  const bool valid
1373 ) const
1374 {
1375  fileName pathName(io.objectPath());
1376 
1377  if (debug)
1378  {
1379  Pout<< "masterUncollatedFileOperation::writeObject:"
1380  << " io:" << pathName << " valid:" << valid << endl;
1381  }
1382 
1383  // Make sure to pick up any new times
1384  setTime(io.time());
1385 
1386  autoPtr<Ostream> osPtr
1387  (
1388  NewOFstream
1389  (
1390  pathName,
1391  fmt,
1392  ver,
1393  cmp,
1394  valid
1395  )
1396  );
1397  Ostream& os = osPtr();
1398 
1399  // If any of these fail, return (leave error handling to Ostream class)
1400  if (!os.good())
1401  {
1402  return false;
1403  }
1404 
1405  if (!io.writeHeader(os))
1406  {
1407  return false;
1408  }
1409 
1410  // Write the data to the Ostream
1411  if (!io.writeData(os))
1412  {
1413  return false;
1414  }
1415 
1417 
1418  return true;
1419 }
1420 
1421 
1424  const fileName& directory,
1425  const word& constantName
1426 ) const
1427 {
1428  if (debug)
1429  {
1430  Pout<< "masterUncollatedFileOperation::findTimes:"
1431  << " Finding times in directory " << directory << endl;
1432  }
1433 
1434  HashPtrTable<instantList>::const_iterator iter = times_.find(directory);
1435  if (iter != times_.end())
1436  {
1437  if (debug)
1438  {
1439  Pout<< "masterUncollatedFileOperation::findTimes:"
1440  << " Found cached times:" << *iter() << endl;
1441  }
1442  return *iter();
1443  }
1444  else
1445  {
1446  instantList times;
1447  if (Pstream::master())
1448  {
1449  times = fileOperation::findTimes(directory, constantName);
1450  }
1451  Pstream::scatter(times);
1452 
1453  instantList* tPtr = new instantList(times.xfer());
1454 
1455  times_.insert(directory, tPtr);
1456 
1457  if (debug)
1458  {
1459  Pout<< "masterUncollatedFileOperation::findTimes:"
1460  << " Caching times:" << *tPtr << endl;
1461  }
1462  return *tPtr;
1463  }
1464 }
1465 
1466 
1469  const Time& tm
1470 ) const
1471 {
1472  HashPtrTable<instantList>::const_iterator iter = times_.find(tm.path());
1473  if (iter != times_.end())
1474  {
1475  if (debug)
1476  {
1477  Pout<< "masterUncollatedFileOperation::setTime:"
1478  << " Caching time " << tm.timeName()
1479  << " for case:" << tm.path() << endl;
1480  }
1481 
1482  instantList& times = *iter();
1483  const instant timeNow(tm.value(), tm.timeName());
1484 
1485  if (times.size() > 0 && times[0].name() == tm.constant())
1486  {
1487  // Exclude constant
1488  SubList<instant> realTimes(times, times.size()-1, 1);
1489  if
1490  (
1492  (
1493  SubList<instant>(times, times.size()-1, 1),
1494  timeNow
1495  )
1496  == -1
1497  )
1498  {
1499  times.append(timeNow);
1500  SubList<instant> realTimes(times, times.size()-1, 1);
1501  Foam::stableSort(realTimes);
1502  }
1503  }
1504  else
1505  {
1506  if (findSortedIndex(times, timeNow) == -1)
1507  {
1508  times.append(timeNow);
1509  Foam::stableSort(times);
1510  }
1511  }
1512  }
1514 }
1515 
1516 
1520  const fileName& filePath
1521 ) const
1522 {
1523  if (Pstream::parRun())
1524  {
1525  // Insert logic of filePath. We assume that if a file is absolute
1526  // on the master it is absolute also on the slaves etc.
1527 
1528  fileNameList filePaths(Pstream::nProcs());
1529  filePaths[Pstream::myProcNo()] = filePath;
1530  Pstream::gatherList(filePaths);
1531 
1533 
1534  if (Pstream::master())
1535  {
1536  const bool uniform = uniformFile(filePaths);
1537 
1538  if (uniform)
1539  {
1540  if (debug)
1541  {
1542  Pout<< "masterUncollatedFileOperation::NewIFstream:"
1543  << " Opening global file " << filePath << endl;
1544  }
1545 
1547  (
1548  Foam::exists(filePath+".gz", false)
1549  ? IOstream::compressionType::COMPRESSED
1550  : IOstream::compressionType::UNCOMPRESSED
1551  );
1552 
1553  labelList procs(Pstream::nProcs()-1);
1554  for (label proci = 1; proci < Pstream::nProcs(); proci++)
1555  {
1556  procs[proci-1] = proci;
1557  }
1558 
1559  readAndSend(filePath, cmp, procs, pBufs);
1560  }
1561  else
1562  {
1563  for (label proci = 1; proci < Pstream::nProcs(); proci++)
1564  {
1566  (
1567  Foam::exists(filePaths[proci]+".gz", false)
1568  ? IOstream::compressionType::COMPRESSED
1569  : IOstream::compressionType::UNCOMPRESSED
1570  );
1571 
1572  readAndSend
1573  (
1574  filePaths[proci],
1575  cmp,
1576  labelList(1, proci),
1577  pBufs
1578  );
1579  }
1580  }
1581  }
1582 
1583 
1584  labelList recvSizes;
1585  pBufs.finishedSends(recvSizes);
1586 
1587  if (Pstream::master())
1588  {
1589  // Read myself
1590  return autoPtr<ISstream>
1591  (
1592  new IFstream(filePaths[Pstream::masterNo()])
1593  );
1594  }
1595  else
1596  {
1597  if (debug)
1598  {
1599  Pout<< "masterUncollatedFileOperation::NewIFstream:"
1600  << " Reading " << filePath
1601  << " from processor " << Pstream::masterNo() << endl;
1602  }
1603 
1604  UIPstream is(Pstream::masterNo(), pBufs);
1605  string buf(recvSizes[Pstream::masterNo()], '\0');
1606  is.read(&buf[0], recvSizes[Pstream::masterNo()]);
1607 
1608  if (debug)
1609  {
1610  Pout<< "masterUncollatedFileOperation::NewIFstream:"
1611  << " Done reading " << buf.size() << " bytes" << endl;
1612  }
1613 
1614  // Note: IPstream is not an IStream so use a IStringStream to
1615  // convert the buffer. Note that we construct with a string
1616  // so it holds a copy of the buffer.
1617  return autoPtr<ISstream>(new IStringStream(filePath, buf));
1618  }
1619  }
1620  else
1621  {
1622  // Read myself
1623  return autoPtr<ISstream>(new IFstream(filePath));
1624  }
1625 }
1626 
1627 
1631  const fileName& pathName,
1635  const bool valid
1636 ) const
1637 {
1638  return autoPtr<Ostream>
1639  (
1640  new masterOFstream
1641  (
1642  pathName,
1643  fmt,
1644  ver,
1645  cmp,
1646  false, // append
1647  valid
1648  )
1649  );
1650 }
1651 
1652 
1655  const fileName& fName
1656 ) const
1657 {
1658  label watchFd;
1659  if (Pstream::master())
1660  {
1661  watchFd = monitor().addWatch(fName);
1662  }
1663  Pstream::scatter(watchFd);
1664  return watchFd;
1665 }
1666 
1667 
1670  const label watchIndex
1671 ) const
1672 {
1673  bool ok;
1674  if (Pstream::master())
1675  {
1676  ok = monitor().removeWatch(watchIndex);
1677  }
1678  Pstream::scatter(ok);
1679  return ok;
1680 }
1681 
1682 
1685  const labelList& watchIndices,
1686  const fileName& fName
1687 ) const
1688 {
1689  label index = -1;
1690 
1691  if (Pstream::master())
1692  {
1693  forAll(watchIndices, i)
1694  {
1695  if (monitor().getFile(watchIndices[i]) == fName)
1696  {
1697  index = i;
1698  break;
1699  }
1700  }
1701  }
1702  Pstream::scatter(index);
1703  return index;
1704 }
1705 
1706 
1709  regIOobject& rio,
1710  const fileNameList& files
1711 ) const
1712 {
1713  const labelList& watchIndices = rio.watchIndices();
1714 
1715  DynamicList<label> newWatchIndices;
1716  labelHashSet removedWatches(watchIndices);
1717 
1718  forAll(files, i)
1719  {
1720  const fileName& f = files[i];
1721  label index = findWatch(watchIndices, f);
1722 
1723  if (index == -1)
1724  {
1725  newWatchIndices.append(addWatch(f));
1726  }
1727  else
1728  {
1729  // Existing watch
1730  newWatchIndices.append(watchIndices[index]);
1731  removedWatches.erase(index);
1732  }
1733  }
1734 
1735  // Remove any unused watches
1736  forAllConstIter(labelHashSet, removedWatches, iter)
1737  {
1738  removeWatch(watchIndices[iter.key()]);
1739  }
1740 
1741  rio.watchIndices() = newWatchIndices;
1742 }
1743 
1744 
1747  const label watchIndex
1748 ) const
1749 {
1750  fileName fName;
1751  if (Pstream::master())
1752  {
1753  fName = monitor().getFile(watchIndex);
1754  }
1755  Pstream::scatter(fName);
1756  return fName;
1757 }
1758 
1759 
1762  const bool masterOnly,
1763  const bool syncPar
1764 ) const
1765 {
1766  if (Pstream::master())
1767  {
1768  monitor().updateStates(true, false);
1769  }
1770 }
1771 
1772 
1776  const label watchFd
1777 ) const
1778 {
1779  unsigned int state = fileMonitor::UNMODIFIED;
1780  if (Pstream::master())
1781  {
1782  state = monitor().getState(watchFd);
1783  }
1784  Pstream::scatter(state);
1785  return fileMonitor::fileState(state);
1786 }
1787 
1788 
1791  const label watchFd
1792 ) const
1793 {
1794  if (Pstream::master())
1795  {
1796  monitor().setUnmodified(watchFd);
1797  }
1798 }
1799 
1800 
1801 // ************************************************************************* //
pathType
Enumeration for the location of an IOobject.
Definition: fileOperation.H:87
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.
Definition: instantList.H:42
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
Definition: UPstream.H:130
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.
Definition: UList.H:428
bool processorCase() const
Return true if this is a processor case.
Definition: TimePaths.H:90
fileName path() const
Return path.
Definition: Time.H:269
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.
Definition: label.H:59
static int masterNo()
Process index of the master.
Definition: UPstream.H:406
const word & name() const
Return name.
Definition: IOobject.H:291
A class for handling file names.
Definition: fileName.H:69
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
An STL-conforming const_iterator.
Definition: HashTable.H:481
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.
Definition: debug.C:196
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
Definition: ListI.H:177
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.
Definition: POSIX.C:572
fileState
Enumeration defining the file state.
Definition: fileMonitor.H:69
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.
Definition: ListI.H:163
static const fileName null
An empty fileName.
Definition: fileName.H:97
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:418
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.
Definition: UPstream.H:266
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.
Definition: IFstream.C:132
virtual bool rmDir(const fileName &) const
Remove a dirctory and its contents.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:412
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:440
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
const labelList & watchIndices() const
Return file-monitoring handles.
Definition: regIOobjectI.H:91
word format(conversionProperties.lookup("format"))
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:465
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:644
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.
Definition: autoPtrI.H:90
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:275
static const List< commsStruct > & linearCommunication(const label communicator=0)
Communication schedule for linear all-to-master (proc 0)
Definition: UPstream.H:448
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
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.
Definition: IOobject.C:385
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
Definition: HashTable.C:371
Input inter-processor communications stream.
Definition: IPstream.H:50
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
void clear()
Delete object (if the pointer is valid) and set pointer to.
Definition: autoPtrI.H:126
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:53
bool readHeader(Istream &)
Read header.
dimensionedScalar pos(const dimensionedScalar &ds)
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:309
A List obtained as a section of another List.
Definition: SubList.H:53
bool read(const char *, int32_t &)
Definition: int32IO.C:85
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.
Definition: autoPtrI.H:114
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
Definition: globalFoam.H:44
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.
Definition: fileName.C:58
A class for handling words, derived from string.
Definition: word.H:59
bool & globalObject()
Is object same for all processors.
Definition: IOobject.H:339
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.
Definition: ListI.H:184
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
const fileName & local() const
Definition: IOobject.H:396
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
word name() const
Return file name (part beyond last /)
Definition: fileName.C:180
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.
Definition: IOstream.H:86
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:292
static const word null
An empty word.
Definition: word.H:77
static const List< commsStruct > & treeCommunication(const label communicator=0)
Communication schedule for tree all-to-master (proc 0)
Definition: UPstream.H:457
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.
Definition: labelList.H:56
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
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)
Definition: autoPtrI.H:83
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
Structure for communicating between processors.
Definition: UPstream.H:76
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...
Definition: HashTable.H:61
const word & system() const
Return system name.
Definition: TimePaths.H:114
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.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:54
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.
Definition: UIPread.C:79
const fileName & globalCaseName() const
Return global case name.
Definition: TimePaths.H:102
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.
Definition: data.H:52
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.
Definition: UOPwrite.C:34
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Definition: IOobject.H:208
Input from file stream.
Definition: IFstream.H:81
labelList f(nPoints)
Output inter-processor communications stream.
Definition: OPstream.H:50
Buffers for inter-processor communications streams (UOPstream, UIPstream).
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
const fileName & rootPath() const
Definition: IOobject.C:379
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
An instant of time. Contains the time value and name.
Definition: instant.H:66
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?
Definition: UPstream.H:394
const fileName & instance() const
Definition: IOobject.H:386
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:400
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
Definition: IOobjectI.H:108
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.
Definition: error.H:331
const Time & time() const
Return time.
Definition: IOobject.C:337
Input from memory buffer stream.
Definition: IStringStream.H:49
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
static fileName processorsPath(const IOobject &, const word &)
Like io.path with provided instance and any &#39;processorXXX&#39;.
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)
Version number type.
Definition: IOstream.H:96
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:65
bool writeHeader(Ostream &) const
Write header.
messageStream Info
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
Uniform/equally-weighted distribution model.
Definition: uniform.H:47
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 /)
Definition: fileName.C:250
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.
Definition: IOobject.C:331
virtual void setTime(const Time &) const
Callback for time change.
void stableSort(UList< T > &)
Definition: UList.C:129
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.
Definition: dummyISstream.H:47
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobject.H:297
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
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
Definition: IOobject.C:343
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:412
static fileName processorsCasePath(const IOobject &)
root+casename with any &#39;processorXXX&#39; replaced by &#39;processsors&#39;
bool equal(const scalar) const
Comparison used for instants to be equal.
Definition: instant.C:59
bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:517
Type
Enumerations to handle file types and modes.
Definition: fileName.H:82
Namespace for OpenFOAM.
IOerror FatalIOError