Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
 ~JFremantle ()
 Destructor.
 
void enqueue (input_type &data)
 Queue data.
 

Static Public Attributes

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

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

◆ output_type

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 katoomba.gandalf.numberOfIterations),
104 result.value,
105 result.begin,
106 JFremantle::squash ? result.begin : result.end));
107 }
108 }
109 }
110 }
111 });
112
113 workers.emplace_back(std::move(worker));
114 }
115 }
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).
return result
Definition JPolint.hh:862
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.
void reset()
Reset.

◆ ~JFremantle()

JACOUSTICS::JFremantle::~JFremantle ( )
inline

Destructor.

Definition at line 121 of file JFremantle_t.hh.

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

Member Function Documentation

◆ enqueue()

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

Queue data.

Parameters
datadata

Definition at line 144 of file JFremantle_t.hh.

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

Member Data Documentation

◆ detid

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

detector identifier

Definition at line 163 of file JFremantle_t.hh.

◆ Q

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

chi2/NDF

Definition at line 164 of file JFremantle_t.hh.

◆ squash

bool JACOUSTICS::JFremantle::squash = false
static

squash transmissions in output

Definition at line 165 of file JFremantle_t.hh.

◆ output

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

optional output

Definition at line 166 of file JFremantle_t.hh.

◆ workers

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

Definition at line 169 of file JFremantle_t.hh.

◆ input

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

Definition at line 170 of file JFremantle_t.hh.

◆ in

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

Definition at line 171 of file JFremantle_t.hh.

◆ out

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

Definition at line 172 of file JFremantle_t.hh.

◆ cv

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

Definition at line 173 of file JFremantle_t.hh.

◆ cw

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

Definition at line 174 of file JFremantle_t.hh.

◆ stop

bool JACOUSTICS::JFremantle::stop
private

Definition at line 175 of file JFremantle_t.hh.

◆ backlog

size_t JACOUSTICS::JFremantle::backlog
private

Definition at line 176 of file JFremantle_t.hh.


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