CASToR  1.1
Tomographic Reconstruction (PET/SPECT)
 All Classes Files Functions Variables Typedefs Macros Groups Pages
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 
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 ofstream& GetLogFile()
204  {return m_logFile;}
209  inline const string& GetBaseName()
210  {return m_baseName;}
215  inline const string& GetPathName()
216  {return m_pathName;}
222  inline void SetMPIRank( int a_mpiRank )
223  {m_mpiRank = a_mpiRank;}
231  inline void SetMergeDynImagesFlag( bool a_flag )
232  {m_mergeOutputDynImgFlag = a_flag;}
239  inline bool MergeDynImages()
240  {return m_mergeOutputDynImgFlag;}
241 
242 
243  // -------------------------------------------------------------------
244  // Public member functions
245  public:
253  int CheckConfigDir( const string& a_path );
262  const string& GetPathToConfigDir();
270  int InitOutputDirectory( const string& a_pathFout, const string& a_pathDout );
278  int LogCommandLine( int argc, char** argv );
279 
280 
281  // -------------------------------------------------------------------
282  // Private member functions
283  private:
290  sOutputManager();
294  ~sOutputManager();
295  // Prevent the compiler to generate methods to copy the object
297  void operator=(sOutputManager const&){};
298 
299 
300  // -------------------------------------------------------------------
301  // Data members
302  private:
303  static sOutputManager* mp_Instance;
304  int m_verbose;
305  int m_mpiRank;
306  string m_baseName;
307  string m_pathName;
309  ofstream m_logFile;
312 };
313 
314 #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
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 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...
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.