Skip to content

Commit

Permalink
Merge pull request #31 from dbarrow257/feature_OscProbCalcerFactory
Browse files Browse the repository at this point in the history
Add factory class to create instances of OscProbCalcerBase objects
  • Loading branch information
dbarrow257 authored Oct 1, 2024
2 parents afc5422 + 14050b7 commit 0d758de
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 85 deletions.
6 changes: 3 additions & 3 deletions OscProbCalcer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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)
Expand Down
96 changes: 96 additions & 0 deletions OscProbCalcer/OscProbCalcerFactory.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

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;
}
40 changes: 40 additions & 0 deletions OscProbCalcer/OscProbCalcerFactory.h
Original file line number Diff line number Diff line change
@@ -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
85 changes: 3 additions & 82 deletions Oscillator/OscillatorBase.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 0d758de

Please sign in to comment.