Jpp  master_rocky
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 139 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 147 of file JPerth.cc.

149  :
150  input(data),
151  stop(false)
152  {
153  using namespace std;
154  using namespace JPP;
155 
156  Q.reset();
157 
158  for (size_t i = 0; i < ns; ++i) {
159 
160  thread worker([this, storage]() {
161 
162  JRegressor_t regressor(storage);
163 
164  regressor.parameters.resize(5);
165 
166  regressor.parameters[0] = JLine3Z::pX();
167  regressor.parameters[1] = JLine3Z::pY();
168  regressor.parameters[2] = JLine3Z::pT();
169  regressor.parameters[3] = JLine3Z::pDX();
170  regressor.parameters[4] = JLine3Z::pDY();
171 
173  JLine3Z value;
174 
175  for ( ; ; ) {
176 
177  {
178  unique_lock<mutex> lock(in);
179 
180  cv.wait(lock, [this]() { return stop || this->input.hasNext(); });
181 
182  if (stop && !this->input.hasNext()) {
183  return;
184  }
185 
186  const event_type* evt = this->input.next();
187 
188  // re-organise data
189 
190  data.clear();
191 
192  for (map_type::const_iterator p = evt->data.begin(); p != evt->data.end(); ++p) {
193  copy(p->second.begin(), p->second.end(), back_inserter(data));
194  }
195 
196  value = evt->value;
197  }
198 
199  const double chi2 = regressor(value, data.begin(), data.end());
200 
201  {
202  unique_lock<mutex> lock(out);
203 
204  Q.put(chi2);
205  }
206  }
207  });
208 
209  workers.emplace_back(std::move(worker));
210  }
211  }
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:237
std::condition_variable cv
Definition: JPerth.cc:241
static JMATH::JQuantile_t Q
Definition: JPerth.cc:234
Auxiliary data structure to store data and fit in memory.
Definition: JPerth.cc:77

◆ ~JPerth()

JRECONSTRUCTION::JPerth::~JPerth ( )
inline

Destructor.

Definition at line 217 of file JPerth.cc.

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

Member Data Documentation

◆ Q

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

Definition at line 234 of file JPerth.cc.

◆ workers

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

Definition at line 237 of file JPerth.cc.

◆ input

input_type JRECONSTRUCTION::JPerth::input
private

Definition at line 238 of file JPerth.cc.

◆ in

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

Definition at line 239 of file JPerth.cc.

◆ out

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

Definition at line 240 of file JPerth.cc.

◆ cv

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

Definition at line 241 of file JPerth.cc.

◆ stop

bool JRECONSTRUCTION::JPerth::stop
private

Definition at line 242 of file JPerth.cc.


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