ndmspc  v1.1.1-1
Ndmspc::NDimensionalExecutor Class Reference

Executes a function over all points in an N-dimensional space, optionally in parallel. More...

#include <NDimensionalExecutor.h>

Public Member Functions

 NDimensionalExecutor (const std::vector< int > &minBounds, const std::vector< int > &maxBounds)
 Constructor from min/max bounds for each dimension. More...
 
 NDimensionalExecutor (THnSparse *hist, bool onlyfilled=false)
 Constructor from THnSparse histogram. More...
 
void Execute (const std::function< void(const std::vector< int > &coords)> &func)
 Execute a function over all coordinates in the N-dimensional space. More...
 
template<typename TObject >
void ExecuteParallel (const std::function< void(const std::vector< int > &coords, TObject &thread_object)> &func, std::vector< TObject > &thread_objects)
 Execute a function in parallel over all coordinates, using thread-local objects. More...
 
size_t Dimensions () const
 Returns the number of dimensions. More...
 
const std::vector< int > & GetMinBounds () const
 Returns the minimum bounds for each dimension. More...
 
const std::vector< int > & GetMaxBounds () const
 Returns the maximum bounds for each dimension. More...
 

Private Member Functions

bool Increment ()
 Increment the current coordinates to the next point in the N-dimensional space. More...
 

Private Attributes

size_t fNumDimensions
 Number of dimensions.
 
std::vector< int > fMinBounds
 Minimum bounds for each dimension.
 
std::vector< int > fMaxBounds
 Maximum bounds for each dimension.
 
std::vector< int > fCurrentCoords
 Current coordinates during iteration.
 

Detailed Description

Executes a function over all points in an N-dimensional space, optionally in parallel.

Author
Martin Vala mvala.nosp@m.@cer.nosp@m.n.ch

Definition at line 28 of file NDimensionalExecutor.h.

Constructor & Destructor Documentation

◆ NDimensionalExecutor() [1/2]

Ndmspc::NDimensionalExecutor::NDimensionalExecutor ( const std::vector< int > &  minBounds,
const std::vector< int > &  maxBounds 
)

Constructor from min/max bounds for each dimension.

Parameters
minBoundsMinimum bounds for each dimension.
maxBoundsMaximum bounds for each dimension.

Constructor

Definition at line 21 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMaxBounds, fMinBounds, and fNumDimensions.

◆ NDimensionalExecutor() [2/2]

Ndmspc::NDimensionalExecutor::NDimensionalExecutor ( THnSparse *  hist,
bool  onlyfilled = false 
)

Constructor from THnSparse histogram.

Parameters
histPointer to THnSparse histogram.
onlyfilledIf true, iterate only filled bins.

Constructor with THnSparse input

Definition at line 49 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMaxBounds, fMinBounds, and fNumDimensions.

Member Function Documentation

◆ Dimensions()

size_t Ndmspc::NDimensionalExecutor::Dimensions ( ) const
inline

Returns the number of dimensions.

Returns
Number of dimensions.

Definition at line 64 of file NDimensionalExecutor.h.

References fNumDimensions.

◆ Execute()

void Ndmspc::NDimensionalExecutor::Execute ( const std::function< void(const std::vector< int > &coords)> &  func)

Execute a function over all coordinates in the N-dimensional space.

Parameters
funcFunction to execute, taking coordinates as argument.

Sequential Execution

Definition at line 79 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMinBounds, fNumDimensions, and Increment().

Referenced by Ndmspc::NBinningDef::RefreshContentFromIds(), Ndmspc::NBinningDef::RefreshIdsFromContent(), and Ndmspc::NGnNavigator::Reshape().

◆ ExecuteParallel()

template<typename TObject >
void Ndmspc::NDimensionalExecutor::ExecuteParallel ( const std::function< void(const std::vector< int > &coords, TObject &thread_object)> &  func,
std::vector< TObject > &  thread_objects 
)

Execute a function in parallel over all coordinates, using thread-local objects.

Execute a function in parallel over all coordinates, using thread-local objects. Handles task distribution, synchronization, and exception propagation.

Template Parameters
TObjectType of thread-local object.
Parameters
funcFunction to execute, taking coordinates and thread-local object.
thread_objectsVector of thread-local objects, one per thread.
Exceptions
std::exceptionIf any worker thread throws, the first exception is rethrown after joining.

Definition at line 99 of file NDimensionalExecutor.h.

References fCurrentCoords, fMinBounds, fNumDimensions, Ndmspc::NThreadData::GetAssignedIndex(), Increment(), and Ndmspc::NLogger::SetThreadName().

Referenced by Ndmspc::NGnTree::Process().

◆ GetMaxBounds()

const std::vector<int>& Ndmspc::NDimensionalExecutor::GetMaxBounds ( ) const
inline

Returns the maximum bounds for each dimension.

Returns
Vector of maximum bounds.

Definition at line 76 of file NDimensionalExecutor.h.

References fMaxBounds.

◆ GetMinBounds()

const std::vector<int>& Ndmspc::NDimensionalExecutor::GetMinBounds ( ) const
inline

Returns the minimum bounds for each dimension.

Returns
Vector of minimum bounds.

Definition at line 70 of file NDimensionalExecutor.h.

References fMinBounds.

◆ Increment()

bool Ndmspc::NDimensionalExecutor::Increment ( )
private

Increment the current coordinates to the next point in the N-dimensional space.

Returns
True if increment was successful, false if end reached.

Definition at line 9 of file NDimensionalExecutor.cxx.

References fCurrentCoords, fMaxBounds, fMinBounds, and fNumDimensions.

Referenced by Execute(), and ExecuteParallel().


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