9 #include "sOutputManager.hh" 10 #include "oImageSpace.hh" 11 #include "oImageDimensionsAndQuantification.hh" 14 #ifdef CASToR_USE_CMAKE 26 if (code!=0)
Cerr(
"***** Exit function called. Abort with code " << code <<
"." << endl);
58 cout << std::scientific;
59 cerr << std::setprecision(std::numeric_limits<FLTNB>::digits10+1);
96 if (
m_verbose>=3)
Cout(
"sOutputManager::CheckConfigDir() -> Directory selected from option as '" << a_path <<
"'" << endl);
102 #ifdef CASToR_USE_CMAKE 104 if (tmp_path.empty())
105 #elif defined(CASTOR_USE_MINGW)
110 if (tmp_path.empty())
114 When cross-compiling, you must define the
CASTOR_CONFIG environment variable before that. This compilation error you are seeing is normal!
117 char* tmp_path = getenv(
"CASTOR_CONFIG");
121 Cerr(
"***** sOutputManager::CheckConfigDir() -> No path for CASTOR_CONFIG variable provided !" << endl);
124 if (
m_verbose>=3)
Cout(
"sOutputManager::CheckConfigDir() -> Directory selected from environment variable as '" << ((
string)tmp_path) <<
"'" << endl);
152 if (
m_verbose>=3)
Cout(
"sOutputManager::GetPathToConfigDir ..."<< endl);
154 #if defined(CASToR_USE_CMAKE) 156 if (tmp_path.empty())
157 #elif defined(CASTOR_USE_MINGW)
162 if (tmp_path.empty())
166 When cross-compiling, you must define the
CASTOR_CONFIG environment variable before that. This compilation error you are seeing is normal!
169 char* tmp_path = getenv(
"CASTOR_CONFIG");
173 Cerr(
"***** sOutputManager::CheckConfigDir() -> No path nor CASTOR_CONFIG variable provided ! Try working directory instead." << endl);
177 #if defined(CASToR_USE_CMAKE) || defined(CASTOR_USE_MINGW) 202 #ifdef CASTOR_VERBOSE 203 if (
m_verbose>=4)
Cout(
"+++++ sOutputManager::InitOutputDirectory() -> Enter"<< endl);
207 if (a_pathFout!=
"" && a_pathDout!=
"")
209 Cerr(
"***** sOutputManager::InitOutputDirectory() -> Either a file path (-fout) or a directory path (dout) should be provided. cannot be both provided, make your choice !" << endl);
214 string the_path = a_pathFout;
215 if (a_pathDout!=
"") the_path = a_pathDout;
216 string last_char = the_path.substr(the_path.length()-1);
217 if (last_char==
"." || last_char==
OS_SEP)
219 Cerr(
"***** sOutputManager::InitOutputDirectory() -> Please provide a path not finishing by '.', '"<<
OS_SEP <<
"' character !" << endl);
224 if (
m_verbose>=1)
Cout(
"sOutputManager::InitOutputDirectory() -> Output path is '" << a_pathFout << a_pathDout <<
"'" << endl);
233 size_t last_slash_pos = a_pathFout.find_last_of(
OS_SEP);
235 if (last_slash_pos==string::npos)
244 m_pathName = a_pathFout.substr(0,last_slash_pos+1);
246 m_baseName = a_pathFout.substr(last_slash_pos+1);
254 else if (a_pathDout!=
"")
257 size_t last_slash_pos = a_pathDout.find_last_of(
OS_SEP);
259 if (last_slash_pos==string::npos)
270 m_baseName = a_pathDout.substr(last_slash_pos+1);
278 string instruction =
"mkdir -p " +
m_pathName;
280 int error = system(instruction.c_str());
283 Cerr(
"***** sOutputManager::InitOutputDirectory() -> Failed to create output directory with name '" << m_pathName <<
"' !" << endl);
304 Cerr(
"***** sOutputManager::InitOutputDirectory() -> Failed to create output log file as '" << log_file_name <<
"' ! Are you sure the provided output path exists ?" << endl);
320 if (
m_verbose>=3)
Cout(
"sOutputManager::LogCommandLine() -> Write command line into the log file"<< endl);
327 m_logFile <<
"==================================================================================================" << endl;
328 m_logFile <<
" COMMAND LINE CONTEXT" << endl;
329 m_logFile <<
"==================================================================================================" << endl;
332 for (
int i=0; i<argc; i++)
m_logFile << argv[i] <<
" ";
336 GetCurrentDirectory(MAX_PATH,pwd);
337 m_logFile <<
"Working directory: " << pwd << endl;
339 m_logFile <<
"Working directory: " << getenv(
"PWD") << endl;
341 std::time_t date_of_execution = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
342 m_logFile <<
"Data of execution: " << std::ctime(&date_of_execution);
343 m_logFile <<
"Float numbers precision in bytes (for matrices and some computations): " <<
sizeof(
FLTNB) << endl;
344 m_logFile <<
"Float numbers precision in bytes (for sensitive computations that require at least double precision): " <<
sizeof(
HPFLTNB) << endl;
345 m_logFile <<
"Float numbers precision in bytes (for datafile reading/writing): " <<
sizeof(
FLTNBDATA) << endl;
346 m_logFile <<
"Float numbers precision in bytes (for scanner LUT reading/writing): " <<
sizeof(
FLTNBLUT) << endl;
348 m_logFile <<
"==================================================================================================" << endl << flush;
374 string option =
"-onbc";
377 size_t pos = a_format.find_first_of(
",");
378 if (pos == string::npos)
380 Cerr(
"***** sOutputManager::SetOutNbPrec() -> Error, format must be (format,precision) (e.g = (f,5) or (s,0)!" << endl);
384 format = a_format.substr(0,pos);
392 cout << std::scientific;
398 Cerr(
"***** sOutputManager::SetOutNbPrec() -> Invalid argument " << a_format <<
" for option " << option <<
" !" << endl);
399 Cerr(
"***** sOutputManager::SetOutNbPrec() -> Format must be (format,precision) (e.g = (f,5) or (s,0)!" << endl);
405 cout << std::setprecision(precision);
410 cout << std::setprecision(std::numeric_limits<FLTNB>::digits10+1);
411 if (
m_logFile) m_logFile << std::setprecision(std::numeric_limits<FLTNB>::digits10+1);
string ConvertAllSlashOccurrencesToBackSlash(const string &a_path)
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.
sOutputManager()
sOutputManager constructor.
bool m_mergeOutputDynImgFlag
int SetOutNbPrec(string a_format)
int LogCommandLine(int argc, char **argv)
int CheckConfigDir(const string &a_path)
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
int InitOutputDirectory(const string &a_pathFout, const string &a_pathDout)
~sOutputManager()
sOutputManager destructor.
vector< string > mp_dataFileName