Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions test/form/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,52 @@ if(FORM_USE_ROOT_STORAGE)
WriteVector
)
target_include_directories(ReadVector PRIVATE ${PROJECT_SOURCE_DIR}/form)

cet_test(
form_root_schema_write_test
SOURCE
form_root_schema_write_test.cpp
toy_tracker.cpp
LIBRARIES
form
form_test_data_products
TEST_WORKDIR
form_root_schema_test
)
target_include_directories(form_root_schema_write_test PRIVATE ${PROJECT_SOURCE_DIR}/form)

cet_test(
form_root_schema_read_test
SOURCE
form_root_schema_read_test.cpp
LIBRARIES
form
form_test_data_products_schema_evolution
DIRTY_WORKDIR
TEST_WORKDIR
form_root_schema_test
REQUIRED_FIXTURES
form_root_schema_write_test
)
target_include_directories(form_root_schema_read_test PRIVATE ${PROJECT_SOURCE_DIR}/form)

cet_test(
check_root_schema_evolution
HANDBUILT
TEST_EXEC
${CMAKE_COMMAND}
TEST_ARGS
-E
compare_files
form_root_schema_write_log.txt
form_root_schema_read_log.txt
DIRTY_WORKDIR
TEST_WORKDIR
form_root_schema_test
REQUIRED_FIXTURES
form_root_schema_write_test
form_root_schema_read_test
)
endif()

cet_test(
Expand Down
2 changes: 2 additions & 0 deletions test/form/data_products/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ if(FORM_USE_ROOT_STORAGE)
${FORM_DATA_PROD_LIB_NAME} dict.h SELECTION classes_def.xml
)
target_link_libraries(${FORM_DATA_PROD_LIB_NAME} PRIVATE ROOT::RIO)

add_subdirectory(extra_member)
endif()
11 changes: 11 additions & 0 deletions test/form/data_products/extra_member/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(FORM_EXTRA_DATA_PROD_LIB_NAME "form_test_data_products_schema_evolution")
add_library(${FORM_EXTRA_DATA_PROD_LIB_NAME} SHARED track_start.cpp)

if(FORM_USE_ROOT_STORAGE)
find_package(ROOT REQUIRED COMPONENTS RIO)
include_directories(${ROOT_INCLUDE_DIRS})
reflex_generate_dictionary(
${FORM_EXTRA_DATA_PROD_LIB_NAME} dict.h SELECTION classes_def.xml
)
target_link_libraries(${FORM_EXTRA_DATA_PROD_LIB_NAME} PRIVATE ROOT::RIO)
endif()
4 changes: 4 additions & 0 deletions test/form/data_products/extra_member/classes_def.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<lcgdict>
<class name="TrackStart"/>
<class name="std::vector<TrackStart>"/>
</lcgdict>
2 changes: 2 additions & 0 deletions test/form/data_products/extra_member/dict.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "track_start.hpp"
#include <vector>
49 changes: 49 additions & 0 deletions test/form/data_products/extra_member/track_start.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "track_start.hpp"

TrackStart::TrackStart() : m_x(0), m_y(0), m_z(0), m_index(0) {}

TrackStart::TrackStart(float x, float y, float z, int index) :
m_x(x), m_y(y), m_z(z), m_index(index)
{
}

float TrackStart::getX() const { return m_x; }

float TrackStart::getY() const { return m_y; }

float TrackStart::getZ() const { return m_z; }

int TrackStart::getIndex() const { return m_index; }

void TrackStart::setX(float x) { m_x = x; }

void TrackStart::setY(float y) { m_y = y; }

void TrackStart::setZ(float z) { m_z = z; }

void TrackStart::setIndex(int index) { m_index = index; }

TrackStart TrackStart::operator+(TrackStart const& other) const
{
return TrackStart(m_x + other.m_x, m_y + other.m_y, m_z + other.m_z, m_index + other.m_index);
}

TrackStart& TrackStart::operator+=(TrackStart const& other)
{
m_x += other.m_x;
m_y += other.m_y;
m_z += other.m_z;
m_index += other.m_index;
return *this;
}

TrackStart TrackStart::operator-(TrackStart const& other) const
{
return TrackStart(m_x - other.m_x, m_y - other.m_y, m_z - other.m_z, m_index - other.m_index);
}

std::ostream& operator<<(std::ostream& os, TrackStart const& track)
{
os << "TrackStart{" << track.getX() << ", " << track.getY() << ", " << track.getZ() << "}";
return os;
}
39 changes: 39 additions & 0 deletions test/form/data_products/extra_member/track_start.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//A TrackStart is a 3-vector of position components.
//This is a simple test data product for demonstrating the features of FORM.

#include <iostream>

#ifndef TRACKSTART_HPP
#define TRACKSTART_HPP

class TrackStart {
public:
TrackStart();
TrackStart(float x, float y, float z, int index);
~TrackStart() = default;

float getX() const;
float getY() const;
float getZ() const;
int getIndex() const;

void setX(float x);
void setY(float y);
void setZ(float z);
void setIndex(int index);

TrackStart operator+(TrackStart const& other) const;
TrackStart& operator+=(TrackStart const& other);
TrackStart operator-(TrackStart const& other) const;

private:
float m_x;
float m_y;
float m_z;

int m_index;
};

std::ostream& operator<<(std::ostream& os, TrackStart const& track);

#endif //TRACKSTART_HPP
24 changes: 24 additions & 0 deletions test/form/form_root_schema_read_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//Part two of schema evolution unit test: can we build a program against a new dictionary for the same product that reads the old product and gets back the correct values?

#include "test/form/data_products/extra_member/track_start.hpp"
#include "test/form/test_utils.hpp"

#include <fstream>
#include <iostream>
#include <vector>

using namespace form::test;

int main(int const argc, char const** argv)
{
int const technology = getTechnology(argc, argv);
if (technology < 0)
return 1;

auto const& [prods] = read<std::vector<TrackStart>>(technology);
std::ofstream outFile("form_root_schema_read_log.txt");
for (auto const& prod : *prods)
outFile << prod << std::endl;

return 0;
}
29 changes: 29 additions & 0 deletions test/form/form_root_schema_write_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//Schema evolution test component: write old version of a data product to disk

#include "test/form/data_products/track_start.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be #include "test/form/data_products/extra_member/track_start.hpp" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is intentional. form_root_schema_write_test writes the old, non-extra_member version of the data product to a file. form_root_schema_read_test reads the old product with only the new product's definition. ROOT should automatically fill in the in-memory new product with as much of the old product's data as possible.

#include "test/form/test_utils.hpp"
#include "test/form/toy_tracker.hpp"

#include <fstream>
#include <iostream>
#include <vector>

using namespace form::test;

int main(int const argc, char const** argv)
{
int const technology = getTechnology(argc, argv);
if (technology < 0)
return 1;

ToyTracker tracker(4 * 1024);
std::vector<TrackStart> const prods = tracker();

std::ofstream outFile("form_root_schema_write_log.txt");
for (auto const& prod : prods)
outFile << prod << std::endl;

write(technology, prods);

return 0;
}
Loading