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";
60 LOG(info) <<
"Testing reading back tree maid by the TreeStream ";
63 TFile inpf(outFName.data());
65 auto tree = (TTree*)inpf.GetObjectChecked(
"TrackTree",
"TTree");
67 int nent =
tree->GetEntries();
76 for (
int i = 0;
i < nent;
i++) {
79 LOG(info) <<
"id: " <<
id <<
" X: " <<
x <<
" Track> ";
85 LOG(info) <<
"Testing loading tree via RootChain";
93 TFile inpf(outFName.data(),
"update");
95 for (
int i = 0;
i < nit;
i++) {
96 TNamed nm(Form(
"obj%d",
i),
"");
97 strm <<
"idx=" <<
i <<
"named=" << &nm <<
"\n";
103 LOG(info) <<
"Doing UnitTestSparse";
125 std::string outFName(
"testTreeStreamSparse.root");
133 for (Int_t ientry = 0; ientry < testEntries; ientry++) {
134 TVectorD vecRandom(200);
135 TVectorD vecZerro(200);
136 for (Int_t
j = 0;
j < 200;
j++) {
137 vecRandom[
j] =
j + ientry + 0.1 * gRandom->Rndm();
139 Bool_t isSelected = (gRandom->Rndm() < scale);
140 TVectorD* pvecFull = &vecRandom;
141 TVectorD* pvecSparse = isSelected ? &vecRandom :
nullptr;
142 TVectorD* pvecSparse0 = isSelected ? &vecRandom :
nullptr;
143 TVectorD* pvecSparse1 = isSelected ? &vecRandom : &vecZerro;
146 pvecSparse0 =
nullptr;
147 pvecSparse = &vecRandom;
149 (*pcstream) <<
"Full" <<
150 "ientry=" << ientry <<
"vec.=" << pvecFull <<
"\n";
151 (*pcstream) <<
"SparseSkip" <<
152 "ientry=" << ientry <<
"vec.=" << pvecSparse <<
"\n";
153 (*pcstream) <<
"SparseSkip0" <<
154 "ientry=" << ientry <<
"vec.=" << pvecSparse0 <<
"\n";
155 (*pcstream) <<
"SparseZerro" <<
156 "ientry=" << ientry <<
"vec.=" << pvecSparse1 <<
"\n";
163 TFile*
f = TFile::Open(outFName.data());
165 printf(
"Failed to open file: %s\n", outFName.data());
168 TTree* treeFull = (TTree*)
f->Get(
"Full");
169 TTree* treeSparseSkip = (TTree*)
f->Get(
"SparseSkip");
170 TTree* treeSparseSkip0 = (TTree*)
f->Get(
"SparseSkip0");
171 TTree* treeSparseZerro = (TTree*)
f->Get(
"SparseZerro");
174 Double_t ratio = (1. / scale) * treeSparseSkip->GetZipBytes() / Double_t(treeFull->GetZipBytes());
175 Double_t ratio0 = (1. / scale) * treeSparseSkip0->GetZipBytes() / Double_t(treeFull->GetZipBytes());
176 Double_t ratio1 = (1. / scale) * treeSparseZerro->GetZipBytes() / Double_t(treeFull->GetZipBytes());
177 printf(
"#UnitTest:\tTestSparse(%f)\tRatioSkip\t%f\n", scale, ratio);
178 printf(
"#UnitTest:\tTestSparse(%f)\tRatioSkip0\t%f\n", scale, ratio0);
179 printf(
"#UnitTest:\tTestSparse(%f)\tRatioZerro\t%f\n", scale, ratio1);
181 Int_t outlyersSparseSkip = treeSparseSkip->Draw(
"1",
"(vec.fElements-ientry-Iteration$-0.5)>0.5",
"goff");
182 Int_t outlyersSparseSkip0 = treeSparseSkip0->Draw(
"1",
"(vec.fElements-ientry-Iteration$-0.5)>0.5",
"goff");
183 printf(
"#UnitTest:\tTestSparse(%f)\tOutlyersSkip\t%d\n", scale, outlyersSparseSkip != 0);
184 printf(
"#UnitTest:\tTestSparse(%f)\tOutlyersSkip0\t%d\n", scale, outlyersSparseSkip0 != 0);
187 Int_t entries = treeFull->GetEntries();
188 Int_t entries0 = treeSparseSkip0->GetEntries();
189 Bool_t isOKStat = (entries == entries0);
190 printf(
"#UnitTest:\tTestSparse(%f)\tEntries\t%d\n", scale, isOKStat);
193 TVectorD* pvecRead =
nullptr;
194 treeSparseSkip0->SetBranchAddress(
"vec.", &pvecRead);
195 Bool_t readOK = kTRUE;
196 for (Int_t ientry = 0; ientry < testEntries; ientry++) {
200 if (pvecRead->GetNrows() == 0) {
203 if (TMath::Abs((*pvecRead)[0] - ientry) > 0.5) {
207 printf(
"#UnitTest:\tTestSparse(%f)\tReadOK\t%d\n", scale, readOK);
210 Bool_t isOK = (outlyersSparseSkip0 == 0) && isOKStat && readOK;
211 printf(
"#UnitTest:\tTestSparse(%f)\tisOk\t%d\n", scale, isOK);