Essentia
2.1-beta6-dev
|
#include <pool.h>
Public Member Functions | |
void | add (const std::string &name, const Real &value, bool validityCheck=false) |
void | add (const std::string &name, const std::vector< Real > &value, bool validityCheck=false) |
void | add (const std::string &name, const std::string &value, bool validityCheck=false) |
void | add (const std::string &name, const std::vector< std::string > &value, bool validityCheck=false) |
void | add (const std::string &name, const TNT::Array2D< Real > &value, bool validityCheck=false) |
void | add (const std::string &name, const Tensor< Real > &value, bool validityCheck=false) |
void | add (const std::string &name, const StereoSample &value, bool validityCheck=false) |
template<typename T > | |
void | append (const std::string &name, const std::vector< T > &values) |
void | set (const std::string &name, const Real &value, bool validityCheck=false) |
Sets the value of a descriptor name. More... | |
void | set (const std::string &name, const std::vector< Real > &value, bool validityCheck=false) |
Sets the value of a descriptor name. More... | |
void | set (const std::string &name, const std::string &value, bool validityCheck=false) |
Sets the value of a descriptor name. More... | |
void | set (const std::string &name, const std::vector< std::string > &value, bool validityCheck=false) |
Sets the value of a descriptor name. More... | |
void | set (const std::string &name, const Tensor< Real > &value, bool validityCheck=false) |
void | merge (Pool &p, const std::string &type="") |
Merges the current pool with the given one p. More... | |
void | merge (const std::string &name, const std::vector< Real > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | merge (const std::string &name, const std::vector< std::vector< Real > > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | merge (const std::string &name, const std::vector< std::string > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | merge (const std::string &name, const std::vector< std::vector< std::string > > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | merge (const std::string &name, const std::vector< TNT::Array2D< Real > > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | merge (const std::string &name, const std::vector< Tensor< Real > > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | merge (const std::string &name, const std::vector< StereoSample > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | mergeSingle (const std::string &name, const Real &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | mergeSingle (const std::string &name, const std::vector< Real > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | mergeSingle (const std::string &name, const std::string &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | mergeSingle (const std::string &name, const std::vector< std::string > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | mergeSingle (const std::string &name, const Tensor< Real > &value, const std::string &type="") |
Merges the values given in value into the current pool's descriptor given by name. More... | |
void | remove (const std::string &name) |
void | removeNamespace (const std::string &ns) |
template<typename T > | |
const T & | value (const std::string &name) const |
template<typename T > | |
bool | contains (const std::string &name) const |
std::vector< std::string > | descriptorNames () const |
std::vector< std::string > | descriptorNames (const std::string &ns) const |
const std::map< std::string, std::vector< Real > > & | getRealPool () const |
const std::map< std::string, std::vector< std::vector< Real > > > & | getVectorRealPool () const |
const std::map< std::string, std::vector< std::string > > & | getStringPool () const |
const std::map< std::string, std::vector< std::vector< std::string > > > & | getVectorStringPool () const |
const std::map< std::string, std::vector< TNT::Array2D< Real > > > & | getArray2DRealPool () const |
const std::map< std::string, std::vector< Tensor< Real > > > & | getTensorRealPool () const |
const std::map< std::string, std::vector< StereoSample > > & | getStereoSamplePool () const |
const std::map< std::string, Real > & | getSingleRealPool () const |
const std::map< std::string, std::string > & | getSingleStringPool () const |
const std::map< std::string, std::vector< Real > > & | getSingleVectorRealPool () const |
const std::map< std::string, std::vector< std::string > > & | getSingleVectorStringPool () const |
const std::map< std::string, Tensor< Real > > & | getSingleTensorRealPool () const |
void | checkIntegrity () const |
void | clear () |
bool | isSingleValue (const std::string &name) |
Protected Member Functions | |
std::vector< std::string > | descriptorNamesNoLocking () const |
void | validateKey (const std::string &name) |
Protected Attributes | |
std::map< std::string, Real > | _poolSingleReal |
std::map< std::string, std::string > | _poolSingleString |
std::map< std::string, std::vector< Real > > | _poolSingleVectorReal |
std::map< std::string, std::vector< std::string > > | _poolSingleVectorString |
std::map< std::string, Tensor< Real > > | _poolSingleTensorReal |
std::map< std::string, std::vector< Real > > | _poolReal |
std::map< std::string, std::vector< std::vector< Real > > > | _poolVectorReal |
std::map< std::string, std::vector< std::string > > | _poolString |
std::map< std::string, std::vector< std::vector< std::string > > > | _poolVectorString |
std::map< std::string, std::vector< TNT::Array2D< Real > > > | _poolArray2DReal |
std::map< std::string, std::vector< Tensor< Real > > > | _poolTensorReal |
std::map< std::string, std::vector< StereoSample > > | _poolStereoSample |
The pool is a storage structure which can hold frames of all kinds of descriptors. A Pool instance is thread-safe.
More specifically, a Pool maps descriptor names to data. A descriptor name is a period ('.') delimited string of identifiers that are associated with the values of some audio descriptor (or any other piece of data). For example, the descriptor name "lowlevel.bpm" identifies a low-level value of beats per minute. Currently, the Pool supports storing:
The Pool supports the ability to repeatedly add data under the same descriptor name as well as associating a descriptor name with only one datum. The set function is used in the latter case, and the former is explained in the next paragraph.
When data is added to the pool under a given descriptor name, it is added to a vector of data for that descriptor name. When the data is retrieved, a vector of data which was stored under that descriptor name is returned. For example, in the case of the descriptor name, "foo.bar", which maps to Real descriptor values, every time a Real is added under the name "foo.bar", it is actually stored in a vector. When the data mapped to by "foo.bar" is retrieved, a vector of Reals is returned, even if only one Real value was added under "foo.bar". In the case of data of type vector of Reals, a vector of vector of Reals is returned when the data is retrieved.
It is not allowed to mix data types under the same descriptor name. Each of the four types listed above are treated as separate types. In addition, a descriptor name that maps to a single datum is considered mapping to a different type than a descriptor name that maps to a vector of the same type.
After a Pool is filled with data, it can be passed to the YamlOutput algorithm for saving the data in the Pool to a file or it can be passed to the PoolAggregator algorithm for computing statistics on the data in the Pool. Similarly, the file generated by YamlOutput can be restored into a Pool using the YamlInput algorithm.
For each type, the pool has its own public mutex (i.e. mutexReal, mutexVectorReal, etc.) If locking the pool globally or partially, lock should be acquired in the following order:
MutexLocker lockReal(mutexReal) MutexLocker lockVectorReal(mutexVectorReal) MutexLocker lockString(mutexString) MutexLocker lockVectorString(mutexVectorString) MutexLocker lockArray2DReal(mutexArray2DReal) MutexLocker lockStereoSample(mutexStereoSample) MutexLocker lockSingleReal(mutexSingleReal) MutexLocker lockSingleString(mutexSingleString) MutexLocker lockSingleVectorReal(mutexSingleVectorReal) MutexLocker lockSingleVectorString(mutexSingleVectorString)
To release the locks, the order should be reversed!
void add | ( | const std::string & | name, |
const Real & | value, | ||
bool | validityCheck = false |
||
) |
Adds value to the Pool under name
name | a descriptor name that identifies the collection of data to add value to |
value | the value to add to the collection of data that name points to |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
Referenced by PoolStorage< TokenType, StorageType >::addToPool().
void add | ( | const std::string & | name, |
const std::string & | value, | ||
bool | validityCheck = false |
||
) |
Adds value to the Pool under name
name | a descriptor name that identifies the collection of data to add value to |
value | the value to add to the collection of data that name points to |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
void add | ( | const std::string & | name, |
const std::vector< Real > & | value, | ||
bool | validityCheck = false |
||
) |
Adds value to the Pool under name
name | a descriptor name that identifies the collection of data to add value to |
value | the value to add to the collection of data that name points to |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
void add | ( | const std::string & | name, |
const std::vector< std::string > & | value, | ||
bool | validityCheck = false |
||
) |
Adds value to the Pool under name
name | a descriptor name that identifies the collection of data to add value to |
value | the value to add to the collection of data that name points to |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
void add | ( | const std::string & | name, |
const StereoSample & | value, | ||
bool | validityCheck = false |
||
) |
Adds value to the Pool under name
name | a descriptor name that identifies the collection of data to add value to |
value | the value to add to the collection of data that name points to |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
void add | ( | const std::string & | name, |
const TNT::Array2D< Real > & | value, | ||
bool | validityCheck = false |
||
) |
Adds value to the Pool under name
name | a descriptor name that identifies the collection of data to add value to |
value | the value to add to the collection of data that name points to |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
void append | ( | const std::string & | name, |
const std::vector< T > & | values | ||
) |
WARNING: this is an utility method that might fail in weird ways if not used correctly. When in doubt, always use the add() method. This is provided for optimization only.
Referenced by PoolStorage< TokenType, StorageType >::process().
void checkIntegrity | ( | ) | const |
Checks that no descriptor name is in two different inner pool types at the same time, and throws an EssentiaException if there is
void clear | ( | ) |
Clears all the values contained in the pool.
bool contains | ( | const std::string & | name | ) | const |
name | is the name of the descriptor you wish to check for |
T | is the type of data that name refers to |
std::vector<std::string> descriptorNames | ( | ) | const |
std::vector<std::string> descriptorNames | ( | const std::string & | ns | ) | const |
|
protected |
|
inline |
References Pool::_poolArray2DReal.
|
inline |
References Pool::_poolReal.
|
inline |
References Pool::_poolSingleReal.
|
inline |
References Pool::_poolSingleString.
References Pool::_poolSingleTensorReal.
|
inline |
References Pool::_poolSingleVectorReal.
|
inline |
References Pool::_poolSingleVectorString.
|
inline |
References Pool::_poolStereoSample.
|
inline |
References Pool::_poolString.
References Pool::_poolTensorReal.
|
inline |
References Pool::_poolVectorReal.
|
inline |
References Pool::_poolVectorString.
bool isSingleValue | ( | const std::string & | name | ) |
returns true if descriptor under name name is supposed to hold one single value
void merge | ( | const std::string & | name, |
const std::vector< Real > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void merge | ( | const std::string & | name, |
const std::vector< std::string > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void merge | ( | const std::string & | name, |
const std::vector< std::vector< Real > > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void merge | ( | const std::string & | name, |
const std::vector< std::vector< std::string > > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void merge | ( | const std::string & | name, |
const std::vector< StereoSample > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void merge | ( | const std::string & | name, |
const std::vector< Tensor< Real > > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void merge | ( | const std::string & | name, |
const std::vector< TNT::Array2D< Real > > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void merge | ( | Pool & | p, |
const std::string & | type = "" |
||
) |
Merges the current pool with the given one p.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void mergeSingle | ( | const std::string & | name, |
const Real & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void mergeSingle | ( | const std::string & | name, |
const std::string & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void mergeSingle | ( | const std::string & | name, |
const std::vector< Real > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void mergeSingle | ( | const std::string & | name, |
const std::vector< std::string > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void mergeSingle | ( | const std::string & | name, |
const Tensor< Real > & | value, | ||
const std::string & | type = "" |
||
) |
Merges the values given in value into the current pool's descriptor given by name.
If the pool contains a descriptor with name name, the current pool will keep its original descriptor values unless a type of merging is specified.
Merge types can be:
void remove | ( | const std::string & | name | ) |
void removeNamespace | ( | const std::string & | ns | ) |
void set | ( | const std::string & | name, |
const Real & | value, | ||
bool | validityCheck = false |
||
) |
Sets the value of a descriptor name.
This function is different than the add functions because set does not append data to the existing data under a given descriptor name, it sets it. Thus there can only be one datum associated with a descriptor name introduced to the pool via the set function. This function is useful when there is only one value associated with a given descriptor name.
name | is the descriptor name of the datum to set |
value | is the datum to associate with name |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
Referenced by PoolStorage< TokenType, StorageType >::addToPool().
void set | ( | const std::string & | name, |
const std::string & | value, | ||
bool | validityCheck = false |
||
) |
Sets the value of a descriptor name.
This function is different than the add functions because set does not append data to the existing data under a given descriptor name, it sets it. Thus there can only be one datum associated with a descriptor name introduced to the pool via the set function. This function is useful when there is only one value associated with a given descriptor name.
name | is the descriptor name of the datum to set |
value | is the datum to associate with name |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
void set | ( | const std::string & | name, |
const std::vector< Real > & | value, | ||
bool | validityCheck = false |
||
) |
Sets the value of a descriptor name.
This function is different than the add functions because set does not append data to the existing data under a given descriptor name, it sets it. Thus there can only be one datum associated with a descriptor name introduced to the pool via the set function. This function is useful when there is only one value associated with a given descriptor name.
name | is the descriptor name of the datum to set |
value | is the datum to associate with name |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
void set | ( | const std::string & | name, |
const std::vector< std::string > & | value, | ||
bool | validityCheck = false |
||
) |
Sets the value of a descriptor name.
This function is different than the add functions because set does not append data to the existing data under a given descriptor name, it sets it. Thus there can only be one datum associated with a descriptor name introduced to the pool via the set function. This function is useful when there is only one value associated with a given descriptor name.
name | is the descriptor name of the datum to set |
value | is the datum to associate with name |
validityCheck | indicates whether value should be checked for NaN or Inf values. If true, an exception is thrown if value is (or contains) a NaN or Inf. |
|
protected |
helper function for key validation when adding/setting/merging values to the pool
const T& value | ( | const std::string & | name | ) | const |
name | is the descriptor name that points to the data to return |
T | is the type of data that name points to |
|
protected |
Referenced by Pool::getArray2DRealPool().
|
protected |
Referenced by Pool::getRealPool().
|
protected |
Referenced by Pool::getSingleRealPool().
|
protected |
Referenced by Pool::getSingleStringPool().
Referenced by Pool::getSingleTensorRealPool().
|
protected |
Referenced by Pool::getSingleVectorRealPool().
|
protected |
Referenced by Pool::getSingleVectorStringPool().
|
protected |
Referenced by Pool::getStereoSamplePool().
|
protected |
Referenced by Pool::getStringPool().
Referenced by Pool::getTensorRealPool().
|
protected |
Referenced by Pool::getVectorRealPool().
|
protected |
Referenced by Pool::getVectorStringPool().
Mutex mutexArray2DReal |
|
mutable |
Mutex mutexSingleReal |
Mutex mutexSingleString |
Mutex mutexSingleTensorReal |
Mutex mutexSingleVectorReal |
Mutex mutexSingleVectorString |
Mutex mutexStereoSample |
Mutex mutexString |
Mutex mutexTensorReal |
Mutex mutexVectorReal |
Mutex mutexVectorString |