Skip to content

Commit a594553

Browse files
Rename scripts to proper names.
1 parent 7b349dc commit a594553

File tree

3 files changed

+179
-178
lines changed

3 files changed

+179
-178
lines changed

ramview.C

Lines changed: 47 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,109 @@
11
//
22
// View a region of a RAM file.
33
//
4-
// Author: Jose Javier Gonzalez Ortiz, 5/7/2017
4+
// Author: Fons Rademakers, 7/12/2017
55
//
66

77
#include <iostream>
8-
#include <string>
8+
#include <cstring>
99

1010
#include <TBranch.h>
1111
#include <TTree.h>
1212
#include <TFile.h>
1313
#include <TStopwatch.h>
14+
#include <TString.h>
15+
#include <TTreeIndex.h>
1416
#include <TTreePerfStats.h>
1517

18+
#include "utils.h"
19+
1620
#include "ramrecord.C"
1721

1822

19-
void ramview(const char *file, const char *query, bool cache = false, bool perfstats = false,
23+
void ramview(const char *file, const char *query, bool cache = true, bool perfstats = false,
2024
const char *perfstatsfilename = "perf.root")
2125
{
2226
TStopwatch stopwatch;
2327
stopwatch.Start();
2428

2529
// Open the file and load tree and reader
2630
auto f = TFile::Open(file);
31+
if (!f) {
32+
printf("ramview: failed to open file %s\n", file);
33+
return;
34+
}
2735
auto t = RAMRecord::GetTree(f);
2836

2937
RAMRecord *r = 0;
3038

31-
if (!cache) {
39+
if (!cache)
3240
t->SetCacheSize(0);
33-
}
3441

3542
TTreePerfStats *ps = 0;
36-
37-
if (perfstats) {
43+
if (perfstats)
3844
ps = new TTreePerfStats("ioperf", t);
39-
}
4045

4146
t->SetBranchAddress("RAMRecord.", &r);
4247

4348
TBranch *b = t->GetBranch("RAMRecord.");
4449

45-
// Parse queried region string
50+
// Parse queried region string (rname:pos1-pos2): chr1:5000-6000
4651
std::string region = query;
4752
int chrDelimiterPos = region.find(":");
4853
TString rname = region.substr(0, chrDelimiterPos);
4954

5055
int rangeDelimiterPos = region.find("-");
5156

52-
UInt_t rangeStart = std::stoi(region.substr(chrDelimiterPos + 1, rangeDelimiterPos - chrDelimiterPos));
53-
UInt_t rangeEnd = std::stoi(region.substr(rangeDelimiterPos + 1, region.size() - rangeDelimiterPos));
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));
5459

55-
// Default values to ensure correctness
56-
int rnameStart = -1;
57-
int posStart = -1;
60+
// Convert rname to refid
61+
auto refid = RAMRecord::GetRnameRefs()->GetRefId(rname);
5862

59-
// Assume RNAME are chunked together
60-
// We look only at the RNAME column
61-
// We can only do this when there are columns
62-
if (b->GetSplitLevel() > 0) {
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) - %d (%lld)\n", rname.Data(), range_start, start_entry,
68+
range_end, end_entry);
69+
70+
if (b->GetSplitLevel() > 0)
6371
t->SetBranchStatus("RAMRecord.*", 0);
64-
t->SetBranchStatus("RAMRecord.v_rname", 1);
72+
73+
if (b->GetSplitLevel() > 0) {
74+
t->SetBranchStatus("RAMRecord.v_refid", 1);
75+
t->SetBranchStatus("RAMRecord.v_pos", 1);
76+
t->SetBranchStatus("RAMRecord.v_lseq", 1);
6577
}
6678

67-
for (int i = 0; i < t->GetEntries(); i++) {
68-
t->GetEntry(i);
69-
if (rname.EqualTo(r->GetRNAME())) {
70-
rnameStart = i;
79+
for (; start_entry < end_entry; start_entry++) {
80+
t->GetEntry(start_entry);
81+
if (r->GetPOS() + r->GetSEQLEN() > range_start) {
82+
// First valid position for printing
7183
break;
7284
}
7385
}
7486

75-
// If the RNAME was found
76-
if (rnameStart >= 0) {
77-
78-
// We need to look both at the leftmost position (v_pos)
79-
// as well as the length of sequence (v_lseq)
80-
if (b->GetSplitLevel() > 0) {
81-
t->SetBranchStatus("RAMRecord.v_pos", 1);
82-
t->SetBranchStatus("RAMRecord.v_lseq", 1);
83-
}
87+
if (b->GetSplitLevel() > 0)
88+
t->SetBranchStatus("RAMRecord.*", 1);
8489

85-
for (int i = rnameStart; i < t->GetEntries(); i++) {
86-
t->GetEntry(i);
87-
88-
// If the RNAME region ends
89-
if (!rname.EqualTo(r->GetRNAME())) {
90-
break;
91-
} else {
92-
if (r->GetPOS() + r->GetSEQLEN() > rangeStart) {
93-
// Register first valid position for printing
94-
posStart = i;
95-
break;
96-
}
97-
}
98-
}
90+
Long64_t j;
91+
for (j = start_entry; j < end_entry; j++) {
92+
t->GetEntry(j);
93+
// r->Print();
94+
}
9995

100-
// If the position was found
101-
if (posStart >= 0) {
102-
103-
// Enable all fields for printing
104-
if (b->GetSplitLevel() > 0) {
105-
t->SetBranchStatus("RAMRecord.*", 1);
106-
}
107-
for (int i = posStart; i < t->GetEntries(); i++) {
108-
t->GetEntry(i);
109-
110-
// If the RNAME region ends
111-
if (!rname.EqualTo(r->GetRNAME())) {
112-
break;
113-
} else {
114-
// Within the region
115-
if (r->GetPOS() <= rangeEnd) {
116-
r->Print();
117-
} else {
118-
break;
119-
}
120-
}
121-
}
122-
}
96+
t->GetEntry(j);
97+
while (r->GetPOS() < range_end) {
98+
// r->Print();
99+
j++;
100+
t->GetEntry(j);
123101
}
124102

125103
stopwatch.Print();
126104

127105
if (perfstats) {
128106
ps->SaveAs(perfstatsfilename);
129107
delete ps;
130-
printf("Reading %lld bytes in %d transactions\n", f->GetBytesRead(), f->GetReadCalls());
131108
}
132109
}

ramview_nidx.C

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)