Jpp  18.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 JLANG::JObjectOutput
< JSuperEvt
output_type
 

Public Member Functions

 JFremantle (const JGeometry &geometry, const JSoundVelocity &velocity, const JFitParameters &parameters, const size_t ns)
 Constructor. More...
 
 ~JFremantle ()
 Destructor. More...
 
size_t backlog ()
 Get number of pending data. More...
 
void enqueue (data_type &data)
 Queue data. More...
 

Static Public Attributes

static std::string oid = ""
 detector identifier More...
 
static JTOOLS::JQuantile Q
 chi2/NDF More...
 
static output_typeoutput = NULL
 optional output More...
 

Private Attributes

std::vector< std::thread > workers
 
std::queue< data_typeinput
 
std::mutex in
 
std::mutex out
 
std::condition_variable cv
 
bool stop
 

Detailed Description

Thread pool for global fits.

Definition at line 34 of file JFremantle_t.hh.

Member Typedef Documentation

Definition at line 168 of file JFremantle_t.hh.

Constructor & Destructor Documentation

JACOUSTICS::JFremantle::JFremantle ( const JGeometry geometry,
const JSoundVelocity velocity,
const JFitParameters parameters,
const size_t  ns 
)
inline

Constructor.

Parameters
geometrydetector geometry
velocitysound velocity
parametersparameters
nsnumber of threads

Definition at line 44 of file JFremantle_t.hh.

47  :
48  stop(false)
49  {
50  using namespace std;
51  using namespace JPP;
52 
53  Q.reset();
54 
55  for (size_t i = 0; i < ns; ++i) {
56 
57  thread worker([this, geometry, velocity, parameters]() {
58 
60 
61  for (JGlobalfit katoomba(geometry, velocity, parameters); ; ) {
62 
63  {
64  unique_lock<mutex> lock(in);
65 
66  cv.wait(lock, [this]() { return stop || !input.empty(); });
67 
68  if (stop && input.empty()) {
69  return;
70  }
71 
72  data.swap(input.front());
73 
74  input.pop();
75  }
76 
77  const auto result = katoomba(data.begin(), data.end());
78 
79  if (result.chi2 / result.ndf <= katoomba.parameters.chi2perNDF) {
80 
81  {
82  unique_lock<mutex> lock(out);
83 
84  Q.put(result.chi2 / result.ndf);
85 
86  if (JFremantle::output != NULL) {
88  result.getTimeRange(),
89  data .size(),
90  result.size(),
91  result.value.getN(),
92  result.ndf,
93  result.chi2),
94  result.value,
95  result.begin,
96  result.end));
97  }
98  }
99  }
100  }
101  });
102 
103  workers.emplace_back(move(worker));
104  }
105  }
void reset()
Reset.
Definition: JQuantile.hh:87
std::vector< size_t > ns
std::condition_variable cv
Global fit of prameterised detector geometry to acoustics data.
Definition: JGlobalfit.hh:29
static std::string oid
detector identifier
void put(const double x, const double w=1.0)
Put value.
Definition: JQuantile.hh:133
std::queue< data_type > input
Monte Carlo run header.
Definition: JHead.hh:1221
static output_type * output
optional output
static JTOOLS::JQuantile Q
chi2/NDF
virtual bool put(const T &object)=0
Object output.
Auxiliary data structure to convert model to super event.
std::vector< std::thread > workers
JACOUSTICS::JFremantle::~JFremantle ( )
inline

Destructor.

Definition at line 111 of file JFremantle_t.hh.

112  {
113  using namespace std;
114 
115  {
116  unique_lock<mutex> lock(in);
117 
118  stop = true;
119  }
120 
121  cv.notify_all();
122 
123  for (auto& worker : workers) {
124  worker.join();
125  }
126  }
std::condition_variable cv
std::vector< std::thread > workers

Member Function Documentation

size_t JACOUSTICS::JFremantle::backlog ( )
inline

Get number of pending data.

Returns
number of pending data

Definition at line 134 of file JFremantle_t.hh.

135  {
136  using namespace std;
137 
138  {
139  unique_lock<mutex> lock(in);
140 
141  return input.size();
142  }
143  }
std::queue< data_type > input
void JACOUSTICS::JFremantle::enqueue ( data_type data)
inline

Queue data.

Parameters
datadata

Definition at line 151 of file JFremantle_t.hh.

152  {
153  using namespace std;
154 
155  {
156  unique_lock<mutex> lock(in);
157 
158  if (stop) {
159  throw runtime_error("The thread pool has been stopped.");
160  }
161 
162  input.emplace(move(data));
163  }
164 
165  cv.notify_one();
166  }
std::condition_variable cv
std::queue< data_type > input

Member Data Documentation

std::string JACOUSTICS::JFremantle::oid = ""
static

detector identifier

Definition at line 170 of file JFremantle_t.hh.

JTOOLS::JQuantile JACOUSTICS::JFremantle::Q
static

chi2/NDF

Definition at line 171 of file JFremantle_t.hh.

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

optional output

Definition at line 172 of file JFremantle_t.hh.

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

Definition at line 175 of file JFremantle_t.hh.

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

Definition at line 176 of file JFremantle_t.hh.

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

Definition at line 177 of file JFremantle_t.hh.

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

Definition at line 178 of file JFremantle_t.hh.

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

Definition at line 179 of file JFremantle_t.hh.

bool JACOUSTICS::JFremantle::stop
private

Definition at line 180 of file JFremantle_t.hh.


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