MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
InfoOut_buffer Class Referenceabstract

#include <infoout.h>

Inheritance diagram for InfoOut_buffer:
[legend]
Collaboration diagram for InfoOut_buffer:
[legend]

Public Member Functions

 InfoOut_buffer ()
 Generic constructor is used when no information is provided during declaration. More...
 
virtual MBool setRootOnly (MBool rootOnly=true)
 Sets interal state of whether only the root domain (rank 0) should write to file. More...
 
virtual MInt setMinFlushSize (MInt minFlushSize)
 Sets the minimum buffer length that has to be reached before the buffer is flushed. More...
 

Protected Member Functions

virtual MString encodeXml (const std::string &str)
 Parses the string input and returns the string with XML entities escaped. More...
 
virtual MString getXmlHeader ()
 Return an XML header that should written at the beginning of each log file. More...
 
virtual MString getXmlFooter ()
 Return an XML footer that should written at the end of each log file. More...
 
virtual void createPrefixMessage ()
 Creates an XML prefix using the domain id that is prepended to each message. More...
 
virtual void createSuffixMessage ()
 Creates an XML suffix that is appended to each message. More...
 
virtual void flushBuffer ()=0
 

Protected Attributes

MBool m_rootOnly
 Stores whether only the root domain writes a log file. More...
 
MInt m_domainId
 Contains the MPI rank (= domain id) of this process. More...
 
MInt m_noDomains
 Contains the MPI rank count (= number of domains) More...
 
MInt m_minFlushSize
 Minimum length of the internal buffer before flushing. More...
 
MString m_prefixMessage
 Stores the prefix that is prepended to each output. More...
 
MString m_suffixMessage
 Stores the suffix that is apended to each output. More...
 
std::ostringstream m_tmpBuffer
 Temporary buffer to hold string until flushing. More...
 
MString m_projectName
 Name of the current Project. More...
 
std::vector< std::pair< MString, MString > > m_prefixAttributes
 

Static Protected Attributes

static const MInt m_fileFormatVersion = 1
 

Friends

class InfoOut
 

Detailed Description

Definition at line 40 of file infoout.h.

Constructor & Destructor Documentation

◆ InfoOut_buffer()

InfoOut_buffer::InfoOut_buffer ( )
Author
Michael Schlottke
Date
June 2012

Definition at line 72 of file infoout.cpp.

73 : m_rootOnly(false),
74 m_domainId(0),
75 m_noDomains(1),
81 // Nothing here
82}
MInt m_minFlushSize
Minimum length of the internal buffer before flushing.
Definition: infoout.h:49
MInt m_domainId
Contains the MPI rank (= domain id) of this process.
Definition: infoout.h:47
MString m_prefixMessage
Stores the prefix that is prepended to each output.
Definition: infoout.h:50
MString m_suffixMessage
Stores the suffix that is apended to each output.
Definition: infoout.h:51
std::ostringstream m_tmpBuffer
Temporary buffer to hold string until flushing.
Definition: infoout.h:52
MInt m_noDomains
Contains the MPI rank count (= number of domains)
Definition: infoout.h:48
MString m_projectName
Name of the current Project.
Definition: infoout.h:53
MBool m_rootOnly
Stores whether only the root domain writes a log file.
Definition: infoout.h:46

Member Function Documentation

◆ createPrefixMessage()

void InfoOut_buffer::createPrefixMessage ( )
inlineprotectedvirtual
Author
Michael Schlottke, Andreas Lintermann
Date
13.08.2012

Makes use of an array attribute filled by the user to gerenate the XML string.

Definition at line 138 of file infoout.cpp.

138 {
139 // Create temporary stream
140 ostringstream tmpStream;
141
142 // Fill stream with formatted domain id
143 tmpStream << "<m d=\"" << m_domainId << "\" ";
144
145 for(MInt i = 0; i < (MInt)(m_prefixAttributes.size()); i++)
146 tmpStream << m_prefixAttributes[i].first << "=\"" << m_prefixAttributes[i].second << "\" ";
147
148 tmpStream << ">";
149
150 // Set prefix message to tmpBuffer string
151 m_prefixMessage = tmpStream.str();
152
153 // Reset buffer
154 tmpStream.str("");
155}
std::vector< std::pair< MString, MString > > m_prefixAttributes
Definition: infoout.h:55
int32_t MInt
Definition: maiatypes.h:62

◆ createSuffixMessage()

void InfoOut_buffer::createSuffixMessage ( )
inlineprotectedvirtual
Author
Michael Schlottke
Date
April 2012

Definition at line 162 of file infoout.cpp.

162{ m_suffixMessage = "</m>\n"; }

◆ encodeXml()

MString InfoOut_buffer::encodeXml ( const std::string &  str)
protectedvirtual
Author
Michael Schlottke
Date
April 2012

This method iterates over each character of the given input string str and replaces relevant XML entities with their escaped counterparts. This code is adapted from http://www.mdawson.net/misc/xmlescape.php (Matson Dawson, 2009).

