37 LOG(info) <<
"Testing TreeStream creation";
38 std::string outFName(
"testTreeStream.root");
44 std::array<float, o2::track::kNParams> par{};
45 for (
int i = 0;
i < nit;
i++) {
47 float x = 10. + float(
i) / nit * 200.;
49 trc.propagateParamTo(
x, 0.5);
50 tstStream <<
"TrackTree"
51 <<
"id=" <<
i <<
"x=" <<
x <<
"track=" << &trc <<
"\n";
53 tstStream <<
"TrackTreeR"
54 <<
"id=" <<
i <<
"x=" <<
x <<
"track=" << trc <<
"\n";
58 int iArray[6] = {1, 2, 3, 4, 5, 6};
59 float fArray[6] = {1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f};
60 for (
int i{0};
i < nit; ++
i) {
61 for (
int j{0};
j < 6; ++
j) {
63 fArray[
j] += (float)
i;
65 tstStream <<
"ArrayTree"
67 <<
"iArray[6]=" << iArray
68 <<
"fArray[6]=" << fArray
76 LOG(info) <<
"Testing reading back tree made by the TreeStream ";
79 TFile inpf(outFName.data());
81 auto tree = (TTree*)inpf.GetObjectChecked(
"TrackTree",
"TTree");
83 int nent =
tree->GetEntries();
92 for (
int i = 0;
i < nent;
i++) {
95 LOG(info) <<
"id: " <<
id <<
" X: " <<
x <<
" Track> ";
101 tree = (TTree*)inpf.GetObjectChecked(
"ArrayTree",
"TTree");
103 nent =
tree->GetEntries();
110 for (
int i = 0;
i < nit;
i++) {
113 for (
int j = 0;
j < 6;
j++) {
116 for (
int j = 0;
j < 6;
j++) {
117 BOOST_CHECK_CLOSE(fArray[
j], (1.f +
j +
i * (
i + 1) / 2.f + 0.1 * (
j + 1)), 1e-5);
122 LOG(info) <<
"Testing loading tree via RootChain";
130 TFile inpf(outFName.data(),
"update");
132 for (
int i = 0;
i < nit;
i++) {
133 TNamed nm(Form(
"obj%d",
i),
"");
134 strm <<
"idx=" <<
i <<
"named=" << &nm <<
"\n";
140 LOG(info) <<
"Doing UnitTestSparse";
161 std::string outFName(
"testTreeStreamSparse.root");
169 for (Int_t ientry = 0; ientry < testEntries; ientry++) {
170 TVectorD vecRandom(200);
171 TVectorD vecZerro(200);
172 for (Int_t
j = 0;
j < 200;
j++) {
173 vecRandom[
j] =
j + ientry + 0.1 * gRandom->Rndm();
175 Bool_t isSelected = (gRandom->Rndm() < scale);
176 TVectorD* pvecFull = &vecRandom;
177 TVectorD* pvecSparse = isSelected ? &vecRandom :
nullptr;
178 TVectorD* pvecSparse0 = isSelected ? &vecRandom :
nullptr;
179 TVectorD* pvecSparse1 = isSelected ? &vecRandom : &vecZerro;
182 pvecSparse0 =
nullptr;
183 pvecSparse = &vecRandom;
185 (*pcstream) <<
"Full" <<
186 "ientry=" << ientry <<
"vec.=" << pvecFull <<
"\n";
187 (*pcstream) <<
"SparseSkip" <<
188 "ientry=" << ientry <<
"vec.=" << pvecSparse <<
"\n";
189 (*pcstream) <<
"SparseSkip0" <<
190 "ientry=" << ientry <<
"vec.=" << pvecSparse0 <<
"\n";
191 (*pcstream) <<
"SparseZerro" <<
192 "ientry=" << ientry <<
"vec.=" << pvecSparse1 <<
"\n";
199 TFile*
f = TFile::Open(outFName.data());
201 printf(
"Failed to open file: %s\n", outFName.data());
204 TTree* treeFull = (TTree*)
f->Get(
"Full");
205 TTree* treeSparseSkip = (TTree*)
f->Get(
"SparseSkip");
206 TTree* treeSparseSkip0 = (TTree*)
f->Get(
"SparseSkip0");
207 TTree* treeSparseZerro = (TTree*)
f->Get(
"SparseZerro");
210 Double_t ratio = (1. / scale) * treeSparseSkip->GetZipBytes() / Double_t(treeFull->GetZipBytes());
211 Double_t ratio0 = (1. / scale) * treeSparseSkip0->GetZipBytes() / Double_t(treeFull->GetZipBytes());
212 Double_t ratio1 = (1. / scale) * treeSparseZerro->GetZipBytes() / Double_t(treeFull->GetZipBytes());
213 printf(
"#UnitTest:\tTestSparse(%f)\tRatioSkip\t%f\n", scale, ratio);
214 printf(
"#UnitTest:\tTestSparse(%f)\tRatioSkip0\t%f\n", scale, ratio0);
215 printf(
"#UnitTest:\tTestSparse(%f)\tRatioZerro\t%f\n", scale, ratio1);
217 Int_t outlyersSparseSkip = treeSparseSkip->Draw(
"1",
"(vec.fElements-ientry-Iteration$-0.5)>0.5",
"goff");
218 Int_t outlyersSparseSkip0 = treeSparseSkip0->Draw(
"1",
"(vec.fElements-ientry-Iteration$-0.5)>0.5",
"goff");
219 printf(
"#UnitTest:\tTestSparse(%f)\tOutlyersSkip\t%d\n", scale, outlyersSparseSkip != 0);
220 printf(
"#UnitTest:\tTestSparse(%f)\tOutlyersSkip0\t%d\n", scale, outlyersSparseSkip0 != 0);
223 Int_t entries = treeFull->GetEntries();
224 Int_t entries0 = treeSparseSkip0->GetEntries();
225 Bool_t isOKStat = (entries == entries0);
226 printf(
"#UnitTest:\tTestSparse(%f)\tEntries\t%d\n", scale, isOKStat);
229 TVectorD* pvecRead =
nullptr;
230 treeSparseSkip0->SetBranchAddress(
"vec.", &pvecRead);
231 Bool_t readOK = kTRUE;
232 for (Int_t ientry = 0; ientry < testEntries; ientry++) {
236 if (pvecRead->GetNrows() == 0) {
239 if (TMath::Abs((*pvecRead)[0] - ientry) > 0.5) {
243 printf(
"#UnitTest:\tTestSparse(%f)\tReadOK\t%d\n", scale, readOK);
246 Bool_t isOK = (outlyersSparseSkip0 == 0) && isOKStat && readOK;
247 printf(
"#UnitTest:\tTestSparse(%f)\tisOk\t%d\n", scale, isOK);