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

improved internals of the implementation classes

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