forked from avartak/TkCommissioner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeViewerRunInfo.cpp
163 lines (136 loc) · 4.82 KB
/
TreeViewerRunInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "TreeViewerRunInfo.h"
#include <TFile.h>
#include <TTree.h>
#include <iostream>
TreeViewerRunInfo::~TreeViewerRunInfo() {
if (tmpFile) {
if (tmpFile->IsOpen()) tmpFile->Close();
delete tmpFile;
}
if (eventList) delete eventList;
}
TreeViewerRunInfo::TreeViewerRunInfo(const QString& tmpFileName_):
currentFileName(""),
referenceFileName(""),
currentTreePath(""),
referenceTreePath(""),
tmpFileName(tmpFileName_),
currentFile(NULL),
referenceFile(NULL),
currentTree(NULL),
referenceTree(NULL)
{
if (tmpFileName_ != "") tmpFile = new TFile(qPrintable(tmpFileName), "RECREATE");
eventList = new TEventList("eventList", "eventList");
}
QString TreeViewerRunInfo::getCurrentRunNumber() const {
return currentRun;
}
QString TreeViewerRunInfo::getReferenceRunNumber() const {
return referenceRun;
}
QString TreeViewerRunInfo::getCurrentPartition() const {
return currentPartition;
}
QString TreeViewerRunInfo::getReferencePartition() const {
return referencePartition;
}
QString TreeViewerRunInfo::getCurrentFileName() const {
return currentFileName;
}
QString TreeViewerRunInfo::getReferenceFileName() const {
return referenceFileName;
}
QString TreeViewerRunInfo::getCurrentTreePath() const {
return currentTreePath;
}
QString TreeViewerRunInfo::getReferenceTreePath() const {
return referenceTreePath;
}
QString TreeViewerRunInfo::getTmpFileName() const {
return tmpFileName;
}
TTree* TreeViewerRunInfo::getCurrentTree() {
return currentTree;
}
TTree* TreeViewerRunInfo::getReferenceTree() {
return referenceTree;
}
TEventList* TreeViewerRunInfo::getEventList() {
return eventList;
}
void TreeViewerRunInfo::closeTree(bool save) {
if (currentFile == NULL || tmpFile == NULL) return;
if (save) {
tmpFile->cd();
if (referenceTree) referenceTree->Write();
if (currentTree) currentTree->Write();
tmpFile->Close();
}
else {
tmpFile->cd();
if (referenceTree) {
referenceTree->Delete();
currentTree->RemoveFriend(referenceTree);
}
if (currentTree) currentTree->Delete();
tmpFile->Close();
}
}
void TreeViewerRunInfo::buildTreeInfo(QPair<QString, QString> runid_, QPair<QString, QString> treePath_, bool isCurrent) {
if (!tmpFile || !tmpFile->IsOpen()) return;
if (isCurrent) {
currentRun = runid_.second;
currentPartition = runid_.first;
currentFileName = treePath_.first;
currentTreePath = treePath_.second;
currentFile = new TFile(qPrintable(currentFileName));
TTree* inputCurrentTree = (TTree*)currentFile->Get(qPrintable(currentTreePath));
if (inputCurrentTree) {
tmpFile->cd();
if (currentTree) {
if (referenceTree) currentTree->RemoveFriend(referenceTree);
currentTree->Delete();
}
currentTree = inputCurrentTree->CloneTree();
currentTree->SetName("currentTree");
inputCurrentTree->Delete();
currentFile->Close();
if (referenceTree) currentTree->AddFriend(referenceTree, "ref");
}
}
else {
referenceRun = runid_.second;
referencePartition = runid_.first;
referenceFileName = treePath_.first;
referenceTreePath = treePath_.second;
referenceFile = new TFile(qPrintable(referenceFileName));
TTree* inputReferenceTree = (TTree*)referenceFile->Get(qPrintable(referenceTreePath));
if (inputReferenceTree) {
tmpFile->cd();
if (referenceTree) {
if (currentTree) currentTree->RemoveFriend(referenceTree);
referenceTree->Delete();
}
referenceTree = inputReferenceTree->CloneTree();
referenceTree->SetName("referenceTree");
inputReferenceTree->Delete();
referenceFile->Close();
if (currentTree) currentTree->AddFriend(referenceTree, "ref");
}
}
}
void TreeViewerRunInfo::useEventList(bool flag) {
if (flag) currentTree->SetEventList(eventList);
else currentTree->SetEventList(NULL);
}
bool TreeViewerRunInfo::isRefTreeTypeSame() {
if (currentTree == NULL || referenceTree == NULL) return false;
if (currentTree->GetListOfBranches()->GetEntries() != referenceTree->GetListOfBranches()->GetEntries()) return false;
TObjArray* currentBranchList = currentTree->GetListOfBranches();
TObjArray* referenceBranchList = referenceTree->GetListOfBranches();
for(Int_t i = 0; i < currentBranchList->GetEntries(); ++i ) {
if (QString((static_cast<TBranch*>(currentBranchList->At(i))->GetName())) != QString((static_cast<TBranch*>(referenceBranchList->At(i))->GetName()))) return false;
}
return true;
}