From 475b1746c133b0286871b7414918704557f1abcc Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Mon, 9 Mar 2015 15:53:07 +0100 Subject: Remove old Logging code (only used in fft.cu) --- build/linux/Makefile.in | 1 - cuda/2d/astra.cu | 3 +- cuda/2d/fft.cu | 10 ++-- include/astra/Logger.h | 72 --------------------------- src/CudaFilteredBackProjectionAlgorithm.cpp | 14 +++--- src/Logger.cpp | 77 ----------------------------- 6 files changed, 10 insertions(+), 167 deletions(-) delete mode 100644 include/astra/Logger.h delete mode 100644 src/Logger.cpp diff --git a/build/linux/Makefile.in b/build/linux/Makefile.in index 92697b2..d9ff045 100644 --- a/build/linux/Makefile.in +++ b/build/linux/Makefile.in @@ -118,7 +118,6 @@ BASE_OBJECTS=\ src/Fourier.lo \ src/GeometryUtil3D.lo \ src/Globals.lo \ - src/Logger.lo \ src/ParallelBeamBlobKernelProjector2D.lo \ src/ParallelBeamLinearKernelProjector2D.lo \ src/ParallelBeamLineKernelProjector2D.lo \ diff --git a/cuda/2d/astra.cu b/cuda/2d/astra.cu index 0b5be06..bcc1a50 100644 --- a/cuda/2d/astra.cu +++ b/cuda/2d/astra.cu @@ -42,7 +42,6 @@ $Id$ #include #include -#include "../../include/astra/Logger.h" #include "../../include/astra/VolumeGeometry2D.h" #include "../../include/astra/ParallelProjectionGeometry2D.h" #include "../../include/astra/FanFlatProjectionGeometry2D.h" @@ -538,7 +537,7 @@ bool AstraFBP::setFilter(E_FBPFILTER _eFilter, const float * _pfHostFilter /* = int iMaxFilterIndex = iStartFilterIndex + iUsedFilterWidth; int iFilterShiftSize = _iFilterWidth / 2; - + for(int iDetectorIndex = iStartFilterIndex; iDetectorIndex < iMaxFilterIndex; iDetectorIndex++) { int iFFTInFilterIndex = (iDetectorIndex + iFFTRealDetCount - iFilterShiftSize) % iFFTRealDetCount; diff --git a/cuda/2d/fft.cu b/cuda/2d/fft.cu index d105e29..5fef360 100644 --- a/cuda/2d/fft.cu +++ b/cuda/2d/fft.cu @@ -34,7 +34,6 @@ $Id$ #include #include -#include "../../include/astra/Logger.h" using namespace astra; @@ -45,7 +44,6 @@ using namespace astra; if( cudaSuccess != err) { \ fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ - CLogger::writeTerminalCUDAError(__FILE__, __LINE__, cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } } while (0) @@ -54,14 +52,12 @@ using namespace astra; if( cudaSuccess != err) { \ fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ __FILE__, __LINE__, cudaGetErrorString( err) ); \ - CLogger::writeTerminalCUDAError(__FILE__, __LINE__, cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } \ err = cudaThreadSynchronize(); \ if( cudaSuccess != err) { \ fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ __FILE__, __LINE__, cudaGetErrorString( err) ); \ - CLogger::writeTerminalCUDAError(__FILE__, __LINE__, cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } } while (0) @@ -460,7 +456,7 @@ void genFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, const float fA1 = 0.48f; const float fA2 = 0.38f; float fNMinusOne = (float)(_iFFTFourierDetectorCount) - 1.0f; - + for(int iDetectorIndex = 1; iDetectorIndex < _iFFTFourierDetectorCount; iDetectorIndex++) { float fSmallN = (float)iDetectorIndex; @@ -746,7 +742,7 @@ void testCudaFFT() { for(int iDetectorIndex = 0; iDetectorIndex < iDetectorCount; iDetectorIndex++) { -// int +// int // pfHostProj[iIndex] = (float)rand() / (float)RAND_MAX; } @@ -787,7 +783,7 @@ void testCudaFFT() float * pfHostFourProjImaginary = new float[iTotalElementCount]; convertComplexToRealImg(pHostFourProj, iTotalElementCount, pfHostFourProjReal, pfHostFourProjImaginary); - + writeToMatlabFile("proj_four_real.mat", pfHostFourProjReal, iProjectionCount, iDetectorCount); writeToMatlabFile("proj_four_imaginary.mat", pfHostFourProjImaginary, iProjectionCount, iDetectorCount); diff --git a/include/astra/Logger.h b/include/astra/Logger.h deleted file mode 100644 index 34fd364..0000000 --- a/include/astra/Logger.h +++ /dev/null @@ -1,72 +0,0 @@ -/* ------------------------------------------------------------------------ -Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp - 2014-2015, CWI, Amsterdam - -Contact: astra@uantwerpen.be -Website: http://sf.net/projects/astra-toolbox - -This file is part of the ASTRA Toolbox. - - -The ASTRA Toolbox is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -The ASTRA Toolbox is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with the ASTRA Toolbox. If not, see . - ------------------------------------------------------------------------ -$Id$ -*/ - -#ifndef _INC_ASTRA_LOGGER -#define _INC_ASTRA_LOGGER - -#include - -namespace astra -{ - -/** - * This is the first stab at a decent logger. If the file "astra_logger.txt", it will be replaced - * with the text sent to this logger. If the file doesn't exist when the app starts, nothing is written. - */ -class CLogger -{ - static std::FILE * m_pOutFile; - static bool m_bInitialized; - - static void _assureIsInitialized(); - - CLogger(); - -public: - - /** - * Writes a line to the log file (newline is added). Ignored if logging is turned off. - * - * @param _text char pointer to text in line - */ - static void writeLine(const char * _text); - - /** - * Formats and writes a CUDA error to the log file. Ignored if logging is turned off. - * - * @param _fileName filename where error occurred (typically __FILE__) - * @param _line line in file (typically __LINE__) - * @param _errString string describing the error, can be output of cudaGetErrorString - */ - static void writeTerminalCUDAError(const char * _fileName, int _iLine, const char * _errString); -}; - -} - -#endif /* _INC_ASTRA_LOGGER */ - diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index fcdf860..77bd412 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -34,8 +34,6 @@ $Id$ #include "astra/AstraObjectManager.h" #include "../cuda/2d/astra.h" -#include - using namespace std; using namespace astra; @@ -105,7 +103,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) } CC.markNodeParsed("FilterType"); ASTRA_DELETE(node); - + // filter node = _cfg.self->getSingleNode("FilterSinogramId"); if(node != NULL) @@ -168,7 +166,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) CC.markOptionParsed("ShortScan"); } - + m_pFBP = new AstraFBP; @@ -186,7 +184,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(CFloat32ProjectionData2D * { clear(); } - + // required classes m_pSinogram = _pSinogram; m_pReconstruction = _pReconstruction; @@ -326,7 +324,7 @@ void CCudaFilteredBackProjectionAlgorithm::run(int _iNrIterations /* = 0 */) const CVolumeGeometry2D& volgeom = *m_pReconstruction->getGeometry(); ok &= m_pFBP->getReconstruction(m_pReconstruction->getData(), volgeom.getGridColCount()); - + ASTRA_ASSERT(ok); } @@ -335,7 +333,7 @@ bool CCudaFilteredBackProjectionAlgorithm::check() // check pointers ASTRA_CONFIG_CHECK(m_pSinogram, "FBP_CUDA", "Invalid Projection Data Object."); ASTRA_CONFIG_CHECK(m_pReconstruction, "FBP_CUDA", "Invalid Reconstruction Data Object."); - + if((m_eFilter == FILTER_PROJECTION) || (m_eFilter == FILTER_SINOGRAM) || (m_eFilter == FILTER_RPROJECTION) || (m_eFilter == FILTER_RSINOGRAM)) { ASTRA_CONFIG_CHECK(m_pfFilter, "FBP_CUDA", "Invalid filter pointer."); @@ -387,7 +385,7 @@ static bool stringCompareLowerCase(const char * _stringA, const char * _stringB) #else iCmpReturn = strcasecmp(_stringA, _stringB); #endif - + return (iCmpReturn == 0); } diff --git a/src/Logger.cpp b/src/Logger.cpp deleted file mode 100644 index 148e18c..0000000 --- a/src/Logger.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* ------------------------------------------------------------------------ -Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp - 2014-2015, CWI, Amsterdam - -Contact: astra@uantwerpen.be -Website: http://sf.net/projects/astra-toolbox - -This file is part of the ASTRA Toolbox. - - -The ASTRA Toolbox is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -The ASTRA Toolbox is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with the ASTRA Toolbox. If not, see . - ------------------------------------------------------------------------ -$Id$ -*/ - -#include - -using namespace astra; - -const char * g_loggerFileName = "astra_logger.txt"; - -void CLogger::_assureIsInitialized() -{ - if(!m_bInitialized) - { - m_pOutFile = fopen(g_loggerFileName, "r"); - if(m_pOutFile != NULL) - { - // file exists, users wants to log - fclose(m_pOutFile); - m_pOutFile = fopen(g_loggerFileName, "w"); - } - - m_bInitialized = true; - } -} - -void CLogger::writeLine(const char * _text) -{ - _assureIsInitialized(); - - if(m_pOutFile != NULL) - { - fprintf(m_pOutFile, "%s\n", _text); - fflush(m_pOutFile); - } -} - -void CLogger::writeTerminalCUDAError(const char * _fileName, int _iLine, const char * _errString) -{ - char buffer[256]; - - sprintf(buffer, "Cuda error in file '%s' in line %i : %s.", _fileName, _iLine, _errString); - - writeLine(buffer); -} - -CLogger::CLogger() -{ - ; -} - -FILE * CLogger::m_pOutFile = NULL; -bool CLogger::m_bInitialized = false; -- cgit v1.2.3 From a1dff91d7d8db49ecd79dfbcc6a6a663b114f9fd Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Mon, 9 Mar 2015 17:51:42 +0100 Subject: Adds new logging capabilities (based on clog.h) --- build/linux/Makefile.in | 1 + include/astra/Logging.h | 147 ++++++++++++ include/astra/clog.h | 622 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Logging.cpp | 175 ++++++++++++++ 4 files changed, 945 insertions(+) create mode 100644 include/astra/Logging.h create mode 100644 include/astra/clog.h create mode 100644 src/Logging.cpp diff --git a/build/linux/Makefile.in b/build/linux/Makefile.in index d9ff045..c2b9994 100644 --- a/build/linux/Makefile.in +++ b/build/linux/Makefile.in @@ -118,6 +118,7 @@ BASE_OBJECTS=\ src/Fourier.lo \ src/GeometryUtil3D.lo \ src/Globals.lo \ + src/Logging.lo \ src/ParallelBeamBlobKernelProjector2D.lo \ src/ParallelBeamLinearKernelProjector2D.lo \ src/ParallelBeamLineKernelProjector2D.lo \ diff --git a/include/astra/Logging.h b/include/astra/Logging.h new file mode 100644 index 0000000..ce777ae --- /dev/null +++ b/include/astra/Logging.h @@ -0,0 +1,147 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp + 2014-2015, CWI, Amsterdam + +Contact: astra@uantwerpen.be +Website: http://sf.net/projects/astra-toolbox + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +$Id$ +*/ + +#ifndef _INC_ASTRA_LOGGING +#define _INC_ASTRA_LOGGING + +#define ASTRA_LOG(id) __FILE__, __LINE__, id + +namespace astra +{ + +enum log_level { + LOG_DEBUG, + LOG_INFO, + LOG_WARN, + LOG_ERROR +}; + +class CLogger +{ + CLogger(); + ~CLogger(); + static bool m_bEnabledFile; + static bool m_bEnabledScreen; + static bool m_bFileProvided; + static bool m_bInitialized; + static void _assureIsInitialized(); + static void _setLevel(int id, log_level m_eLevel); + +public: + + /** + * Writes a line to the log file (newline is added). Ignored if logging is turned off. + * + * @param sfile + * The name of the source file making this log call (e.g. __FILE__). + * + * @param sline + * The line number of the call in the source code (e.g. __LINE__). + * + * @param id + * The id of the logger to write to. + * + * @param fmt + * The format string for the message (printf formatting). + * + * @param ... + * Any additional format arguments. + */ + static void debug(const char *sfile, int sline, const char *fmt, ...); + static void info(const char *sfile, int sline, const char *fmt, ...); + static void warn(const char *sfile, int sline, const char *fmt, ...); + static void error(const char *sfile, int sline, const char *fmt, ...); + + /** + * Sets the file to log to, with logging level. + * + * @param filename + * File to log to. + * + * @param m_eLevel + * Logging level (LOG_DEBUG, LOG_WARN, LOG_INFO, LOG_ERROR). + * + */ + static void setOutputFile(const char *filename, log_level m_eLevel); + + /** + * Sets the screen to log to, with logging level. + * + * @param screen_fd + * Screen file descriptor (1 for stdout, 2 for stderr) + * + * @param m_eLevel + * Logging level (LOG_DEBUG, LOG_WARN, LOG_INFO, LOG_ERROR). + * + */ + static void setOutputScreen(int fd, log_level m_eLevel); + + /** + * Set the format string for log messages. Here are the substitutions you may + * use: + * + * %f: Source file name generating the log call. + * %n: Source line number where the log call was made. + * %m: The message text sent to the logger (after printf formatting). + * %d: The current date, formatted using the logger's date format. + * %t: The current time, formatted using the logger's time format. + * %l: The log level (one of "DEBUG", "INFO", "WARN", or "ERROR"). + * %%: A literal percent sign. + * + * The default format string is "%d %t %f(%n): %l: %m\n". + * + * @param fmt + * The new format string, which must be less than 256 bytes. + * You probably will want to end this with a newline (\n). + * + */ + static void setFormatFile(const char *fmt); + static void setFormatScreen(const char *fmt); + + + /** + * Enable logging. + * + */ + static void enable(); + static void enableScreen(); + static void enableFile(); + + /** + * Disable logging. + * + */ + static void disable(); + static void disableScreen(); + static void disableFile(); + +}; + +} + +#endif /* _INC_ASTRA_LOGGING */ diff --git a/include/astra/clog.h b/include/astra/clog.h new file mode 100644 index 0000000..4d8e39d --- /dev/null +++ b/include/astra/clog.h @@ -0,0 +1,622 @@ +/* clog: Extremely simple logger for C. + * + * Features: + * - Implemented purely as a single header file. + * - Create multiple loggers. + * - Four log levels (debug, info, warn, error). + * - Custom formats. + * - Fast. + * + * Dependencies: + * - Should conform to C89, C++98 (but requires vsnprintf, unfortunately). + * - POSIX environment. + * + * USAGE: + * + * Include this header in any file that wishes to write to logger(s). In + * exactly one file (per executable), define CLOG_MAIN first (e.g. in your + * main .c file). + * + * #define CLOG_MAIN + * #include "clog.h" + * + * This will define the actual objects that all the other units will use. + * + * Loggers are identified by integers (0 - 15). It's expected that you'll + * create meaningful constants and then refer to the loggers as such. + * + * Example: + * + * const int MY_LOGGER = 0; + * + * int main() { + * int r; + * r = clog_init_path(MY_LOGGER, "my_log.txt"); + * if (r != 0) { + * fprintf(stderr, "Logger initialization failed.\n"); + * return 1; + * } + * clog_info(CLOG(MY_LOGGER), "Hello, world!"); + * clog_free(MY_LOGGER); + * return 0; + * } + * + * The CLOG macro used in the call to clog_info is a helper that passes the + * __FILE__ and __LINE__ parameters for you, so you don't have to type them + * every time. (It could be prettier with variadic macros, but that requires + * C99 or C++11 to be standards compliant.) + * + * Errors encountered by clog will be printed to stderr. You can suppress + * these by defining a macro called CLOG_SILENT before including clog.h. + * + * License: Do whatever you want. It would be nice if you contribute + * improvements as pull requests here: + * + * https://github.com/mmueller/clog + * + * Copyright 2013 Mike Mueller . + * + * As is; no warranty is provided; use at your own risk. + */ + +#ifndef __CLOG_H__ +#define __CLOG_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Number of loggers that can be defined. */ +#define CLOG_MAX_LOGGERS 16 + +/* Format strings cannot be longer than this. */ +#define CLOG_FORMAT_LENGTH 256 + +/* Formatted times and dates should be less than this length. If they are not, + * they will not appear in the log. */ +#define CLOG_DATETIME_LENGTH 256 + +/* Default format strings. */ +#define CLOG_DEFAULT_FORMAT "%d %t %f(%n): %l: %m\n" +#define CLOG_DEFAULT_DATE_FORMAT "%Y-%m-%d" +#define CLOG_DEFAULT_TIME_FORMAT "%H:%M:%S" + +#ifdef __cplusplus +extern "C" { +#endif + +enum clog_level { + CLOG_DEBUG, + CLOG_INFO, + CLOG_WARN, + CLOG_ERROR +}; + +struct clog; + +/** + * Create a new logger writing to the given file path. The file will always + * be opened in append mode. + * + * @param id + * A constant integer between 0 and 15 that uniquely identifies this logger. + * + * @param path + * Path to the file where log messages will be written. + * + * @return + * Zero on success, non-zero on failure. + */ +int clog_init_path(int id, const char *const path); + +/** + * Create a new logger writing to a file descriptor. + * + * @param id + * A constant integer between 0 and 15 that uniquely identifies this logger. + * + * @param fd + * The file descriptor where log messages will be written. + * + * @return + * Zero on success, non-zero on failure. + */ +int clog_init_fd(int id, int fd); + +/** + * Destroy (clean up) a logger. You should do this at the end of execution, + * or when you are done using the logger. + * + * @param id + * The id of the logger to destroy. + */ +void clog_free(int id); + +#define CLOG(id) __FILE__, __LINE__, id + +/** + * Log functions (one per level). Call these to write messages to the log + * file. The first three arguments can be replaced with a call to the CLOG + * macro defined above, e.g.: + * + * clog_debug(CLOG(MY_LOGGER_ID), "This is a log message."); + * + * @param sfile + * The name of the source file making this log call (e.g. __FILE__). + * + * @param sline + * The line number of the call in the source code (e.g. __LINE__). + * + * @param id + * The id of the logger to write to. + * + * @param fmt + * The format string for the message (printf formatting). + * + * @param ... + * Any additional format arguments. + */ +void clog_debug(const char *sfile, int sline, int id, const char *fmt, va_list ap); +void clog_info(const char *sfile, int sline, int id, const char *fmt, va_list ap); +void clog_warn(const char *sfile, int sline, int id, const char *fmt, va_list ap); +void clog_error(const char *sfile, int sline, int id, const char *fmt, va_list ap); + +/** + * Set the minimum level of messages that should be written to the log. + * Messages below this level will not be written. By default, loggers are + * created with level == CLOG_DEBUG. + * + * @param id + * The identifier of the logger. + * + * @param level + * The new minimum log level. + * + * @return + * Zero on success, non-zero on failure. + */ +int clog_set_level(int id, enum clog_level level); + +/** + * Set the format string used for times. See strftime(3) for how this string + * should be defined. The default format string is CLOG_DEFAULT_TIME_FORMAT. + * + * @param fmt + * The new format string, which must be less than CLOG_FORMAT_LENGTH bytes. + * + * @return + * Zero on success, non-zero on failure. + */ +int clog_set_time_fmt(int id, const char *fmt); + +/** + * Set the format string used for dates. See strftime(3) for how this string + * should be defined. The default format string is CLOG_DEFAULT_DATE_FORMAT. + * + * @param fmt + * The new format string, which must be less than CLOG_FORMAT_LENGTH bytes. + * + * @return + * Zero on success, non-zero on failure. + */ +int clog_set_date_fmt(int id, const char *fmt); + +/** + * Set the format string for log messages. Here are the substitutions you may + * use: + * + * %f: Source file name generating the log call. + * %n: Source line number where the log call was made. + * %m: The message text sent to the logger (after printf formatting). + * %d: The current date, formatted using the logger's date format. + * %t: The current time, formatted using the logger's time format. + * %l: The log level (one of "DEBUG", "INFO", "WARN", or "ERROR"). + * %%: A literal percent sign. + * + * The default format string is CLOG_DEFAULT_FORMAT. + * + * @param fmt + * The new format string, which must be less than CLOG_FORMAT_LENGTH bytes. + * You probably will want to end this with a newline (\n). + * + * @return + * Zero on success, non-zero on failure. + */ +int clog_set_fmt(int id, const char *fmt); + +/* + * No need to read below this point. + */ + +/** + * The C logger structure. + */ +struct clog { + + /* The current level of this logger. Messages below it will be dropped. */ + enum clog_level level; + + /* The file being written. */ + int fd; + + /* The format specifier. */ + char fmt[CLOG_FORMAT_LENGTH]; + + /* Date format */ + char date_fmt[CLOG_FORMAT_LENGTH]; + + /* Time format */ + char time_fmt[CLOG_FORMAT_LENGTH]; + + /* Tracks whether the fd needs to be closed eventually. */ + int opened; +}; + +void _clog_err(const char *fmt, ...); + +#ifdef CLOG_MAIN +struct clog *_clog_loggers[CLOG_MAX_LOGGERS] = { 0 }; +#else +extern struct clog *_clog_loggers[CLOG_MAX_LOGGERS]; +#endif + +#ifdef CLOG_MAIN + +const char *const CLOG_LEVEL_NAMES[] = { + "DEBUG", + "INFO", + "WARN", + "ERROR", +}; + +int +clog_init_path(int id, const char *const path) +{ + int fd = open(path, O_CREAT | O_WRONLY | O_APPEND, 0666); + if (fd == -1) { + _clog_err("Unable to open %s: %s\n", path, strerror(errno)); + return 1; + } + if (clog_init_fd(id, fd)) { + close(fd); + return 1; + } + _clog_loggers[id]->opened = 1; + return 0; +} + +int +clog_init_fd(int id, int fd) +{ + struct clog *logger; + + if (_clog_loggers[id] != NULL) { + _clog_err("Logger %d already initialized.\n", id); + return 1; + } + + logger = (struct clog *) malloc(sizeof(struct clog)); + if (logger == NULL) { + _clog_err("Failed to allocate logger: %s\n", strerror(errno)); + return 1; + } + + logger->level = CLOG_DEBUG; + logger->fd = fd; + logger->opened = 0; + strcpy(logger->fmt, CLOG_DEFAULT_FORMAT); + strcpy(logger->date_fmt, CLOG_DEFAULT_DATE_FORMAT); + strcpy(logger->time_fmt, CLOG_DEFAULT_TIME_FORMAT); + + _clog_loggers[id] = logger; + return 0; +} + +void +clog_free(int id) +{ + if (_clog_loggers[id]) { + if (_clog_loggers[id]->opened) { + close(_clog_loggers[id]->fd); + } + free(_clog_loggers[id]); + _clog_loggers[id]=NULL; + } +} + +int +clog_set_level(int id, enum clog_level level) +{ + if (_clog_loggers[id] == NULL) { + return 1; + } + if ((unsigned) level > CLOG_ERROR) { + return 1; + } + _clog_loggers[id]->level = level; + return 0; +} + +int +clog_set_time_fmt(int id, const char *fmt) +{ + struct clog *logger = _clog_loggers[id]; + if (logger == NULL) { + _clog_err("clog_set_time_fmt: No such logger: %d\n", id); + return 1; + } + if (strlen(fmt) >= CLOG_FORMAT_LENGTH) { + _clog_err("clog_set_time_fmt: Format specifier too long.\n"); + return 1; + } + strcpy(logger->time_fmt, fmt); + return 0; +} + +int +clog_set_date_fmt(int id, const char *fmt) +{ + struct clog *logger = _clog_loggers[id]; + if (logger == NULL) { + _clog_err("clog_set_date_fmt: No such logger: %d\n", id); + return 1; + } + if (strlen(fmt) >= CLOG_FORMAT_LENGTH) { + _clog_err("clog_set_date_fmt: Format specifier too long.\n"); + return 1; + } + strcpy(logger->date_fmt, fmt); + return 0; +} + +int +clog_set_fmt(int id, const char *fmt) +{ + struct clog *logger = _clog_loggers[id]; + if (logger == NULL) { + _clog_err("clog_set_fmt: No such logger: %d\n", id); + return 1; + } + if (strlen(fmt) >= CLOG_FORMAT_LENGTH) { + _clog_err("clog_set_fmt: Format specifier too long.\n"); + return 1; + } + strcpy(logger->fmt, fmt); + return 0; +} + +/* Internal functions */ + +size_t +_clog_append_str(char **dst, char *orig_buf, const char *src, size_t cur_size) +{ + size_t new_size = cur_size; + + while (strlen(*dst) + strlen(src) >= new_size) { + new_size *= 2; + } + if (new_size != cur_size) { + if (*dst == orig_buf) { + *dst = (char *) malloc(new_size); + strcpy(*dst, orig_buf); + } else { + *dst = (char *) realloc(*dst, new_size); + } + } + + strcat(*dst, src); + return new_size; +} + +size_t +_clog_append_int(char **dst, char *orig_buf, long int d, size_t cur_size) +{ + char buf[40]; /* Enough for 128-bit decimal */ + if (snprintf(buf, 40, "%ld", d) >= 40) { + return cur_size; + } + return _clog_append_str(dst, orig_buf, buf, cur_size); +} + +size_t +_clog_append_time(char **dst, char *orig_buf, struct tm *lt, + const char *fmt, size_t cur_size) +{ + char buf[CLOG_DATETIME_LENGTH]; + size_t result = strftime(buf, CLOG_DATETIME_LENGTH, fmt, lt); + + if (result > 0) { + return _clog_append_str(dst, orig_buf, buf, cur_size); + } + + return cur_size; +} + +const char * +_clog_basename(const char *path) +{ + const char *slash = strrchr(path, '/'); + if (slash) { + path = slash + 1; + } +#ifdef _WIN32 + slash = strrchr(path, '\\'); + if (slash) { + path = slash + 1; + } +#endif + return path; +} + +char * +_clog_format(const struct clog *logger, char buf[], size_t buf_size, + const char *sfile, int sline, const char *level, + const char *message) +{ + size_t cur_size = buf_size; + char *result = buf; + enum { NORMAL, SUBST } state = NORMAL; + size_t fmtlen = strlen(logger->fmt); + size_t i; + time_t t = time(NULL); + struct tm *lt = localtime(&t); + + sfile = _clog_basename(sfile); + result[0] = 0; + for (i = 0; i < fmtlen; ++i) { + if (state == NORMAL) { + if (logger->fmt[i] == '%') { + state = SUBST; + } else { + char str[2] = { 0 }; + str[0] = logger->fmt[i]; + cur_size = _clog_append_str(&result, buf, str, cur_size); + } + } else { + switch (logger->fmt[i]) { + case '%': + cur_size = _clog_append_str(&result, buf, "%", cur_size); + break; + case 't': + cur_size = _clog_append_time(&result, buf, lt, + logger->time_fmt, cur_size); + break; + case 'd': + cur_size = _clog_append_time(&result, buf, lt, + logger->date_fmt, cur_size); + break; + case 'l': + cur_size = _clog_append_str(&result, buf, level, cur_size); + break; + case 'n': + cur_size = _clog_append_int(&result, buf, sline, cur_size); + break; + case 'f': + cur_size = _clog_append_str(&result, buf, sfile, cur_size); + break; + case 'm': + cur_size = _clog_append_str(&result, buf, message, + cur_size); + break; + } + state = NORMAL; + } + } + + return result; +} + +void +_clog_log(const char *sfile, int sline, enum clog_level level, + int id, const char *fmt, va_list ap) +{ + /* For speed: Use a stack buffer until message exceeds 4096, then switch + * to dynamically allocated. This should greatly reduce the number of + * memory allocations (and subsequent fragmentation). */ + char buf[4096]; + size_t buf_size = 4096; + char *dynbuf = buf; + char *message; + int result; + struct clog *logger = _clog_loggers[id]; + + if (!logger) { + _clog_err("No such logger: %d\n", id); + return; + } + + if (level < logger->level) { + return; + } + + /* Format the message text with the argument list. */ + result = vsnprintf(dynbuf, buf_size, fmt, ap); + if ((size_t) result >= buf_size) { + buf_size = result + 1; + dynbuf = (char *) malloc(buf_size); + result = vsnprintf(dynbuf, buf_size, fmt, ap); + if ((size_t) result >= buf_size) { + /* Formatting failed -- too large */ + _clog_err("Formatting failed (1).\n"); + free(dynbuf); + return; + } + } + + /* Format according to log format and write to log */ + { + char message_buf[4096]; + message = _clog_format(logger, message_buf, 4096, sfile, sline, + CLOG_LEVEL_NAMES[level], dynbuf); + if (!message) { + _clog_err("Formatting failed (2).\n"); + if (dynbuf != buf) { + free(dynbuf); + } + return; + } + result = write(logger->fd, message, strlen(message)); + if (result == -1) { + _clog_err("Unable to write to log file: %s\n", strerror(errno)); + } + if (message != message_buf) { + free(message); + } + if (dynbuf != buf) { + free(dynbuf); + } + fsync(logger->fd); + } +} + +void +clog_debug(const char *sfile, int sline, int id, const char *fmt, va_list ap) +{ + _clog_log(sfile, sline, CLOG_DEBUG, id, fmt, ap); +} + +void +clog_info(const char *sfile, int sline, int id, const char *fmt, va_list ap) +{ + _clog_log(sfile, sline, CLOG_INFO, id, fmt, ap); +} + +void +clog_warn(const char *sfile, int sline, int id, const char *fmt, va_list ap) +{ + _clog_log(sfile, sline, CLOG_WARN, id, fmt, ap); +} + +void +clog_error(const char *sfile, int sline, int id, const char *fmt, va_list ap) +{ + _clog_log(sfile, sline, CLOG_ERROR, id, fmt, ap); +} + +void +_clog_err(const char *fmt, ...) +{ +#ifdef CLOG_SILENT + (void) fmt; +#else + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); +#endif +} + +#endif /* CLOG_MAIN */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __CLOG_H__ */ diff --git a/src/Logging.cpp b/src/Logging.cpp new file mode 100644 index 0000000..9011d37 --- /dev/null +++ b/src/Logging.cpp @@ -0,0 +1,175 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp + 2014-2015, CWI, Amsterdam + +Contact: astra@uantwerpen.be +Website: http://sf.net/projects/astra-toolbox + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +$Id$ +*/ + +#define CLOG_MAIN +#include + +#include + +#include + +using namespace astra; + +void CLogger::enableScreen() +{ + m_bEnabledScreen = true; +} + +void CLogger::enableFile() +{ + m_bEnabledFile = true; +} + +void CLogger::enable() +{ + enableScreen(); + enableFile(); +} + +void CLogger::disableScreen() +{ + m_bEnabledScreen = false; +} + +void CLogger::disableFile() +{ + m_bEnabledFile = false; +} + +void CLogger::disable() +{ + disableScreen(); + disableFile(); +} + +void CLogger::debug(const char *sfile, int sline, const char *fmt, ...) +{ + _assureIsInitialized(); + va_list ap; + va_start(ap, fmt); + if(m_bEnabledScreen) clog_debug(sfile,sline,0,fmt,ap); + if(m_bEnabledFile && m_bFileProvided) clog_debug(sfile,sline,1,fmt,ap); +} + +void CLogger::info(const char *sfile, int sline, const char *fmt, ...) +{ + _assureIsInitialized(); + va_list ap; + va_start(ap, fmt); + if(m_bEnabledScreen) clog_info(sfile,sline,0,fmt,ap); + if(m_bEnabledFile && m_bFileProvided) clog_info(sfile,sline,1,fmt,ap); +} + +void CLogger::warn(const char *sfile, int sline, const char *fmt, ...) +{ + _assureIsInitialized(); + va_list ap; + va_start(ap, fmt); + if(m_bEnabledScreen) clog_warn(sfile,sline,0,fmt,ap); + if(m_bEnabledFile && m_bFileProvided) clog_warn(sfile,sline,1,fmt,ap); +} + +void CLogger::error(const char *sfile, int sline, const char *fmt, ...) +{ + _assureIsInitialized(); + va_list ap; + va_start(ap, fmt); + if(m_bEnabledScreen) clog_error(sfile,sline,0,fmt,ap); + if(m_bEnabledFile && m_bFileProvided) clog_error(sfile,sline,1,fmt,ap); +} + +void CLogger::_setLevel(int id, log_level m_eLevel) +{ + switch(m_eLevel){ + case LOG_DEBUG: + clog_set_level(id,CLOG_DEBUG); + break; + case LOG_INFO: + clog_set_level(id,CLOG_INFO); + break; + case LOG_WARN: + clog_set_level(id,CLOG_WARN); + break; + case LOG_ERROR: + clog_set_level(id,CLOG_ERROR); + break; + } +} + +void CLogger::setOutputScreen(int fd, log_level m_eLevel) +{ + _assureIsInitialized(); + clog_free(0); + clog_init_fd(0, fd); + _setLevel(0,m_eLevel); +} + +void CLogger::setOutputFile(const char *filename, log_level m_eLevel) +{ + if(m_bFileProvided){ + clog_free(1); + m_bFileProvided=false; + } + if(!clog_init_path(1,filename)){ + m_bFileProvided=true; + _setLevel(1,m_eLevel); + } +} + +void CLogger::_assureIsInitialized() +{ + if(!m_bInitialized) + { + clog_init_fd(0, 2); + clog_set_level(0, CLOG_INFO); + m_bInitialized = true; + } +} + +void CLogger::setFormatFile(const char *fmt) +{ + if(m_bFileProvided){ + clog_set_fmt(1,fmt); + }else{ + error(__FILE__,__LINE__,"No log file specified"); + } +} +void CLogger::setFormatScreen(const char *fmt) +{ + clog_set_fmt(0,fmt); +} + +CLogger::CLogger() +{ + ; +} + +bool CLogger::m_bEnabledScreen = true; +bool CLogger::m_bEnabledFile = true; +bool CLogger::m_bFileProvided = false; +bool CLogger::m_bInitialized = false; -- cgit v1.2.3 From 535564ccd8b9563fb52be0dff247b99495942f51 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Tue, 10 Mar 2015 12:54:08 +0100 Subject: Add logging support to Python --- python/astra/__init__.py | 1 + python/astra/log.py | 153 +++++++++++++++++++++++++++++++++++++++++++++++ python/astra/log_c.pyx | 96 +++++++++++++++++++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 python/astra/log.py create mode 100644 python/astra/log_c.pyx diff --git a/python/astra/__init__.py b/python/astra/__init__.py index a61aafc..1d3176c 100644 --- a/python/astra/__init__.py +++ b/python/astra/__init__.py @@ -34,6 +34,7 @@ from . import data3d from . import algorithm from . import projector from . import matrix +from . import log import os try: diff --git a/python/astra/log.py b/python/astra/log.py new file mode 100644 index 0000000..3ec0df5 --- /dev/null +++ b/python/astra/log.py @@ -0,0 +1,153 @@ +#----------------------------------------------------------------------- +#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam +# +#Author: Daniel M. Pelt +#Contact: D.M.Pelt@cwi.nl +#Website: http://dmpelt.github.io/pyastratoolbox/ +# +# +#This file is part of the Python interface to the +#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox"). +# +#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with the Python interface to the ASTRA Toolbox. If not, see . +# +#----------------------------------------------------------------------- + +from . import log_c as l + +import inspect + +def debug(message): + """Log a debug message. + + :param message: Message to log. + :type message: :class:`string` + """ + prev_f = inspect.getframeinfo(inspect.currentframe().f_back) + l.log_debug(prev_f.filename,prev_f.lineno,message) + +def info(message): + """Log an info message. + + :param message: Message to log. + :type message: :class:`string` + """ + prev_f = inspect.getframeinfo(inspect.currentframe().f_back) + l.log_info(prev_f.filename,prev_f.lineno,message) + +def warn(message): + """Log a warning message. + + :param message: Message to log. + :type message: :class:`string` + """ + prev_f = inspect.getframeinfo(inspect.currentframe().f_back) + l.log_warn(prev_f.filename,prev_f.lineno,message) + +def error(message): + """Log an error message. + + :param message: Message to log. + :type message: :class:`string` + """ + prev_f = inspect.getframeinfo(inspect.currentframe().f_back) + l.log_error(prev_f.filename,prev_f.lineno,message) + +def enable(): + """Enable logging to screen and file.""" + l.log_enable() + +def enableScreen(): + """Enable logging to screen.""" + l.log_enableScreen() + +def enableFile(): + """Enable logging to file (note that a file has to be set).""" + l.log_enableFile() + +def disable(): + """Disable all logging.""" + l.log_disable() + +def disableScreen(): + """Disable logging to screen.""" + l.log_disableScreen() + +def disableFile(): + """Disable logging to file.""" + l.log_disableFile() + +def setFormatFile(fmt): + """Set the format string for log messages. Here are the substitutions you may use: + + %f: Source file name generating the log call. + %n: Source line number where the log call was made. + %m: The message text sent to the logger (after printf formatting). + %d: The current date, formatted using the logger's date format. + %t: The current time, formatted using the logger's time format. + %l: The log level (one of "DEBUG", "INFO", "WARN", or "ERROR"). + %%: A literal percent sign. + + The default format string is "%d %t %f(%n): %l: %m\n". + + :param fmt: Format to use, end with "\n". + :type fmt: :class:`string` + """ + l.log_setFormatFile(fmt) + +def setFormatScreen(fmt): + """Set the format string for log messages. Here are the substitutions you may use: + + %f: Source file name generating the log call. + %n: Source line number where the log call was made. + %m: The message text sent to the logger (after printf formatting). + %d: The current date, formatted using the logger's date format. + %t: The current time, formatted using the logger's time format. + %l: The log level (one of "DEBUG", "INFO", "WARN", or "ERROR"). + %%: A literal percent sign. + + The default format string is "%d %t %f(%n): %l: %m\n". + + :param fmt: Format to use, end with "\n". + :type fmt: :class:`string` + """ + l.log_setFormatScreen(fmt) + +STDOUT=1 +STDERR=2 + +DEBUG=0 +INFO=1 +WARN=2 +ERROR=3 + +def setOutputScreen(fd, level): + """Set which screen to output to, and which level to use. + + :param fd: File descriptor of output screen (STDOUT or STDERR). + :type fd: :class:`int` + :param level: Logging level to use (DEBUG, INFO, WARN, or ERROR). + :type level: :class:`int` + """ + l.log_setOutputScreen(fd, level) + +def setOutputFile(filename, level): + """Set which file to output to, and which level to use. + + :param filename: File name of output file. + :type filename: :class:`string` + :param level: Logging level to use (DEBUG, INFO, WARN, or ERROR). + :type level: :class:`int` + """ + l.log_setOutputFile(filename, level) \ No newline at end of file diff --git a/python/astra/log_c.pyx b/python/astra/log_c.pyx new file mode 100644 index 0000000..969cc06 --- /dev/null +++ b/python/astra/log_c.pyx @@ -0,0 +1,96 @@ +#----------------------------------------------------------------------- +#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam +# +#Author: Daniel M. Pelt +#Contact: D.M.Pelt@cwi.nl +#Website: http://dmpelt.github.io/pyastratoolbox/ +# +# +#This file is part of the Python interface to the +#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox"). +# +#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with the Python interface to the ASTRA Toolbox. If not, see . +# +#----------------------------------------------------------------------- +# distutils: language = c++ +# distutils: libraries = astra + +import six + +cdef extern from "astra/Logging.h" namespace "astra": + cdef enum log_level: + LOG_DEBUG + LOG_INFO + LOG_WARN + LOG_ERROR + +cdef extern from "astra/Logging.h" namespace "astra::CLogger": + void debug(const char *sfile, int sline, const char *fmt, ...) + void info(const char *sfile, int sline, const char *fmt, ...) + void warn(const char *sfile, int sline, const char *fmt, ...) + void error(const char *sfile, int sline, const char *fmt, ...) + void setOutputScreen(int fd, log_level m_eLevel) + void setOutputFile(const char *filename, log_level m_eLevel) + void enable() + void enableScreen() + void enableFile() + void disable() + void disableScreen() + void disableFile() + void setFormatFile(const char *fmt) + void setFormatScreen(const char *fmt) + +def log_debug(sfile, sline, message): + debug(six.b(sfile),sline,six.b(message)) + +def log_info(sfile, sline, message): + info(six.b(sfile),sline,six.b(message)) + +def log_warn(sfile, sline, message): + warn(six.b(sfile),sline,six.b(message)) + +def log_error(sfile, sline, message): + error(six.b(sfile),sline,six.b(message)) + +def log_enable(): + enable() + +def log_enableScreen(): + enableScreen() + +def log_enableFile(): + enableFile() + +def log_disable(): + disable() + +def log_disableScreen(): + disableScreen() + +def log_disableFile(): + disableFile() + +def log_setFormatFile(fmt): + setFormatFile(six.b(fmt)) + +def log_setFormatScreen(fmt): + setFormatScreen(six.b(fmt)) + +enumList = [LOG_DEBUG,LOG_INFO,LOG_WARN,LOG_ERROR] + +def log_setOutputScreen(fd, level): + setOutputScreen(fd, enumList[level]) + +def log_setOutputFile(filename, level): + setOutputFile(six.b(filename), enumList[level]) \ No newline at end of file -- cgit v1.2.3 From 150951875c236f95a64fd132c26576bd19daca80 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Tue, 10 Mar 2015 15:11:15 +0100 Subject: Use new logging API internally instead of printf / iostream --- cuda/2d/astra.cu | 4 +++- cuda/2d/fft.cu | 31 +++++++++++++++-------------- cuda/2d/util.cu | 8 +++++--- cuda/3d/util3d.cu | 12 ++++++----- src/ConeProjectionGeometry3D.cpp | 4 +++- src/Config.cpp | 7 ++++++- src/CudaFilteredBackProjectionAlgorithm.cpp | 4 +++- src/CudaForwardProjectionAlgorithm.cpp | 4 +++- src/CudaForwardProjectionAlgorithm3D.cpp | 4 +++- src/CudaReconstructionAlgorithm2D.cpp | 4 +++- src/FilteredBackProjectionAlgorithm.cpp | 4 +++- 11 files changed, 55 insertions(+), 31 deletions(-) diff --git a/cuda/2d/astra.cu b/cuda/2d/astra.cu index bcc1a50..71fd089 100644 --- a/cuda/2d/astra.cu +++ b/cuda/2d/astra.cu @@ -47,6 +47,8 @@ $Id$ #include "../../include/astra/FanFlatProjectionGeometry2D.h" #include "../../include/astra/FanFlatVecProjectionGeometry2D.h" +#include "../../include/astra/Logging.h" + // For fan beam FBP weighting #include "../3d/fdk.h" @@ -562,7 +564,7 @@ bool AstraFBP::setFilter(E_FBPFILTER _eFilter, const float * _pfHostFilter /* = } default: { - fprintf(stderr, "AstraFBP::setFilter: Unknown filter type requested"); + astra::CLogger::error(__FILE__,__LINE__,"AstraFBP::setFilter: Unknown filter type requested"); delete [] pHostFilter; return false; } diff --git a/cuda/2d/fft.cu b/cuda/2d/fft.cu index 5fef360..468c7c2 100644 --- a/cuda/2d/fft.cu +++ b/cuda/2d/fft.cu @@ -34,6 +34,7 @@ $Id$ #include #include +#include "../../include/astra/Logging.h" using namespace astra; @@ -42,22 +43,22 @@ using namespace astra; #define CHECK_ERROR(errorMessage) do { \ cudaError_t err = cudaThreadSynchronize(); \ if( cudaSuccess != err) { \ - fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ - errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ + astra::CLogger::error(__FILE__,__LINE__,"Cuda error %s : %s", \ + errorMessage,cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } } while (0) #define SAFE_CALL( call) do { \ cudaError err = call; \ if( cudaSuccess != err) { \ - fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ - __FILE__, __LINE__, cudaGetErrorString( err) ); \ + astra::CLogger::error(__FILE__,__LINE__,"Cuda error: %s ", \ + cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } \ err = cudaThreadSynchronize(); \ if( cudaSuccess != err) { \ - fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ - __FILE__, __LINE__, cudaGetErrorString( err) ); \ + astra::CLogger::error(__FILE__,__LINE__,"Cuda error: %s : ", \ + cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } } while (0) @@ -136,7 +137,7 @@ static bool invokeCudaFFT(int _iProjectionCount, int _iDetectorCount, result = cufftPlan1d(&plan, _iDetectorCount, CUFFT_R2C, _iProjectionCount); if(result != CUFFT_SUCCESS) { - std::cerr << "Failed to plan 1d r2c fft" << std::endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to plan 1d r2c fft"); return false; } @@ -145,7 +146,7 @@ static bool invokeCudaFFT(int _iProjectionCount, int _iDetectorCount, if(result != CUFFT_SUCCESS) { - std::cerr << "Failed to exec 1d r2c fft" << std::endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to exec 1d r2c fft"); return false; } @@ -162,7 +163,7 @@ static bool invokeCudaIFFT(int _iProjectionCount, int _iDetectorCount, result = cufftPlan1d(&plan, _iDetectorCount, CUFFT_C2R, _iProjectionCount); if(result != CUFFT_SUCCESS) { - std::cerr << "Failed to plan 1d c2r fft" << std::endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to plan 1d c2r fft"); return false; } @@ -173,7 +174,7 @@ static bool invokeCudaIFFT(int _iProjectionCount, int _iDetectorCount, if(result != CUFFT_SUCCESS) { - std::cerr << "Failed to exec 1d c2r fft" << std::endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to exec 1d c2r fft"); return false; } @@ -629,7 +630,7 @@ void genFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, } default: { - std::cerr << "Cannot serve requested filter" << std::endl; + astra::CLogger::error(__FILE__,__LINE__,"Cannot serve requested filter"); } } @@ -763,13 +764,13 @@ void testCudaFFT() result = cufftPlan1d(&plan, iDetectorCount, CUFFT_R2C, iProjectionCount); if(result != CUFFT_SUCCESS) { - cerr << "Failed to plan 1d r2c fft" << endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to plan 1d r2c fft"); } result = cufftExecR2C(plan, pfDevProj, pDevFourProj); if(result != CUFFT_SUCCESS) { - cerr << "Failed to exec 1d r2c fft" << endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to exec 1d r2c fft"); } cufftDestroy(plan); @@ -793,13 +794,13 @@ void testCudaFFT() result = cufftPlan1d(&plan, iDetectorCount, CUFFT_C2R, iProjectionCount); if(result != CUFFT_SUCCESS) { - cerr << "Failed to plan 1d c2r fft" << endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to plan 1d c2r fft"); } result = cufftExecC2R(plan, pDevFourProj, pfDevInFourProj); if(result != CUFFT_SUCCESS) { - cerr << "Failed to exec 1d c2r fft" << endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to exec 1d c2r fft"); } cufftDestroy(plan); diff --git a/cuda/2d/util.cu b/cuda/2d/util.cu index 81e368f..6ced557 100644 --- a/cuda/2d/util.cu +++ b/cuda/2d/util.cu @@ -30,6 +30,8 @@ $Id$ #include #include "util.h" +#include "../../include/astra/Logging.h" + namespace astraCUDA { bool copyVolumeToDevice(const float* in_data, unsigned int in_pitch, @@ -91,7 +93,7 @@ bool allocateVolume(float*& ptr, unsigned int width, unsigned int height, unsign cudaError_t ret = cudaMallocPitch((void**)&ptr, &p, sizeof(float)*width, height); if (ret != cudaSuccess) { reportCudaError(ret); - fprintf(stderr, "Failed to allocate %dx%d GPU buffer\n", width, height); + astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%d GPU buffer", width, height); return false; } @@ -259,7 +261,7 @@ bool cudaTextForceKernelsCompletion() cudaError_t returnedCudaError = cudaThreadSynchronize(); if(returnedCudaError != cudaSuccess) { - fprintf(stderr, "Failed to force completion of cuda kernels: %d: %s.\n", returnedCudaError, cudaGetErrorString(returnedCudaError)); + astra::CLogger::error(__FILE__,__LINE__,"Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError)); return false; } @@ -269,7 +271,7 @@ bool cudaTextForceKernelsCompletion() void reportCudaError(cudaError_t err) { if(err != cudaSuccess) - fprintf(stderr, "CUDA error %d: %s.\n", err, cudaGetErrorString(err)); + astra::CLogger::error(__FILE__,__LINE__,"CUDA error %d: %s.", err, cudaGetErrorString(err)); } diff --git a/cuda/3d/util3d.cu b/cuda/3d/util3d.cu index d85a928..f2d16b3 100644 --- a/cuda/3d/util3d.cu +++ b/cuda/3d/util3d.cu @@ -31,6 +31,8 @@ $Id$ #include "util3d.h" #include "../2d/util.h" +#include "../../include/astra/Logging.h" + namespace astraCUDA3d { @@ -46,7 +48,7 @@ cudaPitchedPtr allocateVolumeData(const SDimensions3D& dims) cudaError err = cudaMalloc3D(&volData, extentV); if (err != cudaSuccess) { astraCUDA::reportCudaError(err); - fprintf(stderr, "Failed to allocate %dx%dx%d GPU buffer\n", dims.iVolX, dims.iVolY, dims.iVolZ); + astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%dx%d GPU buffer", dims.iVolX, dims.iVolY, dims.iVolZ); volData.ptr = 0; // TODO: return 0 somehow? } @@ -65,7 +67,7 @@ cudaPitchedPtr allocateProjectionData(const SDimensions3D& dims) cudaError err = cudaMalloc3D(&projData, extentP); if (err != cudaSuccess) { astraCUDA::reportCudaError(err); - fprintf(stderr, "Failed to allocate %dx%dx%d GPU buffer\n", dims.iProjU, dims.iProjAngles, dims.iProjV); + astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%dx%d GPU buffer", dims.iProjU, dims.iProjAngles, dims.iProjV); projData.ptr = 0; // TODO: return 0 somehow? } @@ -303,7 +305,7 @@ cudaArray* allocateVolumeArray(const SDimensions3D& dims) cudaError err = cudaMalloc3DArray(&cuArray, &channelDesc, extentA); if (err != cudaSuccess) { astraCUDA::reportCudaError(err); - fprintf(stderr, "Failed to allocate %dx%dx%d GPU array\n", dims.iVolX, dims.iVolY, dims.iVolZ); + astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%dx%d GPU array", dims.iVolX, dims.iVolY, dims.iVolZ); return 0; } @@ -321,7 +323,7 @@ cudaArray* allocateProjectionArray(const SDimensions3D& dims) if (err != cudaSuccess) { astraCUDA::reportCudaError(err); - fprintf(stderr, "Failed to allocate %dx%dx%d GPU array\n", dims.iProjU, dims.iProjAngles, dims.iProjV); + astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%dx%d GPU array", dims.iProjU, dims.iProjAngles, dims.iProjV); return 0; } @@ -397,7 +399,7 @@ bool cudaTextForceKernelsCompletion() cudaError_t returnedCudaError = cudaThreadSynchronize(); if(returnedCudaError != cudaSuccess) { - fprintf(stderr, "Failed to force completion of cuda kernels: %d: %s.\n", returnedCudaError, cudaGetErrorString(returnedCudaError)); + astra::CLogger::error(__FILE__,__LINE__,"Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError)); return false; } diff --git a/src/ConeProjectionGeometry3D.cpp b/src/ConeProjectionGeometry3D.cpp index eb9adcf..13f147b 100644 --- a/src/ConeProjectionGeometry3D.cpp +++ b/src/ConeProjectionGeometry3D.cpp @@ -28,6 +28,8 @@ $Id$ #include "astra/ConeProjectionGeometry3D.h" +#include "astra/Logging.h" + #include #include @@ -257,7 +259,7 @@ void CConeProjectionGeometry3D::projectPoint(float32 fX, float32 fY, float32 fZ, // Scale fS to detector plane fU = detectorOffsetXToColIndexFloat( (fS * (m_fOriginSourceDistance + m_fOriginDetectorDistance)) / fD ); - fprintf(stderr, "alpha: %f, D: %f, V: %f, S: %f, U: %f\n", alpha, fD, fV, fS, fU); + astra::CLogger::debug(__FILE__,__LINE__,"alpha: %f, D: %f, V: %f, S: %f, U: %f", alpha, fD, fV, fS, fU); } diff --git a/src/Config.cpp b/src/Config.cpp index 653935e..0a85b3c 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -37,6 +37,9 @@ $Id$ #include "astra/Projector2D.h" #include "astra/Projector3D.h" +#include "astra/Logging.h" +#include + using namespace astra; using namespace std; @@ -144,7 +147,9 @@ bool ConfigStackCheck::stopParsing() nodes.clear(); if (!errors.empty()) { - cout << "Warning: " << name << ": unused configuration options: " << errors << std::endl; + ostringstream os; + os << "Warning: " << name << ": unused configuration options: " << errors; + astra::CLogger::warn(__FILE__,__LINE__,os.str().c_str()); return false; } diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index 77bd412..26b848e 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -34,6 +34,8 @@ $Id$ #include "astra/AstraObjectManager.h" #include "../cuda/2d/astra.h" +#include "astra/Logging.h" + using namespace std; using namespace astra; @@ -483,7 +485,7 @@ E_FBPFILTER CCudaFilteredBackProjectionAlgorithm::_convertStringToFilter(const c } else { - cerr << "Failed to convert \"" << _filterType << "\" into a filter." << endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to convert \"%s\" into a filter.",_filterType); } return output; diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index ab0d643..1ae6b83 100644 --- a/src/CudaForwardProjectionAlgorithm.cpp +++ b/src/CudaForwardProjectionAlgorithm.cpp @@ -42,6 +42,8 @@ $Id$ #include "astra/FanFlatVecProjectionGeometry2D.h" #include "astra/CudaProjector2D.h" +#include "astra/Logging.h" + using namespace std; namespace astra { @@ -104,7 +106,7 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - cout << "Warning: non-CUDA Projector2D passed to FP_CUDA" << std::endl; + astra::CLogger::warn(__FILE__,__LINE__,"Warning: non-CUDA Projector2D passed to FP_CUDA"); } delete node; } diff --git a/src/CudaForwardProjectionAlgorithm3D.cpp b/src/CudaForwardProjectionAlgorithm3D.cpp index bb122e0..57e1094 100644 --- a/src/CudaForwardProjectionAlgorithm3D.cpp +++ b/src/CudaForwardProjectionAlgorithm3D.cpp @@ -40,6 +40,8 @@ $Id$ #include "astra/ParallelVecProjectionGeometry3D.h" #include "astra/ConeVecProjectionGeometry3D.h" +#include "astra/Logging.h" + #include "../cuda/3d/astra3d.h" using namespace std; @@ -265,7 +267,7 @@ void CCudaForwardProjectionAlgorithm3D::run(int) for (int k = 0; k < 2; ++k) { float fU, fV; projgeom->projectPoint(fX[i], fY[j], fZ[k], a, fU, fV); - fprintf(stderr, "%3d %c1,%c1,%c1 -> %12f %12f\n", a, i ? ' ' : '-', j ? ' ' : '-', k ? ' ' : '-', fU, fV); + astra::CLogger::debug(__FILE__,__LINE__,"%3d %c1,%c1,%c1 -> %12f %12f", a, i ? ' ' : '-', j ? ' ' : '-', k ? ' ' : '-', fU, fV); } } #endif diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp index d3dedc5..b434e8a 100644 --- a/src/CudaReconstructionAlgorithm2D.cpp +++ b/src/CudaReconstructionAlgorithm2D.cpp @@ -37,6 +37,8 @@ $Id$ #include "astra/FanFlatVecProjectionGeometry2D.h" #include "astra/CudaProjector2D.h" +#include "astra/Logging.h" + #include "../cuda/2d/algo.h" #include @@ -176,7 +178,7 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - cout << "Warning: non-CUDA Projector2D passed" << std::endl; + astra::CLogger::warn(__FILE__,__LINE__,"Warning: non-CUDA Projector2D passed"); } delete node; } diff --git a/src/FilteredBackProjectionAlgorithm.cpp b/src/FilteredBackProjectionAlgorithm.cpp index 50cf939..47315bb 100644 --- a/src/FilteredBackProjectionAlgorithm.cpp +++ b/src/FilteredBackProjectionAlgorithm.cpp @@ -39,6 +39,8 @@ $Id$ #include "astra/Fourier.h" #include "astra/DataProjector.h" +#include "astra/Logging.h" + using namespace std; namespace astra { @@ -133,7 +135,7 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) for (int i = 0; i < angleCount; i ++) { if (projectionIndex[i] > m_pProjector->getProjectionGeometry()->getProjectionAngleCount() -1 ) { - cout << "Invalid Projection Index" << endl; + astra::CLogger::error(__FILE__,__LINE__,"Invalid Projection Index"); return false; } else { int orgIndex = (int)projectionIndex[i]; -- cgit v1.2.3 From c5507b6ef2abfab169150528a374526bb348bf62 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 12:18:21 +0100 Subject: Adds ASTRA_*** defines for easier logging, and changes internal calls to these defines --- cuda/2d/astra.cu | 2 +- cuda/2d/fft.cu | 24 ++++++++++++------------ cuda/2d/util.cu | 6 +++--- cuda/3d/util3d.cu | 10 +++++----- include/astra/Logging.h | 5 ++++- src/ConeProjectionGeometry3D.cpp | 2 +- src/Config.cpp | 2 +- src/CudaFilteredBackProjectionAlgorithm.cpp | 2 +- src/CudaForwardProjectionAlgorithm.cpp | 2 +- src/CudaForwardProjectionAlgorithm3D.cpp | 2 +- src/CudaReconstructionAlgorithm2D.cpp | 2 +- src/FilteredBackProjectionAlgorithm.cpp | 2 +- 12 files changed, 32 insertions(+), 29 deletions(-) diff --git a/cuda/2d/astra.cu b/cuda/2d/astra.cu index 71fd089..2f72db0 100644 --- a/cuda/2d/astra.cu +++ b/cuda/2d/astra.cu @@ -564,7 +564,7 @@ bool AstraFBP::setFilter(E_FBPFILTER _eFilter, const float * _pfHostFilter /* = } default: { - astra::CLogger::error(__FILE__,__LINE__,"AstraFBP::setFilter: Unknown filter type requested"); + ASTRA_ERROR("AstraFBP::setFilter: Unknown filter type requested"); delete [] pHostFilter; return false; } diff --git a/cuda/2d/fft.cu b/cuda/2d/fft.cu index 468c7c2..49c696c 100644 --- a/cuda/2d/fft.cu +++ b/cuda/2d/fft.cu @@ -43,7 +43,7 @@ using namespace astra; #define CHECK_ERROR(errorMessage) do { \ cudaError_t err = cudaThreadSynchronize(); \ if( cudaSuccess != err) { \ - astra::CLogger::error(__FILE__,__LINE__,"Cuda error %s : %s", \ + ASTRA_ERROR("Cuda error %s : %s", \ errorMessage,cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } } while (0) @@ -51,13 +51,13 @@ using namespace astra; #define SAFE_CALL( call) do { \ cudaError err = call; \ if( cudaSuccess != err) { \ - astra::CLogger::error(__FILE__,__LINE__,"Cuda error: %s ", \ + ASTRA_ERROR("Cuda error: %s ", \ cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } \ err = cudaThreadSynchronize(); \ if( cudaSuccess != err) { \ - astra::CLogger::error(__FILE__,__LINE__,"Cuda error: %s : ", \ + ASTRA_ERROR("Cuda error: %s : ", \ cudaGetErrorString( err)); \ exit(EXIT_FAILURE); \ } } while (0) @@ -137,7 +137,7 @@ static bool invokeCudaFFT(int _iProjectionCount, int _iDetectorCount, result = cufftPlan1d(&plan, _iDetectorCount, CUFFT_R2C, _iProjectionCount); if(result != CUFFT_SUCCESS) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to plan 1d r2c fft"); + ASTRA_ERROR("Failed to plan 1d r2c fft"); return false; } @@ -146,7 +146,7 @@ static bool invokeCudaFFT(int _iProjectionCount, int _iDetectorCount, if(result != CUFFT_SUCCESS) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to exec 1d r2c fft"); + ASTRA_ERROR("Failed to exec 1d r2c fft"); return false; } @@ -163,7 +163,7 @@ static bool invokeCudaIFFT(int _iProjectionCount, int _iDetectorCount, result = cufftPlan1d(&plan, _iDetectorCount, CUFFT_C2R, _iProjectionCount); if(result != CUFFT_SUCCESS) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to plan 1d c2r fft"); + ASTRA_ERROR("Failed to plan 1d c2r fft"); return false; } @@ -174,7 +174,7 @@ static bool invokeCudaIFFT(int _iProjectionCount, int _iDetectorCount, if(result != CUFFT_SUCCESS) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to exec 1d c2r fft"); + ASTRA_ERROR("Failed to exec 1d c2r fft"); return false; } @@ -630,7 +630,7 @@ void genFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, } default: { - astra::CLogger::error(__FILE__,__LINE__,"Cannot serve requested filter"); + ASTRA_ERROR("Cannot serve requested filter"); } } @@ -764,13 +764,13 @@ void testCudaFFT() result = cufftPlan1d(&plan, iDetectorCount, CUFFT_R2C, iProjectionCount); if(result != CUFFT_SUCCESS) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to plan 1d r2c fft"); + ASTRA_ERROR("Failed to plan 1d r2c fft"); } result = cufftExecR2C(plan, pfDevProj, pDevFourProj); if(result != CUFFT_SUCCESS) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to exec 1d r2c fft"); + ASTRA_ERROR("Failed to exec 1d r2c fft"); } cufftDestroy(plan); @@ -794,13 +794,13 @@ void testCudaFFT() result = cufftPlan1d(&plan, iDetectorCount, CUFFT_C2R, iProjectionCount); if(result != CUFFT_SUCCESS) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to plan 1d c2r fft"); + ASTRA_ERROR("Failed to plan 1d c2r fft"); } result = cufftExecC2R(plan, pDevFourProj, pfDevInFourProj); if(result != CUFFT_SUCCESS) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to exec 1d c2r fft"); + ASTRA_ERROR("Failed to exec 1d c2r fft"); } cufftDestroy(plan); diff --git a/cuda/2d/util.cu b/cuda/2d/util.cu index 6ced557..a4f8f3e 100644 --- a/cuda/2d/util.cu +++ b/cuda/2d/util.cu @@ -93,7 +93,7 @@ bool allocateVolume(float*& ptr, unsigned int width, unsigned int height, unsign cudaError_t ret = cudaMallocPitch((void**)&ptr, &p, sizeof(float)*width, height); if (ret != cudaSuccess) { reportCudaError(ret); - astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%d GPU buffer", width, height); + ASTRA_ERROR("Failed to allocate %dx%d GPU buffer", width, height); return false; } @@ -261,7 +261,7 @@ bool cudaTextForceKernelsCompletion() cudaError_t returnedCudaError = cudaThreadSynchronize(); if(returnedCudaError != cudaSuccess) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError)); + ASTRA_ERROR("Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError)); return false; } @@ -271,7 +271,7 @@ bool cudaTextForceKernelsCompletion() void reportCudaError(cudaError_t err) { if(err != cudaSuccess) - astra::CLogger::error(__FILE__,__LINE__,"CUDA error %d: %s.", err, cudaGetErrorString(err)); + ASTRA_ERROR("CUDA error %d: %s.", err, cudaGetErrorString(err)); } diff --git a/cuda/3d/util3d.cu b/cuda/3d/util3d.cu index f2d16b3..537ed69 100644 --- a/cuda/3d/util3d.cu +++ b/cuda/3d/util3d.cu @@ -48,7 +48,7 @@ cudaPitchedPtr allocateVolumeData(const SDimensions3D& dims) cudaError err = cudaMalloc3D(&volData, extentV); if (err != cudaSuccess) { astraCUDA::reportCudaError(err); - astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%dx%d GPU buffer", dims.iVolX, dims.iVolY, dims.iVolZ); + ASTRA_ERROR("Failed to allocate %dx%dx%d GPU buffer", dims.iVolX, dims.iVolY, dims.iVolZ); volData.ptr = 0; // TODO: return 0 somehow? } @@ -67,7 +67,7 @@ cudaPitchedPtr allocateProjectionData(const SDimensions3D& dims) cudaError err = cudaMalloc3D(&projData, extentP); if (err != cudaSuccess) { astraCUDA::reportCudaError(err); - astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%dx%d GPU buffer", dims.iProjU, dims.iProjAngles, dims.iProjV); + ASTRA_ERROR("Failed to allocate %dx%dx%d GPU buffer", dims.iProjU, dims.iProjAngles, dims.iProjV); projData.ptr = 0; // TODO: return 0 somehow? } @@ -305,7 +305,7 @@ cudaArray* allocateVolumeArray(const SDimensions3D& dims) cudaError err = cudaMalloc3DArray(&cuArray, &channelDesc, extentA); if (err != cudaSuccess) { astraCUDA::reportCudaError(err); - astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%dx%d GPU array", dims.iVolX, dims.iVolY, dims.iVolZ); + ASTRA_ERROR("Failed to allocate %dx%dx%d GPU array", dims.iVolX, dims.iVolY, dims.iVolZ); return 0; } @@ -323,7 +323,7 @@ cudaArray* allocateProjectionArray(const SDimensions3D& dims) if (err != cudaSuccess) { astraCUDA::reportCudaError(err); - astra::CLogger::error(__FILE__,__LINE__,"Failed to allocate %dx%dx%d GPU array", dims.iProjU, dims.iProjAngles, dims.iProjV); + ASTRA_ERROR("Failed to allocate %dx%dx%d GPU array", dims.iProjU, dims.iProjAngles, dims.iProjV); return 0; } @@ -399,7 +399,7 @@ bool cudaTextForceKernelsCompletion() cudaError_t returnedCudaError = cudaThreadSynchronize(); if(returnedCudaError != cudaSuccess) { - astra::CLogger::error(__FILE__,__LINE__,"Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError)); + ASTRA_ERROR("Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError)); return false; } diff --git a/include/astra/Logging.h b/include/astra/Logging.h index ce777ae..5695663 100644 --- a/include/astra/Logging.h +++ b/include/astra/Logging.h @@ -29,7 +29,10 @@ $Id$ #ifndef _INC_ASTRA_LOGGING #define _INC_ASTRA_LOGGING -#define ASTRA_LOG(id) __FILE__, __LINE__, id +#define ASTRA_DEBUG(...) astra::CLogger::debug(__FILE__,__LINE__, __VA_ARGS__) +#define ASTRA_INFO(...) astra::CLogger::info(__FILE__,__LINE__, __VA_ARGS__) +#define ASTRA_WARN(...) astra::CLogger::warn(__FILE__,__LINE__, __VA_ARGS__) +#define ASTRA_ERROR(...) astra::CLogger::error(__FILE__,__LINE__, __VA_ARGS__) namespace astra { diff --git a/src/ConeProjectionGeometry3D.cpp b/src/ConeProjectionGeometry3D.cpp index 13f147b..1976901 100644 --- a/src/ConeProjectionGeometry3D.cpp +++ b/src/ConeProjectionGeometry3D.cpp @@ -259,7 +259,7 @@ void CConeProjectionGeometry3D::projectPoint(float32 fX, float32 fY, float32 fZ, // Scale fS to detector plane fU = detectorOffsetXToColIndexFloat( (fS * (m_fOriginSourceDistance + m_fOriginDetectorDistance)) / fD ); - astra::CLogger::debug(__FILE__,__LINE__,"alpha: %f, D: %f, V: %f, S: %f, U: %f", alpha, fD, fV, fS, fU); + ASTRA_DEBUG("alpha: %f, D: %f, V: %f, S: %f, U: %f", alpha, fD, fV, fS, fU); } diff --git a/src/Config.cpp b/src/Config.cpp index 0a85b3c..388cfdf 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -149,7 +149,7 @@ bool ConfigStackCheck::stopParsing() if (!errors.empty()) { ostringstream os; os << "Warning: " << name << ": unused configuration options: " << errors; - astra::CLogger::warn(__FILE__,__LINE__,os.str().c_str()); + ASTRA_WARN(os.str().c_str()); return false; } diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index 26b848e..0badc20 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -485,7 +485,7 @@ E_FBPFILTER CCudaFilteredBackProjectionAlgorithm::_convertStringToFilter(const c } else { - astra::CLogger::error(__FILE__,__LINE__,"Failed to convert \"%s\" into a filter.",_filterType); + ASTRA_ERROR("Failed to convert \"%s\" into a filter.",_filterType); } return output; diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index 1ae6b83..19cadd6 100644 --- a/src/CudaForwardProjectionAlgorithm.cpp +++ b/src/CudaForwardProjectionAlgorithm.cpp @@ -106,7 +106,7 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - astra::CLogger::warn(__FILE__,__LINE__,"Warning: non-CUDA Projector2D passed to FP_CUDA"); + ASTRA_WARN("Warning: non-CUDA Projector2D passed to FP_CUDA"); } delete node; } diff --git a/src/CudaForwardProjectionAlgorithm3D.cpp b/src/CudaForwardProjectionAlgorithm3D.cpp index 57e1094..8e6bab5 100644 --- a/src/CudaForwardProjectionAlgorithm3D.cpp +++ b/src/CudaForwardProjectionAlgorithm3D.cpp @@ -267,7 +267,7 @@ void CCudaForwardProjectionAlgorithm3D::run(int) for (int k = 0; k < 2; ++k) { float fU, fV; projgeom->projectPoint(fX[i], fY[j], fZ[k], a, fU, fV); - astra::CLogger::debug(__FILE__,__LINE__,"%3d %c1,%c1,%c1 -> %12f %12f", a, i ? ' ' : '-', j ? ' ' : '-', k ? ' ' : '-', fU, fV); + ASTRA_DEBUG("%3d %c1,%c1,%c1 -> %12f %12f", a, i ? ' ' : '-', j ? ' ' : '-', k ? ' ' : '-', fU, fV); } } #endif diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp index b434e8a..929f0f1 100644 --- a/src/CudaReconstructionAlgorithm2D.cpp +++ b/src/CudaReconstructionAlgorithm2D.cpp @@ -178,7 +178,7 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - astra::CLogger::warn(__FILE__,__LINE__,"Warning: non-CUDA Projector2D passed"); + ASTRA_WARN("Warning: non-CUDA Projector2D passed"); } delete node; } diff --git a/src/FilteredBackProjectionAlgorithm.cpp b/src/FilteredBackProjectionAlgorithm.cpp index 47315bb..4a8e5ac 100644 --- a/src/FilteredBackProjectionAlgorithm.cpp +++ b/src/FilteredBackProjectionAlgorithm.cpp @@ -135,7 +135,7 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) for (int i = 0; i < angleCount; i ++) { if (projectionIndex[i] > m_pProjector->getProjectionGeometry()->getProjectionAngleCount() -1 ) { - astra::CLogger::error(__FILE__,__LINE__,"Invalid Projection Index"); + ASTRA_ERROR("Invalid Projection Index"); return false; } else { int orgIndex = (int)projectionIndex[i]; -- cgit v1.2.3 From e4614cf09b90cc9a0e38d370bb090a11f3877b33 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 14:21:53 +0100 Subject: Add logging support to Matlab --- build/linux/Makefile.in | 1 + matlab/mex/astra_mex_log_c.cpp | 302 +++++++++++++++++++++++++++++++++++++++++ matlab/tools/astra_mex_log.m | 33 +++++ 3 files changed, 336 insertions(+) create mode 100644 matlab/mex/astra_mex_log_c.cpp create mode 100644 matlab/tools/astra_mex_log.m diff --git a/build/linux/Makefile.in b/build/linux/Makefile.in index c2b9994..f862114 100644 --- a/build/linux/Makefile.in +++ b/build/linux/Makefile.in @@ -225,6 +225,7 @@ MATLAB_MEX=\ matlab/mex/astra_mex_matrix_c.$(MEXSUFFIX) \ matlab/mex/astra_mex_projector_c.$(MEXSUFFIX) \ matlab/mex/astra_mex_projector3d_c.$(MEXSUFFIX) \ + matlab/mex/astra_mex_log_c.$(MEXSUFFIX) \ matlab/mex/astra_mex_data3d_c.$(MEXSUFFIX) diff --git a/matlab/mex/astra_mex_log_c.cpp b/matlab/mex/astra_mex_log_c.cpp new file mode 100644 index 0000000..14ae391 --- /dev/null +++ b/matlab/mex/astra_mex_log_c.cpp @@ -0,0 +1,302 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp + 2014-2015, CWI, Amsterdam + +Contact: astra@uantwerpen.be +Website: http://sf.net/projects/astra-toolbox + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +$Id$ +*/ + +/** \file astra_mex_algorithm_c.cpp + * + * \brief Creates and manages algorithms (reconstruction,projection,...). + */ +#include +#include "mexHelpFunctions.h" + +#include "astra/Logging.h" + +using namespace std; +using namespace astra; +//----------------------------------------------------------------------------------------- +/** astra_mex_log('debug', file, line, message); + * + * Log a debug message. + * file: Originating file name + * line: Originating line number + * message: Log message. + */ +void astra_mex_log_debug(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (nrhs < 4) { + mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); + return; + } + string filename = mexToString(prhs[1]); + int linenumber = (int)mxGetScalar(prhs[2]); + string message = mexToString(prhs[3]); + astra::CLogger::debug(filename.c_str(),linenumber,message.c_str()); +} + +//----------------------------------------------------------------------------------------- +/** astra_mex_log('info', file, line, message); + * + * Log an info message. + * file: Originating file name + * line: Originating line number + * message: Log message. + */ +void astra_mex_log_info(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (nrhs < 4) { + mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); + return; + } + string filename = mexToString(prhs[1]); + int linenumber = (int)mxGetScalar(prhs[2]); + string message = mexToString(prhs[3]); + astra::CLogger::info(filename.c_str(),linenumber,message.c_str()); +} + +//----------------------------------------------------------------------------------------- +/** astra_mex_log('warn', file, line, message); + * + * Log a warning message. + * file: Originating file name + * line: Originating line number + * message: Log message. + */ +void astra_mex_log_warn(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (nrhs < 4) { + mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); + return; + } + string filename = mexToString(prhs[1]); + int linenumber = (int)mxGetScalar(prhs[2]); + string message = mexToString(prhs[3]); + astra::CLogger::warn(filename.c_str(),linenumber,message.c_str()); +} + +//----------------------------------------------------------------------------------------- +/** astra_mex_log('error', file, line, message); + * + * Log an error message. + * file: Originating file name + * line: Originating line number + * message: Log message. + */ +void astra_mex_log_error(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (nrhs < 4) { + mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); + return; + } + string filename = mexToString(prhs[1]); + int linenumber = (int)mxGetScalar(prhs[2]); + string message = mexToString(prhs[3]); + astra::CLogger::error(filename.c_str(),linenumber,message.c_str()); +} + +//----------------------------------------------------------------------------------------- +/** astra_mex_log('enable', type); + * + * Enable logging. + * type: which output to enable ('all', 'file', 'screen') + */ +void astra_mex_log_enable(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (nrhs < 2) { + mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); + return; + } + string sType = mexToString(prhs[1]); + if(sType == "all"){ + astra::CLogger::enable(); + }else if(sType == "file"){ + astra::CLogger::enableFile(); + }else if(sType == "screen"){ + astra::CLogger::enableScreen(); + } else { + mexErrMsgTxt("Specify which output to enable ('all', 'file', or 'screen')"); + } +} + +//----------------------------------------------------------------------------------------- +/** astra_mex_log('disable', type); + * + * Disable logging. + * type: which output to disable ('all', 'file', 'screen') + */ +void astra_mex_log_disable(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (nrhs < 2) { + mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); + return; + } + string sType = mexToString(prhs[1]); + if(sType == "all"){ + astra::CLogger::disable(); + }else if(sType == "file"){ + astra::CLogger::disableFile(); + }else if(sType == "screen"){ + astra::CLogger::disableScreen(); + } else { + mexErrMsgTxt("Specify which output to disable ('all', 'file', or 'screen')"); + } +} + +//----------------------------------------------------------------------------------------- +/** astra_mex_log('format', type, fmt); + * + * Enable logging. + * type: which output to format ('file', 'screen') + * fmt: format string + * Here are the substitutions you may use: + * %f: Source file name generating the log call. + * %n: Source line number where the log call was made. + * %m: The message text sent to the logger (after printf formatting). + * %d: The current date, formatted using the logger's date format. + * %t: The current time, formatted using the logger's time format. + * %l: The log level (one of "DEBUG", "INFO", "WARN", or "ERROR"). + * %%: A literal percent sign. + * The default format string is "%d %t %f(%n): %l: %m\n". + */ +void astra_mex_log_format(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (nrhs < 3) { + mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); + return; + } + string sType = mexToString(prhs[1]); + string sFormat = mexToString(prhs[2]); + if (!sFormat.empty()) + { + char lastChar = *sFormat.rbegin(); + if (lastChar!='\n'){ + sFormat += '\n'; + } + }else{ + sFormat += '\n'; + } + if(sType == "file"){ + astra::CLogger::setFormatFile(sFormat.c_str()); + }else if(sType == "screen"){ + astra::CLogger::setFormatScreen(sFormat.c_str()); + } else { + mexErrMsgTxt("Specify which output to format ('file' or 'screen')"); + } +} + +//----------------------------------------------------------------------------------------- +/** astra_mex_log('output', type, output, level); + * + * Set output file / output screen. + * type: which output to set ('file', 'screen') + * output: which output file / screen to use: + * 'file': filename + * 'screen': 'stdout' or 'stderr' + * level: logging level to use ('debug', 'info', 'warn', or 'error') + */ +void astra_mex_log_output(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (nrhs < 4) { + mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); + return; + } + string sType = mexToString(prhs[1]); + string sOutput = mexToString(prhs[2]); + string sLevel = mexToString(prhs[3]); + log_level eLevel; + if(sLevel == "debug"){ + eLevel = LOG_DEBUG; + }else if(sLevel == "info"){ + eLevel = LOG_INFO; + }else if(sLevel == "warn"){ + eLevel = LOG_WARN; + }else if(sLevel == "error"){ + eLevel = LOG_ERROR; + }else{ + mexErrMsgTxt("Specify which log level to use ('debug', 'info', 'warn', or 'error')"); + } + if(sType == "file"){ + astra::CLogger::setOutputFile(sOutput.c_str(),eLevel); + }else if(sType == "screen"){ + int fd; + if(sOutput == "stdout"){ + fd=1; + }else if(sOutput == "stderr"){ + fd=2; + }else{ + mexErrMsgTxt("Specify which screen to output to ('stdout' or 'stderr')"); + } + astra::CLogger::setOutputScreen(fd,eLevel); + } else { + mexErrMsgTxt("Specify which output to set ('file' or 'screen')"); + } +} + +//----------------------------------------------------------------------------------------- +static void printHelp() +{ + mexPrintf("Please specify a mode of operation.\n"); + mexPrintf("Valid modes: debug, info, warn, error, enable, disable, format, output\n"); +} + +//----------------------------------------------------------------------------------------- +/** + * ... = astra_mex_log(mode, ...); + */ +void mexFunction(int nlhs, mxArray* plhs[], + int nrhs, const mxArray* prhs[]) +{ + // INPUT: Mode + string sMode = ""; + if (1 <= nrhs) { + sMode = mexToString(prhs[0]); + } else { + printHelp(); + return; + } + + // SWITCH (MODE) + if (sMode == "debug") { + astra_mex_log_debug(nlhs, plhs, nrhs, prhs); + }else if (sMode == "info") { + astra_mex_log_info(nlhs, plhs, nrhs, prhs); + }else if (sMode == "warn") { + astra_mex_log_warn(nlhs, plhs, nrhs, prhs); + }else if (sMode == "error") { + astra_mex_log_error(nlhs, plhs, nrhs, prhs); + }else if (sMode == "enable") { + astra_mex_log_enable(nlhs, plhs, nrhs, prhs); + }else if (sMode == "disable") { + astra_mex_log_disable(nlhs, plhs, nrhs, prhs); + }else if (sMode == "format") { + astra_mex_log_format(nlhs, plhs, nrhs, prhs); + }else if (sMode == "output") { + astra_mex_log_output(nlhs, plhs, nrhs, prhs); + } else { + printHelp(); + } + return; +} diff --git a/matlab/tools/astra_mex_log.m b/matlab/tools/astra_mex_log.m new file mode 100644 index 0000000..28cfa18 --- /dev/null +++ b/matlab/tools/astra_mex_log.m @@ -0,0 +1,33 @@ +function [varargout] = astra_mex_log(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% astra_mex_log. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the ASTRA Toolbox +% +% Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp +% 2014-2015, CWI, Amsterdam +% License: Open Source under GPLv3 +% Contact: astra@uantwerpen.be +% Website: http://sf.net/projects/astra-toolbox +%------------------------------------------------------------------------ +% $Id$ +if size(varargin,2)==2 && (strcmp(varargin{1},'debug') || strcmp(varargin{1},'info') || strcmp(varargin{1},'warn') || strcmp(varargin{1},'error')) + d = dbstack(1); + if size(d,1)==0 + astra_mex_log_c(varargin{1},'Unknown',0,varargin{2}) + else + astra_mex_log_c(varargin{1},d(1).file,d(1).line,varargin{2}) + end +else + if nargout == 0 + astra_mex_log_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end + else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_log_c(varargin{:}); + end +end \ No newline at end of file -- cgit v1.2.3 From f21700e00e81538d5510973a51b8ae97fb4a24dd Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 17:12:42 +0100 Subject: Enable logging to Matlab window using callback function Also introduces a mex initialize function that is called at the first invocation of any mex method. --- build/linux/Makefile.in | 1 + include/astra/Logging.h | 9 +++++- include/astra/clog.h | 53 ++++++++++++++++++++++++++++++++++ matlab/mex/astra_mex.cpp | 3 ++ matlab/mex/astra_mex_algorithm_c.cpp | 3 ++ matlab/mex/astra_mex_c.cpp | 3 ++ matlab/mex/astra_mex_data2d_c.cpp | 3 ++ matlab/mex/astra_mex_data3d_c.cpp | 3 ++ matlab/mex/astra_mex_log_c.cpp | 3 ++ matlab/mex/astra_mex_matrix_c.cpp | 3 ++ matlab/mex/astra_mex_projector3d_c.cpp | 3 ++ matlab/mex/astra_mex_projector_c.cpp | 3 ++ matlab/mex/mexInitFunctions.cpp | 24 +++++++++++++++ matlab/mex/mexInitFunctions.h | 6 ++++ src/Logging.cpp | 8 +++-- 15 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 matlab/mex/mexInitFunctions.cpp create mode 100644 matlab/mex/mexInitFunctions.h diff --git a/build/linux/Makefile.in b/build/linux/Makefile.in index f862114..49220df 100644 --- a/build/linux/Makefile.in +++ b/build/linux/Makefile.in @@ -216,6 +216,7 @@ TEST_OBJECTS=\ MATLAB_CXX_OBJECTS=\ matlab/mex/mexHelpFunctions.o \ matlab/mex/mexCopyDataHelpFunctions.o \ + matlab/mex/mexInitFunctions.o \ matlab/mex/mexDataManagerHelpFunctions.o MATLAB_MEX=\ diff --git a/include/astra/Logging.h b/include/astra/Logging.h index 5695663..e822c24 100644 --- a/include/astra/Logging.h +++ b/include/astra/Logging.h @@ -75,7 +75,7 @@ public: * @param ... * Any additional format arguments. */ - static void debug(const char *sfile, int sline, const char *fmt, ...); + static void debug(const char *sfile, int sline, const char *fmt, ...); static void info(const char *sfile, int sline, const char *fmt, ...); static void warn(const char *sfile, int sline, const char *fmt, ...); static void error(const char *sfile, int sline, const char *fmt, ...); @@ -143,6 +143,13 @@ public: static void disableScreen(); static void disableFile(); + /** + * Set callback function for logging to screen. + * @return whether callback was set succesfully. + * + */ + static bool setCallbackScreen(void (*cb)(const char *msg, size_t len)); + }; } diff --git a/include/astra/clog.h b/include/astra/clog.h index 4d8e39d..3b7e18b 100644 --- a/include/astra/clog.h +++ b/include/astra/clog.h @@ -231,6 +231,32 @@ int clog_set_date_fmt(int id, const char *fmt); */ int clog_set_fmt(int id, const char *fmt); +/** + * Set the callback function. + * + * @param cb + * The new callback function. + * + * @return + * Zero on success, non-zero on failure. + */ +int clog_set_cb(int id, void (*cb)(const char *msg, size_t len)); + +/** + * Set the file descriptor. + * + * @param id + * The identifier of the logger. + * + * @param fd + * The new file descriptor. + * + * @return + * Zero on success, non-zero on failure. + */ +int clog_set_fd(int id, int fd); + + /* * No need to read below this point. */ @@ -257,6 +283,9 @@ struct clog { /* Tracks whether the fd needs to be closed eventually. */ int opened; + + /* Callback function for each log message. */ + void (*cb)(const char *msg, size_t len); }; void _clog_err(const char *fmt, ...); @@ -314,6 +343,7 @@ clog_init_fd(int id, int fd) strcpy(logger->fmt, CLOG_DEFAULT_FORMAT); strcpy(logger->date_fmt, CLOG_DEFAULT_DATE_FORMAT); strcpy(logger->time_fmt, CLOG_DEFAULT_TIME_FORMAT); + logger->cb = NULL; _clog_loggers[id] = logger; return 0; @@ -344,6 +374,16 @@ clog_set_level(int id, enum clog_level level) return 0; } +int +clog_set_fd(int id, int fd) +{ + if (_clog_loggers[id] == NULL) { + return 1; + } + _clog_loggers[id]->fd = fd; + return 0; +} + int clog_set_time_fmt(int id, const char *fmt) { @@ -392,6 +432,18 @@ clog_set_fmt(int id, const char *fmt) return 0; } +int +clog_set_cb(int id, void (*cb)(const char *msg, size_t len)) +{ + struct clog *logger = _clog_loggers[id]; + if (logger == NULL) { + _clog_err("clog_set_cb: No such logger: %d\n", id); + return 1; + } + logger->cb = cb; + return 0; +} + /* Internal functions */ size_t @@ -563,6 +615,7 @@ _clog_log(const char *sfile, int sline, enum clog_level level, return; } result = write(logger->fd, message, strlen(message)); + if (logger->cb) logger->cb(message,strlen(message)); if (result == -1) { _clog_err("Unable to write to log file: %s\n", strerror(errno)); } diff --git a/matlab/mex/astra_mex.cpp b/matlab/mex/astra_mex.cpp index 0eb5662..4bf42dd 100644 --- a/matlab/mex/astra_mex.cpp +++ b/matlab/mex/astra_mex.cpp @@ -28,6 +28,7 @@ $Id$ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include "astra/Globals.h" @@ -104,6 +105,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // SWITCH (MODE) if (sMode == std::string("version")) { astra_mex_version(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/astra_mex_algorithm_c.cpp b/matlab/mex/astra_mex_algorithm_c.cpp index 669af8c..e4afa63 100644 --- a/matlab/mex/astra_mex_algorithm_c.cpp +++ b/matlab/mex/astra_mex_algorithm_c.cpp @@ -32,6 +32,7 @@ $Id$ */ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include "astra/Globals.h" #define USE_MATLAB_UNDOCUMENTED @@ -325,6 +326,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // SWITCH (MODE) if (sMode == "create") { astra_mex_algorithm_create(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/astra_mex_c.cpp b/matlab/mex/astra_mex_c.cpp index 760bd51..4a331f5 100644 --- a/matlab/mex/astra_mex_c.cpp +++ b/matlab/mex/astra_mex_c.cpp @@ -33,6 +33,7 @@ $Id$ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include "astra/Globals.h" @@ -128,6 +129,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // SWITCH (MODE) if (sMode == std::string("version")) { astra_mex_version(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/astra_mex_data2d_c.cpp b/matlab/mex/astra_mex_data2d_c.cpp index 5f79e98..9576896 100644 --- a/matlab/mex/astra_mex_data2d_c.cpp +++ b/matlab/mex/astra_mex_data2d_c.cpp @@ -32,6 +32,7 @@ $Id$ */ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include @@ -635,6 +636,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // SWITCH (MODE) if (sMode == std::string("get")) { astra_mex_data2d_get(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/astra_mex_data3d_c.cpp b/matlab/mex/astra_mex_data3d_c.cpp index 0a3f85d..32b0ba7 100644 --- a/matlab/mex/astra_mex_data3d_c.cpp +++ b/matlab/mex/astra_mex_data3d_c.cpp @@ -32,6 +32,7 @@ $Id$ */ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include "mexCopyDataHelpFunctions.h" #include "mexDataManagerHelpFunctions.h" @@ -371,6 +372,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // 3D data if (sMode == std::string("create")) { astra_mex_data3d_create(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/astra_mex_log_c.cpp b/matlab/mex/astra_mex_log_c.cpp index 14ae391..79fe3d5 100644 --- a/matlab/mex/astra_mex_log_c.cpp +++ b/matlab/mex/astra_mex_log_c.cpp @@ -32,6 +32,7 @@ $Id$ */ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include "astra/Logging.h" @@ -278,6 +279,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // SWITCH (MODE) if (sMode == "debug") { astra_mex_log_debug(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/astra_mex_matrix_c.cpp b/matlab/mex/astra_mex_matrix_c.cpp index 01ad08b..aa31383 100644 --- a/matlab/mex/astra_mex_matrix_c.cpp +++ b/matlab/mex/astra_mex_matrix_c.cpp @@ -32,6 +32,7 @@ $Id$ */ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include @@ -412,6 +413,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // SWITCH (MODE) if (sMode == std::string("get")) { astra_mex_matrix_get(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/astra_mex_projector3d_c.cpp b/matlab/mex/astra_mex_projector3d_c.cpp index 5381cf6..c3b547f 100644 --- a/matlab/mex/astra_mex_projector3d_c.cpp +++ b/matlab/mex/astra_mex_projector3d_c.cpp @@ -33,6 +33,7 @@ $Id$ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include "astra/Globals.h" @@ -403,6 +404,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // SWITCH (MODE) if (sMode == "create") { astra_mex_projector3d_create(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/astra_mex_projector_c.cpp b/matlab/mex/astra_mex_projector_c.cpp index 58cd953..204ba8e 100644 --- a/matlab/mex/astra_mex_projector_c.cpp +++ b/matlab/mex/astra_mex_projector_c.cpp @@ -34,6 +34,7 @@ $Id$ #include #include "mexHelpFunctions.h" +#include "mexInitFunctions.h" #include "astra/AstraObjectManager.h" #include "astra/Projector2D.h" @@ -476,6 +477,8 @@ void mexFunction(int nlhs, mxArray* plhs[], return; } + initASTRAMex(); + // SWITCH (MODE) if (sMode == "create") { astra_mex_projector_create(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/mexInitFunctions.cpp b/matlab/mex/mexInitFunctions.cpp new file mode 100644 index 0000000..d8a50d7 --- /dev/null +++ b/matlab/mex/mexInitFunctions.cpp @@ -0,0 +1,24 @@ +#include +#include "astra/Logging.h" + +bool mexIsInitialized=false; + +/** + * Callback to print log message to Matlab window. + * + */ +void logCallBack(const char *msg, size_t len){ + mexPrintf(msg); +} + +/** + * Initialize mex functions. + * + */ +void initASTRAMex(){ + if(mexIsInitialized) return; + if(!astra::CLogger::setCallbackScreen(&logCallBack)){ + mexErrMsgTxt("Error initializing mex functions."); + } + mexIsInitialized=true; +} diff --git a/matlab/mex/mexInitFunctions.h b/matlab/mex/mexInitFunctions.h new file mode 100644 index 0000000..f16e9c9 --- /dev/null +++ b/matlab/mex/mexInitFunctions.h @@ -0,0 +1,6 @@ +#ifndef _INC_ASTRA_MEX_INITFUNCTIONS +#define _INC_ASTRA_MEX_INITFUNCTIONS + +void initASTRAMex(); + +#endif \ No newline at end of file diff --git a/src/Logging.cpp b/src/Logging.cpp index 9011d37..9d7c219 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -124,8 +124,7 @@ void CLogger::_setLevel(int id, log_level m_eLevel) void CLogger::setOutputScreen(int fd, log_level m_eLevel) { _assureIsInitialized(); - clog_free(0); - clog_init_fd(0, fd); + clog_set_fd(0, fd); _setLevel(0,m_eLevel); } @@ -169,6 +168,11 @@ CLogger::CLogger() ; } +bool CLogger::setCallbackScreen(void (*cb)(const char *msg, size_t len)){ + _assureIsInitialized(); + return clog_set_cb(0,cb)==0; +} + bool CLogger::m_bEnabledScreen = true; bool CLogger::m_bEnabledFile = true; bool CLogger::m_bFileProvided = false; -- cgit v1.2.3 From 35fadf8641b05d357a37e8098b9a801ba0e815b9 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 17:22:41 +0100 Subject: Use a less verbose default fmt for screen logging and cleaner messages --- include/astra/clog.h | 8 ++++---- src/Config.cpp | 2 +- src/CudaForwardProjectionAlgorithm.cpp | 2 +- src/CudaReconstructionAlgorithm2D.cpp | 2 +- src/Logging.cpp | 1 + 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/astra/clog.h b/include/astra/clog.h index 3b7e18b..ce082df 100644 --- a/include/astra/clog.h +++ b/include/astra/clog.h @@ -299,10 +299,10 @@ extern struct clog *_clog_loggers[CLOG_MAX_LOGGERS]; #ifdef CLOG_MAIN const char *const CLOG_LEVEL_NAMES[] = { - "DEBUG", - "INFO", - "WARN", - "ERROR", + "Debug", + "Info", + "Warning", + "Error", }; int diff --git a/src/Config.cpp b/src/Config.cpp index 388cfdf..d860638 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -148,7 +148,7 @@ bool ConfigStackCheck::stopParsing() if (!errors.empty()) { ostringstream os; - os << "Warning: " << name << ": unused configuration options: " << errors; + os << name << ": unused configuration options: " << errors; ASTRA_WARN(os.str().c_str()); return false; } diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index 19cadd6..95abb62 100644 --- a/src/CudaForwardProjectionAlgorithm.cpp +++ b/src/CudaForwardProjectionAlgorithm.cpp @@ -106,7 +106,7 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - ASTRA_WARN("Warning: non-CUDA Projector2D passed to FP_CUDA"); + ASTRA_WARN("non-CUDA Projector2D passed to FP_CUDA"); } delete node; } diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp index 929f0f1..1c6b763 100644 --- a/src/CudaReconstructionAlgorithm2D.cpp +++ b/src/CudaReconstructionAlgorithm2D.cpp @@ -178,7 +178,7 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - ASTRA_WARN("Warning: non-CUDA Projector2D passed"); + ASTRA_WARN("non-CUDA Projector2D passed"); } delete node; } diff --git a/src/Logging.cpp b/src/Logging.cpp index 9d7c219..f95df0e 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -146,6 +146,7 @@ void CLogger::_assureIsInitialized() { clog_init_fd(0, 2); clog_set_level(0, CLOG_INFO); + clog_set_fmt(0, "%l: %m\n"); m_bInitialized = true; } } -- cgit v1.2.3 From 476fd5388da4aa6e23658460199e26e88e05dc5d Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 17:49:55 +0100 Subject: Only allow stdout and stderr for screen logging --- src/Logging.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Logging.cpp b/src/Logging.cpp index f95df0e..8290ca0 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -124,7 +124,11 @@ void CLogger::_setLevel(int id, log_level m_eLevel) void CLogger::setOutputScreen(int fd, log_level m_eLevel) { _assureIsInitialized(); - clog_set_fd(0, fd); + if(fd==1||fd==2){ + clog_set_fd(0, fd); + }else{ + error(__FILE__,__LINE__,"Invalid file descriptor"); + } _setLevel(0,m_eLevel); } -- cgit v1.2.3 From d1ad446669cea2a76d7146023e4862a1fdbf3e13 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 19 Mar 2015 16:47:23 +0100 Subject: Fix windows build --- include/astra/Logging.h | 4 +++- include/astra/clog.h | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/astra/Logging.h b/include/astra/Logging.h index e822c24..8e19ea4 100644 --- a/include/astra/Logging.h +++ b/include/astra/Logging.h @@ -29,6 +29,8 @@ $Id$ #ifndef _INC_ASTRA_LOGGING #define _INC_ASTRA_LOGGING +#include "astra/Globals.h" + #define ASTRA_DEBUG(...) astra::CLogger::debug(__FILE__,__LINE__, __VA_ARGS__) #define ASTRA_INFO(...) astra::CLogger::info(__FILE__,__LINE__, __VA_ARGS__) #define ASTRA_WARN(...) astra::CLogger::warn(__FILE__,__LINE__, __VA_ARGS__) @@ -44,7 +46,7 @@ enum log_level { LOG_ERROR }; -class CLogger +class _AstraExport CLogger { CLogger(); ~CLogger(); diff --git a/include/astra/clog.h b/include/astra/clog.h index ce082df..c0cbae4 100644 --- a/include/astra/clog.h +++ b/include/astra/clog.h @@ -71,7 +71,15 @@ #include #include #include +#ifndef _MSC_VER #include +#else +#include +#define open _open +#define close _close +#define write _write +#define snprintf _snprintf +#endif /* Number of loggers that can be defined. */ #define CLOG_MAX_LOGGERS 16 @@ -625,7 +633,10 @@ _clog_log(const char *sfile, int sline, enum clog_level level, if (dynbuf != buf) { free(dynbuf); } +#ifndef _MSC_VER + // FIXME fsync(logger->fd); +#endif } } -- cgit v1.2.3 From dc391ca18771ad2e2270aeeb1c0a5ee14319a38a Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 19 Mar 2015 17:47:12 +0100 Subject: Add MSVC project files --- astra_vc09.sln | 22 + astra_vc09.vcproj | 8 +- astra_vc11.sln | 22 + astra_vc11.vcxproj | 5 +- astra_vc11.vcxproj.filters | 7 +- build/msvc/gen.py | 38 +- matlab/mex/astra_mex_algorithm_vc09.vcproj | 8 + matlab/mex/astra_mex_algorithm_vc11.vcxproj | 2 + matlab/mex/astra_mex_data2d_vc09.vcproj | 8 + matlab/mex/astra_mex_data2d_vc11.vcxproj | 2 + matlab/mex/astra_mex_data3d_vc09.vcproj | 8 + matlab/mex/astra_mex_data3d_vc11.vcxproj | 2 + matlab/mex/astra_mex_log_vc09.vcproj | 612 ++++++++++++++++++++++++++ matlab/mex/astra_mex_log_vc11.vcxproj | 306 +++++++++++++ matlab/mex/astra_mex_matrix_vc09.vcproj | 8 + matlab/mex/astra_mex_matrix_vc11.vcxproj | 2 + matlab/mex/astra_mex_projector3d_vc09.vcproj | 8 + matlab/mex/astra_mex_projector3d_vc11.vcxproj | 2 + matlab/mex/astra_mex_projector_vc09.vcproj | 8 + matlab/mex/astra_mex_projector_vc11.vcxproj | 2 + matlab/mex/astra_mex_vc09.vcproj | 8 + matlab/mex/astra_mex_vc11.vcxproj | 2 + 22 files changed, 1080 insertions(+), 10 deletions(-) create mode 100644 matlab/mex/astra_mex_log_vc09.vcproj create mode 100644 matlab/mex/astra_mex_log_vc11.vcxproj diff --git a/astra_vc09.sln b/astra_vc09.sln index 691ad91..9b93a0f 100644 --- a/astra_vc09.sln +++ b/astra_vc09.sln @@ -43,6 +43,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "astra_mex_projector3d", "ma {12926444-6723-46A8-B388-12E65E0577FA} = {12926444-6723-46A8-B388-12E65E0577FA} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "astra_mex_log", "matlab\mex\astra_mex_log_vc09.vcproj", "{CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}" + ProjectSection(ProjectDependencies) = postProject + {12926444-6723-46A8-B388-12E65E0577FA} = {12926444-6723-46A8-B388-12E65E0577FA} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug_CUDA|Win32 = Debug_CUDA|Win32 @@ -183,6 +188,22 @@ Global {F94CCD79-AA11-42DF-AC8A-6C9D2238A883}.Release|Win32.Build.0 = Release|Win32 {F94CCD79-AA11-42DF-AC8A-6C9D2238A883}.Release|x64.ActiveCfg = Release|x64 {F94CCD79-AA11-42DF-AC8A-6C9D2238A883}.Release|x64.Build.0 = Release|x64 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Debug_CUDA|Win32.ActiveCfg = Debug_CUDA|Win32 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Debug_CUDA|Win32.Build.0 = Debug_CUDA|Win32 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Debug_CUDA|x64.ActiveCfg = Debug_CUDA|x64 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Debug_CUDA|x64.Build.0 = Debug_CUDA|x64 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Debug|Win32.ActiveCfg = Debug|Win32 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Debug|Win32.Build.0 = Debug|Win32 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Debug|x64.ActiveCfg = Debug|x64 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Debug|x64.Build.0 = Debug|x64 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Release_CUDA|Win32.ActiveCfg = Release_CUDA|Win32 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Release_CUDA|Win32.Build.0 = Release_CUDA|Win32 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Release_CUDA|x64.ActiveCfg = Release_CUDA|x64 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Release_CUDA|x64.Build.0 = Release_CUDA|x64 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Release|Win32.ActiveCfg = Release|Win32 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Release|Win32.Build.0 = Release|Win32 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Release|x64.ActiveCfg = Release|x64 + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -195,5 +216,6 @@ Global {9D041710-2119-4230-BCF2-5FBE753FDE49} = {33EF0AC5-B475-40BF-BAE5-67075B204D10} {4DD6056F-8EEE-4C9A-B2A9-923F01A32E97} = {33EF0AC5-B475-40BF-BAE5-67075B204D10} {F94CCD79-AA11-42DF-AC8A-6C9D2238A883} = {33EF0AC5-B475-40BF-BAE5-67075B204D10} + {CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8} = {33EF0AC5-B475-40BF-BAE5-67075B204D10} EndGlobalSection EndGlobal diff --git a/astra_vc09.vcproj b/astra_vc09.vcproj index f84eaaf..a56e4bc 100644 --- a/astra_vc09.vcproj +++ b/astra_vc09.vcproj @@ -920,6 +920,10 @@ RelativePath=".\include\astra\AstraObjectManager.h" > + + @@ -933,7 +937,7 @@ > - + @@ -640,7 +640,7 @@ - + @@ -669,6 +669,7 @@ + diff --git a/astra_vc11.vcxproj.filters b/astra_vc11.vcxproj.filters index c7e4db9..a597962 100644 --- a/astra_vc11.vcxproj.filters +++ b/astra_vc11.vcxproj.filters @@ -162,7 +162,7 @@ Global & Other\source - + Global & Other\source @@ -395,6 +395,9 @@ Global & Other\headers + + Global & Other\headers + Global & Other\headers @@ -404,7 +407,7 @@ Global & Other\headers - + Global & Other\headers diff --git a/build/msvc/gen.py b/build/msvc/gen.py index c770641..9f5e367 100644 --- a/build/msvc/gen.py +++ b/build/msvc/gen.py @@ -5,6 +5,10 @@ import os vcppguid = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" # C++ project siguid = "2150E333-8FDC-42A3-9474-1A3956D46DE8" # project group +# to generate a new uuid: +# +# import uuid +# uuid.uuid4().__str__().upper() def create_mex_project(name, uuid11, uuid09): return { "type": vcppguid, "name": name, "file11": "matlab\\mex\\" + name + "_vc11.vcxproj", "file09": "matlab\\mex\\" + name + "_vc09.vcproj", "uuid11": uuid11, "uuid09": uuid09, "files": [] } @@ -19,6 +23,7 @@ P3 = create_mex_project("astra_mex_data3d", "0BEC029B-0929-4BF9-BD8B-9C9806A5206 P4 = create_mex_project("astra_mex_matrix", "9D041710-2119-4230-BCF2-5FBE753FDE49", "9D041710-2119-4230-BCF2-5FBE753FDE49") P5 = create_mex_project("astra_mex_projector", "4DD6056F-8EEE-4C9A-B2A9-923F01A32E97", "4DD6056F-8EEE-4C9A-B2A9-923F01A32E97") P6 = create_mex_project("astra_mex_projector3d", "F94CCD79-AA11-42DF-AC8A-6C9D2238A883", "F94CCD79-AA11-42DF-AC8A-6C9D2238A883") +P7 = create_mex_project("astra_mex_log", "03B833F5-4FD6-4FBE-AAF4-E3305CD56D2E", "CA2840B3-DA68-41B5-AC57-F5DFD20ED8F8") F_astra_mex = { "type": siguid, "name": "astra_mex", @@ -26,18 +31,22 @@ F_astra_mex = { "type": siguid, "file09": "astra_mex", "uuid11": "5E99A109-374E-4102-BE9B-99BA1FA8AA30", "uuid09": "33EF0AC5-B475-40BF-BAE5-67075B204D10", - "entries": [ P0, P1, P2, P3, P4, P5, P6 ] } + "entries": [ P0, P1, P2, P3, P4, P5, P6, P7 ] } P0["files"] = [ "astra_mex_c.cpp", "mexHelpFunctions.cpp", "mexHelpFunctions.h", +"mexInitFunctions.cpp", +"mexInitFunctions.h", ] P1["files"] = [ "astra_mex_algorithm_c.cpp", "mexHelpFunctions.cpp", "mexHelpFunctions.h", +"mexInitFunctions.cpp", +"mexInitFunctions.h", ] P2["files"] = [ "astra_mex_data2d_c.cpp", @@ -47,6 +56,8 @@ P2["files"] = [ "mexCopyDataHelpFunctions.h", "mexDataManagerHelpFunctions.cpp", "mexDataManagerHelpFunctions.h", +"mexInitFunctions.cpp", +"mexInitFunctions.h", ] P3["files"] = [ "astra_mex_data3d_c.cpp", @@ -56,22 +67,38 @@ P3["files"] = [ "mexCopyDataHelpFunctions.h", "mexDataManagerHelpFunctions.cpp", "mexDataManagerHelpFunctions.h", +"mexInitFunctions.cpp", +"mexInitFunctions.h", ] P4["files"] = [ "astra_mex_matrix_c.cpp", "mexHelpFunctions.cpp", "mexHelpFunctions.h", +"mexInitFunctions.cpp", +"mexInitFunctions.h", ] P5["files"] = [ "astra_mex_projector_c.cpp", "mexHelpFunctions.cpp", "mexHelpFunctions.h", +"mexInitFunctions.cpp", +"mexInitFunctions.h", ] P6["files"] = [ "astra_mex_projector3d_c.cpp", "mexHelpFunctions.cpp", "mexHelpFunctions.h", +"mexInitFunctions.cpp", +"mexInitFunctions.h", ] +P7["files"] = [ +"astra_mex_log_c.cpp", +"mexHelpFunctions.cpp", +"mexHelpFunctions.h", +"mexInitFunctions.cpp", +"mexInitFunctions.h", +] + P_astra["filter_names"] = [ @@ -168,7 +195,7 @@ P_astra["filters"]["Global & Other\\source"] = [ "src\\Config.cpp", "src\\Fourier.cpp", "src\\Globals.cpp", -"src\\Logger.cpp", +"src\\Logging.cpp", "src\\PlatformDepSystemCode.cpp", "src\\Utilities.cpp", "src\\XMLDocument.cpp", @@ -295,10 +322,11 @@ P_astra["filters"]["Global & Other\\headers"] = [ "1c52efc8-a77e-4c72-b9be-f6429a87e6d7", "include\\astra\\AstraObjectFactory.h", "include\\astra\\AstraObjectManager.h", +"include\\astra\\clog.h", "include\\astra\\Config.h", "include\\astra\\Fourier.h", "include\\astra\\Globals.h", -"include\\astra\\Logger.h", +"include\\astra\\Logging.h", "include\\astra\\PlatformDepSystemCode.h", "include\\astra\\Singleton.h", "include\\astra\\TypeList.h", @@ -379,7 +407,7 @@ for f in P_astra["filters"]: P_astra["files"].extend(P_astra["filters"][f][1:]) P_astra["files"].sort() -projects = [ P_astra, F_astra_mex, P0, P1, P2, P3, P4, P5, P6 ] +projects = [ P_astra, F_astra_mex, P0, P1, P2, P3, P4, P5, P6, P7 ] bom = "\xef\xbb\xbf" @@ -1081,6 +1109,7 @@ if sys.argv[1] in ["vc11", "all"]: write_mex_project11(P4) write_mex_project11(P5) write_mex_project11(P6) + write_mex_project11(P7) if sys.argv[1] in ["vc09", "all"]: # HACK @@ -1095,3 +1124,4 @@ if sys.argv[1] in ["vc09", "all"]: write_mex_project09(P4) write_mex_project09(P5) write_mex_project09(P6) + write_mex_project09(P7) diff --git a/matlab/mex/astra_mex_algorithm_vc09.vcproj b/matlab/mex/astra_mex_algorithm_vc09.vcproj index 40fcf62..d5cebc0 100644 --- a/matlab/mex/astra_mex_algorithm_vc09.vcproj +++ b/matlab/mex/astra_mex_algorithm_vc09.vcproj @@ -598,6 +598,14 @@ RelativePath=".\mexHelpFunctions.h" > + + + + diff --git a/matlab/mex/astra_mex_algorithm_vc11.vcxproj b/matlab/mex/astra_mex_algorithm_vc11.vcxproj index a297e6d..c133e26 100644 --- a/matlab/mex/astra_mex_algorithm_vc11.vcxproj +++ b/matlab/mex/astra_mex_algorithm_vc11.vcxproj @@ -294,9 +294,11 @@ + + diff --git a/matlab/mex/astra_mex_data2d_vc09.vcproj b/matlab/mex/astra_mex_data2d_vc09.vcproj index 5611ccc..2c8a63f 100644 --- a/matlab/mex/astra_mex_data2d_vc09.vcproj +++ b/matlab/mex/astra_mex_data2d_vc09.vcproj @@ -614,6 +614,14 @@ RelativePath=".\mexDataManagerHelpFunctions.h" > + + + + diff --git a/matlab/mex/astra_mex_data2d_vc11.vcxproj b/matlab/mex/astra_mex_data2d_vc11.vcxproj index 0ecc6ce..636780a 100644 --- a/matlab/mex/astra_mex_data2d_vc11.vcxproj +++ b/matlab/mex/astra_mex_data2d_vc11.vcxproj @@ -296,11 +296,13 @@ + + diff --git a/matlab/mex/astra_mex_data3d_vc09.vcproj b/matlab/mex/astra_mex_data3d_vc09.vcproj index 74a35f4..fd861a3 100644 --- a/matlab/mex/astra_mex_data3d_vc09.vcproj +++ b/matlab/mex/astra_mex_data3d_vc09.vcproj @@ -614,6 +614,14 @@ RelativePath=".\mexDataManagerHelpFunctions.h" > + + + + diff --git a/matlab/mex/astra_mex_data3d_vc11.vcxproj b/matlab/mex/astra_mex_data3d_vc11.vcxproj index 8ac6f7c..1c3c620 100644 --- a/matlab/mex/astra_mex_data3d_vc11.vcxproj +++ b/matlab/mex/astra_mex_data3d_vc11.vcxproj @@ -296,11 +296,13 @@ + + diff --git a/matlab/mex/astra_mex_log_vc09.vcproj b/matlab/mex/astra_mex_log_vc09.vcproj new file mode 100644 index 0000000..0e0d469 --- /dev/null +++ b/matlab/mex/astra_mex_log_vc09.vcproj @@ -0,0 +1,612 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/matlab/mex/astra_mex_log_vc11.vcxproj b/matlab/mex/astra_mex_log_vc11.vcxproj new file mode 100644 index 0000000..0a939cf --- /dev/null +++ b/matlab/mex/astra_mex_log_vc11.vcxproj @@ -0,0 +1,306 @@ + + + + + Debug_CUDA + Win32 + + + Debug_CUDA + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release_CUDA + Win32 + + + Release_CUDA + x64 + + + Release + Win32 + + + Release + x64 + + + + astra_mex_log + {03B833F5-4FD6-4FBE-AAF4-E3305CD56D2E} + astraMatlab + + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>11.0.60610.1 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw32 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw64 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw32 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw64 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw32 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw64 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw32 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw64 + + + + MultiThreadedDebugDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + StreamingSIMDExtensions2 + Disabled + ASTRA_CUDA;__SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw32 + AstraCuda32D.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\win32\;..\..\bin\win32\Debug_CUDA;$(MATLAB_ROOT)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDebugDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + Disabled + ASTRA_CUDA;__SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw64 + AstraCuda64D.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\x64\;..\..\bin\x64\Debug_CUDA;$(MATLAB_ROOT)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDebugDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + StreamingSIMDExtensions2 + Disabled + __SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw32 + Astra32D.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\win32\;..\..\bin\win32\Debug;$(MATLAB_ROOT)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDebugDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + Disabled + __SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw64 + Astra64D.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\x64\;..\..\bin\x64\Debug;$(MATLAB_ROOT)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + StreamingSIMDExtensions2 + MaxSpeed + ASTRA_CUDA;__SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw32 + AstraCuda32.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\win32\;..\..\bin\win32\Release_CUDA;$(MATLAB_ROOT)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + MaxSpeed + ASTRA_CUDA;__SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw64 + AstraCuda64.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\x64\;..\..\bin\x64\Release_CUDA;$(MATLAB_ROOT)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + StreamingSIMDExtensions2 + MaxSpeed + __SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw32 + Astra32.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\win32\;..\..\bin\win32\Release;$(MATLAB_ROOT)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + MaxSpeed + __SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw64 + Astra64.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\x64\;..\..\bin\x64\Release;$(MATLAB_ROOT)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/matlab/mex/astra_mex_matrix_vc09.vcproj b/matlab/mex/astra_mex_matrix_vc09.vcproj index e4b57e9..3aa17a5 100644 --- a/matlab/mex/astra_mex_matrix_vc09.vcproj +++ b/matlab/mex/astra_mex_matrix_vc09.vcproj @@ -598,6 +598,14 @@ RelativePath=".\mexHelpFunctions.h" > + + + + diff --git a/matlab/mex/astra_mex_matrix_vc11.vcxproj b/matlab/mex/astra_mex_matrix_vc11.vcxproj index 91e32bd..abf86a7 100644 --- a/matlab/mex/astra_mex_matrix_vc11.vcxproj +++ b/matlab/mex/astra_mex_matrix_vc11.vcxproj @@ -294,9 +294,11 @@ + + diff --git a/matlab/mex/astra_mex_projector3d_vc09.vcproj b/matlab/mex/astra_mex_projector3d_vc09.vcproj index 09fa3c6..b9464a2 100644 --- a/matlab/mex/astra_mex_projector3d_vc09.vcproj +++ b/matlab/mex/astra_mex_projector3d_vc09.vcproj @@ -598,6 +598,14 @@ RelativePath=".\mexHelpFunctions.h" > + + + + diff --git a/matlab/mex/astra_mex_projector3d_vc11.vcxproj b/matlab/mex/astra_mex_projector3d_vc11.vcxproj index b8e8001..42eb0f1 100644 --- a/matlab/mex/astra_mex_projector3d_vc11.vcxproj +++ b/matlab/mex/astra_mex_projector3d_vc11.vcxproj @@ -294,9 +294,11 @@ + + diff --git a/matlab/mex/astra_mex_projector_vc09.vcproj b/matlab/mex/astra_mex_projector_vc09.vcproj index c0a5cd8..05c207f 100644 --- a/matlab/mex/astra_mex_projector_vc09.vcproj +++ b/matlab/mex/astra_mex_projector_vc09.vcproj @@ -598,6 +598,14 @@ RelativePath=".\mexHelpFunctions.h" > + + + + diff --git a/matlab/mex/astra_mex_projector_vc11.vcxproj b/matlab/mex/astra_mex_projector_vc11.vcxproj index 03a574d..e944949 100644 --- a/matlab/mex/astra_mex_projector_vc11.vcxproj +++ b/matlab/mex/astra_mex_projector_vc11.vcxproj @@ -294,9 +294,11 @@ + + diff --git a/matlab/mex/astra_mex_vc09.vcproj b/matlab/mex/astra_mex_vc09.vcproj index 9615f53..e4d7d07 100644 --- a/matlab/mex/astra_mex_vc09.vcproj +++ b/matlab/mex/astra_mex_vc09.vcproj @@ -598,6 +598,14 @@ RelativePath=".\mexHelpFunctions.h" > + + + + diff --git a/matlab/mex/astra_mex_vc11.vcxproj b/matlab/mex/astra_mex_vc11.vcxproj index 04df41c..f1324b4 100644 --- a/matlab/mex/astra_mex_vc11.vcxproj +++ b/matlab/mex/astra_mex_vc11.vcxproj @@ -294,9 +294,11 @@ + + -- cgit v1.2.3 From 2929e3eb5c398819163727d94981105f0c979f58 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 20 Mar 2015 14:00:10 +0100 Subject: Fix comment --- matlab/mex/astra_mex_log_c.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/mex/astra_mex_log_c.cpp b/matlab/mex/astra_mex_log_c.cpp index 79fe3d5..71b8234 100644 --- a/matlab/mex/astra_mex_log_c.cpp +++ b/matlab/mex/astra_mex_log_c.cpp @@ -26,9 +26,9 @@ along with the ASTRA Toolbox. If not, see . $Id$ */ -/** \file astra_mex_algorithm_c.cpp +/** \file astra_mex_log_c.cpp * - * \brief Creates and manages algorithms (reconstruction,projection,...). + * \brief Manages astra logging */ #include #include "mexHelpFunctions.h" -- cgit v1.2.3 From 10d35e96221675fc62299ba0cfdb0d731c9c7531 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 20 Mar 2015 14:03:44 +0100 Subject: Fix indentation --- cuda/2d/fft.cu | 22 ++--- matlab/mex/astra_mex_log_c.cpp | 184 ++++++++++++++++++++--------------------- 2 files changed, 103 insertions(+), 103 deletions(-) diff --git a/cuda/2d/fft.cu b/cuda/2d/fft.cu index 49c696c..2bfd493 100644 --- a/cuda/2d/fft.cu +++ b/cuda/2d/fft.cu @@ -137,7 +137,7 @@ static bool invokeCudaFFT(int _iProjectionCount, int _iDetectorCount, result = cufftPlan1d(&plan, _iDetectorCount, CUFFT_R2C, _iProjectionCount); if(result != CUFFT_SUCCESS) { - ASTRA_ERROR("Failed to plan 1d r2c fft"); + ASTRA_ERROR("Failed to plan 1d r2c fft"); return false; } @@ -146,7 +146,7 @@ static bool invokeCudaFFT(int _iProjectionCount, int _iDetectorCount, if(result != CUFFT_SUCCESS) { - ASTRA_ERROR("Failed to exec 1d r2c fft"); + ASTRA_ERROR("Failed to exec 1d r2c fft"); return false; } @@ -163,18 +163,18 @@ static bool invokeCudaIFFT(int _iProjectionCount, int _iDetectorCount, result = cufftPlan1d(&plan, _iDetectorCount, CUFFT_C2R, _iProjectionCount); if(result != CUFFT_SUCCESS) { - ASTRA_ERROR("Failed to plan 1d c2r fft"); + ASTRA_ERROR("Failed to plan 1d c2r fft"); return false; } // todo: why do we have to get rid of the const qualifier? result = cufftExecC2R(plan, (cufftComplex *)_pDevSourceComplex, - (cufftReal *)_pfDevTarget); + (cufftReal *)_pfDevTarget); cufftDestroy(plan); if(result != CUFFT_SUCCESS) { - ASTRA_ERROR("Failed to exec 1d c2r fft"); + ASTRA_ERROR("Failed to exec 1d c2r fft"); return false; } @@ -254,7 +254,7 @@ bool runCudaIFFT(int _iProjectionCount, const cufftComplex* _pDevSourceComplex, } rescaleInverseFourier(_iProjectionCount, _iFFTRealDetectorCount, - pfDevRealFFTTarget); + pfDevRealFFTTarget); SAFE_CALL(cudaMemset(_pfRealTarget, 0, sizeof(float) * _iProjectionCount * _iTargetPitch)); @@ -630,7 +630,7 @@ void genFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, } default: { - ASTRA_ERROR("Cannot serve requested filter"); + ASTRA_ERROR("Cannot serve requested filter"); } } @@ -764,13 +764,13 @@ void testCudaFFT() result = cufftPlan1d(&plan, iDetectorCount, CUFFT_R2C, iProjectionCount); if(result != CUFFT_SUCCESS) { - ASTRA_ERROR("Failed to plan 1d r2c fft"); + ASTRA_ERROR("Failed to plan 1d r2c fft"); } result = cufftExecR2C(plan, pfDevProj, pDevFourProj); if(result != CUFFT_SUCCESS) { - ASTRA_ERROR("Failed to exec 1d r2c fft"); + ASTRA_ERROR("Failed to exec 1d r2c fft"); } cufftDestroy(plan); @@ -794,13 +794,13 @@ void testCudaFFT() result = cufftPlan1d(&plan, iDetectorCount, CUFFT_C2R, iProjectionCount); if(result != CUFFT_SUCCESS) { - ASTRA_ERROR("Failed to plan 1d c2r fft"); + ASTRA_ERROR("Failed to plan 1d c2r fft"); } result = cufftExecC2R(plan, pDevFourProj, pfDevInFourProj); if(result != CUFFT_SUCCESS) { - ASTRA_ERROR("Failed to exec 1d c2r fft"); + ASTRA_ERROR("Failed to exec 1d c2r fft"); } cufftDestroy(plan); diff --git a/matlab/mex/astra_mex_log_c.cpp b/matlab/mex/astra_mex_log_c.cpp index 71b8234..ea4621e 100644 --- a/matlab/mex/astra_mex_log_c.cpp +++ b/matlab/mex/astra_mex_log_c.cpp @@ -52,10 +52,10 @@ void astra_mex_log_debug(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prh mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); return; } - string filename = mexToString(prhs[1]); - int linenumber = (int)mxGetScalar(prhs[2]); - string message = mexToString(prhs[3]); - astra::CLogger::debug(filename.c_str(),linenumber,message.c_str()); + string filename = mexToString(prhs[1]); + int linenumber = (int)mxGetScalar(prhs[2]); + string message = mexToString(prhs[3]); + astra::CLogger::debug(filename.c_str(),linenumber,message.c_str()); } //----------------------------------------------------------------------------------------- @@ -72,10 +72,10 @@ void astra_mex_log_info(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); return; } - string filename = mexToString(prhs[1]); - int linenumber = (int)mxGetScalar(prhs[2]); - string message = mexToString(prhs[3]); - astra::CLogger::info(filename.c_str(),linenumber,message.c_str()); + string filename = mexToString(prhs[1]); + int linenumber = (int)mxGetScalar(prhs[2]); + string message = mexToString(prhs[3]); + astra::CLogger::info(filename.c_str(),linenumber,message.c_str()); } //----------------------------------------------------------------------------------------- @@ -92,10 +92,10 @@ void astra_mex_log_warn(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); return; } - string filename = mexToString(prhs[1]); - int linenumber = (int)mxGetScalar(prhs[2]); - string message = mexToString(prhs[3]); - astra::CLogger::warn(filename.c_str(),linenumber,message.c_str()); + string filename = mexToString(prhs[1]); + int linenumber = (int)mxGetScalar(prhs[2]); + string message = mexToString(prhs[3]); + astra::CLogger::warn(filename.c_str(),linenumber,message.c_str()); } //----------------------------------------------------------------------------------------- @@ -112,10 +112,10 @@ void astra_mex_log_error(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prh mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); return; } - string filename = mexToString(prhs[1]); - int linenumber = (int)mxGetScalar(prhs[2]); - string message = mexToString(prhs[3]); - astra::CLogger::error(filename.c_str(),linenumber,message.c_str()); + string filename = mexToString(prhs[1]); + int linenumber = (int)mxGetScalar(prhs[2]); + string message = mexToString(prhs[3]); + astra::CLogger::error(filename.c_str(),linenumber,message.c_str()); } //----------------------------------------------------------------------------------------- @@ -130,15 +130,15 @@ void astra_mex_log_enable(int nlhs, mxArray* plhs[], int nrhs, const mxArray* pr mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); return; } - string sType = mexToString(prhs[1]); - if(sType == "all"){ - astra::CLogger::enable(); - }else if(sType == "file"){ - astra::CLogger::enableFile(); - }else if(sType == "screen"){ - astra::CLogger::enableScreen(); - } else { - mexErrMsgTxt("Specify which output to enable ('all', 'file', or 'screen')"); + string sType = mexToString(prhs[1]); + if(sType == "all"){ + astra::CLogger::enable(); + }else if(sType == "file"){ + astra::CLogger::enableFile(); + }else if(sType == "screen"){ + astra::CLogger::enableScreen(); + } else { + mexErrMsgTxt("Specify which output to enable ('all', 'file', or 'screen')"); } } @@ -154,15 +154,15 @@ void astra_mex_log_disable(int nlhs, mxArray* plhs[], int nrhs, const mxArray* p mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); return; } - string sType = mexToString(prhs[1]); - if(sType == "all"){ - astra::CLogger::disable(); - }else if(sType == "file"){ - astra::CLogger::disableFile(); - }else if(sType == "screen"){ - astra::CLogger::disableScreen(); - } else { - mexErrMsgTxt("Specify which output to disable ('all', 'file', or 'screen')"); + string sType = mexToString(prhs[1]); + if(sType == "all"){ + astra::CLogger::disable(); + }else if(sType == "file"){ + astra::CLogger::disableFile(); + }else if(sType == "screen"){ + astra::CLogger::disableScreen(); + } else { + mexErrMsgTxt("Specify which output to disable ('all', 'file', or 'screen')"); } } @@ -188,23 +188,23 @@ void astra_mex_log_format(int nlhs, mxArray* plhs[], int nrhs, const mxArray* pr mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); return; } - string sType = mexToString(prhs[1]); - string sFormat = mexToString(prhs[2]); - if (!sFormat.empty()) - { - char lastChar = *sFormat.rbegin(); - if (lastChar!='\n'){ - sFormat += '\n'; - } - }else{ - sFormat += '\n'; - } - if(sType == "file"){ - astra::CLogger::setFormatFile(sFormat.c_str()); - }else if(sType == "screen"){ - astra::CLogger::setFormatScreen(sFormat.c_str()); - } else { - mexErrMsgTxt("Specify which output to format ('file' or 'screen')"); + string sType = mexToString(prhs[1]); + string sFormat = mexToString(prhs[2]); + if (!sFormat.empty()) + { + char lastChar = *sFormat.rbegin(); + if (lastChar!='\n'){ + sFormat += '\n'; + } + }else{ + sFormat += '\n'; + } + if(sType == "file"){ + astra::CLogger::setFormatFile(sFormat.c_str()); + }else if(sType == "screen"){ + astra::CLogger::setFormatScreen(sFormat.c_str()); + } else { + mexErrMsgTxt("Specify which output to format ('file' or 'screen')"); } } @@ -224,35 +224,35 @@ void astra_mex_log_output(int nlhs, mxArray* plhs[], int nrhs, const mxArray* pr mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n"); return; } - string sType = mexToString(prhs[1]); - string sOutput = mexToString(prhs[2]); - string sLevel = mexToString(prhs[3]); - log_level eLevel; - if(sLevel == "debug"){ - eLevel = LOG_DEBUG; - }else if(sLevel == "info"){ - eLevel = LOG_INFO; - }else if(sLevel == "warn"){ - eLevel = LOG_WARN; - }else if(sLevel == "error"){ - eLevel = LOG_ERROR; - }else{ - mexErrMsgTxt("Specify which log level to use ('debug', 'info', 'warn', or 'error')"); - } - if(sType == "file"){ - astra::CLogger::setOutputFile(sOutput.c_str(),eLevel); - }else if(sType == "screen"){ - int fd; - if(sOutput == "stdout"){ - fd=1; - }else if(sOutput == "stderr"){ - fd=2; - }else{ - mexErrMsgTxt("Specify which screen to output to ('stdout' or 'stderr')"); - } - astra::CLogger::setOutputScreen(fd,eLevel); - } else { - mexErrMsgTxt("Specify which output to set ('file' or 'screen')"); + string sType = mexToString(prhs[1]); + string sOutput = mexToString(prhs[2]); + string sLevel = mexToString(prhs[3]); + log_level eLevel; + if(sLevel == "debug"){ + eLevel = LOG_DEBUG; + }else if(sLevel == "info"){ + eLevel = LOG_INFO; + }else if(sLevel == "warn"){ + eLevel = LOG_WARN; + }else if(sLevel == "error"){ + eLevel = LOG_ERROR; + }else{ + mexErrMsgTxt("Specify which log level to use ('debug', 'info', 'warn', or 'error')"); + } + if(sType == "file"){ + astra::CLogger::setOutputFile(sOutput.c_str(),eLevel); + }else if(sType == "screen"){ + int fd; + if(sOutput == "stdout"){ + fd=1; + }else if(sOutput == "stderr"){ + fd=2; + }else{ + mexErrMsgTxt("Specify which screen to output to ('stdout' or 'stderr')"); + } + astra::CLogger::setOutputScreen(fd,eLevel); + } else { + mexErrMsgTxt("Specify which output to set ('file' or 'screen')"); } } @@ -286,18 +286,18 @@ void mexFunction(int nlhs, mxArray* plhs[], astra_mex_log_debug(nlhs, plhs, nrhs, prhs); }else if (sMode == "info") { astra_mex_log_info(nlhs, plhs, nrhs, prhs); - }else if (sMode == "warn") { - astra_mex_log_warn(nlhs, plhs, nrhs, prhs); - }else if (sMode == "error") { - astra_mex_log_error(nlhs, plhs, nrhs, prhs); - }else if (sMode == "enable") { - astra_mex_log_enable(nlhs, plhs, nrhs, prhs); - }else if (sMode == "disable") { - astra_mex_log_disable(nlhs, plhs, nrhs, prhs); - }else if (sMode == "format") { - astra_mex_log_format(nlhs, plhs, nrhs, prhs); - }else if (sMode == "output") { - astra_mex_log_output(nlhs, plhs, nrhs, prhs); + }else if (sMode == "warn") { + astra_mex_log_warn(nlhs, plhs, nrhs, prhs); + }else if (sMode == "error") { + astra_mex_log_error(nlhs, plhs, nrhs, prhs); + }else if (sMode == "enable") { + astra_mex_log_enable(nlhs, plhs, nrhs, prhs); + }else if (sMode == "disable") { + astra_mex_log_disable(nlhs, plhs, nrhs, prhs); + }else if (sMode == "format") { + astra_mex_log_format(nlhs, plhs, nrhs, prhs); + }else if (sMode == "output") { + astra_mex_log_output(nlhs, plhs, nrhs, prhs); } else { printHelp(); } -- cgit v1.2.3 From 9ba78fcfa3dec88928df33be26821e3fd5a10727 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 20 Mar 2015 14:57:59 +0100 Subject: Use FlushFileBuffers in Windows --- include/astra/clog.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/astra/clog.h b/include/astra/clog.h index c0cbae4..6ffb660 100644 --- a/include/astra/clog.h +++ b/include/astra/clog.h @@ -74,6 +74,8 @@ #ifndef _MSC_VER #include #else +#define WIN32_LEAN_AND_MEAN +#include #include #define open _open #define close _close @@ -634,8 +636,13 @@ _clog_log(const char *sfile, int sline, enum clog_level level, free(dynbuf); } #ifndef _MSC_VER - // FIXME fsync(logger->fd); +#else + HANDLE h = (HANDLE) _get_osfhandle(logger->fd); + if (h != INVALID_HANDLE_VALUE) { + // This call will fail on a console fd, but that's ok. + FlushFileBuffers(h); + } #endif } } -- cgit v1.2.3