...
 
Commits (5)
......@@ -30,20 +30,29 @@ DataSet::DataSet(DataStore* ds, uint8_t level, const std::string& fullname)
DataSet::DataSet(DataStore* ds, uint8_t level, const std::string& container, const std::string& name)
: m_impl(std::make_unique<DataSet::Impl>(this, ds, level, container, name)) {}
DataSet::DataSet(const DataSet& other)
: m_impl(std::make_unique<DataSet::Impl>(
DataSet::DataSet(const DataSet& other) {
if(other.m_impl) {
m_impl = std::make_unique<DataSet::Impl>(
this, other.m_impl->m_datastore,
other.m_impl->m_level,
other.m_impl->m_container,
other.m_impl->m_name)) {}
other.m_impl->m_name);
}
}
DataSet::DataSet(DataSet&& other)
: m_impl(std::move(other.m_impl)) {
if(m_impl) {
m_impl->m_runset.m_impl->m_dataset = this;
}
}
DataSet& DataSet::operator=(const DataSet& other) {
if(this == &other) return *this;
if(!other.m_impl) {
m_impl.reset();
return *this;
}
m_impl = std::make_unique<DataSet::Impl>(this,
other.m_impl->m_datastore,
other.m_impl->m_level,
......@@ -55,14 +64,18 @@ DataSet& DataSet::operator=(const DataSet& other) {
DataSet& DataSet::operator=(DataSet&& other) {
if(this == &other) return *this;
m_impl = std::move(other.m_impl);
if(m_impl) {
m_impl->m_runset.m_impl->m_dataset = this;
}
return *this;
}
DataSet::~DataSet() {}
DataStore* DataSet::getDataStore() const {
if(!m_impl) return nullptr;
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
return m_impl->m_datastore;
}
......@@ -78,12 +91,11 @@ DataSet DataSet::next() const {
bool DataSet::valid() const {
return m_impl && m_impl->m_datastore;
}
ProductID DataSet::storeRawData(const std::string& key, const std::vector<char>& buffer) {
if(!valid()) {
throw Exception("Calling store() on invalid DataSet");
throw Exception("Calling DataSet member function on an invalid DataSet");
}
// forward the call to the datastore's store function
return m_impl->m_datastore->m_impl->store(0, fullname(), key, buffer);
......@@ -91,13 +103,18 @@ ProductID DataSet::storeRawData(const std::string& key, const std::vector<char>&
bool DataSet::loadRawData(const std::string& key, std::vector<char>& buffer) const {
if(!valid()) {
throw Exception("Calling load() on invalid DataSet");
throw Exception("Calling DataSet member function on an invalid DataSet");
}
// forward the call to the datastore's load function
return m_impl->m_datastore->m_impl->load(0, fullname(), key, buffer);
}
bool DataSet::operator==(const DataSet& other) const {
bool v1 = valid();
bool v2 = other.valid();
if(!v1 && !v2) return true;
if(v1 && !v2) return false;
if(!v2 && 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_container == other.m_impl->m_container
......@@ -109,10 +126,16 @@ bool DataSet::operator!=(const DataSet& other) const {
}
const std::string& DataSet::name() const {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
return m_impl->m_name;
}
const std::string& DataSet::container() const {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
return m_impl->m_container;
}
......@@ -146,15 +169,22 @@ Run DataSet::createRun(const RunNumber& runNumber) {
DataSet DataSet::operator[](const std::string& datasetName) const {
auto it = find(datasetName);
if(!it->valid())
throw Exception("Requested DataSet does not exist");
return std::move(*it);
}
Run DataSet::operator[](const RunNumber& runNumber) const {
auto it = runs().find(runNumber);
if(!it->valid())
throw Exception("Requested Run does not exist");
return std::move(*it);
}
DataSet::iterator DataSet::find(const std::string& datasetPath) {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
int ret;
if(datasetPath.find('%') != std::string::npos) {
throw Exception("Invalid character '%' in dataset name");
......@@ -191,6 +221,9 @@ DataSet::const_iterator DataSet::find(const std::string& datasetName) const {
}
DataSet::iterator DataSet::begin() {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
DataSet ds(m_impl->m_datastore, m_impl->m_level+1, fullname(),"");
ds = ds.next();
if(ds.valid()) return iterator(ds);
......@@ -198,6 +231,9 @@ DataSet::iterator DataSet::begin() {
}
DataSet::iterator DataSet::end() {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
return m_impl->m_datastore->end();
}
......@@ -206,6 +242,9 @@ DataSet::const_iterator DataSet::begin() const {
}
DataSet::const_iterator DataSet::end() const {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
return m_impl->m_datastore->cend();
}
......@@ -214,10 +253,16 @@ DataSet::const_iterator DataSet::cbegin() const {
}
DataSet::const_iterator DataSet::cend() const {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
return m_impl->m_datastore->cend();
}
DataSet::iterator DataSet::lower_bound(const std::string& lb) {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
std::string lb2 = lb;
size_t s = lb2.size();
lb2[s-1] -= 1; // sdskv_list_keys's start_key is exclusive
......@@ -239,6 +284,9 @@ DataSet::const_iterator DataSet::lower_bound(const std::string& lb) const {
}
DataSet::iterator DataSet::upper_bound(const std::string& ub) {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
DataSet ds(m_impl->m_datastore, m_impl->m_level+1, fullname(), ub);
ds = ds.next();
if(!ds.valid()) return end();
......@@ -251,6 +299,9 @@ DataSet::const_iterator DataSet::upper_bound(const std::string& ub) const {
}
RunSet& DataSet::runs() {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
return m_impl->m_runset;
}
......
......@@ -53,6 +53,10 @@ DataStore::~DataStore() {
}
DataStore::iterator DataStore::find(const std::string& datasetPath) {
if(!m_impl) {
throw Exception("Calling DataStore member function on an invalid DataStore object");
}
int ret;
if(datasetPath.find('%') != std::string::npos) {
......@@ -83,6 +87,8 @@ DataStore::iterator DataStore::find(const std::string& datasetPath) {
DataSet DataStore::operator[](const std::string& datasetName) const {
auto it = find(datasetName);
if(!it->valid())
throw Exception("Requested DataSet does not exist");
return std::move(*it);
}
......@@ -92,6 +98,9 @@ DataStore::const_iterator DataStore::find(const std::string& datasetName) const
}
DataStore::iterator DataStore::begin() {
if(!m_impl) {
throw Exception("Calling DataStore member function on an invalid DataStore object");
}
DataSet ds(this, 1, "", "");
ds = ds.next();
if(ds.valid()) return iterator(std::move(ds));
......@@ -104,10 +113,16 @@ DataStore::const_iterator DataStore::begin() const {
}
DataStore::iterator DataStore::end() {
if(!m_impl) {
throw Exception("Calling DataStore member function on an invalid DataStore object");
}
return m_impl->m_end;
}
DataStore::const_iterator DataStore::end() const {
if(!m_impl) {
throw Exception("Calling DataStore member function on an invalid DataStore object");
}
return m_impl->m_end;
}
......@@ -141,6 +156,9 @@ DataStore::const_iterator DataStore::lower_bound(const std::string& lb) const {
}
DataStore::iterator DataStore::upper_bound(const std::string& ub) {
if(!m_impl) {
throw Exception("Calling DataStore member function on an invalid DataStore object");
}
DataSet ds(this, 1, "", ub);
ds = ds.next();
if(!ds.valid()) return end();
......@@ -153,6 +171,9 @@ DataStore::const_iterator DataStore::upper_bound(const std::string& ub) const {
}
DataSet DataStore::createDataSet(const std::string& name) {
if(!m_impl) {
throw Exception("Calling DataStore member function on an invalid DataStore object");
}
if(name.find('/') != std::string::npos
|| name.find('%') != std::string::npos) {
throw Exception("Invalid character ('/' or '%') in dataset name");
......@@ -162,12 +183,18 @@ DataSet DataStore::createDataSet(const std::string& name) {
}
void DataStore::shutdown() {
if(!m_impl) {
throw Exception("Calling DataStore member function on an invalid DataStore object");
}
for(auto addr : m_impl->m_addrs) {
margo_shutdown_remote_instance(m_impl->m_mid, addr.second);
}
}
bool DataStore::loadRawProduct(const ProductID& productID, std::vector<char>& buffer) {
if(!m_impl) {
throw Exception("Calling DataStore member function on an invalid DataStore object");
}
return m_impl->load(productID.m_level, productID.m_containerName, productID.m_objectName, buffer);
}
......@@ -215,15 +242,21 @@ DataStore::const_iterator::const_iterator(DataSet&& dataset)
DataStore::const_iterator::~const_iterator() {}
DataStore::const_iterator::const_iterator(const DataStore::const_iterator& other)
: m_impl(std::make_unique<Impl>(*other.m_impl)) {}
DataStore::const_iterator::const_iterator(const DataStore::const_iterator& other) {
if(other.m_impl) {
m_impl = std::make_unique<Impl>(*other.m_impl);
}
}
DataStore::const_iterator::const_iterator(DataStore::const_iterator&& other)
: m_impl(std::move(other.m_impl)) {}
DataStore::const_iterator& DataStore::const_iterator::operator=(const DataStore::const_iterator& other) {
if(&other == this) return *this;
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
else
m_impl.reset();
return *this;
}
......@@ -255,7 +288,9 @@ const DataStore::const_iterator::reference DataStore::const_iterator::operator*(
}
const DataStore::const_iterator::pointer DataStore::const_iterator::operator->() {
if(!m_impl) return nullptr;
if(!m_impl) {
throw Exception("Trying to dereference an invalid iterator");
}
return &(m_impl->m_current_dataset);
}
......@@ -293,7 +328,10 @@ DataStore::iterator::iterator(DataStore::iterator&& other)
DataStore::iterator& DataStore::iterator::operator=(const DataStore::iterator& other) {
if(this == &other) return *this;
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
else
m_impl.reset();
return *this;
}
......
......@@ -15,13 +15,16 @@ Event::Event()
Event::Event(DataStore* ds, uint8_t level, const std::string& container, const EventNumber& rn)
: m_impl(std::make_unique<Impl>(ds, level, container, rn)) { }
Event::Event(const Event& other)
: m_impl(std::make_unique<Impl>(*other.m_impl)) {}
Event::Event(const Event& other) {
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
}
Event::Event(Event&&) = default;
Event& Event::operator=(const Event& other) {
if(this == &other) return *this;
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
return *this;
}
......@@ -31,7 +34,9 @@ Event& Event::operator=(Event&&) = default;
Event::~Event() = default;
DataStore* Event::getDataStore() const {
if(!m_impl) return nullptr;
if(!valid()) {
throw Exception("Calling Event member function on an invalid Event object");
}
return m_impl->m_datastore;
}
......@@ -61,7 +66,7 @@ bool Event::valid() const {
ProductID Event::storeRawData(const std::string& key, const std::vector<char>& buffer) {
if(!valid()) {
throw Exception("Calling store() on invalid Event");
throw Exception("Calling Event member function on an invalid Event object");
}
// forward the call to the datastore's store function
return m_impl->m_datastore->m_impl->store(0, m_impl->fullpath(), key, buffer);
......@@ -69,13 +74,18 @@ ProductID Event::storeRawData(const std::string& key, const std::vector<char>& b
bool Event::loadRawData(const std::string& key, std::vector<char>& buffer) const {
if(!valid()) {
throw Exception("Calling load() on invalid Event");
throw Exception("Calling Event member function on an invalid Event object");
}
// forward the call to the datastore's load function
return m_impl->m_datastore->m_impl->load(0, m_impl->fullpath(), key, buffer);
}
bool Event::operator==(const Event& other) const {
bool v1 = valid();
bool v2 = other.valid();
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_container == other.m_impl->m_container
......@@ -87,6 +97,9 @@ bool Event::operator!=(const Event& other) const {
}
const EventNumber& Event::number() const {
if(!valid()) {
throw Exception("Calling Event member function on an invalid Event object");
}
return m_impl->m_event_nr;
}
......
......@@ -16,14 +16,18 @@ Run::Run()
Run::Run(DataStore* ds, uint8_t level, const std::string& container, const RunNumber& rn)
: m_impl(std::make_unique<Run::Impl>(ds, level, container, rn)) { }
Run::Run(const Run& other)
: m_impl(std::make_unique<Run::Impl>(*other.m_impl)) {}
Run::Run(const Run& other) {
if(other.m_impl)
m_impl = std::make_unique<Run::Impl>(*other.m_impl);
}
Run::Run(Run&&) = default;
Run& Run::operator=(const Run& other) {
if(this == &other) return *this;
if(other.m_impl) {
m_impl = std::make_unique<Run::Impl>(*other.m_impl);
}
return *this;
}
......@@ -32,7 +36,9 @@ Run& Run::operator=(Run&&) = default;
Run::~Run() = default;
DataStore* Run::getDataStore() const {
if(!m_impl) return nullptr;
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
return m_impl->m_datastore;
}
......@@ -62,7 +68,7 @@ bool Run::valid() const {
ProductID Run::storeRawData(const std::string& key, const std::vector<char>& buffer) {
if(!valid()) {
throw Exception("Calling store() on invalid Run");
throw Exception("Calling Run member function on an invalid Run object");
}
// forward the call to the datastore's store function
return m_impl->m_datastore->m_impl->store(0, m_impl->fullpath(), key, buffer);
......@@ -70,13 +76,18 @@ ProductID Run::storeRawData(const std::string& key, const std::vector<char>& buf
bool Run::loadRawData(const std::string& key, std::vector<char>& buffer) const {
if(!valid()) {
throw Exception("Calling load() on invalid Run");
throw Exception("Calling Run member function on an invalid Run object");
}
// forward the call to the datastore's load function
return m_impl->m_datastore->m_impl->load(0, m_impl->fullpath(), key, buffer);
}
bool Run::operator==(const Run& other) const {
bool v1 = valid();
bool v2 = other.valid();
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_container == other.m_impl->m_container
......@@ -88,14 +99,23 @@ bool Run::operator!=(const Run& other) const {
}
const RunNumber& Run::number() const {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
return m_impl->m_run_nr;
}
const std::string& Run::container() const {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
return m_impl->m_container;
}
SubRun Run::createSubRun(const SubRunNumber& subRunNumber) {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
std::string parent = m_impl->fullpath();
std::string subRunStr = SubRun::Impl::makeKeyStringFromSubRunNumber(subRunNumber);
m_impl->m_datastore->m_impl->store(m_impl->m_level+1, parent, subRunStr, std::vector<char>());
......@@ -104,10 +124,15 @@ SubRun Run::createSubRun(const SubRunNumber& subRunNumber) {
SubRun Run::operator[](const SubRunNumber& subRunNumber) const {
auto it = find(subRunNumber);
if(!it->valid())
throw Exception("Requested SubRun does not exist");
return std::move(*it);
}
Run::iterator Run::find(const SubRunNumber& subRunNumber) {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
int ret;
std::vector<char> data;
std::string parent = m_impl->fullpath();
......@@ -139,6 +164,9 @@ Run::iterator Run::begin() {
}
Run::iterator Run::end() {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
return m_impl->m_end;
}
......@@ -147,6 +175,9 @@ Run::const_iterator Run::begin() const {
}
Run::const_iterator Run::end() const {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
return m_impl->m_end;
}
......@@ -155,6 +186,9 @@ Run::const_iterator Run::cbegin() const {
}
Run::const_iterator Run::cend() const {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
return m_impl->m_end;
}
......@@ -192,6 +226,9 @@ Run::const_iterator Run::lower_bound(const SubRunNumber& lb) const {
}
Run::iterator Run::upper_bound(const SubRunNumber& ub) {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
SubRun subrun(m_impl->m_datastore,
m_impl->m_level+1,
m_impl->fullpath(), ub);
......@@ -249,15 +286,20 @@ Run::const_iterator::const_iterator(SubRun&& subrun)
Run::const_iterator::~const_iterator() {}
Run::const_iterator::const_iterator(const Run::const_iterator& other)
: m_impl(std::make_unique<Impl>(*other.m_impl)) {}
Run::const_iterator::const_iterator(const Run::const_iterator& other) {
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
}
Run::const_iterator::const_iterator(Run::const_iterator&& other)
: m_impl(std::move(other.m_impl)) {}
Run::const_iterator& Run::const_iterator::operator=(const Run::const_iterator& other) {
if(&other == this) return *this;
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
else
m_impl.reset();
return *this;
}
......@@ -327,7 +369,10 @@ Run::iterator::iterator(Run::iterator&& other)
Run::iterator& Run::iterator::operator=(const Run::iterator& other) {
if(this == &other) return *this;
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
else
m_impl.reset();
return *this;
}
......
......@@ -27,6 +27,8 @@ RunSet::~RunSet() {}
Run RunSet::operator[](const RunNumber& runNumber) {
auto it = find(runNumber);
if(!it->valid())
throw Exception("Requested Run does not exist");
return std::move(*it);
}
......
......@@ -17,14 +17,19 @@ SubRun::SubRun()
SubRun::SubRun(DataStore* ds, uint8_t level, const std::string& container, const SubRunNumber& rn)
: m_impl(std::make_unique<Impl>(ds, level, container, rn)) { }
SubRun::SubRun(const SubRun& other)
: m_impl(std::make_unique<Impl>(*other.m_impl)) {}
SubRun::SubRun(const SubRun& other) {
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
}
SubRun::SubRun(SubRun&&) = default;
SubRun& SubRun::operator=(const SubRun& other) {
if(this == &other) return *this;
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
else
m_impl.reset();
return *this;
}
......@@ -33,7 +38,9 @@ SubRun& SubRun::operator=(SubRun&&) = default;
SubRun::~SubRun() = default;
DataStore* SubRun::getDataStore() const {
if(!m_impl) return nullptr;
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
return m_impl->m_datastore;
}
......@@ -58,12 +65,11 @@ SubRun SubRun::next() const {
bool SubRun::valid() const {
return m_impl && m_impl->m_datastore;
}
ProductID SubRun::storeRawData(const std::string& key, const std::vector<char>& buffer) {
if(!valid()) {
throw Exception("Calling store() on invalid SubRun");
throw Exception("Calling SubRun member function on invalid SubRun object");
}
// forward the call to the datastore's store function
return m_impl->m_datastore->m_impl->store(0, m_impl->fullpath(), key, buffer);
......@@ -71,13 +77,18 @@ ProductID SubRun::storeRawData(const std::string& key, const std::vector<char>&
bool SubRun::loadRawData(const std::string& key, std::vector<char>& buffer) const {
if(!valid()) {
throw Exception("Calling load() on invalid SubRun");
throw Exception("Calling SubRun member function on invalid SubRun object");
}
// forward the call to the datastore's load function
return m_impl->m_datastore->m_impl->load(0, m_impl->fullpath(), key, buffer);
}
bool SubRun::operator==(const SubRun& other) const {
bool v1 = valid();
bool v2 = other.valid();
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_container == other.m_impl->m_container
......@@ -93,6 +104,9 @@ const SubRunNumber& SubRun::number() const {
}
Event SubRun::createEvent(const EventNumber& eventNumber) {
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
std::string parent = m_impl->fullpath();
std::string eventStr = Event::Impl::makeKeyStringFromEventNumber(eventNumber);
m_impl->m_datastore->m_impl->store(m_impl->m_level+1, parent, eventStr, std::vector<char>());
......@@ -101,10 +115,15 @@ Event SubRun::createEvent(const EventNumber& eventNumber) {
Event SubRun::operator[](const EventNumber& eventNumber) const {
auto it = find(eventNumber);
if(!it->valid())
throw Exception("Requested Event does not exist");
return std::move(*it);
}
SubRun::iterator SubRun::find(const EventNumber& eventNumber) {
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
int ret;
std::vector<char> data;
std::string parent = m_impl->fullpath();
......@@ -136,6 +155,9 @@ SubRun::iterator SubRun::begin() {
}
SubRun::iterator SubRun::end() {
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
return m_impl->m_end;
}
......@@ -144,6 +166,9 @@ SubRun::const_iterator SubRun::begin() const {
}
SubRun::const_iterator SubRun::end() const {
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
return m_impl->m_end;
}
......@@ -152,6 +177,9 @@ SubRun::const_iterator SubRun::cbegin() const {
}
SubRun::const_iterator SubRun::cend() const {
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
return m_impl->m_end;
}
......@@ -189,6 +217,9 @@ SubRun::const_iterator SubRun::lower_bound(const EventNumber& lb) const {
}
SubRun::iterator SubRun::upper_bound(const EventNumber& ub) {
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
Event event(m_impl->m_datastore,
m_impl->m_level+1,
m_impl->fullpath(), ub);
......@@ -246,15 +277,20 @@ SubRun::const_iterator::const_iterator(Event&& event)
SubRun::const_iterator::~const_iterator() {}
SubRun::const_iterator::const_iterator(const SubRun::const_iterator& other)
: m_impl(std::make_unique<Impl>(*other.m_impl)) {}
SubRun::const_iterator::const_iterator(const SubRun::const_iterator& other) {
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
}
SubRun::const_iterator::const_iterator(SubRun::const_iterator&& other)
: m_impl(std::move(other.m_impl)) {}
SubRun::const_iterator& SubRun::const_iterator::operator=(const SubRun::const_iterator& other) {
if(&other == this) return *this;
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
else
m_impl.reset();
return *this;
}
......@@ -286,7 +322,9 @@ const SubRun::const_iterator::reference SubRun::const_iterator::operator*() {
}
const SubRun::const_iterator::pointer SubRun::const_iterator::operator->() {
if(!m_impl) return nullptr;
if(!m_impl) {
throw Exception("Trying to dereference an invalid iterator");
}
return &(m_impl->m_current_event);
}
......@@ -324,7 +362,10 @@ SubRun::iterator::iterator(SubRun::iterator&& other)
SubRun::iterator& SubRun::iterator::operator=(const SubRun::iterator& other) {
if(this == &other) return *this;
if(other.m_impl)
m_impl = std::make_unique<Impl>(*other.m_impl);
else
m_impl.reset();
return *this;
}
......
......@@ -71,8 +71,7 @@ void DataSetTest::testBraketOperator() {
CPPUNIT_ASSERT(mds.valid());
// check that accessing a dataset that does not exist
// yields a non-valid DataSet
DataSet ds6 = mds["ds6"];
CPPUNIT_ASSERT(!ds6.valid());
CPPUNIT_ASSERT_THROW(mds["ds6"], hepnos::Exception);
// check that accessing a dataset that exists yields
// a valid DataSet instance with correct information
......@@ -169,9 +168,7 @@ void DataSetTest::testCreateRuns() {
CPPUNIT_ASSERT(mds.valid());
{
Run r = mds[45];
CPPUNIT_ASSERT(!r.valid());
CPPUNIT_ASSERT(r.number() == InvalidRunNumber);
CPPUNIT_ASSERT_THROW(mds[45], hepnos::Exception);
}
{
......
......@@ -26,6 +26,8 @@ void DataStoreTest::testFillDataStore() {
CPPUNIT_ASSERT_EQUAL_STR("ds1", ds1.name());
CPPUNIT_ASSERT_EQUAL_STR("", ds1.container());
CPPUNIT_ASSERT_EQUAL_STR("ds1", ds1.fullname());
// assert invalid dataset when it does not exist
CPPUNIT_ASSERT_THROW((*datastore)["invalid"], hepnos::Exception);
// assert comparison with a default-constructed dataset
DataSet ds0;
CPPUNIT_ASSERT(ds0 != ds1);
......@@ -51,9 +53,8 @@ void DataStoreTest::testFillDataStore() {
void DataStoreTest::testBraketOperator() {
// check that accessing a dataset that does not exist
// yields a non-valid DataSet
DataSet ds6 = (*datastore)["ds6"];
CPPUNIT_ASSERT(!ds6.valid());
// throws an exception
CPPUNIT_ASSERT_THROW((*datastore)["ds6"], hepnos::Exception);
// check that accessing a dataset that exists yields
// a valid DataSet instance with correct information
......
......@@ -20,7 +20,7 @@ void RunSetTest::testFillDataStore() {
// default-constructed run has InvalidRunNumber number
Run r0;
CPPUNIT_ASSERT(!r0.valid());
CPPUNIT_ASSERT(InvalidRunNumber == r0.number());
CPPUNIT_ASSERT_THROW(r0.number(), hepnos::Exception);
// correct run creation
Run r1 = mds.createRun(42);
// assert the characteristics of the created dataset
......@@ -54,8 +54,7 @@ void RunSetTest::testBraketOperator() {
CPPUNIT_ASSERT(mds.valid());
// check that accessing a Run that does not exist
// yields a non-valid Run instance
Run r6 = mds[43];
CPPUNIT_ASSERT(!r6.valid());
CPPUNIT_ASSERT_THROW(mds[43], hepnos::Exception);
// check that accessing a run that exists yields
// a valid Run instance with correct information
......@@ -156,9 +155,7 @@ void RunSetTest::testCreateSubRuns() {
Run r2 = mds[45];
{
SubRun sr = r2[73];
CPPUNIT_ASSERT(!sr.valid());
CPPUNIT_ASSERT(sr.number() == InvalidSubRunNumber);
CPPUNIT_ASSERT_THROW(r2[73], hepnos::Exception);
}
{
......
......@@ -47,9 +47,7 @@ void RunTest::testBraketOperator() {
CPPUNIT_ASSERT(r1.valid());
// check access to non-existing SubRun
SubRun sr0 = r1[12];
CPPUNIT_ASSERT(!sr0.valid());
CPPUNIT_ASSERT(sr0.number() == InvalidSubRunNumber);
CPPUNIT_ASSERT_THROW(r1[12], hepnos::Exception);
// check access to existing SubRun
SubRun sr13 = r1[13];
......
......@@ -52,9 +52,7 @@ void SubRunTest::testBraketOperator() {
CPPUNIT_ASSERT(sr1.valid());
// check access to non-existing SubRun
Event e0 = sr1[12];
CPPUNIT_ASSERT(!e0.valid());
CPPUNIT_ASSERT(e0.number() == InvalidEventNumber);
CPPUNIT_ASSERT_THROW(sr1[12], hepnos::Exception);
// check access to existing SubRun
Event e13 = sr1[13];
......