Commit 756aeb5e authored by Matthieu Dorier's avatar Matthieu Dorier

Runs are now using the uuid of their DataSet instead of the full path

parent 591250eb
......@@ -151,14 +151,6 @@ class Run : public KeyValueContainer {
*/
const RunNumber& number() const;
/**
* @brief Returns the full name of the DataSet containing
* this Run.
*
* @return the full name of the DataSet containing this Run.
*/
const std::string& container() const;
class const_iterator;
class iterator;
......
......@@ -44,6 +44,8 @@ struct UUID {
static UUID generate();
void randomize();
bool operator==(const UUID& other) const;
};
template<typename T>
......
......@@ -130,26 +130,27 @@ Run DataSet::createRun(const RunNumber& runNumber) {
if(InvalidRunNumber == runNumber) {
throw Exception("Trying to create a Run with InvalidRunNumber");
}
std::string parent = fullname();
std::string parent_uuid = m_impl->m_uuid.to_string();
std::string runStr = makeKeyStringFromNumber(runNumber);
m_impl->m_datastore->store(m_impl->m_level+1, parent, runStr);
return Run(
std::make_shared<RunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
std::make_shared<std::string>(parent), runNumber));
m_impl->m_datastore->store(m_impl->m_level+1, parent_uuid, runStr);
return Run(std::make_shared<RunImpl>(
m_impl->m_datastore,
m_impl->m_level+1,
m_impl->m_uuid,
runNumber));
}
Run DataSet::createRun(WriteBatch& batch, const RunNumber& runNumber) {
if(InvalidRunNumber == runNumber) {
throw Exception("Trying to create a Run with InvalidRunNumber");
}
std::string parent = fullname();
std::string parent_uuid = m_impl->m_uuid.to_string();
std::string runStr = makeKeyStringFromNumber(runNumber);
batch.m_impl->store(m_impl->m_level+1, parent, runStr);
batch.m_impl->store(m_impl->m_level+1, parent_uuid, runStr);
return Run(
std::make_shared<RunImpl>(
m_impl->m_datastore, m_impl->m_level+1,
std::make_shared<std::string>(parent), runNumber));
m_impl->m_uuid, runNumber));
}
DataSet DataSet::operator[](const std::string& datasetName) const {
......
......@@ -14,7 +14,7 @@ namespace hepnos {
Run::iterator RunImpl::m_end;
Run::Run()
: m_impl(std::make_shared<RunImpl>(nullptr, 0, std::make_shared<std::string>(""), InvalidRunNumber)) {}
: m_impl(std::make_shared<RunImpl>(nullptr, 0, UUID(), InvalidRunNumber)) {}
Run::Run(std::shared_ptr<RunImpl>&& impl)
: m_impl(std::move(impl)) { }
......@@ -34,17 +34,17 @@ Run Run::next() const {
std::vector<std::string> keys;
size_t s = m_impl->m_datastore->nextKeys(
m_impl->m_level, *m_impl->m_dataset_name,
m_impl->m_level, m_impl->m_dataset_uuid.to_string(),
m_impl->makeKeyStringFromRunNumber(), keys, 1);
if(s == 0) return Run();
size_t i = m_impl->m_dataset_name->size()+1;
size_t i = 33;
if(keys[0].size() <= i) return Run();
RunNumber rn = parseNumberFromKeyString<RunNumber>(&keys[0][i]);
if(rn == InvalidRunNumber) return Run();
return Run(std::make_shared<RunImpl>(
m_impl->m_datastore,
m_impl->m_level,
m_impl->m_dataset_name,
m_impl->m_dataset_uuid,
rn));
}
......@@ -105,13 +105,6 @@ const RunNumber& Run::number() const {
return m_impl->m_run_number;
}
const std::string& Run::container() const {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
}
return *m_impl->m_dataset_name;
}
SubRun Run::createSubRun(const SubRunNumber& subRunNumber) {
if(!valid()) {
throw Exception("Calling Run member function on an invalid Run object");
......
......@@ -21,24 +21,23 @@ class RunImpl {
std::shared_ptr<DataStoreImpl> m_datastore;
uint8_t m_level;
std::shared_ptr<std::string> m_dataset_name;
UUID m_dataset_uuid;
RunNumber m_run_number;
static Run::iterator m_end;
RunImpl(const std::shared_ptr<DataStoreImpl>& ds,
uint8_t level,
const std::shared_ptr<std::string>& dataset,
const UUID& uuid,
const RunNumber& rn)
: m_datastore(ds)
, m_level(level)
, m_dataset_name(dataset)
, m_dataset_uuid(uuid)
, 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;
return (m_run_number == other.m_run_number)
&& (m_dataset_uuid == other.m_dataset_uuid);
}
std::string makeKeyStringFromRunNumber() const {
......@@ -46,11 +45,11 @@ class RunImpl {
}
std::string container() const {
return *m_dataset_name;
return m_dataset_uuid.to_string();
}
std::string fullpath() const {
return *m_dataset_name + "/" + makeKeyStringFromRunNumber();
return container() + "/" + makeKeyStringFromRunNumber();
}
};
......
......@@ -39,17 +39,17 @@ DataStore RunSet::datastore() const {
RunSet::iterator RunSet::find(const RunNumber& runNumber) {
int ret;
std::string parent = m_impl->fullname();
std::string parent_uuid = m_impl->m_uuid.to_string();
std::string strNum = makeKeyStringFromNumber(runNumber);
auto datastore = m_impl->m_datastore;
auto level = m_impl->m_level;
bool b = datastore->exists(level+1, parent, strNum);
bool b = datastore->exists(level+1, parent_uuid, strNum);
if(!b) return end();
return iterator(
std::make_shared<RunImpl>(
datastore,
level+1,
std::make_shared<std::string>(parent),
m_impl->m_uuid,
runNumber));
}
......@@ -64,9 +64,8 @@ RunSet::iterator RunSet::begin() {
auto ds_level = m_impl->m_level;
auto datastore = m_impl->m_datastore;
std::string container = m_impl->fullname();
auto new_run_impl = std::make_shared<RunImpl>(datastore,
ds_level+1, std::make_shared<std::string>(container), 0);
ds_level+1, m_impl->m_uuid, 0);
Run run(std::move(new_run_impl));
run = run.next();
......@@ -103,7 +102,7 @@ RunSet::iterator RunSet::lower_bound(const RunNumber& lb) {
Run run(std::make_shared<RunImpl>(
m_impl->m_datastore,
m_impl->m_level+1,
std::make_shared<std::string>(m_impl->fullname()), 0));
m_impl->m_uuid, 0));
run = run.next();
if(!run.valid()) return end();
else return iterator(run);
......@@ -117,7 +116,7 @@ RunSet::iterator RunSet::lower_bound(const RunNumber& lb) {
Run run(std::make_shared<RunImpl>(
m_impl->m_datastore,
m_impl->m_level+1,
std::make_shared<std::string>(m_impl->fullname()), lb-1));
m_impl->m_uuid, lb-1));
run = run.next();
if(!run.valid()) return end();
else return iterator(run);
......@@ -132,7 +131,7 @@ RunSet::const_iterator RunSet::lower_bound(const RunNumber& lb) const {
RunSet::iterator RunSet::upper_bound(const RunNumber& ub) {
Run run(std::make_shared<RunImpl>(m_impl->m_datastore,
m_impl->m_level+1,
std::make_shared<std::string>(m_impl->fullname()), ub));
m_impl->m_uuid, ub));
run = run.next();
if(!run.valid()) return end();
else return iterator(run);
......
......@@ -22,4 +22,9 @@ UUID UUID::generate() {
return result;
}
bool UUID::operator==(const UUID& other) const {
int c = memcmp(data, other.data, sizeof(data));
return c == 0;
}
}
......@@ -28,7 +28,6 @@ void DataSetTest::testFillDataStore() {
hepnos::Exception);
// correct dataset creation
DataSet ds1 = mds.createDataSet("ds1");
std::cerr << "AAAA" << std::endl;
// assert the characteristics of the created dataset
CPPUNIT_ASSERT(ds1.valid());
CPPUNIT_ASSERT_EQUAL_STR("ds1", ds1.name());
......@@ -36,21 +35,15 @@ void DataSetTest::testFillDataStore() {
CPPUNIT_ASSERT_EQUAL_STR("/matthieu/ds1", ds1.fullname());
// assert access from DataStore using full path
DataSet matthieu_ds1 = root["matthieu/ds1"];
std::cerr << "BBBB" << std::endl;
CPPUNIT_ASSERT(matthieu_ds1.valid());
CPPUNIT_ASSERT(matthieu_ds1 == ds1);
std::cerr << "CCCC" << std::endl;
// create a dataset inside ds1
DataSet ds11 = ds1.createDataSet("ds11");
std::cerr << "DDDD" << std::endl;
CPPUNIT_ASSERT(ds11.valid());
std::cerr << "EEEE" << std::endl;
// access ds11 using path from "matthieu"
DataSet ds1_ds11 = mds["ds1/ds11"];
std::cerr << "FFFF" << std::endl;
CPPUNIT_ASSERT(ds1_ds11.valid());
CPPUNIT_ASSERT(ds1_ds11 == ds11);
std::cerr << "GGGG" << std::endl;
// assert comparison with a default-constructed dataset
DataSet ds0;
CPPUNIT_ASSERT(ds0 != ds1);
......@@ -59,11 +52,8 @@ void DataSetTest::testFillDataStore() {
DataSet ds2 = ds1.next();
CPPUNIT_ASSERT(!ds2.valid());
// create more datasets
std::cerr << "HHHH" << std::endl;
DataSet ds3 = mds.createDataSet("ds3");
std::cerr << "IIII" << std::endl;
ds2 = mds.createDataSet("ds2");
std::cerr << "JJJJ" << std::endl;
// assert that these are valid
CPPUNIT_ASSERT(ds2.valid());
CPPUNIT_ASSERT(ds3.valid());
......@@ -72,9 +62,7 @@ void DataSetTest::testFillDataStore() {
CPPUNIT_ASSERT(ds3 == ds2.next());
// create more datasets for future tests
DataSet ds4 = mds.createDataSet("dsB");
std::cerr << "KKKK" << std::endl;
DataSet ds5 = mds.createDataSet("dsD");
std::cerr << "LLLL" << std::endl;
CPPUNIT_ASSERT(ds4.valid());
CPPUNIT_ASSERT(ds5.valid());
}
......@@ -193,7 +181,6 @@ void DataSetTest::testCreateRuns() {
Run r = mds.createRun(45);
CPPUNIT_ASSERT(r.valid());
CPPUNIT_ASSERT(45 == r.number());
CPPUNIT_ASSERT_EQUAL_STR("/matthieu", r.container());
}
}
......@@ -26,7 +26,6 @@ void RunSetTest::testFillDataStore() {
// assert the characteristics of the created dataset
CPPUNIT_ASSERT(r1.valid());
CPPUNIT_ASSERT(42 == r1.number());
CPPUNIT_ASSERT_EQUAL_STR("/matthieu", r1.container());
// assert comparison with a default-constructed run
CPPUNIT_ASSERT(r0 != r1);
CPPUNIT_ASSERT(!(r0 == r1));
......@@ -62,7 +61,6 @@ void RunSetTest::testBraketOperator() {
Run r2 = mds[45];
CPPUNIT_ASSERT(r2.valid());
CPPUNIT_ASSERT(45 == r2.number());
CPPUNIT_ASSERT_EQUAL_STR("/matthieu", r2.container());
// check that we access the same Run using the runs() function
// to go through the RunSet
......
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