Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
HEP
HEPnOS
Commits
eac328c5
Commit
eac328c5
authored
Mar 09, 2020
by
Matthieu Dorier
Browse files
added RunDescriptor, SubRunDescriptor, and EventDescriptor
parent
79924272
Changes
13
Hide whitespace changes
Inline
Side-by-side
include/hepnos/Event.hpp
View file @
eac328c5
...
...
@@ -15,9 +15,15 @@
namespace
hepnos
{
constexpr
const
int
EventDescriptorLength
=
40
;
class
SubRun
;
class
EventSet
;
struct
EventDescriptor
{
char
data
[
EventDescriptorLength
];
};
class
Event
:
public
KeyValueContainer
{
private:
...
...
@@ -156,6 +162,28 @@ class Event : public KeyValueContainer {
* @return Parent SubRun.
*/
SubRun
subrun
()
const
;
/**
* @brief Fills an EventDescriptor with the information from this Event object.
*
* @param descriptor EventDescriptor to fill.
*/
void
toDescriptor
(
EventDescriptor
&
descriptor
);
/**
* @brief Creates a Event instance from an EventDescriptor.
* If validate is true, this function will check that the corresponding Event
* exists in the DataStore. If it does not exist, the returned Event will be
* invalid. validate can be set to false if, for example, the client
* application already knows by some other means that the Event exists.
*
* @param ds DataStore
* @param descriptor EventDescriptor
* @param validate whether to validate the existence of the Event.
*
* @return An Event object.
*/
static
Event
fromDescriptor
(
const
DataStore
&
ds
,
const
EventDescriptor
&
descriptor
,
bool
validate
=
true
);
};
}
...
...
include/hepnos/Run.hpp
View file @
eac328c5
...
...
@@ -16,8 +16,14 @@
namespace
hepnos
{
constexpr
const
int
RunDescriptorLength
=
24
;
class
RunSet
;
struct
RunDescriptor
{
char
data
[
RunDescriptorLength
];
};
class
Run
:
public
KeyValueContainer
{
private:
...
...
@@ -304,6 +310,28 @@ class Run : public KeyValueContainer {
SubRun
createSubRun
(
const
SubRunNumber
&
subRunNumber
);
SubRun
createSubRun
(
AsyncEngine
&
async
,
const
SubRunNumber
&
subRunNumber
);
SubRun
createSubRun
(
WriteBatch
&
batch
,
const
SubRunNumber
&
subRunNumber
);
/**
* @brief Fills a RunDescriptor with the information from this Run object.
*
* @param descriptor RunDescriptor to fill.
*/
void
toDescriptor
(
RunDescriptor
&
descriptor
);
/**
* @brief Creates a Run instance from a RunDescriptor.
* If validate is true, this function will check that the corresponding Run
* exists in the DataStore. If it does not exist, the returned Run will be
* invalid. validate can be set to false if, for example, the client
* application already knows by some other means that the Run exists.
*
* @param ds DataStore
* @param descriptor RunDescriptor
* @param validate whether to validate the existence of the Run.
*
* @return A Run object.
*/
static
Run
fromDescriptor
(
const
DataStore
&
ds
,
const
RunDescriptor
&
descriptor
,
bool
validate
=
true
);
};
class
Run
::
const_iterator
{
...
...
include/hepnos/SubRun.hpp
View file @
eac328c5
...
...
@@ -16,6 +16,12 @@
namespace
hepnos
{
constexpr
const
int
SubRunDescriptorLength
=
32
;
struct
SubRunDescriptor
{
char
data
[
SubRunDescriptorLength
];
};
class
SubRun
:
public
KeyValueContainer
{
private:
...
...
@@ -306,6 +312,28 @@ class SubRun : public KeyValueContainer {
Event
createEvent
(
const
EventNumber
&
eventNumber
);
Event
createEvent
(
WriteBatch
&
batch
,
const
EventNumber
&
eventNumber
);
Event
createEvent
(
AsyncEngine
&
batch
,
const
EventNumber
&
eventNumber
);
/**
* @brief Fills a SubRunDescriptor with the information from this SubRun object.
*
* @param descriptor SubRunDescriptor to fill.
*/
void
toDescriptor
(
SubRunDescriptor
&
descriptor
);
/**
* @brief Creates a SubRun instance from a SubRunDescriptor.
* If validate is true, this function will check that the corresponding SubRun
* exists in the DataStore. If it does not exist, the returned SubRun will be
* invalid. validate can be set to false if, for example, the client
* application already knows by some other means that the SubRun exists.
*
* @param ds DataStore
* @param descriptor SubRunDescriptor
* @param validate whether to validate the existence of the SubRun.
*
* @return A SubRun object.
*/
static
SubRun
fromDescriptor
(
const
DataStore
&
ds
,
const
SubRunDescriptor
&
descriptor
,
bool
validate
=
true
);
};
class
SubRun
::
const_iterator
{
...
...
src/DataStoreImpl.hpp
View file @
eac328c5
...
...
@@ -563,33 +563,41 @@ class DataStoreImpl {
/**
* @brief Checks if a particular Run/SubRun/Event exists.
*/
bool
itemExists
(
const
UUID
&
containerUUID
,
const
RunNumber
&
run_number
,
const
SubRunNumber
&
subrun_number
=
InvalidSubRunNumber
,
const
EventNumber
&
event_number
=
InvalidEventNumber
,
bool
itemExists
(
const
ItemDescriptor
&
descriptor
,
int
target
=
-
1
)
const
{
// build the key
ItemDescriptor
k
;
k
.
dataset
=
containerUUID
;
k
.
run
=
run_number
;
k
.
subrun
=
subrun_number
;
k
.
event
=
event_number
;
ItemType
type
=
ItemType
::
RUN
;
if
(
subrun_number
!=
InvalidSubRunNumber
)
{
if
(
descriptor
.
subrun
!=
InvalidSubRunNumber
)
{
type
=
ItemType
::
SUBRUN
;
if
(
event_number
!=
InvalidEventNumber
)
if
(
descriptor
.
event
!=
InvalidEventNumber
)
type
=
ItemType
::
EVENT
;
}
// find out which DB to access
auto
&
db
=
locateItemDb
(
type
,
k
,
target
);
auto
&
db
=
locateItemDb
(
type
,
descriptor
,
target
);
try
{
bool
b
=
db
.
exists
(
&
k
,
sizeof
(
k
));
bool
b
=
db
.
exists
(
&
descriptor
,
sizeof
(
descriptor
));
return
b
;
}
catch
(
sdskv
::
exception
&
ex
)
{
throw
Exception
(
"Error occured when calling sdskv::database::exists (SDSKV error="
+
std
::
to_string
(
ex
.
error
())
+
")"
);
}
return
false
;
}
/**
* @brief Checks if a particular Run/SubRun/Event exists.
*/
bool
itemExists
(
const
UUID
&
containerUUID
,
const
RunNumber
&
run_number
,
const
SubRunNumber
&
subrun_number
=
InvalidSubRunNumber
,
const
EventNumber
&
event_number
=
InvalidEventNumber
,
int
target
=
-
1
)
const
{
// build the key
ItemDescriptor
k
;
k
.
dataset
=
containerUUID
;
k
.
run
=
run_number
;
k
.
subrun
=
subrun_number
;
k
.
event
=
event_number
;
return
itemExists
(
k
,
target
);
}
/**
* Creates a Run, SubRun, or Event
...
...
src/Event.cpp
View file @
eac328c5
...
...
@@ -13,7 +13,7 @@
namespace
hepnos
{
Event
::
Event
()
:
m_impl
(
std
::
make_shared
<
ItemImpl
>
(
nullptr
,
UUID
(),
InvalidRunNumber
))
{}
:
m_impl
(
std
::
make_shared
<
ItemImpl
>
(
nullptr
,
UUID
(),
InvalidRunNumber
))
{}
Event
::
Event
(
std
::
shared_ptr
<
ItemImpl
>&&
impl
)
:
m_impl
(
std
::
move
(
impl
))
{
}
...
...
@@ -124,4 +124,19 @@ const EventNumber& Event::number() const {
return
m_impl
->
m_descriptor
.
event
;
}
void
Event
::
toDescriptor
(
EventDescriptor
&
descriptor
)
{
std
::
memset
(
descriptor
.
data
,
0
,
sizeof
(
descriptor
.
data
));
if
(
!
valid
())
return
;
std
::
memcpy
(
descriptor
.
data
,
&
(
m_impl
->
m_descriptor
),
sizeof
(
descriptor
.
data
));
}
Event
Event
::
fromDescriptor
(
const
DataStore
&
datastore
,
const
EventDescriptor
&
descriptor
,
bool
validate
)
{
auto
itemImpl
=
std
::
make_shared
<
ItemImpl
>
(
datastore
.
m_impl
,
UUID
(),
InvalidRunNumber
);
auto
&
itemDescriptor
=
itemImpl
->
m_descriptor
;
std
::
memcpy
(
&
itemDescriptor
,
descriptor
.
data
,
sizeof
(
descriptor
.
data
));
if
((
!
validate
)
||
datastore
.
m_impl
->
itemExists
(
itemDescriptor
))
return
Event
(
std
::
move
(
itemImpl
));
else
return
Event
();
}
}
src/Run.cpp
View file @
eac328c5
...
...
@@ -273,6 +273,21 @@ Run::const_iterator Run::upper_bound(const SubRunNumber& ub) const {
return
it
;
}
void
Run
::
toDescriptor
(
RunDescriptor
&
descriptor
)
{
std
::
memset
(
descriptor
.
data
,
0
,
sizeof
(
descriptor
.
data
));
if
(
!
valid
())
return
;
std
::
memcpy
(
descriptor
.
data
,
&
(
m_impl
->
m_descriptor
),
sizeof
(
descriptor
.
data
));
}
Run
Run
::
fromDescriptor
(
const
DataStore
&
datastore
,
const
RunDescriptor
&
descriptor
,
bool
validate
)
{
auto
itemImpl
=
std
::
make_shared
<
ItemImpl
>
(
datastore
.
m_impl
,
UUID
(),
InvalidRunNumber
);
auto
&
itemDescriptor
=
itemImpl
->
m_descriptor
;
std
::
memcpy
(
&
itemDescriptor
,
descriptor
.
data
,
sizeof
(
descriptor
.
data
));
if
((
!
validate
)
||
datastore
.
m_impl
->
itemExists
(
itemDescriptor
))
return
Run
(
std
::
move
(
itemImpl
));
else
return
Run
();
}
////////////////////////////////////////////////////////////////////////////////////////////
// Run::const_iterator::Impl implementation
////////////////////////////////////////////////////////////////////////////////////////////
...
...
src/SubRun.cpp
View file @
eac328c5
...
...
@@ -269,6 +269,21 @@ SubRun::const_iterator SubRun::upper_bound(const EventNumber& ub) const {
return
it
;
}
void
SubRun
::
toDescriptor
(
SubRunDescriptor
&
descriptor
)
{
std
::
memset
(
descriptor
.
data
,
0
,
sizeof
(
descriptor
.
data
));
if
(
!
valid
())
return
;
std
::
memcpy
(
descriptor
.
data
,
&
(
m_impl
->
m_descriptor
),
sizeof
(
descriptor
.
data
));
}
SubRun
SubRun
::
fromDescriptor
(
const
DataStore
&
datastore
,
const
SubRunDescriptor
&
descriptor
,
bool
validate
)
{
auto
itemImpl
=
std
::
make_shared
<
ItemImpl
>
(
datastore
.
m_impl
,
UUID
(),
InvalidRunNumber
);
auto
&
itemDescriptor
=
itemImpl
->
m_descriptor
;
std
::
memcpy
(
&
itemDescriptor
,
descriptor
.
data
,
sizeof
(
descriptor
.
data
));
if
((
!
validate
)
||
datastore
.
m_impl
->
itemExists
(
itemDescriptor
))
return
SubRun
(
std
::
move
(
itemImpl
));
else
return
SubRun
();
}
////////////////////////////////////////////////////////////////////////////////////////////
// SubRun::const_iterator::Impl implementation
////////////////////////////////////////////////////////////////////////////////////////////
...
...
test/EventTest.cpp
View file @
eac328c5
...
...
@@ -21,3 +21,24 @@ void EventTest::testFillDataStore() {
CPPUNIT_ASSERT
(
ev1
.
valid
());
}
void
EventTest
::
testDescriptor
()
{
auto
root
=
datastore
->
root
();
auto
mds
=
root
[
"matthieu"
];
auto
r1
=
mds
[
42
];
auto
sr1
=
r1
[
3
];
auto
ev1
=
sr1
[
22
];
CPPUNIT_ASSERT
(
ev1
.
valid
());
EventDescriptor
ev1_desc
;
ev1
.
toDescriptor
(
ev1_desc
);
Event
ev2
=
Event
::
fromDescriptor
(
*
datastore
,
ev1_desc
);
CPPUNIT_ASSERT
(
ev2
.
valid
());
EventDescriptor
invalid_desc
;
Event
ev3
=
Event
::
fromDescriptor
(
*
datastore
,
invalid_desc
);
CPPUNIT_ASSERT
(
!
ev3
.
valid
());
Event
ev4
=
Event
::
fromDescriptor
(
*
datastore
,
invalid_desc
,
false
);
CPPUNIT_ASSERT
(
ev4
.
valid
());
}
test/EventTest.hpp
View file @
eac328c5
...
...
@@ -10,6 +10,7 @@ class EventTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE
(
EventTest
);
CPPUNIT_TEST
(
testFillDataStore
);
CPPUNIT_TEST
(
testDescriptor
);
CPPUNIT_TEST_SUITE_END
();
public:
...
...
@@ -18,6 +19,7 @@ class EventTest : public CppUnit::TestFixture
void
tearDown
();
void
testFillDataStore
();
void
testDescriptor
();
};
#endif
test/RunTest.cpp
View file @
eac328c5
...
...
@@ -17,6 +17,25 @@ void RunTest::testFillDataStore() {
CPPUNIT_ASSERT
(
r1
.
valid
());
}
void
RunTest
::
testDescriptor
()
{
auto
root
=
datastore
->
root
();
auto
mds
=
root
[
"matthieu"
];
auto
r1
=
mds
[
42
];
CPPUNIT_ASSERT
(
r1
.
valid
());
RunDescriptor
r1_desc
;
r1
.
toDescriptor
(
r1_desc
);
Run
r2
=
Run
::
fromDescriptor
(
*
datastore
,
r1_desc
);
CPPUNIT_ASSERT
(
r2
.
valid
());
RunDescriptor
invalid_desc
;
Run
r3
=
Run
::
fromDescriptor
(
*
datastore
,
invalid_desc
);
CPPUNIT_ASSERT
(
!
r3
.
valid
());
Run
r4
=
Run
::
fromDescriptor
(
*
datastore
,
invalid_desc
,
false
);
CPPUNIT_ASSERT
(
r4
.
valid
());
}
void
RunTest
::
testCreateSubRuns
()
{
auto
root
=
datastore
->
root
();
DataSet
mds
=
root
[
"matthieu"
];
...
...
test/RunTest.hpp
View file @
eac328c5
...
...
@@ -10,6 +10,7 @@ class RunTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE
(
RunTest
);
CPPUNIT_TEST
(
testFillDataStore
);
CPPUNIT_TEST
(
testDescriptor
);
CPPUNIT_TEST
(
testCreateSubRuns
);
CPPUNIT_TEST
(
testBraketOperator
);
CPPUNIT_TEST
(
testFind
);
...
...
@@ -24,6 +25,7 @@ class RunTest : public CppUnit::TestFixture
void
tearDown
();
void
testFillDataStore
();
void
testDescriptor
();
void
testCreateSubRuns
();
void
testBraketOperator
();
void
testFind
();
...
...
test/SubRunTest.cpp
View file @
eac328c5
...
...
@@ -18,6 +18,26 @@ void SubRunTest::testFillDataStore() {
SubRun
sr1
=
r1
.
createSubRun
(
3
);
}
void
SubRunTest
::
testDescriptor
()
{
auto
root
=
datastore
->
root
();
auto
mds
=
root
[
"matthieu"
];
auto
r1
=
mds
[
42
];
auto
sr1
=
r1
[
3
];
CPPUNIT_ASSERT
(
sr1
.
valid
());
SubRunDescriptor
sr1_desc
;
sr1
.
toDescriptor
(
sr1_desc
);
SubRun
sr2
=
SubRun
::
fromDescriptor
(
*
datastore
,
sr1_desc
);
CPPUNIT_ASSERT
(
sr2
.
valid
());
SubRunDescriptor
invalid_desc
;
SubRun
sr3
=
SubRun
::
fromDescriptor
(
*
datastore
,
invalid_desc
);
CPPUNIT_ASSERT
(
!
sr3
.
valid
());
SubRun
sr4
=
SubRun
::
fromDescriptor
(
*
datastore
,
invalid_desc
,
false
);
CPPUNIT_ASSERT
(
sr4
.
valid
());
}
void
SubRunTest
::
testCreateEvents
()
{
auto
root
=
datastore
->
root
();
auto
mds
=
root
[
"matthieu"
];
...
...
test/SubRunTest.hpp
View file @
eac328c5
...
...
@@ -10,6 +10,7 @@ class SubRunTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE
(
SubRunTest
);
CPPUNIT_TEST
(
testFillDataStore
);
CPPUNIT_TEST
(
testDescriptor
);
CPPUNIT_TEST
(
testCreateEvents
);
CPPUNIT_TEST
(
testBraketOperator
);
CPPUNIT_TEST
(
testFind
);
...
...
@@ -24,6 +25,7 @@ class SubRunTest : public CppUnit::TestFixture
void
tearDown
();
void
testFillDataStore
();
void
testDescriptor
();
void
testCreateEvents
();
void
testBraketOperator
();
void
testFind
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment