BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
OutputData.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Data/OutputData.h
6 //! @brief Defines and implements templated class OutputData.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_DEVICE_DATA_OUTPUTDATA_H
16 #define BORNAGAIN_DEVICE_DATA_OUTPUTDATA_H
17 
18 #include "Base/Axis/FixedBinAxis.h"
19 #include "Base/Py/PyObject.h"
21 #include "Base/Utils/Assert.h"
22 #include "Base/Utils/ThreadInfo.h"
23 #include "Device/Data/LLData.h"
25 #include <sstream>
26 
27 using std::size_t;
28 
29 //! Templated class to store data of type double or CumulativeValue in multi-dimensional space.
30 //! @ingroup tools
31 
32 template <class T> class OutputData {
33 public:
34  using value_type = T;
35 
37  OutputData(const OutputData&) = delete;
39  const OutputData& operator=(const OutputData&) = delete;
41  OutputData* clone() const;
42 
43  void copyFrom(const OutputData<T>& x);
44  template <class U> void copyShapeFrom(const OutputData<U>& other);
46 
47  void addAxis(const IAxis& new_axis);
48  void addAxis(const std::string& name, size_t size, double start, double end);
49 
50  //! returns axis with given serial number
51  const IAxis& axis(size_t serial_number) const;
52 
53  // retrieve basic info
54 
55  //! Returns number of dimensions.
56  size_t rank() const { return m_value_axes.size(); }
57 
58  //! Returns total size of data buffer (product of bin number in every dimension).
59  size_t getAllocatedSize() const
60  {
61  if (m_ll_data)
62  return m_ll_data->getTotalSize();
63  return 0;
64  }
65 
66  //! Returns all sizes of its axes
67  std::vector<size_t> getAllSizes() const;
68 
69  //! Returns copy of raw data vector
70  std::vector<T> getRawDataVector() const;
71 
72  //! Returns sum of all values in the data structure
73  T totalSum() const;
74 
75  // iterators
76 
77  friend class OutputDataIterator<T, OutputData<T>>;
78  friend class OutputDataIterator<const T, const OutputData<T>>;
79 
80  //! Read/write iterator type
82 
83  //! Read-only iterator type
85 
86  //! Returns read/write iterator that points to the first element
88 
89  //! Returns read-only iterator that points to the first element
91 
92  //! Returns read/write iterator that points to the one past last element
93  iterator end() { return iterator(this, getAllocatedSize()); }
94 
95  //! Returns read-only iterator that points to the one past last element
96  const_iterator end() const { return const_iterator(this, getAllocatedSize()); }
97 
98  // coordinate and index functions
99 
100  //! Returns vector of axes indices for given global index
101  //! @param global_index The global index of this data structure.
102  //! @return Vector of bin indices for all axes defined
103  std::vector<int> getAxesBinIndices(size_t global_index) const;
104 
105  //! Returns axis bin index for given global index
106  //! @param global_index The global index of this data structure.
107  //! @param i_selected_axis Serial number of selected axis.
108  //! @return Corresponding bin index for selected axis
109  size_t getAxisBinIndex(size_t global_index, size_t i_selected_axis) const;
110 
111  //! Returns axis bin index for given global index
112  //! @param global_index The global index of this data structure.
113  //! @param axis_name The name of selected axis.
114  //! @return Corresponding bin index for selected axis
115  size_t getAxisBinIndex(size_t global_index, const std::string& axis_name) const;
116 
117  //! Returns global index for specified indices of axes
118  //! @param axes_indices Vector of axes indices for all specified axes in this dataset
119  //! @return Corresponding global index
120  size_t toGlobalIndex(const std::vector<unsigned>& axes_indices) const;
121 
122  //! Returns global index for specified axes values
123  //! @param coordinates Vector of axes coordinates for all specified axes in this dataset
124  //! @return Closest global index
125  size_t findGlobalIndex(const std::vector<double>& coordinates) const;
126 
127  //! Returns the value of selected axis for given global_index.
128  //! @param global_index The global index of this data structure.
129  //! @param i_selected_axis Serial number of selected axis.
130  //! @return corresponding bin center of selected axis
131  double getAxisValue(size_t global_index, size_t i_selected_axis) const;
132 
133  //! Returns the value of selected axis for given global_index.
134  //! @param global_index The global index of this data structure.
135  //! @param axis_name The name of selected axis.
136  //! @return corresponding bin center of selected axis
137  double getAxisValue(size_t global_index, const std::string& axis_name) const;
138 
139  //! Returns values on all defined axes for given globalbin number
140  //! @param global_index The global index of this data structure.
141  //! @return Vector of corresponding bin centers
142  std::vector<double> getAxesValues(size_t global_index) const;
143 
144  //! Returns bin of selected axis for given global_index.
145  //! @param global_index The global index of this data structure.
146  //! @param i_selected_axis Serial number of selected axis.
147  //! @return Corresponding Bin1D object
148  Bin1D getAxisBin(size_t global_index, size_t i_selected_axis) const;
149 
150  //! Returns bin of selected axis for given global_index.
151  //! @param global_index The global index of this data structure.
152  //! @param axis_name The name of selected axis.
153  //! @return Corresponding Bin1D object
154  Bin1D getAxisBin(size_t global_index, const std::string& axis_name) const;
155 
156  // modifiers
157 
158  //! Sets object into initial state (no dimensions, data)
159  void clear();
160 
161  //! Sets content of output data to specific value
162  void setAllTo(const T& value);
163 
164  //! multiply every item of this output data by value
165  void scaleAll(const T& factor);
166 
167  //! Adds 'rank' axes with indicated sizes
168  void setAxisSizes(size_t rank, int* n_dims);
169 
170  //! Sets new values to raw data vector
171  void setRawDataVector(const std::vector<T>& data_vector);
172 
173  //! Sets new values to raw data array
174  void setRawDataArray(const T* source);
175 
176  //! addition-assignment operator for two output data
177  const OutputData<T>& operator+=(const OutputData<T>& right);
178 
179  //! substraction-assignment operator for two output data
180  const OutputData<T>& operator-=(const OutputData<T>& right);
181 
182  //! division-assignment operator for two output data
183  const OutputData<T>& operator/=(const OutputData<T>& right);
184 
185  //! multiplication-assignment operator for two output data
186  const OutputData<T>& operator*=(const OutputData<T>& right);
187 
188  //! Returns value or summed value, depending on T
189  double getValue(size_t index) const;
190 
191  //! indexed accessor
192  T& operator[](size_t index)
193  {
194  ASSERT(m_ll_data);
195  return (*m_ll_data)[index];
196  }
197 
198  //! indexed accessor (const)
199  const T& operator[](size_t index) const
200  {
201  ASSERT(m_ll_data);
202  return (*m_ll_data)[index];
203  }
204 
205  // helpers
206 
207  //! Returns true if object have same dimensions and number of axes bins
208  template <class U> bool hasSameDimensions(const OutputData<U>& right) const;
209 
210  //! Returns true if objects a) have same dimensions b) bin boundaries of axes coincide
211  template <class U> bool hasSameShape(const OutputData<U>& right) const;
212 
213  //! returns data as Python numpy array
214 #ifdef BORNAGAIN_PYTHON
215  PyObject* getArray() const;
216 #endif
217 
218  //! returns true if object is correctly initialized
219  bool isInitialized() const;
220 
221  //! memory allocation for current dimensions configuration
222  void allocate();
223 
224 private:
225  //! returns serial number of axis with given name
226  size_t getAxisIndex(const std::string& axis_name) const;
227 
228  //! checks if given axis name exists
229  bool axisNameExists(const std::string& axis_name) const;
230 
233 };
234 
235 // --------------------------------------------------------------------- //
236 // Implementation
237 // --------------------------------------------------------------------- //
238 
239 template <class T> OutputData<T>::OutputData(OutputData<T>&& other)
240 {
241  m_value_axes = std::move(other.m_value_axes);
242  m_ll_data = other.m_ll_data;
243 
244  other.m_ll_data = nullptr;
245  other.allocate();
246 }
247 
248 template <class T> OutputData<T>::OutputData() : m_value_axes(), m_ll_data(nullptr)
249 {
250  allocate();
251 }
252 
253 template <class T> OutputData<T>::~OutputData()
254 {
255  clear();
256  delete m_ll_data;
257 }
258 
259 template <class T> OutputData<T>* OutputData<T>::clone() const
260 {
261  OutputData<T>* ret = new OutputData<T>();
262  ret->m_value_axes = m_value_axes;
263  (*ret->m_ll_data) = *m_ll_data;
264  return ret;
265 }
266 
267 template <class T> void OutputData<T>::copyFrom(const OutputData<T>& other)
268 {
269  clear();
270  m_value_axes = other.m_value_axes;
271  delete m_ll_data;
272  m_ll_data = 0;
273  if (other.m_ll_data)
274  m_ll_data = new LLData<T>(*other.m_ll_data);
275 }
276 
277 template <class T> template <class U> void OutputData<T>::copyShapeFrom(const OutputData<U>& other)
278 {
279  clear();
280  size_t rank = other.rank();
281  for (size_t i = 0; i < rank; ++i)
282  addAxis(other.axis(i));
283 }
284 
286 {
287  auto* ret = new OutputData<double>();
288  ret->copyShapeFrom(*this);
289  ret->allocate();
290  for (size_t i = 0; i < m_ll_data->getTotalSize(); ++i)
291  (*ret)[i] = getValue(i);
292  return ret;
293 }
294 
295 template <class T> void OutputData<T>::addAxis(const IAxis& new_axis)
296 {
297  if (axisNameExists(new_axis.getName()))
298  throw std::runtime_error("OutputData<T>::addAxis(const IAxis& new_axis) -> "
299  "Error! Attempt to add axis with already existing name '"
300  + new_axis.getName() + "'");
301  if (new_axis.size() > 0) {
302  m_value_axes.push_back(new_axis.clone());
303  allocate();
304  }
305 }
306 
307 template <class T>
308 void OutputData<T>::addAxis(const std::string& name, size_t size, double start, double end)
309 {
310  if (axisNameExists(name))
311  throw std::runtime_error("OutputData<T>::addAxis(std::string name) -> "
312  "Error! Attempt to add axis with already existing name '"
313  + name + "'");
314  FixedBinAxis new_axis(name, size, start, end);
315  addAxis(new_axis);
316 }
317 
318 template <class T> const IAxis& OutputData<T>::axis(size_t serial_number) const
319 {
320  return *m_value_axes[serial_number];
321 }
322 
323 template <class T> inline std::vector<size_t> OutputData<T>::getAllSizes() const
324 {
325  ASSERT(m_ll_data);
326  std::vector<size_t> result;
327  for (size_t i = 0; i < rank(); ++i) {
328  int dim = m_ll_data->dimensions()[i];
329  result.push_back(dim);
330  }
331  return result;
332 }
333 
334 template <class T> inline std::vector<T> OutputData<T>::getRawDataVector() const
335 {
336  ASSERT(m_ll_data);
337  std::vector<T> result;
338  for (size_t i = 0; i < getAllocatedSize(); ++i)
339  result.push_back((*m_ll_data)[i]);
340  return result;
341 }
342 
343 template <class T> typename OutputData<T>::iterator OutputData<T>::begin()
344 {
345  typename OutputData<T>::iterator result(this);
346  return result;
347 }
348 
349 template <class T> typename OutputData<T>::const_iterator OutputData<T>::begin() const
350 {
351  typename OutputData<T>::const_iterator result(this);
352  return result;
353 }
354 
355 template <class T> std::vector<int> OutputData<T>::getAxesBinIndices(size_t global_index) const
356 {
357  ASSERT(m_ll_data);
358  size_t remainder = global_index;
359  std::vector<int> result;
360  result.resize(m_ll_data->rank());
361  for (size_t i = 0; i < m_ll_data->rank(); ++i) {
362  result[m_ll_data->rank() - 1 - i] =
363  (int)(remainder % m_value_axes[m_ll_data->rank() - 1 - i]->size());
364  remainder /= m_value_axes[m_ll_data->rank() - 1 - i]->size();
365  }
366  return result;
367 }
368 
369 template <class T>
370 size_t OutputData<T>::getAxisBinIndex(size_t global_index, size_t i_selected_axis) const
371 {
372  ASSERT(m_ll_data);
373  size_t remainder(global_index);
374  for (size_t i = 0; i < m_ll_data->rank(); ++i) {
375  size_t i_axis = m_ll_data->rank() - 1 - i;
376  size_t result = remainder % m_value_axes[i_axis]->size();
377  if (i_selected_axis == i_axis)
378  return result;
379  remainder /= m_value_axes[i_axis]->size();
380  }
381  throw std::runtime_error("OutputData<T>::getAxisBinIndex() -> "
382  "Error! No axis with given number");
383 }
384 
385 template <class T>
386 size_t OutputData<T>::getAxisBinIndex(size_t global_index, const std::string& axis_name) const
387 {
388  return getAxisBinIndex(global_index, getAxisIndex(axis_name));
389 }
390 
391 template <class T>
392 size_t OutputData<T>::toGlobalIndex(const std::vector<unsigned>& axes_indices) const
393 {
394  ASSERT(m_ll_data);
395  if (axes_indices.size() != m_ll_data->rank())
396  throw std::runtime_error("size_t OutputData<T>::toGlobalIndex() -> "
397  "Error! Number of coordinates must match rank of data structure");
398  size_t result = 0;
399  size_t step_size = 1;
400  for (size_t i = m_ll_data->rank(); i > 0; --i) {
401  if (axes_indices[i - 1] >= m_value_axes[i - 1]->size()) {
402  std::ostringstream message;
403  message << "size_t OutputData<T>::toGlobalIndex() -> Error. Index ";
404  message << axes_indices[i - 1] << " is out of range. Axis ";
405  message << m_value_axes[i - 1]->getName();
406  message << " size " << m_value_axes[i - 1]->size() << ".\n";
407  throw std::runtime_error(message.str());
408  }
409  result += axes_indices[i - 1] * step_size;
410  step_size *= m_value_axes[i - 1]->size();
411  }
412  return result;
413 }
414 
415 template <class T>
416 size_t OutputData<T>::findGlobalIndex(const std::vector<double>& coordinates) const
417 {
418  ASSERT(m_ll_data);
419  if (coordinates.size() != m_ll_data->rank())
420  throw std::runtime_error("OutputData<T>::findClosestIndex() -> "
421  "Error! Number of coordinates must match rank of data structure");
422  std::vector<unsigned> axes_indexes;
423  axes_indexes.resize(m_ll_data->rank());
424  for (size_t i = 0; i < m_ll_data->rank(); ++i)
425  axes_indexes[i] = static_cast<unsigned>(m_value_axes[i]->findClosestIndex(coordinates[i]));
426  return toGlobalIndex(axes_indexes);
427 }
428 
429 template <class T>
430 double OutputData<T>::getAxisValue(size_t global_index, size_t i_selected_axis) const
431 {
432  auto axis_index = getAxisBinIndex(global_index, i_selected_axis);
433  return (*m_value_axes[i_selected_axis])[axis_index];
434 }
435 
436 template <class T>
437 double OutputData<T>::getAxisValue(size_t global_index, const std::string& axis_name) const
438 {
439  return getAxisValue(global_index, getAxisIndex(axis_name));
440 }
441 
442 template <class T> std::vector<double> OutputData<T>::getAxesValues(size_t global_index) const
443 {
444  std::vector<int> indices = getAxesBinIndices(global_index);
445  std::vector<double> result;
446  for (size_t i_axis = 0; i_axis < indices.size(); ++i_axis)
447  result.push_back((*m_value_axes[i_axis])[indices[i_axis]]);
448  return result;
449 }
450 
451 template <class T>
452 Bin1D OutputData<T>::getAxisBin(size_t global_index, size_t i_selected_axis) const
453 {
454  auto axis_index = getAxisBinIndex(global_index, i_selected_axis);
455  return m_value_axes[i_selected_axis]->bin(axis_index);
456 }
457 
458 template <class T>
459 Bin1D OutputData<T>::getAxisBin(size_t global_index, const std::string& axis_name) const
460 {
461  return getAxisBin(global_index, getAxisIndex(axis_name));
462 }
463 
464 template <class T> inline T OutputData<T>::totalSum() const
465 {
466  ASSERT(m_ll_data);
467  return m_ll_data->getTotalSum();
468 }
469 
470 template <class T> void OutputData<T>::clear()
471 {
472  m_value_axes.clear();
473  allocate();
474 }
475 
476 template <class T> void OutputData<T>::setAllTo(const T& value)
477 {
478  if (!m_ll_data)
479  throw std::runtime_error(
480  "OutputData::setAllTo() -> Error! Low-level data object was not yet initialized.");
481  m_ll_data->setAll(value);
482 }
483 
484 template <class T> void OutputData<T>::scaleAll(const T& factor)
485 {
486  if (!m_ll_data)
487  throw std::runtime_error(
488  "OutputData::scaleAll() -> Error! Low-level data object was not yet initialized.");
489  m_ll_data->scaleAll(factor);
490 }
491 
492 template <class T> void OutputData<T>::setAxisSizes(size_t rank, int* n_dims)
493 {
494  clear();
495  std::string basename("axis");
496  for (size_t i = 0; i < rank; ++i) {
497  std::ostringstream name;
498  name << basename << i;
499  addAxis(name.str(), n_dims[i], 0.0, (double)(n_dims[i] - 1));
500  }
501 }
502 
503 template <class T> const OutputData<T>& OutputData<T>::operator+=(const OutputData<T>& right)
504 {
505  ASSERT(m_ll_data);
506  *this->m_ll_data += *right.m_ll_data;
507  return *this;
508 }
509 
510 template <class T> const OutputData<T>& OutputData<T>::operator-=(const OutputData<T>& right)
511 {
512  ASSERT(m_ll_data);
513  *this->m_ll_data -= *right.m_ll_data;
514  return *this;
515 }
516 
517 template <class T> const OutputData<T>& OutputData<T>::operator*=(const OutputData<T>& right)
518 {
519  ASSERT(m_ll_data);
520  *this->m_ll_data *= *right.m_ll_data;
521  return *this;
522 }
523 
524 template <class T> bool OutputData<T>::isInitialized() const
525 {
526  if (!m_ll_data)
527  return false;
528  if (rank() != m_ll_data->rank())
529  return false;
530  if (!rank())
531  return false;
532  return true;
533 }
534 
535 template <class T> const OutputData<T>& OutputData<T>::operator/=(const OutputData<T>& right)
536 {
537  ASSERT(m_ll_data);
538  *this->m_ll_data /= *right.m_ll_data;
539  return *this;
540 }
541 
542 template <class T> void OutputData<T>::allocate()
543 {
544  delete m_ll_data;
545  size_t rank = m_value_axes.size();
546  int* dims = new int[rank];
547  for (size_t i = 0; i < rank; ++i) {
548  dims[i] = (int)axis(i).size();
549  }
550  m_ll_data = new LLData<T>(rank, dims);
551  T default_value = {};
552  m_ll_data->setAll(default_value);
553  delete[] dims;
554 }
555 
556 template <class T> inline void OutputData<T>::setRawDataVector(const std::vector<T>& data_vector)
557 {
558  if (data_vector.size() != getAllocatedSize())
559  throw std::runtime_error(
560  "OutputData<T>::setRawDataVector() -> Error! "
561  "setRawDataVector can only be called with a data vector of the correct size.");
562  for (size_t i = 0; i < getAllocatedSize(); ++i)
563  (*m_ll_data)[i] = data_vector[i];
564 }
565 
566 template <class T> inline void OutputData<T>::setRawDataArray(const T* source)
567 {
568  for (size_t i = 0; i < getAllocatedSize(); ++i)
569  (*m_ll_data)[i] = source[i];
570 }
571 
572 //! Returns true if object have same dimensions
573 template <class T>
574 template <class U>
575 inline bool OutputData<T>::hasSameDimensions(const OutputData<U>& right) const
576 {
577  if (!isInitialized())
578  return false;
579  if (!right.isInitialized())
580  return false;
581  if (rank() != right.rank())
582  return false;
583  for (size_t i_axis = 0; i_axis < rank(); ++i_axis)
584  if (axis(i_axis).size() != right.axis(i_axis).size())
585  return false;
586  return true;
587 }
588 
589 //! Returns true if object have same dimensions and shape of axis
590 template <class T>
591 template <class U>
593 {
594  if (!hasSameDimensions(right))
595  return false;
596 
597  for (size_t i = 0; i < m_value_axes.size(); ++i)
598  if (!HaveSameNameAndShape(axis(i), right.axis(i)))
599  return false;
600  return true;
601 }
602 
603 //! returns data as Python numpy array
604 #ifdef BORNAGAIN_PYTHON
605 template <> PyObject* OutputData<double>::getArray() const;
606 #endif
607 
608 // return index of axis
609 template <class T> size_t OutputData<T>::getAxisIndex(const std::string& axis_name) const
610 {
611  for (size_t i = 0; i < m_value_axes.size(); ++i)
612  if (m_value_axes[i]->getName() == axis_name)
613  return i;
614  throw std::runtime_error("OutputData<T>::getAxisIndex() -> "
615  "Error! Axis with given name not found '"
616  + axis_name + "'");
617 }
618 
619 template <class T> bool OutputData<T>::axisNameExists(const std::string& axis_name) const
620 {
621  for (size_t i = 0; i < m_value_axes.size(); ++i)
622  if (m_value_axes[i]->getName() == axis_name)
623  return true;
624  return false;
625 }
626 
627 #endif // BORNAGAIN_DEVICE_DATA_OUTPUTDATA_H
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:31
Defines class FixedBinAxis.
bool HaveSameNameAndShape(const IAxis &left, const IAxis &right)
global helper function for comparison of axes
Definition: IAxis.h:100
Defines class LLData.
Defines and implements template class OutputDataIterator.
PyObvject forward declaration.
_object PyObject
Definition: PyObject.h:25
Defines and implements template class SafePointerVector.
Defines struct ThreadInfo.
Axis with fixed bin size.
Definition: FixedBinAxis.h:23
Interface for one-dimensional axes.
Definition: IAxis.h:25
virtual IAxis * clone() const =0
clone function
virtual size_t size() const =0
retrieve the number of bins
std::string getName() const
retrieve the label of the axis
Definition: IAxis.h:40
Template class to store data of any type in multi-dimensional space (low-level).
Definition: LLData.h:31
Iterator for underlying OutputData container.
Templated class to store data of type double or CumulativeValue in multi-dimensional space.
Definition: OutputData.h:32
double getValue(size_t index) const
Returns value or summed value, depending on T.
void setAxisSizes(size_t rank, int *n_dims)
Adds 'rank' axes with indicated sizes.
Definition: OutputData.h:492
void copyFrom(const OutputData< T > &x)
Definition: OutputData.h:267
OutputData< double > * meanValues() const
Definition: OutputData.h:285
void allocate()
memory allocation for current dimensions configuration
Definition: OutputData.h:542
OutputData(OutputData &&)
Definition: OutputData.h:239
T & operator[](size_t index)
indexed accessor
Definition: OutputData.h:192
size_t getAxisBinIndex(size_t global_index, size_t i_selected_axis) const
Returns axis bin index for given global index.
Definition: OutputData.h:370
iterator end()
Returns read/write iterator that points to the one past last element.
Definition: OutputData.h:93
size_t toGlobalIndex(const std::vector< unsigned > &axes_indices) const
Returns global index for specified indices of axes.
Definition: OutputData.h:392
const OutputData< T > & operator+=(const OutputData< T > &right)
addition-assignment operator for two output data
Definition: OutputData.h:503
bool hasSameShape(const OutputData< U > &right) const
Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.
Definition: OutputData.h:592
OutputData(const OutputData &)=delete
size_t rank() const
Returns number of dimensions.
Definition: OutputData.h:56
void setRawDataArray(const T *source)
Sets new values to raw data array.
Definition: OutputData.h:566
OutputDataIterator< const T, const OutputData< T > > const_iterator
Read-only iterator type.
Definition: OutputData.h:84
std::vector< T > getRawDataVector() const
Returns copy of raw data vector.
Definition: OutputData.h:334
void setAllTo(const T &value)
Sets content of output data to specific value.
Definition: OutputData.h:476
std::vector< double > getAxesValues(size_t global_index) const
Returns values on all defined axes for given globalbin number.
Definition: OutputData.h:442
size_t findGlobalIndex(const std::vector< double > &coordinates) const
Returns global index for specified axes values.
Definition: OutputData.h:416
OutputDataIterator< T, OutputData< T > > iterator
Read/write iterator type.
Definition: OutputData.h:81
const OutputData & operator=(const OutputData &)=delete
T totalSum() const
Returns sum of all values in the data structure.
Definition: OutputData.h:464
const IAxis & axis(size_t serial_number) const
returns axis with given serial number
Definition: OutputData.h:318
std::vector< int > getAxesBinIndices(size_t global_index) const
Returns vector of axes indices for given global index.
Definition: OutputData.h:355
const OutputData< T > & operator-=(const OutputData< T > &right)
substraction-assignment operator for two output data
Definition: OutputData.h:510
void copyShapeFrom(const OutputData< U > &other)
Definition: OutputData.h:277
LLData< T > * m_ll_data
Definition: OutputData.h:232
Bin1D getAxisBin(size_t global_index, const std::string &axis_name) const
Returns bin of selected axis for given global_index.
Definition: OutputData.h:459
void addAxis(const IAxis &new_axis)
Definition: OutputData.h:295
bool isInitialized() const
returns true if object is correctly initialized
Definition: OutputData.h:524
Bin1D getAxisBin(size_t global_index, size_t i_selected_axis) const
Returns bin of selected axis for given global_index.
Definition: OutputData.h:452
const OutputData< T > & operator*=(const OutputData< T > &right)
multiplication-assignment operator for two output data
Definition: OutputData.h:517
const OutputData< T > & operator/=(const OutputData< T > &right)
division-assignment operator for two output data
Definition: OutputData.h:535
SafePointerVector< IAxis > m_value_axes
Definition: OutputData.h:231
void setRawDataVector(const std::vector< T > &data_vector)
Sets new values to raw data vector.
Definition: OutputData.h:556
bool axisNameExists(const std::string &axis_name) const
checks if given axis name exists
Definition: OutputData.h:619
double getAxisValue(size_t global_index, const std::string &axis_name) const
Returns the value of selected axis for given global_index.
Definition: OutputData.h:437
bool hasSameDimensions(const OutputData< U > &right) const
Returns true if object have same dimensions and number of axes bins.
Definition: OutputData.h:575
const_iterator begin() const
Returns read-only iterator that points to the first element.
Definition: OutputData.h:349
void scaleAll(const T &factor)
multiply every item of this output data by value
Definition: OutputData.h:484
void addAxis(const std::string &name, size_t size, double start, double end)
Definition: OutputData.h:308
iterator begin()
Returns read/write iterator that points to the first element.
Definition: OutputData.h:343
size_t getAxisBinIndex(size_t global_index, const std::string &axis_name) const
Returns axis bin index for given global index.
Definition: OutputData.h:386
std::vector< size_t > getAllSizes() const
Returns all sizes of its axes.
Definition: OutputData.h:323
size_t getAllocatedSize() const
Returns total size of data buffer (product of bin number in every dimension).
Definition: OutputData.h:59
const_iterator end() const
Returns read-only iterator that points to the one past last element.
Definition: OutputData.h:96
const T & operator[](size_t index) const
indexed accessor (const)
Definition: OutputData.h:199
size_t getAxisIndex(const std::string &axis_name) const
returns serial number of axis with given name
Definition: OutputData.h:609
OutputData * clone() const
Definition: OutputData.h:259
PyObject * getArray() const
returns data as Python numpy array
double getAxisValue(size_t global_index, size_t i_selected_axis) const
Returns the value of selected axis for given global_index.
Definition: OutputData.h:430
void clear()
Sets object into initial state (no dimensions, data)
Definition: OutputData.h:470
size_t size() const
QString const & name(EShape k)
Definition: particles.cpp:21
Definition: Bin.h:20