OFstreamCollator.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 | 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 Class
25  Foam::OFstreamCollator
26 
27 Description
28  Threaded file writer.
29 
30 SourceFiles
31  OFstreamCollator.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef OFstreamCollator_H
36 #define OFstreamCollator_H
37 
38 #include "IOstream.H"
39 #include "List.H"
40 #include "FIFOStack.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class OFstreamCollator Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class OFstreamCollator
52 {
53  // Private class
54 
55  class writeData
56  {
57  public:
58 
59  const word typeName_;
60  const fileName pathName_;
61  const string data_;
62  const IOstream::streamFormat format_;
63  const IOstream::versionNumber version_;
64  const IOstream::compressionType compression_;
65  const bool append_;
66 
67  writeData
68  (
69  const word& typeName,
70  const fileName& pathName,
71  const string& data,
74  IOstream::compressionType compression,
75  const bool append
76  )
77  :
78  typeName_(typeName),
79  pathName_(pathName),
80  data_(data),
81  format_(format),
82  version_(version),
83  compression_(compression),
84  append_(append)
85  {}
86  };
87 
88 
89  // Private data
90 
91  const off_t maxBufferSize_;
92 
93  //pthread_mutex_t mutex_;
94  label mutex_;
95 
96  //pthread_t thread_;
97  label thread_;
98 
99  FIFOStack<writeData*> objects_;
100 
101  bool threadRunning_;
102 
103  //- Communicator to use for all parallel ops
104  label comm_;
105 
106 
107  // Private Member Functions
108 
109  //- Write actual file
110  static bool writeFile
111  (
112  const label comm,
113  const word& typeName,
114  const fileName& fName,
115  const string& data,
119  const bool append
120  );
121 
122  //- Write all files in stack
123  static void* writeAll(void *threadarg);
124 
125 
126 public:
127 
128  // Declare name of the class and its debug switch
129  TypeName("OFstreamCollator");
130 
131 
132  // Constructors
133 
134  //- Construct from buffer size. 0 = do not use thread
135  OFstreamCollator(const off_t maxBufferSize);
136 
137 
138  //- Destructor
139  virtual ~OFstreamCollator();
140 
141 
142  // Member functions
143 
144  //- Write file with contents. Blocks until writethread has space
145  // available (total file sizes < maxBufferSize)
146  bool write
147  (
148  const word& typeName,
149  const fileName&,
150  const string& data,
154  const bool append
155  );
156 };
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
A FIFO stack based on a singly-linked list.
Definition: FIFOStack.H:51
Threaded file writer.
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
A class for handling file names.
Definition: fileName.H:69
virtual ~OFstreamCollator()
Destructor.
word format(conversionProperties.lookup("format"))
A class for handling words, derived from string.
Definition: word.H:59
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
OFstreamCollator(const off_t maxBufferSize)
Construct from buffer size. 0 = do not use thread.
Version number type.
Definition: IOstream.H:96
bool write(const word &typeName, const fileName &, const string &data, IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool append)
Write file with contents. Blocks until writethread has space.
TypeName("OFstreamCollator")
Namespace for OpenFOAM.