Skip to content

Commit e66e839

Browse files
Use new RAMIndex to find range.
1 parent 772b2a3 commit e66e839

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

ramview_nidx.C

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// View a region of a RAM file.
3+
//
4+
// Author: Jose Javier Gonzalez Ortiz, 5/7/2017
5+
//
6+
7+
#include <iostream>
8+
#include <cstring>
9+
10+
#include <TBranch.h>
11+
#include <TTree.h>
12+
#include <TFile.h>
13+
#include <TStopwatch.h>
14+
#include <TString.h>
15+
#include <TTreeIndex.h>
16+
#include <TTreePerfStats.h>
17+
18+
#include "utils.h"
19+
20+
#include "ramrecord.C"
21+
22+
23+
void ramview_nidx(const char *file, const char *query, bool cache = true, bool perfstats = false,
24+
const char *perfstatsfilename = "perf.root")
25+
{
26+
TStopwatch stopwatch;
27+
stopwatch.Start();
28+
29+
// Open the file and load tree and reader
30+
auto f = TFile::Open(file);
31+
if (!f) {
32+
printf("ramview: failed to open file %s\n", file);
33+
return;
34+
}
35+
auto t = RAMRecord::GetTree(f);
36+
37+
RAMRecord *r = 0;
38+
39+
if (!cache)
40+
t->SetCacheSize(0);
41+
42+
TTreePerfStats *ps = 0;
43+
if (perfstats)
44+
ps = new TTreePerfStats("ioperf", t);
45+
46+
t->SetBranchAddress("RAMRecord.", &r);
47+
48+
TBranch *b = t->GetBranch("RAMRecord.");
49+
50+
// Parse queried region string (rname:pos1-pos2): chr1:5000-6000
51+
std::string region = query;
52+
int chrDelimiterPos = region.find(":");
53+
TString rname = region.substr(0, chrDelimiterPos);
54+
55+
int rangeDelimiterPos = region.find("-");
56+
57+
Int_t range_start = std::stoi(region.substr(chrDelimiterPos + 1, rangeDelimiterPos - chrDelimiterPos));
58+
Int_t range_end = std::stoi(region.substr(rangeDelimiterPos + 1, region.size() - rangeDelimiterPos));
59+
60+
// Convert rname to refid
61+
auto refid = RAMRecord::GetRnameRefs()->GetRefId(rname);
62+
63+
// Find starting row in index
64+
auto start_entry = RAMRecord::GetIndex()->GetRow(refid, range_start);
65+
auto end_entry = RAMRecord::GetIndex()->GetRow(refid, range_end);
66+
67+
printf("ramview: %s:%d = %lld\n", rname.Data(), range_start, start_entry);
68+
69+
if (b->GetSplitLevel() > 0)
70+
t->SetBranchStatus("RAMRecord.*", 0);
71+
72+
if (b->GetSplitLevel() > 0) {
73+
t->SetBranchStatus("RAMRecord.v_refid", 1);
74+
t->SetBranchStatus("RAMRecord.v_pos", 1);
75+
t->SetBranchStatus("RAMRecord.v_lseq", 1);
76+
}
77+
78+
for (; start_entry < end_entry; start_entry++) {
79+
t->GetEntry(start_entry);
80+
if (r->GetPOS() + r->GetSEQLEN() > range_start) {
81+
// First valid position for printing
82+
break;
83+
}
84+
}
85+
86+
if (b->GetSplitLevel() > 0)
87+
t->SetBranchStatus("RAMRecord.*", 1);
88+
89+
Long64_t j;
90+
for (j = start_entry; j <= end_entry; j++) {
91+
t->GetEntry(j);
92+
r->Print();
93+
}
94+
95+
t->GetEntry(j++);
96+
while (r->GetPOS() <= range_end) {
97+
t->GetEntry(j++);
98+
r->Print();
99+
}
100+
101+
stopwatch.Print();
102+
103+
if (perfstats) {
104+
ps->SaveAs(perfstatsfilename);
105+
delete ps;
106+
}
107+
}

0 commit comments

Comments
 (0)