CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-2018 all CASToR contributors listed below:
18 
19  --> current contributors: Thibaut MERLIN, Simon STUTE, Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Mael MILLARDET
20  --> past contributors: Valentin VIELZEUF
21 
22 This is CASToR version 2.0.
23 */
24 
31 #ifndef SOUTPUTMANAGER_HH
32 #define SOUTPUTMANAGER_HH 1
33 
34 #include "gVariables.hh"
36 
37 // ---------------------------------------------------------------------
38 // ---------------------------------------------------------------------
39 
40 // Cross-platform directory separator, if required
41 // Windows might auto-convert '/' to '\' though
42 #ifdef _WIN32
43 #define OS_SEP "\\"
44 #else
45 #define OS_SEP "/"
46 #endif
47 
48 // ---------------------------------------------------------------------
49 // ---------------------------------------------------------------------
50 
51 // Use to convert a macro variable provided by the pre-processor, to a string
52 #define QUOTES(value) #value
53 #define TOSTRING(macro) QUOTES(macro)
54 // The CASTOR_CONFIG environment variable converted to a string
55 #ifdef CASTOR_CONFIG
56 #define CASTOR_CONFIG_STRING TOSTRING(CASTOR_CONFIG)
57 #endif
58 
59 // ---------------------------------------------------------------------
60 // ---------------------------------------------------------------------
61 
62 #ifdef CASTOR_MPI
63 // Macros for logging messages on standard output (with MPI)
64 #define Cout(MESSAGE) \
65  do \
66  { \
67  int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); \
68  if (mpi_rank==0) \
69  { \
70  std::cout << MESSAGE; \
71  sOutputManager* instance = sOutputManager::GetInstance(); \
72  if (instance!=NULL) \
73  { \
74  ofstream& logMac = instance->GetLogFile(); \
75  if (logMac) logMac << MESSAGE; \
76  } \
77  } \
78  } while(0)
79 // Macros for logging messages on standard error (with MPI)
80 #define Cerr(MESSAGE) \
81  do \
82  { \
83  int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); \
84  std::cerr << "***** The following error message was issued" \
85  << " by MPI instance " << mpi_rank << endl; \
86  std::cerr << MESSAGE; \
87  sOutputManager* instance = sOutputManager::GetInstance(); \
88  if (instance!=NULL) \
89  { \
90  ofstream& logMac = instance->GetLogFile(); \
91  if (logMac) \
92  { \
93  logMac << "***** The following error message was issued"\
94  << " by MPI instance " << mpi_rank << endl; \
95  logMac << MESSAGE; \
96  } \
97  } \
98  } while(0)
99 #else
100 // Macros for logging messages on standard output (without MPI)
101 #define Cout(MESSAGE) \
102  do \
103  { \
104  std::cout << MESSAGE; \
105  sOutputManager* instance = sOutputManager::GetInstance(); \
106  if (instance!=NULL) \
107  { \
108  ofstream& logMac = instance->GetLogFile(); \
109  if (logMac) logMac << MESSAGE; \
110  } \
111  } while(0)
112 // Macros for logging messages on standard error (without MPI)
113 #define Cerr(MESSAGE) \
114  do \
115  { \
116  std::cerr << MESSAGE; \
117  sOutputManager* instance = sOutputManager::GetInstance(); \
118  if (instance!=NULL) \
119  { \
120  ofstream& logMac = instance->GetLogFile(); \
121  if (logMac) logMac << MESSAGE; \
122  } \
123  } while(0)
124 #endif
125 
126 // ---------------------------------------------------------------------
127 // ---------------------------------------------------------------------
128 
129 // Verbose levels definitions
130 #define VERBOSE_LIGHT 1
131 #define VERBOSE_NORMAL 2
132 #define VERBOSE_DETAIL 3
133 #define VERBOSE_DEBUG_LIGHT 4
134 #define VERBOSE_DEBUG_NORMAL 5
135 #define VERBOSE_DEBUG_EVENT 6
136 #define VERBOSE_DEBUG_MAX 7
137 
138 // Macro for CASTOR_VERBOSE to print out the entering of each function.
139 // This may be used for debugging. When this compilation variable is not
140 // set, this does nothing.
141 
142 // If CASTOR_VERBOSE is not set, we define this macro as doing nothing ';'
143 #ifndef CASTOR_VERBOSE
144 
145  #define DEBUG_VERBOSE(IGNORED1,IGNORED2) ;
146 
147 // If CASTOR_VERBOSE is set, we differentiate between windows/unix systems
148 #else
149  // Case for pure windows
150  #if defined(_WIN32) && !defined(CASTOR_USE_MINGW)
151  #define DEBUG_VERBOSE(CURRENT_LEVEL,APPLICABLE_LEVEL) \
152  do \
153  { \
154  if (CURRENT_LEVEL >= APPLICABLE_LEVEL) \
155  { \
156  cout << "+++++ " << __FUNCSIG__ \
157  << " -> Entering this function" << endl; \
158  } \
159  } while(0);
160  // Case for unix and cross-compilation from unix to windows
161  #else
162  #define DEBUG_VERBOSE(CURRENT_LEVEL,APPLICABLE_LEVEL) \
163  do \
164  { \
165  if (CURRENT_LEVEL >= APPLICABLE_LEVEL) \
166  { \
167  cout << "+++++ " << __PRETTY_FUNCTION__ \
168  << " -> Entering this function" << endl; \
169  } \
170  } while(0);
171  #endif
172 #endif
173 
174 // ---------------------------------------------------------------------
175 // ---------------------------------------------------------------------
176 
177 // Function used to make an clean exit taking MPI finalize into account
184 void Exit(int code);
185 
186 // ---------------------------------------------------------------------
187 // ---------------------------------------------------------------------
188 
195 {
196  // -------------------------------------------------------------------
197  // Constructor & Destructor
198  public:
206  {
207  if (mp_Instance == NULL) mp_Instance = new sOutputManager();
208  return mp_Instance;
209  }
210 
211 
212  // -------------------------------------------------------------------
213  // Get & Set functions
214  public:
220  inline void SetVerbose( int a_verbose )
221  {m_verbose = a_verbose;}
226  inline void SetDataFileName( vector<string> ap_dataFileName )
227  {mp_dataFileName = ap_dataFileName;}
232  inline ofstream& GetLogFile()
233  {return m_logFile;}
238  inline const string& GetBaseName()
239  {return m_baseName;}
244  inline const string& GetPathName()
245  {return m_pathName;}
250  inline vector<string> GetDataFileName()
251  {return mp_dataFileName;}
257  inline void SetMPIRank( int a_mpiRank )
258  {m_mpiRank = a_mpiRank;}
266  inline void SetMergeDynImagesFlag( bool a_flag )
267  {m_mergeOutputDynImgFlag = a_flag;}
274  inline bool MergeDynImages()
275  {return m_mergeOutputDynImgFlag;}
276 
277 
284  int SetOutNbPrec(string a_format);
285 
286 
287  // -------------------------------------------------------------------
288  // Public member functions
289  public:
297  int CheckConfigDir( const string& a_path );
306  const string& GetPathToConfigDir();
314  int InitOutputDirectory( const string& a_pathFout, const string& a_pathDout );
322  int LogCommandLine( int argc, char** argv );
323 
324 
325  // -------------------------------------------------------------------
326  // Private member functions
327  private:
334  sOutputManager();
338  ~sOutputManager();
339  // Prevent the compiler to generate methods to copy the object
341  void operator=(sOutputManager const&){};
342 
343 
344  // -------------------------------------------------------------------
345  // Data members
346  private:
347  static sOutputManager* mp_Instance;
348  int m_verbose;
349  int m_mpiRank;
350  string m_baseName;
351  string m_pathName;
353  vector<string> mp_dataFileName;
354  ofstream m_logFile;
357 };
358 
359 #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)