Commit 210b7dc8 authored by Matthieu Dorier's avatar Matthieu Dorier

added functions to get from Event to parent SubRun and from SubRun to parent Run

parent 1e4c689f
......@@ -150,6 +150,12 @@ class Event : public KeyValueContainer {
*/
const EventNumber& number() const;
/**
* @brief Returns an intance of the enclosing SubRun.
*
* @return Parent SubRun.
*/
SubRun subrun() const;
};
}
......
......@@ -22,6 +22,7 @@ class Run : public KeyValueContainer {
private:
friend class SubRun;
friend class RunSet;
friend class DataSet;
......
......@@ -20,6 +20,7 @@ class SubRun : public KeyValueContainer {
private:
friend class Event;
friend class Run;
std::shared_ptr<ItemImpl> m_impl;
......@@ -149,6 +150,11 @@ class SubRun : public KeyValueContainer {
*/
const SubRunNumber& number() const;
/**
* @brief Returns an instance of the enclosing Run.
*/
Run run() const;
class const_iterator;
class iterator;
......
......@@ -28,6 +28,17 @@ DataStore Event::datastore() const {
return DataStore(m_impl->m_datastore);
}
SubRun Event::subrun() const {
if(!valid()) {
throw Exception("Calling Event member function on invalid Event object");
}
ItemDescriptor subrun_descriptor(
m_impl->m_descriptor.dataset,
m_impl->m_descriptor.run,
m_impl->m_descriptor.subrun);
return SubRun(std::make_shared<ItemImpl>(m_impl->m_datastore, subrun_descriptor));
}
Event Event::next() const {
if(!valid()) return Event();
......
......@@ -4,6 +4,7 @@
* See COPYRIGHT in top-level directory.
*/
#include "hepnos/Run.hpp"
#include "hepnos/DataSet.hpp"
#include "hepnos/AsyncEngine.hpp"
#include "ItemImpl.hpp"
#include "ItemImpl.hpp"
......
......@@ -32,6 +32,16 @@ DataStore SubRun::datastore() const {
return DataStore(m_impl->m_datastore);
}
Run SubRun::run() const {
if(!valid()) {
throw Exception("Calling SubRun member function on invalid SubRun object");
}
ItemDescriptor run_descriptor(
m_impl->m_descriptor.dataset,
m_impl->m_descriptor.run);
return Run(std::make_shared<ItemImpl>(m_impl->m_datastore, run_descriptor));
}
SubRun SubRun::next() const {
if(!valid()) return SubRun();
......
......@@ -97,9 +97,38 @@ void EventSetTest::testBeginEnd() {
for(auto& ev : eventset) {
CPPUNIT_ASSERT(ev.valid());
i += 1;
auto ev_number = ev.number();
auto sr = ev.subrun();
auto sr_number = sr.number();
auto r_number = sr.run().number();
events.emplace_back(r_number, sr_number, ev_number);
}
}
CPPUNIT_ASSERT_EQUAL(2*3*4, (int)i);
std::sort(events.begin(), events.end(), [](const auto& t1, const auto& t2) {
auto run1 = std::get<0>(t1);
auto subrun1 = std::get<1>(t1);
auto event1 = std::get<2>(t1);
auto run2 = std::get<0>(t2);
auto subrun2 = std::get<1>(t2);
auto event2 = std::get<2>(t2);
if(run1 < run2) return true;
if(run1 > run2) return false;
if(subrun1 < subrun2) return true;
if(subrun1 > subrun2) return false;
if(event1 < event2) return true;
return false;
});
unsigned e = 0;
for(unsigned i=3; i < 5; i++) {
for(unsigned j=6; j < 9; j++) {
for(unsigned k=1; k < 5; k++, e++) {
CPPUNIT_ASSERT_EQUAL(i, (unsigned)std::get<0>(events[e]));
CPPUNIT_ASSERT_EQUAL(j, (unsigned)std::get<1>(events[e]));
CPPUNIT_ASSERT_EQUAL(k, (unsigned)std::get<2>(events[e]));
}
}
}
// iteration all targets at once
i = 0;
eventset = mds.events();
......
......@@ -19,6 +19,7 @@ hepnos_test_start_servers 2 2 20 $CFG_FILE $CON_FILE
export HEPNOS_CONFIG_FILE=$CON_FILE
sleep 1
# run a connect test client
run_to ${timeout_sec} $1 $CON_FILE $1.xml
if [ $? -ne 0 ]; then
......
......@@ -17,6 +17,7 @@ export HEPNOS_CONFIG_FILE=$CON_FILE
# Run HEPnOS
hepnos_test_start_servers 2 1 20 $CFG_FILE $CON_FILE
sleep 1
# Run a test client
run_to 10 $1 $CON_FILE
if [ $? -ne 0 ]; then
......@@ -30,6 +31,7 @@ wait
# Run HEPnOS again
hepnos_test_start_servers 2 1 20 $CFG_FILE $CON_FILE
sleep 1
# Run the second test client
run_to 10 $2 $CON_FILE
if [ $? -ne 0 ]; then
......
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