Jpp  19.1.0-rc.1
the software that should make you happy
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
JRECONSTRUCTION::JPerth Struct Reference

Thread pool for fits to data. More...

Public Member Functions

 JPerth (const JRegressorStorage_t &storage, const data_type &data, const size_t ns)
 Constructor. More...
 
 ~JPerth ()
 Destructor. More...
 

Static Public Attributes

static JMATH::JQuantile_t Q
 

Private Attributes

std::vector< std::thread > workers
 
input_type input
 
std::mutex in
 
std::mutex out
 
std::condition_variable cv
 
bool stop
 

Detailed Description

Thread pool for fits to data.

Definition at line 138 of file JPerth.cc.

Constructor & Destructor Documentation

◆ JPerth()

JRECONSTRUCTION::JPerth::JPerth ( const JRegressorStorage_t storage,
const data_type data,
const size_t  ns 
)
inline

Constructor.

Parameters
storagestorage for PDFs
datadata
nsnumber of threads

Definition at line 146 of file JPerth.cc.

148  :
149  input(data),
150  stop(false)
151  {
152  using namespace std;
153  using namespace JPP;
154 
155  Q.reset();
156 
157  for (size_t i = 0; i < ns; ++i) {
158 
159  thread worker([this, storage]() {
160 
161  JRegressor_t regressor(storage);
162 
163  regressor.parameters.resize(5);
164 
165  regressor.parameters[0] = JLine3Z::pX();
166  regressor.parameters[1] = JLine3Z::pY();
167  regressor.parameters[2] = JLine3Z::pT();
168  regressor.parameters[3] = JLine3Z::pDX();
169  regressor.parameters[4] = JLine3Z::pDY();
170 
172  JLine3Z value;
173 
174  for ( ; ; ) {
175 
176  {
177  unique_lock<mutex> lock(in);
178 
179  cv.wait(lock, [this]() { return stop || this->input.hasNext(); });
180 
181  if (stop && !this->input.hasNext()) {
182  return;
183  }
184 
185  const event_type* evt = this->input.next();
186 
187  // re-organise data
188 
189  data.clear();
190 
191  for (map_type::const_iterator p = evt->data.begin(); p != evt->data.end(); ++p) {
192  copy(p->second.begin(), p->second.end(), back_inserter(data));
193  }
194 
195  value = evt->value;
196  }
197 
198  const double chi2 = regressor(value, data.begin(), data.end());
199 
200  {
201  unique_lock<mutex> lock(out);
202 
203  Q.put(chi2);
204  }
205  }
206  });
207 
208  workers.emplace_back(std::move(worker));
209  }
210  }
static parameter_type pY()
Definition: JLine1Z.hh:181
static parameter_type pX()
Definition: JLine1Z.hh:180
static parameter_type pT()
Definition: JLine1Z.hh:182
Data structure for fit of straight line in positive z-direction.
Definition: JLine3Z.hh:40
static parameter_type pDY()
Definition: JLine3Z.hh:320
static parameter_type pDX()
Definition: JLine3Z.hh:319
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< size_t > ns
Definition: JSTDTypes.hh:14
Template definition of a data regressor of given model.
Definition: JRegressor.hh:70
void put(const double x)
Put value.
Definition: JQuantile_t.hh:49
void reset()
Reset.
Definition: JQuantile_t.hh:38
std::vector< std::thread > workers
Definition: JPerth.cc:236
std::condition_variable cv
Definition: JPerth.cc:240
static JMATH::JQuantile_t Q
Definition: JPerth.cc:233
Auxiliary data structure to store data and fit in memory.
Definition: JPerth.cc:76

◆ ~JPerth()

JRECONSTRUCTION::JPerth::~JPerth ( )
inline

Destructor.

Definition at line 216 of file JPerth.cc.

217  {
218  using namespace std;
219 
220  {
221  unique_lock<mutex> lock(in);
222 
223  stop = true;
224  }
225 
226  cv.notify_all();
227 
228  for (auto& worker : workers) {
229  worker.join();
230  }
231  }

Member Data Documentation

◆ Q

JMATH::JQuantile_t JRECONSTRUCTION::JPerth::Q
static

Definition at line 233 of file JPerth.cc.

◆ workers

std::vector<std::thread> JRECONSTRUCTION::JPerth::workers
private

Definition at line 236 of file JPerth.cc.

◆ input

input_type JRECONSTRUCTION::JPerth::input
private

Definition at line 237 of file JPerth.cc.

◆ in

std::mutex JRECONSTRUCTION::JPerth::in
private

Definition at line 238 of file JPerth.cc.

◆ out

std::mutex JRECONSTRUCTION::JPerth::out
private

Definition at line 239 of file JPerth.cc.

◆ cv

std::condition_variable JRECONSTRUCTION::JPerth::cv
private

Definition at line 240 of file JPerth.cc.

◆ stop

bool JRECONSTRUCTION::JPerth::stop
private

Definition at line 241 of file JPerth.cc.


The documentation for this struct was generated from the following file: