CASToR  1.0
Tomographic Reconstruction (PET/SPECT)
sOutputManager.hh
Go to the documentation of this file.
00001 
00008 #ifndef SOUTPUTMANAGER_HH
00009 #define SOUTPUTMANAGER_HH 1
00010 
00011 // Cross-platform directory separator, if required
00012 // Windows might auto-convert '/' to '\' though
00013 #ifdef _WIN32
00014 #define OS_SEP "\\"
00015 #else
00016 #define OS_SEP "/"
00017 #endif
00018 
00019 // Use to convert a macro variable provided by the pre-processor, to a string
00020 #define QUOTES(value) #value
00021 #define TOSTRING(macro) QUOTES(macro)
00022 // The CASTOR_CONFIG environment variable converted to a string
00023 #ifdef CASTOR_CONFIG
00024 #define CASTOR_CONFIG_STRING TOSTRING(CASTOR_CONFIG)
00025 #endif
00026 
00027 #include "gVariables.hh"
00028 
00029 class oImageDimensionsAndQuantification;
00030 
00031 // ---------------------------------------------------------------------
00032 #ifdef CASTOR_MPI
00033 // Macros for logging messages on standard output (with MPI)
00034 #define Cout(MESSAGE)                                           \
00035   do                                                            \
00036   {                                                             \
00037     int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);     \
00038     if (mpi_rank==0)                                            \
00039     {                                                           \
00040       std::cout << MESSAGE;                                     \
00041       sOutputManager* instance = sOutputManager::GetInstance(); \
00042       if (instance!=NULL)                                       \
00043       {                                                         \
00044         ofstream& logMac = instance->GetLogFile();              \
00045         if (logMac) logMac << MESSAGE;                          \
00046       }                                                         \
00047     }                                                           \
00048   } while(0)
00049 // Macros for logging messages on standard error (with MPI)
00050 #define Cerr(MESSAGE)                                           \
00051   do                                                            \
00052   {                                                             \
00053     int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);     \
00054     if (mpi_rank==0)                                            \
00055     {                                                           \
00056       std::cerr << MESSAGE;                                     \
00057       sOutputManager* instance = sOutputManager::GetInstance(); \
00058       if (instance!=NULL)                                       \
00059       {                                                         \
00060         ofstream& logMac = instance->GetLogFile();              \
00061         if (logMac) logMac << MESSAGE;                          \
00062       }                                                         \
00063     }                                                           \
00064   } while(0)
00065 #else
00066 // Macros for logging messages on standard output (without MPI)
00067 #define Cout(MESSAGE)                                         \
00068   do                                                          \
00069   {                                                           \
00070     std::cout << MESSAGE;                                     \
00071     sOutputManager* instance = sOutputManager::GetInstance(); \
00072     if (instance!=NULL)                                       \
00073     {                                                         \
00074       ofstream& logMac = instance->GetLogFile();              \
00075       if (logMac) logMac << MESSAGE;                          \
00076     }                                                         \
00077   } while(0)
00078 // Macros for logging messages on standard error (without MPI)
00079 #define Cerr(MESSAGE)                                         \
00080   do                                                          \
00081   {                                                           \
00082     std::cerr << MESSAGE;                                     \
00083     sOutputManager* instance = sOutputManager::GetInstance(); \
00084     if (instance!=NULL)                                       \
00085     {                                                         \
00086       ofstream& logMac = instance->GetLogFile();              \
00087       if (logMac) logMac << MESSAGE;                          \
00088     }                                                         \
00089   } while(0)
00090 #endif
00091 
00092 
00093 // ---------------------------------------------------------------------
00094 
00095 // Function used to make an clean exit taking MPI finalize into account
00102 void Exit(int code);
00103 
00104 
00105 
00106 
00112 class sOutputManager
00113 {
00114   // -------------------------------------------------------------------
00115   // Constructor & Destructor
00116   public:
00123     static sOutputManager* GetInstance() 
00124     { 
00125       if (mp_Instance == NULL) mp_Instance = new sOutputManager();
00126       return mp_Instance;
00127     }
00128 
00129 
00130   // -------------------------------------------------------------------
00131   // Get & Set functions
00132   public:
00138     inline void SetVerbose( int a_verbose )
00139            {m_verbose = a_verbose;}
00144     inline ofstream& GetLogFile()
00145            {return m_logFile;}
00150     inline const string& GetBaseName()
00151            {return m_baseName;}
00156     inline const string& GetPathName()
00157            {return m_pathName;}
00163     inline void SetMPIRank( int a_mpiRank )
00164            {m_mpiRank = a_mpiRank;}
00172     inline void SetMergeDynImagesFlag( bool a_flag )
00173            {m_mergeOutputDynImgFlag = a_flag;}
00180     inline bool MergeDynImages()
00181            {return m_mergeOutputDynImgFlag;}
00182 
00183 
00184   // -------------------------------------------------------------------
00185   // Public member functions
00186   public:
00194     int CheckConfigDir( const string& a_path );
00203     const string& GetPathToConfigDir();
00211     int InitOutputDirectory( const string& a_pathFout, const string& a_pathDout );
00219     int LogCommandLine( int argc, char** argv );
00220     
00221     
00222   // -------------------------------------------------------------------
00223   // Private member functions
00224   private:
00231     sOutputManager();
00235     ~sOutputManager();
00236     // Prevent the compiler to generate methods to copy the object
00237     sOutputManager(sOutputManager const&){};     
00238     void operator=(sOutputManager const&){};
00239 
00240 
00241   // -------------------------------------------------------------------
00242   // Data members
00243   private:
00244     static sOutputManager* mp_Instance; 
00245     int m_verbose;                      
00246     int m_mpiRank;                      
00247     string m_baseName;                  
00248     string m_pathName;                  
00249     string m_pathToConfigDir;           
00250     ofstream m_logFile;                 
00251     bool m_mergeOutputDynImgFlag;       
00253 };
00254 
00255 #endif
 All Classes Files Functions Variables Typedefs Defines