37 #ifdef CASToR_USE_CMAKE
38 #include "oCASToRConfig.hh"
49 if (code!=0)
Cerr(
"***** Exit function called. Abort with code " << code <<
"." << endl);
80 cout << std::scientific;
81 cerr << std::setprecision(std::numeric_limits<FLTNB>::digits10+1);
118 if (
m_verbose>=3)
Cout(
"sOutputManager::CheckConfigDir() -> Directory selected from option as '" << a_path <<
"'" << endl);
124 #ifdef CASToR_USE_CMAKE
125 string tmp_path = CASTOR_CONFIG;
126 if (tmp_path.empty())
127 #elif defined(CASTOR_USE_MINGW)
132 if (tmp_path.empty())
136 When cross-compiling, you must define the CASTOR_CONFIG environment variable before that. This compilation error you are seeing is normal!
139 char* tmp_path = getenv(
"CASTOR_CONFIG");
143 Cerr(
"***** sOutputManager::CheckConfigDir() -> No path nor CASTOR_CONFIG variable provided !" << endl);
146 if (
m_verbose>=3)
Cout(
"sOutputManager::CheckConfigDir() -> Directory selected from environment variable as '" << ((
string)tmp_path) <<
"'" << endl);
174 if (
m_verbose>=3)
Cout(
"sOutputManager::GetPathToConfigDir ..."<< endl);
176 #if defined(CASToR_USE_CMAKE)
177 string tmp_path = CASTOR_CONFIG;
178 if (tmp_path.empty())
179 #elif defined(CASTOR_USE_MINGW)
184 if (tmp_path.empty())
188 When cross-compiling, you must define the CASTOR_CONFIG environment variable before that. This compilation error you are seeing is normal!
191 char* tmp_path = getenv(
"CASTOR_CONFIG");
195 Cerr(
"***** sOutputManager::CheckConfigDir() -> No path nor CASTOR_CONFIG variable provided ! Try working directory instead." << endl);
199 #if defined(CASToR_USE_CMAKE) || defined(CASTOR_USE_MINGW)
224 #ifdef CASTOR_VERBOSE
225 if (
m_verbose>=4)
Cout(
"+++++ sOutputManager::InitOutputDirectory() -> Enter"<< endl);
229 if (a_pathFout!=
"" && a_pathDout!=
"")
231 Cerr(
"***** sOutputManager::InitOutputDirectory() -> Either a file path (-fout) or a directory path (dout) should be provided. cannot be both provided, make your choice !" << endl);
236 string the_path = a_pathFout;
237 if (a_pathDout!=
"") the_path = a_pathDout;
238 string last_char = the_path.substr(the_path.length()-1);
239 if (last_char==
"." || last_char==
OS_SEP)
241 Cerr(
"***** sOutputManager::InitOutputDirectory() -> Please provide a path not finishing by '.', '"<<
OS_SEP <<
"' character !" << endl);
246 if (
m_verbose>=1)
Cout(
"sOutputManager::InitOutputDirectory() -> Output path is '" << a_pathFout << a_pathDout <<
"'" << endl);
255 size_t last_slash_pos = a_pathFout.find_last_of(
OS_SEP);
257 if (last_slash_pos==string::npos)
266 m_pathName = a_pathFout.substr(0,last_slash_pos+1);
268 m_baseName = a_pathFout.substr(last_slash_pos+1);
276 else if (a_pathDout!=
"")
279 size_t last_slash_pos = a_pathDout.find_last_of(
OS_SEP);
281 if (last_slash_pos==string::npos)
292 m_baseName = a_pathDout.substr(last_slash_pos+1);
300 string instruction =
"mkdir -p " +
m_pathName;
302 int error = system(instruction.c_str());
305 Cerr(
"***** sOutputManager::InitOutputDirectory() -> Failed to create output directory with name '" << m_pathName <<
"' !" << endl);
326 Cerr(
"***** sOutputManager::InitOutputDirectory() -> Failed to create output log file as '" << log_file_name <<
"' ! Are you sure the provided output path exists ?" << endl);
342 if (
m_verbose>=3)
Cout(
"sOutputManager::LogCommandLine() -> Write command line into the log file"<< endl);
349 m_logFile <<
"==================================================================================================" << endl;
350 m_logFile <<
" COMMAND LINE CONTEXT" << endl;
351 m_logFile <<
"==================================================================================================" << endl;
354 for (
int i=0; i<argc; i++)
m_logFile << argv[i] <<
" ";
358 GetCurrentDirectory(MAX_PATH,pwd);
359 m_logFile <<
"Working directory: " << pwd << endl;
361 m_logFile <<
"Working directory: " << getenv(
"PWD") << endl;
363 std::time_t date_of_execution = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
364 m_logFile <<
"Data of execution: " << std::ctime(&date_of_execution);
365 m_logFile <<
"Float numbers precision in bytes (for matrices and some computations): " <<
sizeof(
FLTNB) << endl;
366 m_logFile <<
"Float numbers precision in bytes (for sensitive computations that require at least double precision): " <<
sizeof(
HPFLTNB) << endl;
367 m_logFile <<
"Float numbers precision in bytes (for datafile reading/writing): " <<
sizeof(
FLTNBDATA) << endl;
368 m_logFile <<
"Float numbers precision in bytes (for scanner LUT reading/writing): " <<
sizeof(
FLTNBLUT) << endl;
370 m_logFile <<
"==================================================================================================" << endl << flush;
396 string option =
"-onbc";
399 size_t pos = a_format.find_first_of(
",");
400 if (pos == string::npos)
402 Cerr(
"***** sOutputManager::SetOutNbPrec() -> Error, format must be (format,precision) (e.g = (f,5) or (s,0)!" << endl);
406 format = a_format.substr(0,pos);
412 Cerr(
"***** sOutputManager::SetOutNbPrec() -> Invalid argument " << a_format <<
" for option " << option <<
" !" << endl);
413 Cerr(
"***** sOutputManager::SetOutNbPrec() -> Format must be (format,precision) (e.g = (f,5) or (s,0)!" << endl);
418 cout << std::setprecision(precision);
420 cout << std::setprecision(std::numeric_limits<FLTNB>::digits10+1);
string ConvertAllSlashOccurrencesToBackSlash(const string &a_path)
Declaration of class oImageDimensionsAndQuantification.
vector< string > mp_dataFileName
sOutputManager()
sOutputManager constructor.
bool m_mergeOutputDynImgFlag
int SetOutNbPrec(string a_format)
Set the output format and precision used for numeric display.
int LogCommandLine(int argc, char **argv)
Write log file header with the provided command line options and different informations.
int CheckConfigDir(const string &a_path)
Set the path to the CASTOR config directory from the given path if not empty or through the existence...
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
const string & GetPathToConfigDir()
Return the path to the CASTOR config directory.
static sOutputManager * mp_Instance
Declaration of class oImageSpace.
Declaration of class sOutputManager.
int InitOutputDirectory(const string &a_pathFout, const string &a_pathDout)
Create the output directory if any, extract the base name and create the log file.
~sOutputManager()
sOutputManager destructor.
int ReadStringOption(const string &a_input, T *ap_return, int a_nbElts, const string &sep, const string &a_option)
Parse the 'a_input' string corresponding to the 'a_option' into 'a_nbElts' elements, using the 'sep' separator. The results are returned in the templated 'ap_return' dynamic templated array. Call "ConvertFromString()" to perform the correct conversion depending on the type of the data to convert.