GenericOutput.cpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23 \*---------------------------------------------------------------------------*/
24 #include "GenericOutput.hpp"
25 
26 namespace mimmo{
27 
34 GenericOutput::GenericOutput(std::string dir, std::string filename, bool csv){
35  m_dir = dir;
36  m_filename = filename;
37  m_csv = csv;
38  m_portsType = ConnectionType::BACKWARD;
39  m_name = "mimmo.GenericOutput";
40 };
41 
46 GenericOutput::GenericOutput(const bitpit::Config::Section & rootXML){
47 
48  m_dir = "./";
49  m_filename = "output.txt";
50  m_portsType = ConnectionType::BACKWARD;
51  m_name = "mimmo.GenericOutput";
52  m_csv = false;
53 
54  std::string fallback_name = "ClassNONE";
55  std::string input = rootXML.get("ClassName", fallback_name);
56  input = bitpit::utils::string::trim(input);
57  if(input == "mimmo.GenericOutput"){
58  absorbSectionXML(rootXML);
59  }else{
61  };
62 }
63 
68 
73  m_dir = other.m_dir;
74  m_filename = other.m_filename;
75  m_csv = other.m_csv;
76 };
77 
82  swap(other);
83  return *this;
84 }
85 
91 {
92  std::swap(m_dir, x.m_dir);
93  std::swap(m_filename, x.m_filename);
94  std::swap(m_csv, x.m_csv);
95  std::swap(m_input, x.m_input);
97 }
98 
102 void
104 
105  bool built = true;
106  built = (built && createPortIn<dvecarr3E, GenericOutput>(this, &mimmo::GenericOutput::setInput<dvecarr3E>, M_COORDS, true, 1));
107  built = (built && createPortIn<dvecarr3E, GenericOutput>(this, &mimmo::GenericOutput::setInput<dvecarr3E>, M_DISPLS, true, 1));
108  built = (built && createPortIn<dvector1D, GenericOutput>(this, &mimmo::GenericOutput::setInput<dvector1D>, M_DATAFIELD, true, 1));
109  built = (built && createPortIn<darray3E, GenericOutput>(this, &mimmo::GenericOutput::setInput<darray3E>, M_POINT, true, 1));
110  built = (built && createPortIn<darray3E, GenericOutput>(this, &mimmo::GenericOutput::setInput<darray3E>, M_SPAN, true, 1));
111  built = (built && createPortIn<iarray3E, GenericOutput>(this, &mimmo::GenericOutput::setInput<iarray3E>, M_DIMENSION, true, 1));
112  built = (built && createPortIn<double, GenericOutput>(this, &mimmo::GenericOutput::setInput<double>, M_VALUED, true, 1));
113  built = (built && createPortIn<int, GenericOutput>(this, &mimmo::GenericOutput::setInput<int>, M_VALUEI, true, 1));
114  built = (built && createPortIn<bool, GenericOutput>(this, &mimmo::GenericOutput::setInput<bool>, M_VALUEB, true, 1));
115  built = (built && createPortIn<iarray3E, GenericOutput>(this, &mimmo::GenericOutput::setInput<iarray3E>, M_DEG, true, 1));
116 
117  m_arePortsBuilt = built;
118 }
119 
124 void
125 GenericOutput::setWriteDir(std::string dir){
126  m_dir = dir;
127 };
128 
133 void
134 GenericOutput::setFilename(std::string filename){
135  m_filename = filename;
136 };
137 
142 void
144  m_csv = csv;
145 };
146 
147 
151 void
153  m_input.reset(nullptr);
154 }
155 
160 void
162 
163  // bool ok = rename("output.txt", m_filename.c_str());
164  // if (!ok)
165  // (*m_log)<<"Generic Output execution failed renaming..."<<std::endl;
166 };
167 
173 void
174 GenericOutput::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
175 
176  BITPIT_UNUSED(name);
177  std::string input;
178 
179  BaseManipulation::absorbSectionXML(slotXML, name);
180 
181  if(slotXML.hasOption("Filename")){
182  std::string input = slotXML.get("Filename");
183  input = bitpit::utils::string::trim(input);
184  setFilename(input);
185  };
186 
187  if(slotXML.hasOption("WriteDir")){
188  std::string input = slotXML.get("WriteDir");
189  input = bitpit::utils::string::trim(input);
190  setWriteDir(input);
191  };
192 
193  if(slotXML.hasOption("CSV")){
194  std::string input = slotXML.get("CSV");
195  input = bitpit::utils::string::trim(input);
196  bool temp = false;
197  if(!input.empty()){
198  std::stringstream ss(input);
199  ss>>temp;
200  }
201  setCSV(temp);
202  };
203 
204 }
205 
211 void
212 GenericOutput::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
213 
214  BITPIT_UNUSED(name);
215 
216  BaseManipulation::flushSectionXML(slotXML, name);
217 
218  slotXML.set("Filename", m_filename);
219  slotXML.set("WriteDir", m_dir);
220  slotXML.set("CSV", std::to_string((int)m_csv));
221 };
222 
223 
230 GenericOutputMPVData::GenericOutputMPVData(std::string dir, std::string filename, bool csv){
231  m_dir = dir;
232  m_filename = filename;
233  m_csv = csv;
234  m_portsType = ConnectionType::BACKWARD;
235  m_name = "mimmo.GenericOutputMPVData";
236  m_binary = false;
237 };
238 
243 GenericOutputMPVData::GenericOutputMPVData(const bitpit::Config::Section & rootXML){
244 
245  m_dir = "./";
246  m_filename = "output.txt";
247  m_portsType = ConnectionType::BACKWARD;
248  m_name = "mimmo.GenericOutputMPVData";
249  m_csv = false;
250  m_binary = false;
251 
252  std::string fallback_name = "ClassNONE";
253  std::string input = rootXML.get("ClassName", fallback_name);
254  input = bitpit::utils::string::trim(input);
255  if(input == "mimmo.GenericOutputMPVData"){
256  absorbSectionXML(rootXML);
257  }else{
259  };
260 }
261 
266 
271  m_dir = other.m_dir;
272  m_filename = other.m_filename;
273  m_csv = other.m_csv;
274  m_binary = other.m_binary;
275 };
276 
281  swap(other);
282  return *this;
283 }
284 
290 {
291  std::swap(m_dir, x.m_dir);
292  std::swap(m_filename, x.m_filename);
293  std::swap(m_csv, x.m_csv);
294  std::swap(m_binary, x.m_binary);
295  std::swap(m_input, x.m_input);
297 }
298 
302 void
304 
305  bool built = true;
306  built = (built && createPortIn<dmpvector1D*, GenericOutputMPVData>(this, &mimmo::GenericOutputMPVData::setInput<double>, M_SCALARFIELD));
307  built = (built && createPortIn<dmpvecarr3E*, GenericOutputMPVData>(this, &mimmo::GenericOutputMPVData::setInput<darray3E>, M_VECTORFIELD));
308 
309  m_arePortsBuilt = built;
310 }
311 
316 void
318  m_dir = dir;
319 };
320 
325 void
326 GenericOutputMPVData::setFilename(std::string filename){
327  m_filename = filename;
328 };
329 
334 void
336  m_csv = csv;
337 };
338 
342 void
344  m_binary = binary;
345 };
346 
347 
351 void
353  m_input.reset(nullptr);
354 }
355 
356 
361 void
363 
364  // bool ok = rename("output.txt", m_filename.c_str());
365  // if (!ok)
366  // (*m_log)<<"Generic Output execution failed renaming..."<<std::endl;
367 };
368 
374 void
375 GenericOutputMPVData::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
376 
377  BITPIT_UNUSED(name);
378  std::string input;
379 
380  BaseManipulation::absorbSectionXML(slotXML, name);
381 
382  if(slotXML.hasOption("Filename")){
383  std::string input = slotXML.get("Filename");
384  input = bitpit::utils::string::trim(input);
385  setFilename(input);
386  };
387 
388  if(slotXML.hasOption("WriteDir")){
389  std::string input = slotXML.get("WriteDir");
390  input = bitpit::utils::string::trim(input);
391  setWriteDir(input);
392  };
393 
394  if(slotXML.hasOption("CSV")){
395  std::string input = slotXML.get("CSV");
396  input = bitpit::utils::string::trim(input);
397  bool temp = false;
398  if(!input.empty()){
399  std::stringstream ss(input);
400  ss>>temp;
401  }
402  setCSV(temp);
403  };
404 
405  if(slotXML.hasOption("Binary")){
406  std::string input = slotXML.get("Binary");
407  input = bitpit::utils::string::trim(input);
408  bool temp = false;
409  if(!input.empty()){
410  std::stringstream ss(input);
411  ss>>temp;
412  }
413  setBinary(temp);
414  };
415 }
416 
422 void
423 GenericOutputMPVData::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
424 
425  BITPIT_UNUSED(name);
426 
427  BaseManipulation::flushSectionXML(slotXML, name);
428 
429  slotXML.set("Filename", m_filename);
430  slotXML.set("WriteDir", m_dir);
431  slotXML.set("CSV", std::to_string((int)m_csv));
432  slotXML.set("Binary", std::to_string((int)m_binary));
433 };
434 
435 
436 }
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
GenericOutputMPVData is the class that write a generic data to file output as mimmo::MimmoPiercedVect...
void swap(GenericOutput &x) noexcept
void setFilename(std::string filename)
void swap(GenericOutputMPVData &x) noexcept
#define M_DATAFIELD
#define M_DISPLS
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
GenericOutput & operator=(GenericOutput other)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void setFilename(std::string filename)
#define M_VALUEI
#define M_POINT
#define M_DIMENSION
void setWriteDir(std::string dir)
void warningXML(bitpit::Logger *log, std::string name)
BaseManipulation is the base class of any manipulation object of the library.
#define M_VECTORFIELD
GenericOutput is the class that write generic data in a file output.
GenericOutputMPVData(std::string dir="./", std::string filename="output.txt", bool csv=false)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void setCSV(bool csv)
#define M_SPAN
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_VALUED
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_DEG
void setWriteDir(std::string dir)
#define M_SCALARFIELD
GenericOutputMPVData & operator=(GenericOutputMPVData other)
void swap(BaseManipulation &x) noexcept
GenericOutput(std::string dir="./", std::string filename="output.txt", bool csv=false)
#define M_COORDS
#define M_VALUEB