17 #include "TDictionary.h"
18 #include "TTreeReaderValue.h"
33 template <
typename T,
typename... Args>
34 static std::pair<AnyVector, std::vector<T>*>
create(Args&&... args) {
35 std::vector<T>* vector =
new std::vector<T>(std::forward<Args>(args)...);
36 std::function<void()> deleter = [vector] {
delete vector; };
37 return std::make_pair(
38 AnyVector{
static_cast<void*
>(vector), std::move(deleter)}, vector);
46 : m_vector{other.m_vector},
m_deleter{std::move(other.m_deleter)} {
47 other.m_vector =
nullptr;
53 m_vector = other.m_vector;
55 other.m_vector =
nullptr;
73 : m_vector{vector},
m_deleter{std::move(deleter)} {}
82 enum class Ordering { SMALLER, EQUAL, GREATER };
89 return Ordering::SMALLER;
91 return Ordering::EQUAL;
93 return Ordering::GREATER;
100 if (std::isless(x, y)) {
101 return Ordering::SMALLER;
102 }
else if (std::isgreater(x, y)) {
103 return Ordering::GREATER;
105 return Ordering::EQUAL;
121 template <
typename U>
124 if (v1.size() < v2.size()) {
125 return Ordering::SMALLER;
126 }
else if (v1.size() > v2.size()) {
127 return Ordering::GREATER;
132 for (std::size_t i = 0; i < v1.size(); ++i) {
134 return Ordering::SMALLER;
135 }
else if (v1[i] > v2[i]) {
136 return Ordering::GREATER;
141 return Ordering::EQUAL;
155 void selectionSort(
const std::size_t firstIndex,
const std::size_t lastIndex,
158 for (
size_t targetIndex = firstIndex; targetIndex < lastIndex;
160 size_t minIndex = targetIndex;
161 for (std::size_t readIndex = targetIndex + 1; readIndex <= lastIndex;
163 if (
compare(readIndex, minIndex) == Ordering::SMALLER) {
164 minIndex = readIndex;
167 if (minIndex != targetIndex)
168 swap(minIndex, targetIndex);
173 void quickSort(
const std::size_t firstIndex,
const std::size_t lastIndex,
177 static const std::size_t NON_RECURSIVE_THRESHOLD = 25;
178 if (lastIndex - firstIndex < NON_RECURSIVE_THRESHOLD) {
186 std::size_t pivotIndex = firstIndex + (lastIndex - firstIndex) / 2;
189 std::size_t splitIndex;
192 std::size_t i = firstIndex - 1;
193 std::size_t j = lastIndex + 1;
199 }
while (
compare(i, pivotIndex) == Ordering::SMALLER);
205 }
while (
compare(j, pivotIndex) == Ordering::GREATER);
215 if (i == pivotIndex) {
217 }
else if (j == pivotIndex) {
231 if (splitIndex - firstIndex <= lastIndex - splitIndex - 1) {
232 quickSort(firstIndex, splitIndex, compare, swap);
233 quickSort(splitIndex + 1, lastIndex, compare, swap);
235 quickSort(splitIndex + 1, lastIndex, compare, swap);
236 quickSort(firstIndex, splitIndex, compare, swap);
288 const EDataType dataType,
289 const std::string& className) {
292 return BranchComparisonHarness::create<char>(treeMetadata,
branchName);
294 return BranchComparisonHarness::create<unsigned char>(treeMetadata,
297 return BranchComparisonHarness::create<short>(treeMetadata,
branchName);
299 return BranchComparisonHarness::create<unsigned short>(treeMetadata,
302 return BranchComparisonHarness::create<int>(treeMetadata,
branchName);
304 return BranchComparisonHarness::create<unsigned int>(treeMetadata,
307 return BranchComparisonHarness::create<long>(treeMetadata,
branchName);
309 return BranchComparisonHarness::create<unsigned long>(treeMetadata,
312 return BranchComparisonHarness::create<unsigned long long>(treeMetadata,
316 return BranchComparisonHarness::create<float>(treeMetadata,
branchName);
318 return BranchComparisonHarness::create<double>(treeMetadata,
321 return BranchComparisonHarness::create<bool>(treeMetadata,
branchName);
323 if (className.substr(0, 6) ==
"vector") {
324 std::string elementType = className.substr(7, className.size() - 8);
326 std::move(elementType));
338 template <
typename T>
348 auto tree1DataStorage = AnyVector::create<T>();
349 auto tree2DataStorage = AnyVector::create<T>();
350 result.
eventData = std::make_pair(std::move(tree1DataStorage.first),
351 std::move(tree2DataStorage.first));
352 std::vector<T>& tree1Data = *tree1DataStorage.second;
353 std::vector<T>& tree2Data = *tree2DataStorage.second;
367 [&tree1Data](std::size_t i, std::size_t j) ->
Ordering {
368 return compare(tree1Data[i], tree1Data[j]);
370 [&tree1Data](std::size_t i, std::size_t j) {
374 [&tree2Data](std::size_t i, std::size_t j) ->
Ordering {
375 return compare(tree2Data[i], tree2Data[j]);
377 [&tree2Data](std::size_t i, std::size_t j) {
383 for (std::size_t i = 0; i < tree1Data.size(); ++i) {
384 if (
compare(tree1Data[i], tree2Data[i]) != Ordering::EQUAL)
392 std::cout <<
"File 1 \tFile 2" << std::endl;
393 for (std::size_t i = 0; i < tree1Data.size(); ++i) {
394 std::cout <<
toString(tree1Data[i]) <<
" \t"
395 <<
toString(tree2Data[i]) << std::endl;
400 return std::move(result);
413 template <
typename T>
417 const std::string&
branchName, std::vector<T>& tree1Data,
418 std::vector<T>& tree2Data)
441 const std::string elemType) {
443 #define CREATE_VECTOR__HANDLE_TYPE(type_name) \
444 if (elemType == #type_name) { \
445 return BranchComparisonHarness::create<std::vector<type_name>>( \
446 treeMetadata, branchName); \
457 #define CREATE_VECTOR__HANDLE_INTEGER_TYPE(integer_type_name) \
458 CREATE_VECTOR__HANDLE_TYPE(integer_type_name) \
459 else CREATE_VECTOR__HANDLE_TYPE(unsigned integer_type_name)
471 template <
typename T>
473 std::ostringstream oss;
478 template <
typename U>
479 static std::string
toString(
const std::vector<U>& vector) {
480 std::ostringstream oss{
"{ "};
481 for (
const auto&
data : vector) {
482 oss <<
data <<
" \t";