Helios++
Helios software for LiDAR simulations
PulseThreadPoolFactory.h
1 #pragma once
2 
3 #include <scanner/detector/PulseThreadPool.h>
4 #include <scanner/detector/PulseWarehouseThreadPool.h>
5 #include <scanner/detector/PulseThreadPoolInterface.h>
6 #include <util/HeliosException.h>
7 
8 #include <memory>
9 #include <sstream>
10 
20 protected:
21  // *** ATTRIBUTES *** //
22  // ******************** //
34  std::size_t poolSize;
44  int chunkSize;
52 
53 public:
54  // *** CONSTRUCTION / DESTRUCTION *** //
55  // ************************************ //
60  int const parallelizationStrategy,
61  std::size_t const poolSize,
62  double const deviceAccuracy,
63  int const chunkSize,
64  int const warehouseFactor=1
65  ) :
71  {}
72  virtual ~PulseThreadPoolFactory() = default;
73 
74  // *** FACTORY METHODS *** //
75  // ************************* //
81  std::shared_ptr<PulseThreadPoolInterface> makePulseThreadPool(){
82  if(parallelizationStrategy == 0){
83  return makeBasicPulseThreadPool();
84  }
85  else if(parallelizationStrategy == 1){
87  }
88  else{
89  std::stringstream ss;
90  ss << "Unexpected parallelization strategy: "
92  throw HeliosException(ss.str());
93  }
94  }
95 
101  inline std::shared_ptr<PulseThreadPool> makeBasicPulseThreadPool() const {
102  return std::make_shared<PulseThreadPool>(
103  poolSize,
105  chunkSize < 0
106  );
107  }
108 
114  inline std::shared_ptr<PulseWarehouseThreadPool>
116  return std::make_shared<PulseWarehouseThreadPool>(
117  poolSize,
120  );
121  }
122 
123 
124 
125 };
Base class for Helios exceptions.
Definition: HeliosException.h:12
Factory to build different types of pulse thread pools.
Definition: PulseThreadPoolFactory.h:19
int chunkSize
The size of chunks handled by the thread pool, if needed.
Definition: PulseThreadPoolFactory.h:44
int warehouseFactor
The warehouse factor for the thread pool, if needed. The maximum number of tasks for a TaskWarehouse ...
Definition: PulseThreadPoolFactory.h:51
std::shared_ptr< PulseWarehouseThreadPool > makePulseWarehouseThreadPool() const
Build a warehouse based pulse thread pool.
Definition: PulseThreadPoolFactory.h:115
std::shared_ptr< PulseThreadPool > makeBasicPulseThreadPool() const
Build a basic pulse thread pool.
Definition: PulseThreadPoolFactory.h:101
std::size_t poolSize
How many threads the thread pool should use.
Definition: PulseThreadPoolFactory.h:34
int parallelizationStrategy
The parallelization strategy defining the thread pool.
Definition: PulseThreadPoolFactory.h:29
double deviceAccuracy
The accuracy of the detector in meters.
Definition: PulseThreadPoolFactory.h:39
PulseThreadPoolFactory(int const parallelizationStrategy, std::size_t const poolSize, double const deviceAccuracy, int const chunkSize, int const warehouseFactor=1)
Default constructor.
Definition: PulseThreadPoolFactory.h:59
std::shared_ptr< PulseThreadPoolInterface > makePulseThreadPool()
Build the pulse thread pool corresponding with current factory configuration/state.
Definition: PulseThreadPoolFactory.h:81