Skip to content

Commit

Permalink
refs #4201 Fixed minor conflict
Browse files Browse the repository at this point in the history
Merge branch 'master' of https://github.com/mantidproject/mantid

Conflicts:
	Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/ConvertToMDEventsMethods.h
  • Loading branch information
abuts committed Jan 2, 2012
2 parents d233f21 + 333fe1a commit 26784d2
Show file tree
Hide file tree
Showing 494 changed files with 6,608 additions and 2,968 deletions.
5 changes: 5 additions & 0 deletions Code/Mantid/Build/CMake/CommonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ if ( CMAKE_COMPILER_IS_GNUCXX )
include ( GNUSetup )
endif ()

###########################################################################
# The inital stuff for cppcheck
###########################################################################
find_package ( Cppcheck )

###########################################################################
# Set up the unit tests target
###########################################################################
Expand Down
121 changes: 121 additions & 0 deletions Code/Mantid/Build/CMake/FindCppcheck.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
file(TO_CMAKE_PATH "${CPPCHECK_ROOT_DIR}" CPPCHECK_ROOT_DIR)
set(CPPCHECK_ROOT_DIR
"${CPPCHECK_ROOT_DIR}"
CACHE
PATH
"Path to search for cppcheck")

# cppcheck app bundles on Mac OS X are GUI, we want command line only
set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE})
set(CMAKE_FIND_APPBUNDLE NEVER)

if(CPPCHECK_EXECUTABLE AND NOT EXISTS "${CPPCHECK_EXECUTABLE}")
set(CPPCHECK_EXECUTABLE "notfound" CACHE PATH FORCE "")
endif()

# If we have a custom path, look there first.
if(CPPCHECK_ROOT_DIR)
find_program(CPPCHECK_EXECUTABLE
NAMES
cppcheck
cli
PATHS
"${CPPCHECK_ROOT_DIR}"
PATH_SUFFIXES
cli
NO_DEFAULT_PATH)
endif()

find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)

if(MSVC)
set(CPPCHECK_TEMPLATE_ARG --template vs)
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
elseif(CMAKE_COMPILER_IS_GNUCXX)
set(CPPCHECK_TEMPLATE_ARG --template gcc)
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
else()
set(CPPCHECK_TEMPLATE_ARG --template gcc)
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
endif()

if(CPPCHECK_EXECUTABLE OR CPPCHECK_MARK_AS_ADVANCED)
mark_as_advanced(CPPCHECK_ROOT_DIR)
endif()

if(CPPCHECK_EXECUTABLE)
if(NOT TARGET cppcheck)
add_custom_target(cppcheck)
set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
execute_process ( COMMAND ${CPPCHECK_EXECUTABLE} --version
OUTPUT_VARIABLE CPPCHECK_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE )
string ( TOUPPER ${CPPCHECK_VERSION} CPPCHECK_VERSION )
string ( REPLACE "CPPCHECK" "" CPPCHECK_VERSION ${CPPCHECK_VERSION} )
string ( STRIP ${CPPCHECK_VERSION} CPPCHECK_VERSION )
message ( STATUS "cppcheck version: ${CPPCHECK_VERSION}" )
endif()

mark_as_advanced(CPPCHECK_EXECUTABLE)
set ( CPPCHECK_ARGS "--enable=all" CACHE STRING "Arguments for running cppcheck" )
set ( CPPCHECK_GENERATE_XML OFF CACHE BOOL "Generate xml output files from cppcheck" )

function(add_cppcheck _name) # additional arguments are files to ignore
if(NOT TARGET ${_name})
message(FATAL_ERROR
"add_cppcheck given a target name that does not exist: '${_name}' !")
endif()

set (_cppcheck_ignores)
foreach (f ${ARGN})
list ( APPEND _cppcheck_ignores ${CMAKE_CURRENT_SOURCE_DIR}/${f} )
endforeach()

