diff --git a/OscProbCalcer/CMakeLists.txt b/OscProbCalcer/CMakeLists.txt index ca6b973..1538085 100644 --- a/OscProbCalcer/CMakeLists.txt +++ b/OscProbCalcer/CMakeLists.txt @@ -1,6 +1,6 @@ -set(HEADERS OscProbCalcerBase.h) +set(HEADERS OscProbCalcerBase.h OscProbCalcerFactory.h) -add_library(OscProbCalcer SHARED OscProbCalcerBase.cpp) +add_library(OscProbCalcer SHARED OscProbCalcerBase.cpp OscProbCalcerFactory.cpp) target_link_libraries(OscProbCalcer yaml-cpp NuOscillatorCompilerOptions) @@ -22,7 +22,7 @@ install(DIRECTORY ${yaml-cpp_SOURCE_DIR}/include/ if(${UseCUDAProb3} EQUAL 1) target_sources(OscProbCalcer PRIVATE OscProbCalcer_CUDAProb3.cpp) if(${UseGPU} EQUAL 1) - set_source_files_properties(OscProbCalcer_CUDAProb3.cpp PROPERTIES LANGUAGE CUDA) + set_source_files_properties(OscProbCalcer_CUDAProb3.cpp PROPERTIES LANGUAGE CUDA) endif() target_include_directories(OscProbCalcer PRIVATE ${CUDAProb3_SOURCE_DIR}) list(APPEND HEADERS OscProbCalcer_CUDAProb3.h) diff --git a/OscProbCalcer/OscProbCalcerFactory.cpp b/OscProbCalcer/OscProbCalcerFactory.cpp new file mode 100644 index 0000000..5fc80ae --- /dev/null +++ b/OscProbCalcer/OscProbCalcerFactory.cpp @@ -0,0 +1,96 @@ +#include "OscProbCalcerFactory.h" + +#if UseCUDAProb3==1 +#include "OscProbCalcer/OscProbCalcer_CUDAProb3.h" +#endif + +#if UseCUDAProb3Linear==1 +#include "OscProbCalcer/OscProbCalcer_CUDAProb3Linear.h" +#endif + +#if UseProb3ppLinear==1 +#include "OscProbCalcer/OscProbCalcer_Prob3ppLinear.h" +#endif + +#if UseProbGPULinear==1 +#include "OscProbCalcer/OscProbCalcer_ProbGPULinear.h" +#endif + +#if UseNuFASTLinear==1 +#include "OscProbCalcer/OscProbCalcer_NuFASTLinear.h" +#endif + +#include + +OscProbCalcerFactory::OscProbCalcerFactory() { +} + +OscProbCalcerFactory::~OscProbCalcerFactory() { +} + +OscProbCalcerBase* OscProbCalcerFactory::CreateOscProbCalcer(std::string OscProbCalcerImplementationToCreate, std::string OscProbCalcerConfigName, int Instance, int Verbose) { + OscProbCalcerBase* Calcer = NULL; + + if (OscProbCalcerImplementationToCreate == "CUDAProb3") { +#if UseCUDAProb3==1 + OscProbCalcerCUDAProb3* CUDAProb3 = new OscProbCalcerCUDAProb3(OscProbCalcerConfigName,Instance); + Calcer = (OscProbCalcerBase*)CUDAProb3; + if (Verbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} +#else + std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; + throw; +#endif + } + + else if (OscProbCalcerImplementationToCreate == "CUDAProb3Linear") { +#if UseCUDAProb3Linear==1 + OscProbCalcerCUDAProb3Linear* CUDAProb3Linear = new OscProbCalcerCUDAProb3Linear(OscProbCalcerConfigName,Instance); + Calcer = (OscProbCalcerBase*)CUDAProb3Linear; + if (Verbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} +#else + std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; + throw; +#endif + } + + else if (OscProbCalcerImplementationToCreate == "Prob3ppLinear") { +#if UseProb3ppLinear==1 + OscProbCalcerProb3ppLinear* Prob3ppLinear = new OscProbCalcerProb3ppLinear(OscProbCalcerConfigName,Instance); + Calcer = (OscProbCalcerBase*)Prob3ppLinear; + if (Verbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} +#else + std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; + throw; +#endif + } + + else if (OscProbCalcerImplementationToCreate == "ProbGPULinear") { +#if UseProbGPULinear==1 + OscProbCalcerProbGPULinear* ProbGPULinear = new OscProbCalcerProbGPULinear(OscProbCalcerConfigName,Instance); + Calcer = (OscProbCalcerBase*)ProbGPULinear; + if (Verbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} +#else + std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; + throw; +#endif + } + + else if (OscProbCalcerImplementationToCreate == "NuFASTLinear") { +#if UseNuFASTLinear==1 + OscProbCalcerNuFASTLinear* NuFASTLinear = new OscProbCalcerNuFASTLinear(OscProbCalcerConfigName,Instance); + Calcer = (OscProbCalcerBase*)NuFASTLinear; + if (Verbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} +#else + std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; + throw; +#endif + } + + else { + std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but this is not implemented within " << __FILE__ << std::endl; + std::cerr << "Please correct the mistake or implement the new OscProbCalcer" << std::endl; + throw; + } + + return Calcer; +} diff --git a/OscProbCalcer/OscProbCalcerFactory.h b/OscProbCalcer/OscProbCalcerFactory.h new file mode 100644 index 0000000..2bb2a18 --- /dev/null +++ b/OscProbCalcer/OscProbCalcerFactory.h @@ -0,0 +1,40 @@ +#ifndef __OSCPROBCALCERFACTORY_H__ +#define __OSCPROBCALCERFACTORY_H__ + +#include "OscProbCalcerBase.h" + +/** + * @file OscProbCalcerFactory.h + * + * @class OscProbCalcerFactory + * + * @brief Factory method for creating instances of OscProbCalcerBase::OscProbCalcerBase() obejcts + */ +class OscProbCalcerFactory { + public: + + /** + * @brief Default constructor + */ + OscProbCalcerFactory(); + + /** + * @brief Destructor + */ + virtual ~OscProbCalcerFactory(); + + /** + * @brief Create an instance of OscProbCalcerBase::OscProbCalcerBase() objects from a YAML config. + * + * @param ConfigName_ Path to YAML config file + * + * @return OscillatorBase::OscillatorBase() object + */ + OscProbCalcerBase* CreateOscProbCalcer(std::string OscProbCalcerImplementationToCreate, std::string OscProbCalcerConfigName_, int Instance, int Verbose=INFO); + + protected: + + private: +}; + +#endif diff --git a/Oscillator/OscillatorBase.cpp b/Oscillator/OscillatorBase.cpp index 6e70bf1..bf704e5 100644 --- a/Oscillator/OscillatorBase.cpp +++ b/Oscillator/OscillatorBase.cpp @@ -1,24 +1,6 @@ #include "Oscillator/OscillatorBase.h" -#if UseCUDAProb3==1 -#include "OscProbCalcer/OscProbCalcer_CUDAProb3.h" -#endif - -#if UseCUDAProb3Linear==1 -#include "OscProbCalcer/OscProbCalcer_CUDAProb3Linear.h" -#endif - -#if UseProb3ppLinear==1 -#include "OscProbCalcer/OscProbCalcer_Prob3ppLinear.h" -#endif - -#if UseProbGPULinear==1 -#include "OscProbCalcer/OscProbCalcer_ProbGPULinear.h" -#endif - -#if UseNuFASTLinear==1 -#include "OscProbCalcer/OscProbCalcer_NuFASTLinear.h" -#endif +#include "OscProbCalcer/OscProbCalcerFactory.h" #include @@ -125,69 +107,8 @@ void OscillatorBase::InitialiseOscProbCalcers() { } OscProbCalcerBase* OscillatorBase::InitialiseOscProbCalcer(std::string OscProbCalcerImplementationToCreate, std::string OscProbCalcerConfigname, int Instance) { - OscProbCalcerBase* Calcer; - - if (OscProbCalcerImplementationToCreate == "CUDAProb3") { -#if UseCUDAProb3==1 - OscProbCalcerCUDAProb3* CUDAProb3 = new OscProbCalcerCUDAProb3(OscProbCalcerConfigname,Instance); - Calcer = (OscProbCalcerBase*)CUDAProb3; - if (fVerbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} -#else - std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; - throw; -#endif - } - - else if (OscProbCalcerImplementationToCreate == "CUDAProb3Linear") { -#if UseCUDAProb3Linear==1 - OscProbCalcerCUDAProb3Linear* CUDAProb3Linear = new OscProbCalcerCUDAProb3Linear(OscProbCalcerConfigname,Instance); - Calcer = (OscProbCalcerBase*)CUDAProb3Linear; - if (fVerbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} -#else - std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; - throw; -#endif - } - - else if (OscProbCalcerImplementationToCreate == "Prob3ppLinear") { -#if UseProb3ppLinear==1 - OscProbCalcerProb3ppLinear* Prob3ppLinear = new OscProbCalcerProb3ppLinear(OscProbCalcerConfigname,Instance); - Calcer = (OscProbCalcerBase*)Prob3ppLinear; - if (fVerbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} -#else - std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; - throw; -#endif - } - - else if (OscProbCalcerImplementationToCreate == "ProbGPULinear") { -#if UseProbGPULinear==1 - OscProbCalcerProbGPULinear* ProbGPULinear = new OscProbCalcerProbGPULinear(OscProbCalcerConfigname,Instance); - Calcer = (OscProbCalcerBase*)ProbGPULinear; - if (fVerbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} -#else - std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; - throw; -#endif - } - - else if (OscProbCalcerImplementationToCreate == "NuFASTLinear") { -#if UseNuFASTLinear==1 - OscProbCalcerNuFASTLinear* NuFASTLinear = new OscProbCalcerNuFASTLinear(OscProbCalcerConfigname,Instance); - Calcer = (OscProbCalcerBase*)NuFASTLinear; - if (fVerbose >= INFO) {std::cout << "Initalised OscProbCalcer Implementation:" << Calcer->ReturnImplementationName() << " in OscillatorBase object" << std::endl;} -#else - std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but Use" << OscProbCalcerImplementationToCreate << " is undefined. Indicates problem in setup" << std::endl; - throw; -#endif - } - - else { - std::cerr << "Oscillator was requsted to create " << OscProbCalcerImplementationToCreate << " OscProbCalcer but this is not implemented within " << __FILE__ << std::endl; - std::cerr << "Please correct the mistake or implement the new OscProbCalcer" << std::endl; - throw; - } - + OscProbCalcerFactory* OscProbCalcFactory = new OscProbCalcerFactory(); + OscProbCalcerBase* Calcer = OscProbCalcFactory->CreateOscProbCalcer(OscProbCalcerImplementationToCreate,OscProbCalcerConfigname,Instance,fVerbose); return Calcer; }