CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
sOutputManager.hh
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2019 all CASToR contributors listed below:
18 
19  --> Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Thibaut MERLIN, Mael MILLARDET, Simon STUTE, Valentin VIELZEUF
20 
21 This is CASToR version 3.0.
22 */
23 
30 #ifndef SOUTPUTMANAGER_HH
31 #define SOUTPUTMANAGER_HH 1
32 
33 #include "gVariables.hh"
35 
36 // ---------------------------------------------------------------------
37 // ---------------------------------------------------------------------
38 
39 // Cross-platform directory separator, if required
40 // Windows might auto-convert '/' to '\' though
41 #ifdef _WIN32
42 #define OS_SEP "\\"
43 #else
44 #define OS_SEP "/"
45 #endif
46 
47 // ---------------------------------------------------------------------
48 // ---------------------------------------------------------------------
49 
50 // Use to convert a macro variable provided by the pre-processor, to a string
51 #define QUOTES(value) #value
52 #define TOSTRING(macro) QUOTES(macro)
53 // The CASTOR_CONFIG environment variable converted to a string
54 #ifdef CASTOR_CONFIG
55 #define CASTOR_CONFIG_STRING TOSTRING(CASTOR_CONFIG)
56 #endif
57 
58 // ---------------------------------------------------------------------
59 // ---------------------------------------------------------------------
60 
61 #ifdef CASTOR_MPI
62 // Macros for logging messages on standard output (with MPI)
63 #define Cout(MESSAGE) \
64  do \
65  { \
66  int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); \
67  if (mpi_rank==0) \
68  { \
69  std::cout << MESSAGE; \
70  sOutputManager* instance = sOutputManager::GetInstance(); \
71  if (instance!=NULL) \
72  { \
73  ofstream& logMac = instance->GetLogFile(); \
74  if (logMac) logMac << MESSAGE; \
75  } \
76  } \
77  } while(0)
78 // Macros for logging messages on standard error (with MPI)
79 #define Cerr(MESSAGE) \
80  do \
81  { \
82  int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); \
83  std::cerr << "***** The following error message was issued" \
84  << " by MPI instance " << mpi_rank << endl; \
85  std::cerr << MESSAGE; \
86  sOutputManager* instance = sOutputManager::GetInstance(); \
87  if (instance!=NULL) \
88  { \
89  ofstream& logMac = instance->GetLogFile(); \
90  if (logMac) \
91  { \
92  logMac << "***** The following error message was issued"\
93  << " by MPI instance " << mpi_rank << endl; \
94  logMac << MESSAGE; \
95  } \
96  } \
97  } while(0)
98 #else
99 // Macros for logging messages on standard output (without MPI)
100 #define Cout(MESSAGE) \
101  do \
102  { \
103  std::cout << MESSAGE; \
104  sOutputManager* instance = sOutputManager::GetInstance(); \
105  if (instance!=NULL) \
106  { \
107  ofstream& logMac = instance->GetLogFile(); \
108  if (logMac) logMac << MESSAGE; \
109  } \
110  } while(0)
111 // Macros for logging messages on standard error (without MPI)
112 #define Cerr(MESSAGE) \
113  do \
114  { \
115  std::cerr << MESSAGE; \
116  sOutputManager* instance = sOutputManager::GetInstance(); \
117  if (instance!=NULL) \
118  { \
119  ofstream& logMac = instance->GetLogFile(); \
120  if (logMac) logMac << MESSAGE; \
121  } \
122  } while(0)
123 #endif
124 
125 // ---------------------------------------------------------------------
126 // ---------------------------------------------------------------------
127 
128 // Verbose levels definitions
129 #define VERBOSE_LIGHT 1
130 #define VERBOSE_NORMAL 2
131 #define VERBOSE_DETAIL 3
132 #define VERBOSE_DEBUG_LIGHT 4
133 #define VERBOSE_DEBUG_NORMAL 5
134 #define VERBOSE_DEBUG_EVENT 6
135 #define VERBOSE_DEBUG_MAX 7
136 
137 // Macro for CASTOR_VERBOSE to print out the entering of each function.
138 // This may be used for debugging. When this compilation variable is not
139 // set, this does nothing.
140 
141 // If CASTOR_VERBOSE is not set, we define this macro as doing nothing ';'
142 #ifndef CASTOR_VERBOSE
143 
144  #define DEBUG_VERBOSE(IGNORED1,IGNORED2) ;
145 
146 // If CASTOR_VERBOSE is set, we differentiate between windows/unix systems
147 #else
148  // Case for pure windows
149  #if defined(_WIN32) && !defined(CASTOR_USE_MINGW)
150  #define DEBUG_VERBOSE(CURRENT_LEVEL,APPLICABLE_LEVEL) \
151  do \
152  { \
153  if (CURRENT_LEVEL >= APPLICABLE_LEVEL) \
154  { \
155  cout << "+++++ " << __FUNCSIG__ \
156  << " -> Entering this function" << endl; \
157  } \
158  } while(0);
159  // Case for unix and cross-compilation from unix to windows
160  #else
161  #define DEBUG_VERBOSE(CURRENT_LEVEL,APPLICABLE_LEVEL) \
162  do \
163  { \
164  if (CURRENT_LEVEL >= APPLICABLE_LEVEL) \
165  { \
166  cout << "+++++ " << __PRETTY_FUNCTION__ \
167  << " -> Entering this function" << endl; \
168  } \
169  } while(0);
170  #endif
171 #endif
172 
173 // ---------------------------------------------------------------------
174 // ---------------------------------------------------------------------
175 
176 // Function used to make an clean exit taking MPI finalize into account
183 void Exit(int code);
184 
185 // ---------------------------------------------------------------------
186 // ---------------------------------------------------------------------
187 
194 {
195  // -------------------------------------------------------------------
196  // Constructor & Destructor
197  public:
205  {
206  if (mp_Instance == NULL) mp_Instance = new sOutputManager();
207  return mp_Instance;
208  }
209 
210 
211  // -------------------------------------------------------------------
212  // Get & Set functions
213  public:
219  inline void SetVerbose( int a_verbose )
220  {m_verbose = a_verbose;}
225  inline void SetDataFileName( vector<string> ap_dataFileName )
226  {mp_dataFileName = ap_dataFileName;}
231  inline ofstream& GetLogFile()
232  {return m_logFile;}
237  inline const string& GetBaseName()
238  {return m_baseName;}
243  inline const string& GetPathName()
244  {return m_pathName;}
249  inline vector<string> GetDataFileName()
250  {return mp_dataFileName;}
256  inline void SetMPIRank( int a_mpiRank )
257  {m_mpiRank = a_mpiRank;}
265  inline void SetMergeDynImagesFlag( bool a_flag )
266  {m_mergeOutputDynImgFlag = a_flag;}
273  inline bool MergeDynImages()
274  {return m_mergeOutputDynImgFlag;}
275 
276 
283  int SetOutNbPrec(string a_format);
284 
285 
286  // -------------------------------------------------------------------
287  // Public member functions
288  public:
296  int CheckConfigDir( const string& a_path );
305  const string& GetPathToConfigDir();
313  int InitOutputDirectory( const string& a_pathFout, const string& a_pathDout );
321  int LogCommandLine( int argc, char** argv );
322 
323 
324  // -------------------------------------------------------------------
325  // Private member functions
326  private:
333  sOutputManager();
337  ~sOutputManager();
338  // Prevent the compiler to generate methods to copy the object
340  void operator=(sOutputManager const&){};
341 
342 
343  // -------------------------------------------------------------------
344  // Data members
345  private:
346  static sOutputManager* mp_Instance;
347  int m_verbose;
348  int m_mpiRank;
349  string m_baseName;
350  string m_pathName;
352  vector<string> mp_dataFileName;
353  ofstream m_logFile;
356 };
357 
358 #endif
This header file is mainly used to declare some macro definitions and all includes needed from the st...
void operator=(sOutputManager const &)
void SetVerbose(int a_verbose)
set verbosity
vector< string > mp_dataFileName
sOutputManager()
sOutputManager constructor.
bool m_mergeOutputDynImgFlag
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
void Exit(int code)
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...
const string & GetPathName()
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.
sOutputManager(sOutputManager const &)
void SetMergeDynImagesFlag(bool a_flag)
Set to on the flag indicating that a dynamic serie of 3D images should be written on disk in one file...
void SetMPIRank(int a_mpiRank)
Initialize the machine index for MPI.
string m_pathToConfigDir
static sOutputManager * mp_Instance
ofstream & GetLogFile()
const string & GetBaseName()
bool MergeDynImages()
Indicate if a dynamic serie of 3D images should be merged in one file (true) or written on disk as on...
vector< string > GetDataFileName()
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.
This class is designed to manage all dimensions and quantification related stuff. ...
~sOutputManager()
sOutputManager destructor.
void SetDataFileName(vector< string > ap_dataFileName)