16#include <Sortie_Fichier_base.h>
40Sortie_Fichier_base::~Sortie_Fichier_base()
45void Sortie_Fichier_base::set_toFlush()
52 char* theValue = getenv(
"TRUST_FLUSHFILES");
53 if (theValue !=
nullptr)
55 toFlush_=atoi(theValue);
59void Sortie_Fichier_base::set_buffer()
63 char* theValue = getenv(
"TRUST_BUFFSIZE");
66 int buffSize = 3000000;
67 if (theValue !=
nullptr)
69 buffSize = atoi(theValue);
73 size_t internalBuffSize = buffSize;
74 internalBuff_ =
new char[internalBuffSize];
75 ofstream_->rdbuf()->pubsetbuf(internalBuff_,internalBuffSize);
94 delete[] internalBuff_;
95 internalBuff_ =
nullptr;
123 std::string cmd=
"mkdir -p ";
125 int err = system(cmd.c_str());
128 Cerr <<
"Sortie_Fichier_base::ouvrir: Error while creating " <<
root <<
" folder!" << finl;
132 std::string pathname =
root;
133 if (!pathname.empty()) pathname+=
"/";
138 Cerr <<
"Warning, file " << pathname <<
" has been opened/closed " << counter_ <<
" times..." << finl;
140 IOS_OPEN_MODE ios_mod=mode;
145 if (ios_mod==ios::out)
148 assert((ios_mod==ios::app)||(ios_mod==(ios::app|ios::out)));
149 ios_mod=ios_mod|ios::binary;
151 ostream_ = std::make_unique<ofstream>(pathname,ios_mod);
157 Cerr <<
"Error when opening the file " << pathname <<
". File was opened " << counter_ <<
" time(s) ..." << finl;
158 Cerr <<
"Either:\n you don't have write rights,\n or your filesystem is very slow and multiple file open/close." << finl;
159 Cerr <<
"Contact TRUST support team." << finl;
194 Cerr <<
"[IO] Setting output directory to: " <<
root << finl;
bool bin_
Is this a binary flux?
bool is_64b_
Will we be reading/writing in 64b? (Init in ctor to avoid including arch.h probably).
Class defining operators and methods for all reading operation in an input flow (file,...
class Nom: a character string for naming TRUST objects.
virtual int finit_par(const char *const n) const
Base class for TRUST objects (Objet_U).
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
static int exception_sur_exit
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
virtual int get_precision()
ofstream * ofstream_
This pointer is just a (typed) view on the smart ptr hold by the base class (Sortie)....
virtual int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out)
Sortie & flush() override
Forces the data in the buffer to be written to disk. Uses the ofstream class implementation.
void precision(int pre) override
void setf(IOS_FORMAT code) override
static void set_root(const std::string dirname)
ofstream & get_ofstream()
Base class for output streams.
std::unique_ptr< ostream > ostream_