Parameters
[in]strInput string that has characters which need escaping.
Returns
Modified string with XML entities escaped.

Definition at line 95 of file infoout.cpp.

95 {
96 MChar c; // Contains the current character
97 ostringstream tmpEncodeBuffer; // Used as a temporary string buffer
98
99 // Create a for loop that uses an iterator to traverse the complete string
100 for(MString::const_iterator iter = inputStr.begin(); iter < inputStr.end(); iter++) {
101 // Get current character
102 c = (MChar)*iter;
103
104 // Use a switch/case statement for the five XML entities
105 switch(c) {
106 case '"':
107 tmpEncodeBuffer << "&quot;";
108 break; // Replace double quotes
109 case '&':
110 tmpEncodeBuffer << "&amp;";
111 break; // Replace ampersand
112 case '\'':
113 tmpEncodeBuffer << "&apos;";
114 break; // Replace single quote
115 case '<':
116 tmpEncodeBuffer << "&lt;";
117 break; // Replace less-than sign
118 case '>':
119 tmpEncodeBuffer << "&gt;";
120 break; // Replace greater-than sign
121 default:
122 tmpEncodeBuffer << c; // By default just append current character
123 }
124 }
125
126 // Return encoded stream as a string
127 return tmpEncodeBuffer.str();
128}
char MChar
Definition: maiatypes.h:56

◆ flushBuffer()

virtual void InfoOut_buffer::flushBuffer ( )
protectedpure virtual

◆ getXmlFooter()

MString InfoOut_buffer::getXmlFooter ( )
protectedvirtual
Author
Michael Schlottke
Date
June 2012
Returns
The XML footer.

Definition at line 299 of file infoout.cpp.

299 {
300 // Create timestamp
301 MChar tmpDateTime[128];
302 tm* timeInfo;
303 time_t rawTime;
304
305 // Get the current time and write it to rawTime
306 time(&rawTime);
307
308 // Convert to time struct
309 timeInfo = localtime(&rawTime);
310
311 // Format time to string and save to buffer
312 strftime(tmpDateTime, 128, "%Y-%m-%d %H:%M:%S", timeInfo);
313
314 // Create temporary buffer
315 ostringstream tmpBuffer;
316
317 // Write XML footer to buffer
318 tmpBuffer << "<meta name=\"dateClosing\" content=\"" << tmpDateTime << "\" />\n";
319 tmpBuffer << "</root>\n";
320
321 // Return XML footer
322 return tmpBuffer.str();
323}

◆ getXmlHeader()

MString InfoOut_buffer::getXmlHeader ( )
protectedvirtual
Author
Michael Schlottke
Date
June 2012
Returns
The XML header.

Definition at line 199 of file infoout.cpp.

