#include "ArrayWrapper.h" void PrintArrayWrapper(ArrayWrapper item) { std::cout << "(" << item._values[0] << "," << item._values[1] << ")"; } void PrintVectorArrayWrapper(std::vector vector_array) { std::cout << "[ "; for (int i_array = 0; i_array < vector_array.size(); ++i_array) { PrintArrayWrapper(vector_array[i_array]); if (i_array < vector_array.size()-1) { std::cout << ", "; } } std::cout << " ]"; } void PrintVectorVectorArrayWrapper(std::vector> vector_array) { std::cout << "{ "; for (int i_array = 0; i_array < vector_array.size(); ++i_array) { PrintVectorArrayWrapper(vector_array[i_array]); if (i_array < vector_array.size()-1) { std::cout << ", "; } } std::cout << " }"; } void mwe(){ gInterpreter->GenerateDictionary("ArrayWrapper", "ArrayWrapper.h"); gInterpreter->GenerateDictionary("vector", "ArrayWrapper.h;vector"); gInterpreter->GenerateDictionary("vector>", "ArrayWrapper.h;vector"); ArrayWrapper first_item; first_item._values[0] = 1.0; first_item._values[1] = 2.0; // std::cout << "ArrayWrapper first_item = "; PrintArrayWrapper(first_item); std::cout << ";" << std::endl; ArrayWrapper second_item; second_item._values[0] = 3.0; second_item._values[1] = 4.0; // std::cout << "ArrayWrapper second_item = "; PrintArrayWrapper(second_item); std::cout << ";" << std::endl; std::vector first_vector_array; first_vector_array.push_back(first_item); // std::cout << "first_vector_array = "; PrintVectorArrayWrapper(first_vector_array); std::cout << std::endl; std::vector second_vector_array; second_vector_array.push_back(second_item); // std::cout << "second_vector_array = "; PrintVectorArrayWrapper(second_vector_array); std::cout << std::endl; std::vector> vector_vector_array; vector_vector_array.push_back(first_vector_array); vector_vector_array.push_back(second_vector_array); // std::cout << "vector_vector_array = "; PrintVectorVectorArrayWrapper(vector_vector_array); std::cout << std::endl; // std::cout << std::endl; TTree* tree = new TTree("tree", ""); tree->Branch("vec_arr", &first_vector_array); tree->Branch("vec_vec_arr", &vector_vector_array); std::cout << "Entry #1:" << std::endl; std::cout << "\tvec_arr = "; PrintVectorArrayWrapper(first_vector_array); std::cout << std::endl; std::cout << "\tvec_vec_arr = "; PrintVectorVectorArrayWrapper(vector_vector_array); std::cout << std::endl; tree->Fill(); first_vector_array[0]._values[0] = 5.0; first_vector_array[0]._values[1] = 7.0; vector_vector_array[0][0]._values[0] = 20; vector_vector_array[0][0]._values[1] = 25; vector_vector_array[1][0]._values[0] = 30; vector_vector_array[1][0]._values[1] = 35; std::cout << "Entry #2:" << std::endl; std::cout << "\tvec_arr = "; PrintVectorArrayWrapper(first_vector_array); std::cout << std::endl; std::cout << "\tvec_vec_arr = "; PrintVectorVectorArrayWrapper(vector_vector_array); std::cout << std::endl; tree->Fill(); // tree->Print(); std::cout << std::endl; std::cout << "TTree::Scan of the vec_arr branch works as expected..." << std::endl; std::cout << " printing all values:" << std::endl; tree->Scan("vec_arr._values", "", "colsize=16"); std::cout << std::endl << " printing just first and second value of pair:" << std::endl; tree->Scan("vec_arr._values[][0]:vec_arr._values[][1]", "", "colsize=25"); std::cout << std::endl << " printing the difference between the first and second value of pair:" << std::endl; tree->Scan("vec_arr._values[][0]-vec_arr._values[][1]", "", "colsize=40"); std::cout << std::endl << std::endl << "TTree:Scan of the vec_vec_arr branch *does* works as expected for..." << std::endl; std::cout << " printing all values:" << std::endl; tree->Scan("vec_vec_arr._values[]", "", "colsize=30"); std::cout << std::endl << " and printing each array separately:" << std::endl; tree->Scan("vec_vec_arr._values[0]:vec_vec_arr._values[1]", "", "colsize=30"); std::cout << std::endl << std::endl << "But does *not* work as expected for..." << std::endl; std::cout << std::endl << " printing the first and second elements of each entry (trying a few different ways):" << std::endl; tree->Scan("vec_vec_arr._values[][0]:vec_vec_arr._values[][1]", "", "colsize=30"); tree->Scan("vec_vec_arr._values[][][0]:vec_vec_arr._values[][][1]", "", "colsize=30"); tree->Scan("vec_vec_arr[]._values[][0]:vec_vec_arr[]._values[][1]", "", "colsize=30"); std::cout << std::endl << " or taking the difference between each pair (trying a few different ways):" << std::endl; tree->Scan("vec_vec_arr._values[][0]-vec_vec_arr._values[][1]", "", "colsize=60"); tree->Scan("vec_vec_arr._values[][][0]-vec_vec_arr._values[][][1]", "", "colsize=60"); tree->Scan("vec_vec_arr[]._values[][0]-vec_vec_arr[]._values[][1]", "", "colsize=60"); }