CASToR  3.2
Tomographic Reconstruction (PET/SPECT/CT)
include/management/sOutputManager.hh
Go to the documentation of this file.
1 
8 #ifndef SOUTPUTMANAGER_HH
9 #define SOUTPUTMANAGER_HH 1
10 
11 #include "gVariables.hh"
13 
14 // ---------------------------------------------------------------------
15 // ---------------------------------------------------------------------
16 
17 // Cross-platform directory separator, if required
18 // Windows might auto-convert '/' to '\' though
19 #ifdef _WIN32
20 #define OS_SEP "\\"
21 #else
22 #define OS_SEP "/"
23 #endif
24 
25 // ---------------------------------------------------------------------
26 // ---------------------------------------------------------------------
27 
28 // Use to convert a macro variable provided by the pre-processor, to a string
29 #define QUOTES(value) #value
30 #define TOSTRING(macro) QUOTES(macro)
31 // The CASTOR_CONFIG environment variable converted to a string
32 #ifdef CASTOR_CONFIG
33 #define CASTOR_CONFIG_STRING TOSTRING(CASTOR_CONFIG)
34 #endif
35 
36 // ---------------------------------------------------------------------
37 // ---------------------------------------------------------------------
38 
39 #ifdef CASTOR_MPI
40 // Macros for logging messages on standard output (with MPI)
41 #define Cout(MESSAGE) \
42  do \
43  { \
44  int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); \
45  if (mpi_rank==0) \
46  { \
47  std::cout << MESSAGE; \
48  sOutputManager* instance = sOutputManager::GetInstance(); \
49  if (instance!=NULL) \
50  { \
51  ofstream& logMac = instance->GetLogFile(); \
52  if (logMac) logMac << MESSAGE; \
53  } \
54  } \
55  } while(0)
56 // Macros for logging messages on standard error (with MPI)
57 #define Cerr(MESSAGE) \
58  do \
59  { \
60  int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); \
61  std::cerr << "***** The following error message was issued" \
62  << " by MPI instance " << mpi_rank << endl; \
63  std::cerr << MESSAGE; \
64  sOutputManager* instance = sOutputManager::GetInstance(); \
65  if (instance!=NULL) \
66  { \
67  ofstream& logMac = instance->GetLogFile(); \
68  if (logMac) \
69  { \
70  logMac << "***** The following error message was issued"\
71  << " by MPI instance " << mpi_rank << endl; \
72  logMac << MESSAGE; \
73  } \
74  } \
75  } while(0)
76 #else
77 // Macros for logging messages on standard output (without MPI)
78 #define Cout(MESSAGE) \
79  do \
80  { \
81  std::cout << MESSAGE; \
82  sOutputManager* instance = sOutputManager::GetInstance(); \
83  if (instance!=NULL) \
84  { \
85  ofstream& logMac = instance->GetLogFile(); \
86  if (logMac) logMac << MESSAGE; \
87  } \
88  } while(0)
89 // Macros for logging messages on standard error (without MPI)
90 #define Cerr(MESSAGE) \
91  do \
92  { \
93  std::cerr << MESSAGE; \
94  sOutputManager* instance = sOutputManager::GetInstance(); \
95  if (instance!=NULL) \
96  { \
97  ofstream& logMac = instance->GetLogFile(); \
98  if (logMac) logMac << MESSAGE; \
99  } \
100  } while(0)
101 #endif
102 
103 // ---------------------------------------------------------------------
104 // ---------------------------------------------------------------------
105 
106 // Verbose levels definitions
107 #define VERBOSE_LIGHT 1
108 #define VERBOSE_NORMAL 2
109 #define VERBOSE_DETAIL 3
110 #define VERBOSE_DEBUG_LIGHT 4
111 #define VERBOSE_DEBUG_NORMAL 5
112 #define VERBOSE_DEBUG_EVENT 6
113 #define VERBOSE_DEBUG_MAX 7
114 
115 // Macro for CASTOR_VERBOSE to print out the entering of each function.
116 // This may be used for debugging. When this compilation variable is not
117 // set, this does nothing.
118 
119 // If CASTOR_VERBOSE is not set, we define this macro as doing nothing ';'
120 #ifndef CASTOR_VERBOSE
121 
122  #define DEBUG_VERBOSE(IGNORED1,IGNORED2) ;
123 
124 // If CASTOR_VERBOSE is set, we differentiate between windows/unix systems
125 #else
126  // Case for pure windows
127  #if defined(_WIN32) && !defined(CASTOR_USE_MINGW)
128  #define DEBUG_VERBOSE(CURRENT_LEVEL,APPLICABLE_LEVEL) \
129  do \
130  { \
131  if (CURRENT_LEVEL >= APPLICABLE_LEVEL) \
132  { \
133  cout << "+++++ " << __FUNCSIG__ \
134  << " -> Entering this function" << endl; \
135  } \
136  } while(0);
137  // Case for unix and cross-compilation from unix to windows
138  #else
139  #define DEBUG_VERBOSE(CURRENT_LEVEL,APPLICABLE_LEVEL) \
140  do \
141  { \
142  if (CURRENT_LEVEL >= APPLICABLE_LEVEL) \
143  { \
144  cout << "+++++ " << __PRETTY_FUNCTION__ \
145  << " -> Entering this function" << endl; \
146  } \
147  } while(0);
148  #endif
149 #endif
150 
151 // ---------------------------------------------------------------------
152 // ---------------------------------------------------------------------
153 
154 // Function used to make an clean exit taking MPI finalize into account
161 void Exit(int code);
162 
163 // ---------------------------------------------------------------------
164 // ---------------------------------------------------------------------
165 
171 class sOutputManager
172 {
173  // -------------------------------------------------------------------
174  // Constructor & Destructor
175  public:
183  {
184  if (mp_Instance == NULL) mp_Instance = new sOutputManager();
185  return mp_Instance;
186  }
187 
188 
189  // -------------------------------------------------------------------
190  // Get & Set functions
191  public:
197  inline void SetVerbose( int a_verbose )
198  {m_verbose = a_verbose;}
203  inline void SetDataFileName( vector<string> ap_dataFileName )
204  {mp_dataFileName = ap_dataFileName;}
209  inline ofstream& GetLogFile()
210  {return m_logFile;}
215  inline const string& GetBaseName()
216  {return m_baseName;}
221  inline const string& GetPathName()
222  {return m_pathName;}
227  inline vector<string> GetDataFileName()
228  {return mp_dataFileName;}
234  inline void SetMPIRank( int a_mpiRank )
235  {m_mpiRank = a_mpiRank;}
243  inline void SetMergeDynImagesFlag( bool a_flag )
244  {m_mergeOutputDynImgFlag = a_flag;}
251  inline bool MergeDynImages()
252  {return m_mergeOutputDynImgFlag;}
253 
254 
261  int SetOutNbPrec(string a_format);
262 
263 
264  // -------------------------------------------------------------------
265  // Public member functions
266  public:
274  int CheckConfigDir( const string& a_path );
283  const string& GetPathToConfigDir();
291  int InitOutputDirectory( const string& a_pathFout, const string& a_pathDout );
299  int LogCommandLine( int argc, char** argv );
300 
301 
302  // -------------------------------------------------------------------
303  // Private member functions
304  private:
311  sOutputManager();
315  ~sOutputManager();
316  // Prevent the compiler to generate methods to copy the object
318  void operator=(sOutputManager const&){};
319 
320 
321  // -------------------------------------------------------------------
322  // Data members
323  private:
324  static sOutputManager* mp_Instance;
325  int m_verbose;
326  int m_mpiRank;
327  string m_baseName;
328  string m_pathName;
329  string m_pathToConfigDir;
330  vector<string> mp_dataFileName;
331  ofstream m_logFile;
334 };
335 
336 #endif
void operator=(sOutputManager const &)
sOutputManager()
sOutputManager constructor.
static sOutputManager * GetInstance()
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.
void Exit(int code)
sOutputManager(sOutputManager const &)
int InitOutputDirectory(const string &a_pathFout, const string &a_pathDout)
This header file is mainly used to declare some macro definitions and all includes needed from the st...
This class is designed to manage all dimensions and quantification related stuff. ...
~sOutputManager()
sOutputManager destructor.
void SetDataFileName(vector< string > ap_dataFileName)