Commit c2c42bdb authored by Matthieu Dorier's avatar Matthieu Dorier

enable specifying prefix type for nextItems function

parent d49d349c
......@@ -504,14 +504,15 @@ class DataStoreImpl {
* current run. Returns the number of Runs read.
*/
size_t nextItems(
const ItemType& type,
const ItemType& item_type,
const ItemType& prefix_type,
const std::shared_ptr<ItemImpl>& current,
std::vector<std::shared_ptr<ItemImpl>>& result,
size_t maxItems) const {
int ret;
result.resize(0);
const ItemDescriptor& start_key = current->m_descriptor;
auto& db = locateItemDb(type, start_key);
auto& db = locateItemDb(item_type, start_key);
// ignore keys that don't have the same uuid
// issue an sdskv_list_keys
std::vector<ItemDescriptor> descriptors(maxItems);
......@@ -523,7 +524,7 @@ class DataStoreImpl {
try {
hg_size_t s = maxItems;
db.list_keys(&start_key, sizeof(start_key),
&start_key, current->parentPrefixSize(),
&start_key, ItemImpl::descriptorSize(prefix_type),
keys_addr.data(), keys_sizes.data(), &s);
maxItems = s;
} catch(sdskv::exception& ex) {
......
......@@ -32,7 +32,7 @@ Event Event::next() const {
if(!valid()) return Event();
std::vector<std::shared_ptr<ItemImpl>> next_events;
size_t s = m_impl->m_datastore->nextItems(ItemType::EVENT, m_impl, next_events, 1);
size_t s = m_impl->m_datastore->nextItems(ItemType::EVENT, ItemType::SUBRUN, m_impl, next_events, 1);
if(s == 0) return Event();
return Event(std::move(next_events[0]));
}
......
......@@ -11,6 +11,7 @@
#include <memory>
#include "hepnos/Run.hpp"
#include "hepnos/UUID.hpp"
#include "ItemType.hpp"
#include "ItemDescriptor.hpp"
namespace hepnos {
......@@ -41,12 +42,14 @@ class ItemImpl {
return m_descriptor == other.m_descriptor;
}
size_t parentPrefixSize() const {
size_t s = sizeof(ItemDescriptor) - sizeof(m_descriptor.event);
if(m_descriptor.event == InvalidEventNumber)
s -= sizeof(m_descriptor.subrun);
if(m_descriptor.subrun == InvalidSubRunNumber)
s -= sizeof(m_descriptor.run);
static size_t descriptorSize(const ItemType& type) {
size_t s = sizeof(ItemDescriptor);
if(type == ItemType::EVENT) return s;
s -= sizeof(EventNumber);
if(type == ItemType::SUBRUN) return s;
s -= sizeof(SubRunNumber);
if(type == ItemType::RUN) return s;
s -= sizeof(RunNumber);
return s;
}
};
......
......@@ -4,6 +4,7 @@
namespace hepnos {
enum class ItemType : uint32_t {
DATASET,
RUN,
SUBRUN,
EVENT
......
......@@ -35,7 +35,7 @@ Run Run::next() const {
if(!valid()) return Run();
std::vector<std::shared_ptr<ItemImpl>> next_runs;
size_t s = m_impl->m_datastore->nextItems(ItemType::RUN, m_impl, next_runs, 1);
size_t s = m_impl->m_datastore->nextItems(ItemType::RUN, ItemType::DATASET, m_impl, next_runs, 1);
if(s == 0) return Run();
return Run(std::move(next_runs[0]));
}
......
......@@ -36,7 +36,7 @@ SubRun SubRun::next() const {
if(!valid()) return SubRun();
std::vector<std::shared_ptr<ItemImpl>> next_subruns;
size_t s = m_impl->m_datastore->nextItems(ItemType::SUBRUN, m_impl, next_subruns, 1);
size_t s = m_impl->m_datastore->nextItems(ItemType::SUBRUN, ItemType::RUN, m_impl, next_subruns, 1);
if(s == 0) return SubRun();
return SubRun(std::move(next_subruns[0]));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment