Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
HEP
HEPnOS
Commits
39c230b4
Commit
39c230b4
authored
Feb 18, 2020
by
Matthieu Dorier
Browse files
removed iterator functionalities from DataStore and put them in DataSet
parent
91903f4f
Changes
22
Hide whitespace changes
Inline
Side-by-side
bin/hepnos-ls.cpp
View file @
39c230b4
...
...
@@ -37,7 +37,7 @@ int main(int argc, char* argv[])
}
hepnos
::
DataStore
datastore
=
hepnos
::
DataStore
::
connect
(
argv
[
1
]);
for
(
auto
&
ds
:
datastore
)
{
for
(
auto
&
ds
:
datastore
.
root
()
)
{
navigate_dataset
(
0
,
ds
);
}
...
...
include/hepnos/DataSet.hpp
View file @
39c230b4
...
...
@@ -212,9 +212,6 @@ class DataSet : public KeyValueContainer {
Run
createRun
(
const
RunNumber
&
runNumber
);
Run
createRun
(
WriteBatch
&
batch
,
const
RunNumber
&
runNumber
);
typedef
DataStore
::
const_iterator
const_iterator
;
typedef
DataStore
::
iterator
iterator
;
/**
* @brief Accesses an existing DataSet using the []
* operator. If no DataSet correspond to the provided name,
...
...
@@ -227,6 +224,20 @@ class DataSet : public KeyValueContainer {
*/
DataSet
operator
[](
const
std
::
string
&
datasetName
)
const
;
/**
* @brief iterator class to navigate DataSets.
* This iterator is a forward iterator. DataSets are sorted
* alphabetically inside the DataStore.
*/
class
iterator
;
/**
* @brief const_iterator class to navigate DataSets.
* This iterator is a forward iterator. DataSets are sorted
* alphabetically inside the DataStore.
*/
class
const_iterator
;
/**
* @brief Searches this DataSet for a DataSet with
* the provided path and returns an iterator to it if found,
...
...
@@ -373,6 +384,229 @@ class DataSet : public KeyValueContainer {
Run
operator
[](
const
RunNumber
&
runNumber
)
const
;
};
class
DataSet
::
const_iterator
{
protected:
/**
* @brief Implementation of the class (using Pimpl idiom)
*/
class
Impl
;
std
::
unique_ptr
<
Impl
>
m_impl
;
/*!< Pointer to implementation */
public:
/**
* @brief Constructor. Creates a const_iterator pointing
* to an invalid DataSet.
*/
const_iterator
();
/**
* @brief Constructor. Creates a const_iterator pointing
* to a given DataSet. The DataSet may or may not be valid.
*
* @param current DataSet to make the const_iterator point to.
*/
const_iterator
(
const
DataSet
&
current
);
/**
* @brief Constructor. Creates a const_iterator pointing
* to a given DataSet. The DataSet may or may not be valid.
*
* @param current DataSet to make the const_iterator point to.
*/
const_iterator
(
DataSet
&&
current
);
typedef
const_iterator
self_type
;
typedef
DataSet
value_type
;
typedef
DataSet
&
reference
;
typedef
DataSet
*
pointer
;
typedef
int
difference_type
;
typedef
std
::
forward_iterator_tag
iterator_category
;
/**
* @brief Destructor. This destructor is virtual because
* the iterator class inherits from const_iterator.
*/
virtual
~
const_iterator
();
/**
* @brief Copy-constructor.
*
* @param other const_iterator to copy.
*/
const_iterator
(
const
const_iterator
&
other
);
/**
* @brief Move-constructor.
*
* @param other const_iterator to move.
*/
const_iterator
(
const_iterator
&&
other
);
/**
* @brief Copy-assignment operator.
*
* @param other const_iterator to copy.
*
* @return this.
*/
const_iterator
&
operator
=
(
const
const_iterator
&
);
/**
* @brief Move-assignment operator.
*
* @param other const_iterator to move.
*
* @return this.
*/
const_iterator
&
operator
=
(
const_iterator
&&
);
/**
* @brief Increments the const_iterator, returning
* a copy of the iterator after incrementation.
*
* @return a copy of the iterator after incrementation.
*/
self_type
operator
++
();
/**
* @brief Increments the const_iterator, returning
* a copy of the iterator before incrementation.
*
* @return a copy of the iterator after incrementation.
*/
self_type
operator
++
(
int
);
/**
* @brief Dereference operator. Returns a const reference
* to the DataSet this const_iterator points to.
*
* @return a const reference to the DataSet this
* const_iterator points to.
*/
const
reference
operator
*
();
/**
* @brief Returns a const pointer to the DataSet this
* const_iterator points to.
*
* @return a const pointer to the DataSet this
* const_iterator points to.
*/
const
pointer
operator
->
();
/**
* @brief Compares two const_iterators. The two const_iterators
* are equal if they point to the same DataSet or if both
* correspond to DataStore::cend().
*
* @param rhs const_iterator to compare with.
*
* @return true if the two const_iterators are equal, false otherwise.
*/
bool
operator
==
(
const
self_type
&
rhs
)
const
;
/**
* @brief Compares two const_iterators.
*
* @param rhs const_iterator to compare with.
*
* @return true if the two const_iterators are different, false otherwise.
*/
bool
operator
!=
(
const
self_type
&
rhs
)
const
;
};
class
DataSet
::
iterator
:
public
DataSet
::
const_iterator
{
public:
/**
* @brief Constructor. Builds an iterator pointing to an
* invalid DataSet.
*/
iterator
();
/**
* @brief Constructor. Builds an iterator pointing to
* an existing DataSet. The DataSet may or may not be
* valid.
*
* @param current DataSet to point to.
*/
iterator
(
const
DataSet
&
current
);
/**
* @brief Constructor. Builds an iterator pointing to
* an existing DataSet. The DataSet may or may not be
* valid.
*
* @param current DataSet to point to.
*/
iterator
(
DataSet
&&
current
);
typedef
iterator
self_type
;
typedef
DataSet
value_type
;
typedef
DataSet
&
reference
;
typedef
DataSet
*
pointer
;
typedef
int
difference_type
;
typedef
std
::
forward_iterator_tag
iterator_category
;
/**
* @brief Destructor.
*/
~
iterator
();
/**
* @brief Copy constructor.
*
* @param other iterator to copy.
*/
iterator
(
const
iterator
&
other
);
/**
* @brief Move constructor.
*
* @param other iterator to move.
*/
iterator
(
iterator
&&
other
);
/**
* @brief Copy-assignment operator.
*
* @param other iterator to copy.
*
* @return this.
*/
iterator
&
operator
=
(
const
iterator
&
other
);
/**
* @brief Move-assignment operator.
*
* @param other iterator to move.
*
* @return this.
*/
iterator
&
operator
=
(
iterator
&&
other
);
/**
* @brief Dereference operator. Returns a reference
* to the DataSet this iterator points to.
*
* @return A reference to the DataSet this iterator
* points to.
*/
reference
operator
*
();
/**
* @brief Returns a pointer to the DataSet this iterator
* points to.
*
* @return A pointer to the DataSet this iterator points to.
*/
pointer
operator
->
();
};
}
#endif
include/hepnos/DataStore.hpp
View file @
39c230b4
...
...
@@ -44,8 +44,6 @@ class DataStore {
public:
typedef
DataSet
value_type
;
/**
* @brief Constructor. Initializes the DataStore by taking
* the name of the configuration file from the environment
...
...
@@ -104,181 +102,9 @@ class DataStore {
bool
valid
()
const
;
/**
* @brief Accesses an existing DataSet using the []
* operator. If no DataSet correspond to the provided name,
* the function returns a DataSet instance d such that
* d.valid() is false.
*
* @param datasetName Name of the DataSet to retrieve.
*
* @return a DataSet corresponding to the provided name.
*/
DataSet
operator
[](
const
std
::
string
&
datasetName
)
const
;
/**
* @brief iterator class to navigate DataSets.
* This iterator is a forward iterator. DataSets are sorted
* alphabetically inside the DataStore.
*/
class
iterator
;
/**
* @brief const_iterator class to navigate DataSets.
* This iterator is a forward iterator. DataSets are sorted
* alphabetically inside the DataStore.
*/
class
const_iterator
;
/**
* @brief Searches the DataStore for an DataSet with
* the provided path and returns an iterator to it if found,
* otherwise it returns an iterator to DataStore::end().
*
* @param datasetPath Path of the DataSet to find.
*
* @return an iterator pointing to the DataSet if found,
* DataStore::end() otherwise.
*/
iterator
find
(
const
std
::
string
&
datasetPath
);
/**
* @brief Searches the DataStore for an DataSet with
* the provided path and returns a const_iterator to it
* if found, otherwise it returns an iterator to DataStore::end().
*
* @param datasetPath Path of the DataSet to find.
*
* @return a const_iterator pointing to the DataSet if found,
* DataStore::cend() otherwise.
*/
const_iterator
find
(
const
std
::
string
&
datasetPath
)
const
;
/**
* @brief Returns an iterator referring to the first DataSet
* in the DataStore.
*
* @return an iterator referring to the first DataSet in the DataStore.
*/
iterator
begin
();
/**
* @brief Returns an iterator referring to the end of the DataStore.
* The DataSet pointed to by this iterator is not valid (that is,
* `end()->valid()` returns `false`).
*
* @return an iterator referring to the end of the DataStore.
*/
iterator
end
();
/**
* @brief Returns a const_iterator referring to the first DataSet
* in the DataStore.
*
* @return a const_iterator referring to the first DataSet in the DataStore.
*/
const_iterator
begin
()
const
;
/**
* @brief Returns a const_iterator referring to the end of the DataStore.
* The DataSet pointed to by this iterator is not valid (that is,
* `end()->valid()` returns `false`).
*
* @return a const_iterator referring to the end of the DataStore.
*/
const_iterator
end
()
const
;
/**
* @brief Returns a const_iterator referring to the first DataSet
* in the DataStore.
*
* @return a const_iterator referring to the first DataSet in the DataStore.
*/
const_iterator
cbegin
()
const
;
/**
* @brief Returns a const_iterator referring to the end of the DataStore.
* The DataSet pointed to by this iterator is not valid (that is,
* `cend()->valid()` return `false`).
*
* @return a const_iterator referring to the end of the DataStore.
*/
const_iterator
cend
()
const
;
/**
* @brief Returns an iterator pointing to the first DataSet in the
* DataStore whose name is not considered to go before lb
* (i.e., either it is equal or goes after, alphabetically).
*
* @param lb DataSet name to search for.
*
* @return An iterator to the the first DataSet in the DataStore
* whose name is not considered to go before lb, or DataStore::end()
* if all keys are considered to go before it.
*/
iterator
lower_bound
(
const
std
::
string
&
lb
);
/**
* @brief Returns a const_iterator pointing to the first DataSet in the
* DataStore whose name is not considered to go before lb
* (i.e., either it is equal or goes after, alphabetically).
*
* @param lb DataSet name to search for.
*
* @return A const_iterator to the the first DataSet in the DataStore
* whose name is not considered to go before lb, or DataStore::cend()
* if all DataSet names are considered to go before it.
*/
const_iterator
lower_bound
(
const
std
::
string
&
lb
)
const
;
/**
* @brief Returns an iterator pointing to the first DataSet in the
* DataStore whose key is considered to go after ub.
*
* @param ub DataSet name to search for.
*
* @return An iterator to the the first DataSet in the DataStore
* whose name is considered to go after ub, or DataStore::end() if
* no DataSet names are considered to go after it.
*/
iterator
upper_bound
(
const
std
::
string
&
ub
);
/**
* @brief Returns a const_iterator pointing to the first DataSet in the
* DataStore whose key is considered to go after ub.
*
* @param ub DataSet name to search for.
*
* @return A const_iterator to the the first DataSet in the DataStore
* whose name is considered to go after ub, or DataStore::end() if
* no DataSet names are considered to go after it.
*/
const_iterator
upper_bound
(
const
std
::
string
&
ub
)
const
;
/**
* @brief Creates a dataset with a given name inside the
* DataStore. This name must not have the '/' and '%' characters.
* A DataSet object pointing to the created dataset is returned.
* If a dataset with this name already exists in the DataStore,
* it is not created, but a DataSet object pointing to the
* existing one is returned instead.
*
* @param name Name of DataSet.
*
* @return A DataSet instance pointing to the created dataset.
*/
DataSet
createDataSet
(
const
std
::
string
&
name
);
/**
* @brief Creates a dataset with a given name inside the data store.
* This function takes a WriteBatch instance, the dataset will be
* actually created when this batch is flushed or destroyed.
*
* @param batch WriteBatch in which to enqueue the creation.
* @param name Name of the dataset.
*
* @return A DataSet instance pointing to the created dataset.
* @brief Get the root of the DataStore as a DataSet instance.
*/
DataSet
createDataSet
(
WriteBatch
&
batch
,
const
std
::
string
&
name
)
;
DataSet
root
()
const
;
/**
* @brief Create a pointer to a product. The type T used must
...
...
@@ -429,229 +255,6 @@ class DataStore {
bool
loadProductImpl
(
const
ProductID
&
productID
,
std
::
vector
<
T
>&
t
,
const
std
::
integral_constant
<
bool
,
true
>&
);
};
class
DataStore
::
const_iterator
{
protected:
/**
* @brief Implementation of the class (using Pimpl idiom)
*/
class
Impl
;
std
::
unique_ptr
<
Impl
>
m_impl
;
/*!< Pointer to implementation */
public:
/**
* @brief Constructor. Creates a const_iterator pointing
* to an invalid DataSet.
*/
const_iterator
();
/**
* @brief Constructor. Creates a const_iterator pointing
* to a given DataSet. The DataSet may or may not be valid.
*
* @param current DataSet to make the const_iterator point to.
*/
const_iterator
(
const
DataSet
&
current
);
/**
* @brief Constructor. Creates a const_iterator pointing
* to a given DataSet. The DataSet may or may not be valid.
*
* @param current DataSet to make the const_iterator point to.
*/
const_iterator
(
DataSet
&&
current
);
typedef
const_iterator
self_type
;
typedef
DataSet
value_type
;
typedef
DataSet
&
reference
;
typedef
DataSet
*
pointer
;
typedef
int
difference_type
;
typedef
std
::
forward_iterator_tag
iterator_category
;
/**
* @brief Destructor. This destructor is virtual because
* the iterator class inherits from const_iterator.
*/
virtual
~
const_iterator
();
/**
* @brief Copy-constructor.
*
* @param other const_iterator to copy.
*/
const_iterator
(
const
const_iterator
&
other
);
/**
* @brief Move-constructor.
*
* @param other const_iterator to move.
*/
const_iterator
(
const_iterator
&&
other
);
/**
* @brief Copy-assignment operator.
*
* @param other const_iterator to copy.
*
* @return this.
*/
const_iterator
&
operator
=
(
const
const_iterator
&
);
/**
* @brief Move-assignment operator.
*
* @param other const_iterator to move.
*
* @return this.
*/
const_iterator
&
operator
=
(
const_iterator
&&
);
/**
* @brief Increments the const_iterator, returning
* a copy of the iterator after incrementation.
*
* @return a copy of the iterator after incrementation.
*/
self_type
operator
++
();
/**
* @brief Increments the const_iterator, returning
* a copy of the iterator before incrementation.
*
* @return a copy of the iterator after incrementation.
*/
self_type
operator
++
(
int
);
/**
* @brief Dereference operator. Returns a const reference
* to the DataSet this const_iterator points to.
*
* @return a const reference to the DataSet this
* const_iterator points to.
*/
const
reference
operator
*
();
/**
* @brief Returns a const pointer to the DataSet this
* const_iterator points to.
*
* @return a const pointer to the DataSet this
* const_iterator points to.
*/
const
pointer
operator
->
();
/**
* @brief Compares two const_iterators. The two const_iterators
* are equal if they point to the same DataSet or if both
* correspond to DataStore::cend().
*
* @param rhs const_iterator to compare with.
*
* @return true if the two const_iterators are equal, false otherwise.
*/
bool
operator
==
(
const
self_type
&
rhs
)
const
;
/**
* @brief Compares two const_iterators.
*
* @param rhs const_iterator to compare with.
*
* @return true if the two const_iterators are different, false otherwise.
*/
bool
operator
!=
(
const
self_type
&
rhs
)
const
;
};
class
DataStore
::
iterator
:
public
DataStore
::
const_iterator
{
public:
/**
* @brief Constructor. Builds an iterator pointing to an
* invalid DataSet.
*/
iterator
();
/**
* @brief Constructor. Builds an iterator pointing to
* an existing DataSet. The DataSet may or may not be
* valid.
*
* @param current DataSet to point to.
*/
iterator
(
const
DataSet
&
current
);
/**
* @brief Constructor. Builds an iterator pointing to
* an existing DataSet. The DataSet may or may not be
* valid.
*
* @param current DataSet to point to.
*/
iterator
(
DataSet
&&
current
);
typedef
iterator
self_type
;
typedef
DataSet
value_type
;
typedef
DataSet
&
reference
;
typedef
DataSet
*
pointer
;
typedef
int
difference_type
;