Commit 11f84b91 authored by Matthieu Dorier's avatar Matthieu Dorier

improved internals of the implementation classes

parent fe9485cf
......@@ -11,8 +11,7 @@
namespace hepnos {
Event::Event()
: m_impl(std::make_shared<EventImpl>(nullptr, 0, std::make_shared<std::string>(""),
InvalidRunNumber, InvalidSubRunNumber, InvalidEventNumber)) {}
: m_impl(std::make_shared<EventImpl>(0, nullptr, InvalidEventNumber)) {}
Event::Event(std::shared_ptr<EventImpl>&& impl)
: m_impl(std::move(impl)) { }
......@@ -40,9 +39,7 @@ Event Event::next() const {
if(keys[0].size() <= i) return Event();
EventNumber n = parseNumberFromKeyString<EventNumber>(&keys[0][i]);
if(n == InvalidEventNumber) return Event();
return Event(std::make_shared<EventImpl>(m_impl->m_datastore,
m_impl->m_level, m_impl->m_dataset_name,
m_impl->m_run_number, m_impl->m_subrun_number, n));
return Event(std::make_shared<EventImpl>(m_impl->m_level, m_impl->m_subrun, n));
}
bool Event::valid() const {
......@@ -88,13 +85,7 @@ bool Event::operator==(const Event& other) const {
if(!v1 && !v2) return true;
if(!v1 && v2) return false;
if(v1 && !v2) return false;
return m_impl->m_datastore == other.m_impl->m_datastore
&& m_impl->m_level == other.m_impl->m_level
&& (m_impl->m_dataset_name == other.m_impl->m_dataset_name
|| *m_impl->m_dataset_name == *other.m_impl->m_dataset_name)
&& m_impl->m_run_number == other.m_impl->m_run_number
&& m_impl->m_subrun_number == other.m_impl->m_subrun_number
&& m_impl->m_event_number == other.m_impl->m_event_number;
return (m_impl == other.m_impl) || (*m_impl == *other.m_impl);
}
bool Event::operator!=(const Event& other) const {
......
......@@ -15,6 +15,7 @@
#include "hepnos/SubRun.hpp"
#include "hepnos/Event.hpp"
#include "NumberUtil.hpp"
#include "SubRunImpl.hpp"
namespace hepnos {
......@@ -23,33 +24,31 @@ class EventImpl {
public:
std::shared_ptr<DataStoreImpl> m_datastore;
uint8_t m_level;
std::shared_ptr<std::string> m_dataset_name;
RunNumber m_run_number;
SubRunNumber m_subrun_number;
std::shared_ptr<SubRunImpl> m_subrun;
EventNumber m_event_number;
uint8_t m_level;
EventImpl(const std::shared_ptr<DataStoreImpl>& ds,
uint8_t level,
const std::shared_ptr<std::string>& dataset,
const RunNumber& rn,
const SubRunNumber& srn,
const EventNumber& evn)
: m_datastore(ds)
, m_level(level)
, m_dataset_name(dataset)
, m_run_number(rn)
, m_subrun_number(srn)
, m_event_number(evn) {}
EventImpl(uint8_t level,
const std::shared_ptr<SubRunImpl>& subrun,
const EventNumber& evn)
: m_subrun(subrun)
, m_event_number(evn)
, m_level(level) {
if(subrun) m_datastore = subrun->m_datastore;
}
bool operator==(const EventImpl& other) const {
if(m_event_number != other.m_event_number) return false;
if(m_subrun == other.m_subrun) return true;
return *m_subrun == *other.m_subrun;
}
std::string makeKeyStringFromEventNumber() const {
return makeKeyStringFromNumber(m_event_number);
}
std::string container() const {
return *m_dataset_name + "/"
+ makeKeyStringFromNumber(m_run_number) + "/"
+ makeKeyStringFromNumber(m_subrun_number);
return m_subrun->fullpath();
}
std::string fullpath() const {
......
......@@ -91,11 +91,7 @@ bool Run::operator==(const Run& other) const {
if(!v1 && !v2) return true;
if(v1 && !v2) return false;
if(!v1 && v2) return false;
return m_impl->m_datastore == other.m_impl->m_datastore
&& m_impl->m_level == other.m_impl->m_level
&& (m_impl->m_dataset_name == other.m_impl->m_dataset_name
|| *m_impl->m_dataset_name == *other.m_impl->m_dataset_name)
&& m_impl->m_run_number == other.m_impl->m_run_number;
return (m_impl == other.m_impl) || (*m_impl == *other.m_impl);
}
bool Run::operator!=(const Run& other) const {
......@@ -123,9 +119,7 @@ SubRun Run::createSubRun(const SubRunNumber& subRunNumber) {
std::string parent = m_impl->fullpath();
std::string subRunStr = makeKeyStringFromNumber(subRunNumber);
m_impl->m_datastore->store(m_impl->m_level+1, parent, subRunStr);
auto new_subrun_impl = std::make_shared<SubRunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, subRunNumber);
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_level+1, m_impl, subRunNumber);
return SubRun(std::move(new_subrun_impl));
}
......@@ -136,9 +130,7 @@ SubRun Run::createSubRun(WriteBatch& batch, const SubRunNumber& subRunNumber) {
std::string parent = m_impl->fullpath();
std::string subRunStr = makeKeyStringFromNumber(subRunNumber);
batch.m_impl->store(m_impl->m_level+1, parent, subRunStr);
auto new_subrun_impl = std::make_shared<SubRunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, subRunNumber);
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_level+1, m_impl, subRunNumber);
return SubRun(std::move(new_subrun_impl));
}
......@@ -160,9 +152,7 @@ Run::iterator Run::find(const SubRunNumber& subRunNumber) {
if(!b) {
return m_impl->m_end;
}
auto new_subrun_impl = std::make_shared<SubRunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, subRunNumber);
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_level+1, m_impl, subRunNumber);
return iterator(SubRun(std::move(new_subrun_impl)));
}
......@@ -175,9 +165,7 @@ Run::iterator Run::begin() {
auto it = find(0);
if(it != end()) return *it;
auto new_subrun_impl = std::make_shared<SubRunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, 0);
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_level+1, m_impl, 0);
SubRun subrun(std::move(new_subrun_impl));
subrun = subrun.next();
......@@ -221,9 +209,7 @@ Run::iterator Run::lower_bound(const SubRunNumber& lb) {
if(it != end()) {
return it;
} else {
auto new_subrun_impl = std::make_shared<SubRunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, 0);
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_level+1, m_impl, 0);
SubRun subrun(std::move(new_subrun_impl));
subrun = subrun.next();
if(!subrun.valid()) return end();
......@@ -235,9 +221,7 @@ Run::iterator Run::lower_bound(const SubRunNumber& lb) {
++it;
return it;
}
auto new_subrun_impl = std::make_shared<SubRunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, lb-1);
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_level+1, m_impl, lb-1);
SubRun subrun(std::move(new_subrun_impl));
subrun = subrun.next();
if(!subrun.valid()) return end();
......@@ -254,9 +238,7 @@ Run::iterator Run::upper_bound(const SubRunNumber& ub) {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
auto new_subrun_impl = std::make_shared<SubRunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, ub);
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_level+1, m_impl, ub);
SubRun subrun(std::move(new_subrun_impl));
subrun = subrun.next();
if(!subrun.valid()) return end();
......
......@@ -35,6 +35,12 @@ class RunImpl {
, m_dataset_name(dataset)
, m_run_number(rn) {}
bool operator==(const RunImpl& other) const {
if(m_run_number != other.m_run_number) return false;
if(m_dataset_name == other.m_dataset_name) return true;
return *m_dataset_name == *other.m_dataset_name;
}
std::string makeKeyStringFromRunNumber() const {
return makeKeyStringFromNumber(m_run_number);
}
......
......@@ -16,7 +16,7 @@ namespace hepnos {
SubRun::iterator SubRunImpl::m_end;
SubRun::SubRun()
: m_impl(std::make_shared<SubRunImpl>(nullptr, 0, std::make_shared<std::string>(""), InvalidRunNumber, InvalidSubRunNumber)) {}
: m_impl(std::make_shared<SubRunImpl>(0, nullptr, InvalidSubRunNumber)) {}
SubRun::SubRun(std::shared_ptr<SubRunImpl>&& impl)
: m_impl(std::move(impl)) { }
......@@ -44,8 +44,7 @@ SubRun SubRun::next() const {
if(keys[0].size() <= i) return SubRun();
SubRunNumber srn = parseNumberFromKeyString<SubRunNumber>(&keys[0][i]);
if(srn == InvalidSubRunNumber) return SubRun();
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_datastore, m_impl->m_level,
m_impl->m_dataset_name, m_impl->m_run_number, srn);
auto new_subrun_impl = std::make_shared<SubRunImpl>(m_impl->m_level, m_impl->m_run, srn);
return SubRun(std::move(new_subrun_impl));
}
......@@ -91,12 +90,7 @@ bool SubRun::operator==(const SubRun& other) const {
if(!v1 && !v2) return true;
if(!v1 && v2) return false;
if(v1 && !v2) return false;
return m_impl->m_datastore == other.m_impl->m_datastore
&& m_impl->m_level == other.m_impl->m_level
&& (m_impl->m_dataset_name == other.m_impl->m_dataset_name
|| *m_impl->m_dataset_name == *other.m_impl->m_dataset_name)
&& m_impl->m_run_number == other.m_impl->m_run_number
&& m_impl->m_subrun_number == other.m_impl->m_subrun_number;
return (m_impl == other.m_impl) || (*m_impl == *other.m_impl);
}
bool SubRun::operator!=(const SubRun& other) const {
......@@ -114,8 +108,7 @@ Event SubRun::createEvent(const EventNumber& eventNumber) {
std::string parent = m_impl->fullpath();
std::string eventStr = makeKeyStringFromNumber(eventNumber);
m_impl->m_datastore->store(m_impl->m_level+1, parent, eventStr);
return Event(std::make_shared<EventImpl>(m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, m_impl->m_subrun_number, eventNumber));
return Event(std::make_shared<EventImpl>(m_impl->m_level+1, m_impl, eventNumber));
}
Event SubRun::createEvent(WriteBatch& batch, const EventNumber& eventNumber) {
......@@ -125,8 +118,7 @@ Event SubRun::createEvent(WriteBatch& batch, const EventNumber& eventNumber) {
std::string parent = m_impl->fullpath();
std::string eventStr = makeKeyStringFromNumber(eventNumber);
batch.m_impl->store(m_impl->m_level+1, parent, eventStr);
return Event(std::make_shared<EventImpl>(m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, m_impl->m_subrun_number, eventNumber));
return Event(std::make_shared<EventImpl>(m_impl->m_level+1, m_impl, eventNumber));
}
Event SubRun::operator[](const EventNumber& eventNumber) const {
......@@ -147,9 +139,7 @@ SubRun::iterator SubRun::find(const EventNumber& eventNumber) {
if(!b) {
return m_impl->m_end;
}
return iterator(Event(std::make_shared<EventImpl>(
m_impl->m_datastore, m_impl->m_level+1,
m_impl->m_dataset_name, m_impl->m_run_number, m_impl->m_subrun_number, eventNumber)));
return iterator(Event(std::make_shared<EventImpl>(m_impl->m_level+1, m_impl, eventNumber)));
}
SubRun::const_iterator SubRun::find(const EventNumber& eventNumber) const {
......@@ -164,8 +154,7 @@ SubRun::iterator SubRun::begin() {
auto level = m_impl->m_level;
auto datastore = m_impl->m_datastore;
std::string container = m_impl->fullpath();
Event event(std::make_shared<EventImpl>(datastore,
level+1, m_impl->m_dataset_name, m_impl->m_run_number, m_impl->m_subrun_number, 0));
Event event(std::make_shared<EventImpl>(level+1, m_impl, 0));
event = event.next();
if(event.valid()) return iterator(std::move(event));
......@@ -207,9 +196,7 @@ SubRun::iterator SubRun::lower_bound(const EventNumber& lb) {
if(it != end()) {
return it;
} else {
Event event(std::make_shared<EventImpl>(m_impl->m_datastore,
m_impl->m_level+1, m_impl->m_dataset_name,
m_impl->m_run_number, m_impl->m_subrun_number, 0));
Event event(std::make_shared<EventImpl>(m_impl->m_level+1, m_impl, 0));
event = event.next();
if(!event.valid()) return end();
else return iterator(event);
......@@ -220,9 +207,7 @@ SubRun::iterator SubRun::lower_bound(const EventNumber& lb) {
++it;
return it;
}
Event event(std::make_shared<EventImpl>(m_impl->m_datastore,
m_impl->m_level+1, m_impl->m_dataset_name,
m_impl->m_run_number, m_impl->m_subrun_number, lb-1));
Event event(std::make_shared<EventImpl>(m_impl->m_level+1, m_impl, lb-1));
event = event.next();
if(!event.valid()) return end();
else return iterator(event);
......@@ -238,9 +223,7 @@ SubRun::iterator SubRun::upper_bound(const EventNumber& ub) {
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
Event event(std::make_shared<EventImpl>(m_impl->m_datastore,
m_impl->m_level+1, m_impl->m_dataset_name,
m_impl->m_run_number, m_impl->m_subrun_number, ub));
Event event(std::make_shared<EventImpl>(m_impl->m_level+1, m_impl, ub));
event = event.next();
if(!event.valid()) return end();
else return iterator(event);
......
......@@ -12,6 +12,7 @@
#include "DataStoreImpl.hpp"
#include "hepnos/Run.hpp"
#include "hepnos/SubRun.hpp"
#include "RunImpl.hpp"
#include "NumberUtil.hpp"
namespace hepnos {
......@@ -21,29 +22,33 @@ class SubRunImpl {
public:
std::shared_ptr<DataStoreImpl> m_datastore;
uint8_t m_level;
std::shared_ptr<std::string> m_dataset_name;
RunNumber m_run_number;
std::shared_ptr<RunImpl> m_run;
SubRunNumber m_subrun_number;
uint8_t m_level;
static SubRun::iterator m_end;
SubRunImpl(const std::shared_ptr<DataStoreImpl>& ds,
uint8_t level,
const std::shared_ptr<std::string>& dataset,
const RunNumber& rn, const SubRunNumber& srn)
: m_datastore(ds)
, m_level(level)
, m_dataset_name(dataset)
, m_run_number(rn)
, m_subrun_number(srn) {}
SubRunImpl(uint8_t level,
const std::shared_ptr<RunImpl>& run,
const SubRunNumber& srn)
: m_run(run)
, m_subrun_number(srn)
, m_level(level) {
if(m_run) m_datastore = m_run->m_datastore;
}
bool operator==(const SubRunImpl& other) const {
if(m_subrun_number != other.m_subrun_number) return false;
if(m_run == other.m_run) return true;
return *m_run == *other.m_run;
}
std::string makeKeyStringFromSubRunNumber() const {
return makeKeyStringFromNumber(m_subrun_number);
}
std::string container() const {
return *m_dataset_name + "/" + makeKeyStringFromNumber(m_run_number);
return m_run->fullpath();
}
std::string fullpath() const {
......
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