199 {
200 const MInt maxNoChars = 1024;
201
202 // Gets the current hostname
203 MChar host[maxNoChars];
204 gethostname(host, maxNoChars - 1);
205 host[maxNoChars - 1] = '\0';
206
207 // Gets the current username
208 MString user;
209#if defined(MAIA_MS_COMPILER)
210 constexpr MInt INFO_BUFFER_SIZE = 32767;
211 TCHAR infoBuf[INFO_BUFFER_SIZE];
212 DWORD bufCharCount = INFO_BUFFER_SIZE;
213 if(!GetUserName(infoBuf, &bufCharCount)) {
214 user = "n/a";
215 } else {
216 user = infoBuf;
217 }
218#else
219 passwd* p;
220 p = getpwuid(getuid());
221 if(p) {
222 user = MString(p->pw_name);
223 } else {
224 user = "n/a";
225 }
226#endif
227
228 // Gets the current directory
229 MChar dir[maxNoChars];
230#if defined(MAIA_MS_COMPILER)
231 _getcwd(dir, maxNoChars - 1);
232#else
233 if(!getcwd(dir, maxNoChars - 1)) {
234 TERM(-1);
235 }
236#endif
237 dir[maxNoChars - 1] = '\0';
238
239 // Gets the current executionCommand
240 stringstream executionCommand;
241 executionCommand.str("");
242 // m_argv and m_argc additionaly described in maia.cpp
243#ifndef PVPLUGIN
244 executionCommand << Environment::m_argv[0];
245 for(MInt n = 1; n < Environment::m_argc; n++) {
246 executionCommand << " " << Environment::m_argv[n];
247 }
248#else
249 executionCommand << "paraview plugin was started --> no execution command";
250#endif
251
252
253 // Create start timestamp
254 MChar tmpDateTime[128];
255 tm* timeInfo;
256 time_t rawTime;
257
258 // Get the current time and write it to rawTime
259 time(&rawTime);
260
261 // Convert to time struct
262 timeInfo = localtime(&rawTime);
263
264 // Format time to string and save to buffer
265 strftime(tmpDateTime, 128, "%Y-%m-%d %H:%M:%S", timeInfo);
266
267 // Create temporary buffer
268 ostringstream tmpBuffer;
269
270 // Write XML header information to buffer
271 tmpBuffer << "<?xml version=\"1.0\" standalone=\"yes\" ?>\n";
272 tmpBuffer << "<root>\n";
273 tmpBuffer << "<meta name=\"noDomains\" content=\"" << m_noDomains << "\" />\n";
274 tmpBuffer << "<meta name=\"dateCreation\" content=\"" << tmpDateTime << "\" />\n";
275 tmpBuffer << "<meta name=\"fileFormatVersion\" content=\"" << m_fileFormatVersion << "\" />\n";
276 tmpBuffer << "<meta name=\"projectName\" content=\"" << m_projectName << "\" />\n";
277 tmpBuffer << "<meta name=\"user\" content=\"" << user << "\" />\n";
278 tmpBuffer << "<meta name=\"host\" content=\"" << host << " (" << XSTRINGIFY(MAIA_HOST_STRING) << ")"
279 << "\" />\n";
280 tmpBuffer << "<meta name=\"dir\" content=\"" << dir << "\" />\n";
281 tmpBuffer << "<meta name=\"executionCommand\" content=\"" << executionCommand.str() << "\" />\n";
282 tmpBuffer << "<meta name=\"revision\" content=\"" << XSTRINGIFY(MAIA_VERSION_STRING) << "\" />\n";
283 tmpBuffer << "<meta name=\"build\" content=\"" << XSTRINGIFY(MAIA_COMPILER_STRING) << " "
284 << XSTRINGIFY(MAIA_BUILD_TYPE_STRING) << " (" << MString(XSTRINGIFY(MAIA_COMPILER_VERSION_STRING)) << ")"
285 << "\" />\n";
286
287
288 // Return XML header
289 return tmpBuffer.str();
290}
static MChar ** m_argv
Definition: environment.h:29
static MInt m_argc
Reads the name of the property-file and creates a new Application.
Definition: environment.h:28
static const MInt m_fileFormatVersion
Definition: infoout.h:44
std::basic_string< char > MString
Definition: maiatypes.h:55
constexpr std::underlying_type< FcCell >::type p(const FcCell property)
Converts property name to underlying integer value.

◆ setMinFlushSize()

MInt InfoOut_buffer::setMinFlushSize ( MInt  minFlushSize)
inlinevirtual
Author
Michael Schlottke
Date
June 2012

\params[in] minFlushSize Minimum buffer length.

Returns
The previous value of the minimum flush size.

Reimplemented in InfoOut_mpiFileBuffer.

Definition at line 187 of file infoout.cpp.

187 {
188 MInt previousValue = m_minFlushSize;
189 m_minFlushSize = minFlushSize;
190 return previousValue;
191}

◆ setRootOnly()

MBool InfoOut_buffer::setRootOnly ( MBool  rootOnly = true)
inlinevirtual
Author
Michael Schlottke
Date
June 2012

\params[in] rootOnly If true, only rank 0 of the specified MPI communicator writes to file.

Returns
The previous internal state (may be stored to return to the previous behavior).

Definition at line 173 of file infoout.cpp.

173 {
174 MBool previousValue = m_rootOnly;
175 m_rootOnly = rootOnly;
176 return previousValue;
177}
bool MBool
Definition: maiatypes.h:58

Friends And Related Function Documentation

◆ InfoOut

friend class InfoOut
friend

Definition at line 41 of file infoout.h.

Member Data Documentation

◆ m_domainId

MInt InfoOut_buffer::m_domainId
protected

Definition at line 47 of file infoout.h.

◆ m_fileFormatVersion

const MInt InfoOut_buffer::m_fileFormatVersion = 1
staticprotected

File format version (increase this by one every time you make changes that could affect postprocessing tools)

Definition at line 44 of file infoout.h.

◆ m_minFlushSize

MInt InfoOut_buffer::m_minFlushSize
protected

Definition at line 49 of file infoout.h.

◆ m_noDomains

MInt InfoOut_buffer::m_noDomains
protected

Definition at line 48 of file infoout.h.

◆ m_prefixAttributes

std::vector<std::pair<MString, MString> > InfoOut_buffer::m_prefixAttributes
protected

Definition at line 55 of file infoout.h.

◆ m_prefixMessage

MString InfoOut_buffer::m_prefixMessage
protected

Definition at line 50 of file infoout.h.

◆ m_projectName

MString InfoOut_buffer::m_projectName
protected

Definition at line 53 of file infoout.h.

◆ m_rootOnly

MBool InfoOut_buffer::m_rootOnly
protected

Definition at line 46 of file infoout.h.

◆ m_suffixMessage

MString InfoOut_buffer::m_suffixMessage
protected

Definition at line 51 of file infoout.h.

◆ m_tmpBuffer

std::ostringstream InfoOut_buffer::m_tmpBuffer
protected

Definition at line 52 of file infoout.h.


The documentation for this class was generated from the following files: