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