Commit d49d349c authored by Matthieu Dorier's avatar Matthieu Dorier

added itemtype

parent 6aaf25a3
......@@ -96,10 +96,16 @@ class AsyncEngineImpl {
id.run = run_number;
id.subrun = subrun_number;
id.event = event_number;
ItemType type = ItemType::RUN;
if(subrun_number != InvalidSubRunNumber) {
type = ItemType::SUBRUN;
if(event_number != InvalidEventNumber)
type = ItemType::EVENT;
}
// make a thread that will store the data
m_pool.make_thread([this, id, ds=m_datastore]() {
m_pool.make_thread([this, id, type, ds=m_datastore]() {
// locate db
auto& db = ds->locateItemDb(id);
auto& db = ds->locateItemDb(type, id);
try {
db.put(&id, sizeof(id), nullptr, 0);
} catch(sdskv::exception& ex) {
......
......@@ -20,6 +20,7 @@
#include "StringHash.hpp"
#include "DataSetImpl.hpp"
#include "ItemImpl.hpp"
#include "ItemType.hpp"
namespace hepnos {
......@@ -476,15 +477,15 @@ class DataStoreImpl {
// Access functions for numbered items (Runs, SubRuns, and Events)
///////////////////////////////////////////////////////////////////////////
const sdskv::database& locateItemDb(const ItemDescriptor& id) const {
const sdskv::database& locateItemDb(const ItemType& type, const ItemDescriptor& id) const {
long unsigned db_idx = 0;
uint64_t hash;
size_t prime = 1099511628211ULL;
hash = id.dataset.hash();
if(id.subrun == InvalidSubRunNumber) { // we are locating a Run
if(type == ItemType::RUN) { // we are locating a Run
ch_placement_find_closest(m_run_dbs.chi, hash, 1, &db_idx);
return m_run_dbs.dbs[db_idx];
} else if(id.event == InvalidEventNumber) { // we are locating a SubRun
} else if(type == ItemType::SUBRUN) { // we are locating a SubRun
hash *= prime;
hash = hash ^ id.run;
ch_placement_find_closest(m_subrun_dbs.chi, hash, 1, &db_idx);
......@@ -502,13 +503,15 @@ class DataStoreImpl {
* maxRuns shared_ptr to RunImpl coming after the
* current run. Returns the number of Runs read.
*/
size_t nextItems(const std::shared_ptr<ItemImpl>& current,
size_t nextItems(
const ItemType& 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(start_key);
auto& db = locateItemDb(type, start_key);
// ignore keys that don't have the same uuid
// issue an sdskv_list_keys
std::vector<ItemDescriptor> descriptors(maxItems);
......@@ -546,8 +549,14 @@ class DataStoreImpl {
k.run = run_number;
k.subrun = subrun_number;
k.event = event_number;
ItemType type = ItemType::RUN;
if(subrun_number != InvalidSubRunNumber) {
type = ItemType::SUBRUN;
if(event_number != InvalidEventNumber)
type = ItemType::EVENT;
}
// find out which DB to access
auto& db = locateItemDb(k);
auto& db = locateItemDb(type, k);
try {
bool b = db.exists(&k, sizeof(k));
return b;
......@@ -570,8 +579,14 @@ class DataStoreImpl {
k.run = run_number;
k.subrun = subrun_number;
k.event = event_number;
ItemType type = ItemType::RUN;
if(subrun_number != InvalidSubRunNumber) {
type = ItemType::SUBRUN;
if(event_number != InvalidEventNumber)
type = ItemType::EVENT;
}
// find out which DB to access
auto& db = locateItemDb(k);
auto& db = locateItemDb(type, k);
try {
db.put(&k, sizeof(k), nullptr, 0);
} 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(m_impl, next_events, 1);
size_t s = m_impl->m_datastore->nextItems(ItemType::EVENT, m_impl, next_events, 1);
if(s == 0) return Event();
return Event(std::move(next_events[0]));
}
......
#ifndef __HEPNOS_ITEM_TYPE_HPP
#define __HEPNOS_ITEM_TYPE_HPP
namespace hepnos {
enum class ItemType : uint32_t {
RUN,
SUBRUN,
EVENT
};
}
#endif
......@@ -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(m_impl, next_runs, 1);
size_t s = m_impl->m_datastore->nextItems(ItemType::RUN, 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(m_impl, next_subruns, 1);
size_t s = m_impl->m_datastore->nextItems(ItemType::SUBRUN, m_impl, next_subruns, 1);
if(s == 0) return SubRun();
return SubRun(std::move(next_subruns[0]));
}
......
......@@ -140,8 +140,14 @@ class WriteBatchImpl {
id.run = run_number;
id.subrun = subrun_number;
id.event = event_number;
ItemType type = ItemType::RUN;
if(subrun_number != InvalidSubRunNumber) {
type = ItemType::SUBRUN;
if(event_number != InvalidEventNumber)
type = ItemType::EVENT;
}
// locate db
auto& db = m_datastore->locateItemDb(id);
auto& db = m_datastore->locateItemDb(type, id);
// insert in the map of entries
bool was_empty;
{
......
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