if(CPPCHECK_EXECUTABLE)
get_target_property(_cppcheck_sources "${_name}" SOURCES)
set(_files)
foreach(_source ${_cppcheck_sources})
get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
if("${_cppcheck_lang}" MATCHES "CXX")
list(FIND _cppcheck_ignores "${_cppcheck_loc}" _cppcheck_ignore_index)
if (_cppcheck_ignore_index LESS 0)
list(APPEND _files "${_cppcheck_loc}")
endif (_cppcheck_ignore_index LESS 0)
endif()
endforeach()

if ( NOT _files)
return() # nothing to check
endif ( NOT _files)

# set the standard arguments
set ( _cppcheck_args )
list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} ${CPPCHECK_ARGS} )
list ( APPEND _cppcheck_args "-I" ${CMAKE_CURRENT_SOURCE_DIR} "-I" "${CMAKE_CURRENT_SOURCE_DIR}/inc" )

# add the target
if (CPPCHECK_GENERATE_XML )
add_custom_target( cppcheck_${_name}
COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} --xml --xml-version=2 ${_files} 2> ${CMAKE_BINARY_DIR}/cppcheck-${_name}.xml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${_files}
COMMENT "cppcheck_${_name}: Running cppcheck to generate cppcheck-${_name}.xml"
)
else (CPPCHECK_GENERATE_XML )
add_custom_target( cppcheck_${_name}
COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_files}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${_files}
COMMENT "cppcheck_${_name}: Running cppcheck on ${_name} source files"
)
endif (CPPCHECK_GENERATE_XML )
add_dependencies ( cppcheck cppcheck_${_name} )

endif()

endfunction()
66 changes: 58 additions & 8 deletions Code/Mantid/Build/python_export_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import optparse
import os
import re
import sys

def get_exportfile(headerfile):
"""
Expand All @@ -17,6 +18,15 @@ def get_exportfile(headerfile):
exportfile = os.path.join(exportpath, os.path.basename(headerfile).replace('.h','.cpp'))
return exportfile

def get_unittest_file(headerfile):
"""
For the given header path create a path to the corresponding
Python unit test file
"""
frameworkdir = get_frameworkdir(headerfile)
testpath = os.path.join(frameworkdir, 'PythonInterface', 'test', 'python')
return os.path.join(testpath, os.path.basename(headerfile).replace('.h','Test.py'))

def get_submodule(headerfile):
"""
Returns the corresponding Python submodule for the header
Expand Down Expand Up @@ -70,13 +80,12 @@ def get_modulepath(frameworkdir, submodule):
"""
return os.path.join(frameworkdir, 'PythonInterface', 'mantid',submodule)


def write_export_file(headerfile, overwrite):
"""Write the export cpp file
"""
# Where are we writing the output
exportfile = get_exportfile(headerfile)
print 'Writing export to \"%s\" '% exportfile
print 'Writing export file \"%s\" '% os.path.basename(exportfile)
if os.path.exists(exportfile) and not overwrite:
raise RuntimeError("Export file '%s' already exists, use the --overwrite option to overwrite the file." % exportfile)

Expand All @@ -101,18 +110,53 @@ def write_export_file(headerfile, overwrite):
cppfile.write(cppcode % {'header':include, 'namespace':namespace,'class':classname})
cppfile.close()

print 'Generated export file "%s"' % exportfile
print 'Generated export file "%s"' % os.path.basename(exportfile)
print
print " ** Add this to the EXPORT_FILES variable in '%s'" % \
os.path.join(get_modulepath(get_frameworkdir(headerfile), get_submodule(headerfile)), 'CMakeLists.txt')

return exportfile

def write_unittest(headerfile, overwrite):
"""
Write a unit test for the given header
"""
filename = get_unittest_file(headerfile)
print 'Writing unit test \"%s\" '% os.path.basename(filename)
if os.path.exists(filename) and not overwrite:
raise RuntimeError("A unit test file '%s' already exists, use the --overwrite-test option to overwrite the file." % filename)

classname = get_classname(headerfile)
pytest = \
"""import unittest
from mantid import %(classname)s
class %(classname)sTest(object):
def test_something(self):
self.fail("Test something")
if __name__ == '__main__':
unittest.main()
"""
unittest = open(filename, 'w')
unittest.write(pytest % {'classname':classname})
unittest.close()

print 'Generated unit test file "%s"' % os.path.basename(filename)
print
print " ** Add this to the TEST_PY_FILES variable in '%s'" % \
os.path.join('PythonInterface', 'CMakeLists.txt')

def main():
"""Main function
"""
parser = optparse.OptionParser(usage="usage: %prog [options] headerfile ", description="Creates a simple template for exporting a class to Python")
parser = optparse.OptionParser(usage="usage: %prog [options] headerfile ", description="Creates a simple template for exporting a class to Python along with a unit test")
parser.add_option("--overwrite", "-o", dest='overwrite', action='store_true', default=False, help='If the file already exists, overwrite it')
parser.add_option("--export-only", "-e", dest='export_only', action='store_true', default=False, help='If True only attempt to generate the export file')
parser.add_option("--test-only", "-t", dest='test_only', action='store_true', default=False, help='If True only attempt to generate the unit test')
parser.add_option("--overwrite-test", "-w", dest='overwrite_test', action='store_true', default=False, help='If true overwrite a test file if it exists')

(options, args) = parser.parse_args()
if len(args) != 1:
parser.error("Incorrect number of arguments")
Expand All @@ -121,11 +165,17 @@ def main():
if not os.path.exists(headerfile):
parser.error("Invalid header path")

# Options
overwrite = options.overwrite

# Sanity
if options.export_only and options.test_only:
parser.error("The export_only and test_only options are mutually exclusive, please specify only one.")

# Generate
write_export_file(os.path.abspath(headerfile), overwrite)
if not options.test_only:
write_export_file(os.path.abspath(headerfile), options.overwrite)

# Unit test
if not options.export_only:
write_unittest(os.path.abspath(headerfile), options.overwrite_test)

if __name__ == '__main__':
main()
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ endif ()
ADD_PRECOMPILED_HEADER( inc/MantidAPI/PrecompiledHeader.h MantidAPI src/PrecompiledHeader.cpp SRC_FILES INC_FILES )
# Add the target for this directory
add_library ( API ${SRC_FILES} ${INC_FILES})
add_cppcheck ( API )
# Set the name of the generated library
set_target_properties ( API PROPERTIES OUTPUT_NAME MantidAPI
COMPILE_DEFINITIONS IN_MANTID_API )
Expand Down
36 changes: 14 additions & 22 deletions Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef BOXCONTROLLER_H_
#define BOXCONTROLLER_H_

#include "MantidKernel/DiskMRU.h"
#include "MantidKernel/DiskBuffer.h"
#include "MantidKernel/MultiThreaded.h"
#include "MantidKernel/System.h"
#include "MantidKernel/ThreadPool.h"
Expand Down Expand Up @@ -35,7 +35,7 @@ namespace API
* @return BoxController instance
*/
BoxController(size_t nd)
:nd(nd), m_maxId(0), m_file(NULL), m_diskMRU(), m_useMRU(true)
:nd(nd), m_maxId(0), m_file(NULL), m_diskMRU(), m_useWriteBuffer(true)
{
// TODO: Smarter ways to determine all of these values
m_maxDepth = 5;
Expand Down Expand Up @@ -366,37 +366,33 @@ namespace API
void closeFile(bool deleteFile = false);

//-----------------------------------------------------------------------------------
/** Return the disk MRU for disk caching */
const Mantid::Kernel::DiskMRU & getDiskMRU() const
/** Return the DiskBuffer for disk caching */
const Mantid::Kernel::DiskBuffer & getDiskBuffer() const
{ return m_diskMRU; }

/** Return the disk MRU for disk caching */
Mantid::Kernel::DiskMRU & getDiskMRU()
/** Return the DiskBuffer for disk caching */
Mantid::Kernel::DiskBuffer & getDiskBuffer()
{ return m_diskMRU; }

/** Return true if the MRU should be used */
bool useMRU() const
{ return m_useMRU; }
/** Return true if the DiskBuffer should be used */
bool useWriteBuffer() const
{ return m_useWriteBuffer; }

//-----------------------------------------------------------------------------------
/** Set the memory-caching parameters for a file-backed
* MDEventWorkspace.
*
* @param bytesPerEvent :: sizeof(MDLeanEvent) that is in the workspace
* @param mruSize :: number of EVENTS to keep in the MRU.
* @param writeBufferSize :: number of EVENTS to accumulate before performing a disk write.
* @param smallBufferSize :: number of EVENTS to allow to stay in memory for small objects.
*/
void setCacheParameters(size_t bytesPerEvent, uint64_t mruSize, uint64_t writeBufferSize, uint64_t smallBufferSize)
void setCacheParameters(size_t bytesPerEvent,uint64_t writeBufferSize)
{
if (bytesPerEvent == 0)
throw std::invalid_argument("Size of an event cannot be == 0.");
// Save the values
m_diskMRU.setMruSize(mruSize);
m_diskMRU.setWriteBufferSize(writeBufferSize);
m_diskMRU.setSmallBufferSize(smallBufferSize);
// If all caches are 0, don't use the MRU at all
m_useMRU = !(mruSize==0 && writeBufferSize==0 && smallBufferSize==0);
m_useWriteBuffer = !(writeBufferSize==0);
m_bytesPerEvent = bytesPerEvent;
}

Expand Down Expand Up @@ -474,14 +470,10 @@ namespace API
::NeXus::File * m_file;

/// Instance of the disk-caching MRU list.
mutable Mantid::Kernel::DiskMRU m_diskMRU;
mutable Mantid::Kernel::DiskBuffer m_diskMRU;

/// Do we use the DiskMRU at all?
bool m_useMRU;

public:
/// Mutex for locking access to the file, for file-back-end MDBoxes.
Mantid::Kernel::Mutex fileMutex;
/// Do we use the DiskBuffer at all?
bool m_useWriteBuffer;

private:
/// Number of bytes in a single MDLeanEvent<> of the workspace.
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/Column.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Column_DllExport Column

/// Returns typeid for the pointer type to the data element in the column
virtual const std::type_info& get_pointer_type_info()const = 0;
/// Is the column to be read-only? @retur true by default.
/// Is the column to be read-only? @return true by default.
virtual bool getReadOnly() const
{ return true; }

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/ICatalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Mantid
//forward declarations
namespace ICat
{
class CSearchParam;
class CatalogSearchParam;
}

namespace API
Expand Down Expand Up @@ -50,7 +50,7 @@ class DLLExport ICatalog
/// logout from catalog
virtual void logout()=0;
///Search investigations
virtual void search(const ICat::CSearchParam&,ITableWorkspace_sptr &)=0;
virtual void search(const ICat::CatalogSearchParam&,ITableWorkspace_sptr &)=0;
/// search logged in users data
virtual void myData(ITableWorkspace_sptr &)=0;
/// get datasets.
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class MANTID_API_DLL IFunction
virtual const std::string category() const { return "General";}

/// Function you want to fit to.
/// @param out :: The buffer for writing the calculated values. Must be big enough to accept dataSize() values
/// @param domain :: The buffer for writing the calculated values. Must be big enough to accept dataSize() values
virtual void function(FunctionDomain& domain)const = 0;
/// Derivatives of function with respect to active parameters
virtual void functionDeriv(FunctionDomain& domain, Jacobian& jacobian);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IPeaksWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace API

//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param peak :: Peak object to add (copy) into this.
* @param ipeak :: Peak object to add (copy) into this.
*/
virtual void addPeak(const IPeak& ipeak) = 0;

Expand Down

0 comments on commit 26784d2

Please sign in to comment.