Jpp  master_rocky-43-ge265d140c
the software that should make you happy
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
JACOUSTICS::JFremantle Class Reference

Thread pool for global fits. More...

#include <JFremantle_t.hh>

Public Types

typedef std::vector< JHitinput_type
 
typedef JLANG::JObjectOutput< JSuperEvtoutput_type
 

Public Member Functions

 JFremantle (const JGeometry &geometry, const JSoundVelocity &velocity, const JFitParameters &parameters, const size_t ns, const size_t backlog=std::numeric_limits< size_t >::max())
 Constructor. More...
 
 ~JFremantle ()
 Destructor. More...
 
void enqueue (input_type &data)
 Queue data. More...
 

Static Public Attributes

static int detid = -1
 detector identifier More...
 
static JMATH::JQuantile_t Q
 chi2/NDF More...
 
static bool squash = false
 squash transmissions in output More...
 
static output_typeoutput = NULL
 optional output More...
 

Private Attributes

std::vector< std::thread > workers
 
std::queue< input_typeinput
 
std::mutex in
 
std::mutex out
 
std::condition_variable cv
 
std::condition_variable cw
 
bool stop
 
size_t backlog
 

Detailed Description

Thread pool for global fits.

Definition at line 33 of file JFremantle_t.hh.

Member Typedef Documentation

◆ input_type

Definition at line 36 of file JFremantle_t.hh.

◆ output_type

Definition at line 37 of file JFremantle_t.hh.

Constructor & Destructor Documentation

◆ JFremantle()

JACOUSTICS::JFremantle::JFremantle ( const JGeometry geometry,
const JSoundVelocity velocity,
const JFitParameters parameters,
const size_t  ns,
const size_t  backlog = std::numeric_limits<size_t>::max() 
)
inline

Constructor.

Parameters
geometrydetector geometry
velocitysound velocity
parametersparameters
nsnumber of threads
backlogbacklog

Definition at line 49 of file JFremantle_t.hh.

53  :
54  stop(false),
56  {
57  using namespace std;
58  using namespace JPP;
59 
60  Q.reset();
61 
62  for (size_t i = 0; i < ns; ++i) {
63 
64  thread worker([this, geometry, velocity, parameters]() {
65 
67 
68  for (JGlobalfit katoomba(geometry, velocity, parameters); ; ) {
69 
70  {
71  unique_lock<mutex> lock(in);
72 
73  cv.wait(lock, [this]() { return stop || !input.empty(); });
74 
75  if (stop && input.empty()) {
76  return;
77  }
78 
79  data.swap(input.front());
80 
81  input.pop();
82  }
83 
84  cw.notify_one();
85 
86  const auto result = katoomba(data.begin(), data.end());
87 
88  if (result.chi2 / result.ndf <= katoomba.parameters.chi2perNDF) {
89 
90  {
91  unique_lock<mutex> lock(out);
92 
93  Q.put(result.chi2 / result.ndf);
94 
95  if (JFremantle::output != NULL) {
97  result.getTimeRange(),
98  data .size(),
99  result.size(),
100  result.value.getN(),
101  result.ndf,
102  result.chi2),
103  result.value,
104  result.begin,
105  JFremantle::squash ? result.begin : result.end));
106  }
107  }
108  }
109  }
110  });
111 
112  workers.emplace_back(std::move(worker));
113  }
114  }
Monte Carlo run header.
Definition: JHead.hh:1236
static output_type * output
optional output
std::condition_variable cw
std::vector< std::thread > workers
static JMATH::JQuantile_t Q
chi2/NDF
std::condition_variable cv
static int detid
detector identifier
static bool squash
squash transmissions in output
std::queue< input_type > input
virtual bool put(const T &object)=0
Object output.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< size_t > ns
Definition: JSTDTypes.hh:14
Global fit of prameterised detector geometry to acoustics data.
Definition: JGlobalfit.hh:29
Auxiliary data structure to convert model to super event.
void put(const double x)
Put value.
Definition: JQuantile_t.hh:49
void reset()
Reset.
Definition: JQuantile_t.hh:38

◆ ~JFremantle()

JACOUSTICS::JFremantle::~JFremantle ( )
inline

Destructor.

Definition at line 120 of file JFremantle_t.hh.

121  {
122  using namespace std;
123 
124  {
125  unique_lock<mutex> lock(in);
126 
127  stop = true;
128  }
129 
130  cv.notify_all();
131 
132  for (auto& worker : workers) {
133  worker.join();
134  }
135  }

Member Function Documentation

◆ enqueue()

void JACOUSTICS::JFremantle::enqueue ( input_type data)
inline

Queue data.

Parameters
datadata

Definition at line 143 of file JFremantle_t.hh.

144  {
145  using namespace std;
146 
147  {
148  unique_lock<mutex> lock(in);
149 
150  cw.wait(lock, [this]() { return stop || input.size() <= backlog; });
151 
152  if (stop) {
153  throw runtime_error("The thread pool has been stopped.");
154  }
155 
156  input.emplace(std::move(data));
157  }
158 
159  cv.notify_one();
160  }

Member Data Documentation

◆ detid

int JACOUSTICS::JFremantle::detid = -1
static

detector identifier

Definition at line 162 of file JFremantle_t.hh.

◆ Q

JMATH::JQuantile_t JACOUSTICS::JFremantle::Q
static

chi2/NDF

Definition at line 163 of file JFremantle_t.hh.

◆ squash

bool JACOUSTICS::JFremantle::squash = false
static

squash transmissions in output

Definition at line 164 of file JFremantle_t.hh.

◆ output

JFremantle::output_type * JACOUSTICS::JFremantle::output = NULL
static

optional output

Definition at line 165 of file JFremantle_t.hh.

◆ workers

std::vector<std::thread> JACOUSTICS::JFremantle::workers
private

Definition at line 168 of file JFremantle_t.hh.

◆ input

std::queue<input_type> JACOUSTICS::JFremantle::input
private

Definition at line 169 of file JFremantle_t.hh.

◆ in

std::mutex JACOUSTICS::JFremantle::in
private

Definition at line 170 of file JFremantle_t.hh.

◆ out

std::mutex JACOUSTICS::JFremantle::out
private

Definition at line 171 of file JFremantle_t.hh.

◆ cv

std::condition_variable JACOUSTICS::JFremantle::cv
private

Definition at line 172 of file JFremantle_t.hh.

◆ cw

std::condition_variable JACOUSTICS::JFremantle::cw
private

Definition at line 173 of file JFremantle_t.hh.

◆ stop

bool JACOUSTICS::JFremantle::stop
private

Definition at line 174 of file JFremantle_t.hh.

◆ backlog

size_t JACOUSTICS::JFremantle::backlog
private

Definition at line 175 of file JFremantle_t.hh.


The documentation for this class was generated from the following files: