1 |
loizides |
1.4 |
// $Id: Selector.cc,v 1.3 2008/07/01 11:19:31 loizides Exp $
|
2 |
loizides |
1.1 |
|
3 |
|
|
#include "MitAna/TreeMod/interface/Selector.h"
|
4 |
loizides |
1.2 |
#include "MitAna/DataTree/interface/Names.h"
|
5 |
|
|
|
6 |
|
|
#include <TProcessID.h>
|
7 |
|
|
#include <TFile.h>
|
8 |
|
|
#include <TTree.h>
|
9 |
|
|
|
10 |
loizides |
1.1 |
|
11 |
|
|
using namespace mithep;
|
12 |
|
|
|
13 |
|
|
ClassImp(mithep::Selector)
|
14 |
|
|
|
15 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
16 |
loizides |
1.2 |
Selector::Selector() :
|
17 |
|
|
fDoRunInfo(kTRUE),
|
18 |
|
|
fRunTree(0),
|
19 |
|
|
fEventHeader(0),
|
20 |
|
|
fRunInfo(0),
|
21 |
|
|
fLATree(0),
|
22 |
loizides |
1.3 |
fLAHeader(0),
|
23 |
|
|
fCurRunNum(UInt_t(-1))
|
24 |
loizides |
1.1 |
{
|
25 |
|
|
}
|
26 |
|
|
|
27 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
28 |
loizides |
1.1 |
Selector::~Selector()
|
29 |
|
|
{
|
30 |
|
|
}
|
31 |
loizides |
1.2 |
|
32 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
33 |
loizides |
1.2 |
Bool_t Selector::BeginRun()
|
34 |
|
|
{
|
35 |
|
|
// Determines whether we are at beginning of a new run.
|
36 |
|
|
|
37 |
|
|
if (!fDoRunInfo)
|
38 |
|
|
return kFALSE;
|
39 |
|
|
|
40 |
|
|
LoadBranch(Names::gkEvtHeaderBrn);
|
41 |
|
|
if (!fEventHeader)
|
42 |
|
|
return kFALSE;
|
43 |
|
|
|
44 |
|
|
if (ConsistentRunNum())
|
45 |
|
|
return kFALSE;
|
46 |
|
|
|
47 |
|
|
UpdateRunInfo();
|
48 |
|
|
return ValidRunNum();
|
49 |
|
|
}
|
50 |
|
|
|
51 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
52 |
loizides |
1.2 |
Bool_t Selector::EndRun()
|
53 |
|
|
{
|
54 |
|
|
// Determines whether we are at the end of a run.
|
55 |
|
|
|
56 |
|
|
if (!fDoRunInfo)
|
57 |
|
|
return kFALSE;
|
58 |
|
|
|
59 |
|
|
if (!ValidRunNum())
|
60 |
|
|
return kFALSE;
|
61 |
|
|
|
62 |
|
|
// determine if run will end
|
63 |
|
|
if (fCurEvt+1==fTree->GetTree()->GetEntries())
|
64 |
|
|
return kTRUE; // we are at last entry in current file
|
65 |
|
|
|
66 |
|
|
fLAHeader=0;
|
67 |
|
|
Int_t ret = fLATree->GetEvent(fCurEvt);
|
68 |
|
|
if (ret<0 || fLAHeader==0) {
|
69 |
|
|
Error("EndRun", "Could not get entry lookahead entry for next event,"
|
70 |
|
|
" assuming end of run %ld reached!", fCurRunNum);
|
71 |
|
|
return kTRUE;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
return (fLAHeader->RunNum()!=fCurRunNum);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
78 |
loizides |
1.2 |
Bool_t Selector::Notify()
|
79 |
|
|
{
|
80 |
|
|
// The Notify() function is called when a new file is opened. Here, we check for a new run info
|
81 |
|
|
// tree.
|
82 |
|
|
|
83 |
|
|
if (!GetCurrentFile())
|
84 |
|
|
return kTRUE;
|
85 |
|
|
|
86 |
|
|
if (fDoRunInfo)
|
87 |
|
|
UpdateRunInfoTree();
|
88 |
|
|
|
89 |
|
|
return TAMSelector::Notify();
|
90 |
|
|
}
|
91 |
|
|
|
92 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
93 |
loizides |
1.2 |
void Selector::SlaveBegin(TTree* tree)
|
94 |
|
|
{
|
95 |
|
|
// The SlaveBegin() function is called after the Begin() function and can be used to setup
|
96 |
|
|
// analysis on the slaves. Here, we request the event header branch.
|
97 |
|
|
|
98 |
|
|
if (fDoRunInfo) {
|
99 |
|
|
ReqBranch(Names::gkEvtHeaderBrn, fEventHeader);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
TAMSelector::SlaveBegin(tree);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
106 |
loizides |
1.2 |
void Selector::UpdateRunInfo()
|
107 |
|
|
{
|
108 |
|
|
// Update the run info to be consistent with the information from the event header.
|
109 |
|
|
|
110 |
|
|
fRunInfo = 0;
|
111 |
|
|
|
112 |
|
|
if (!fRunTree)
|
113 |
|
|
return;
|
114 |
|
|
|
115 |
|
|
Int_t ret = fRunTree->GetEvent(fEventHeader->RunEntry());
|
116 |
|
|
if (ret<0 || fRunInfo==0) {
|
117 |
|
|
Error("UpdateRunInfo", "Error updating run info for run %ld, entry %ld, return value %d",
|
118 |
|
|
fEventHeader->RunNum(), fEventHeader->RunEntry(), ret);
|
119 |
|
|
return;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
fCurRunNum = fEventHeader->RunNum();
|
123 |
|
|
if (!ValidRunInfo()) {
|
124 |
|
|
Error("UpdateRunInfo", "Error updating run info, run values do not match %d %d",
|
125 |
|
|
fCurRunNum, fRunInfo->RunNum());
|
126 |
|
|
return;
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
131 |
loizides |
1.2 |
void Selector::UpdateRunInfoTree()
|
132 |
|
|
{
|
133 |
|
|
// Get the run info tree from current file and set our branches.
|
134 |
|
|
|
135 |
|
|
// first erase previous entries
|
136 |
|
|
fRunTree = 0;
|
137 |
|
|
fRunInfo = 0;
|
138 |
|
|
fCurRunNum = UInt_t(-1);
|
139 |
|
|
fLATree = 0;
|
140 |
|
|
fLAHeader = 0;
|
141 |
|
|
|
142 |
|
|
// get current file and retrieve trees
|
143 |
|
|
TFile *f = GetCurrentFile();
|
144 |
|
|
if (!f) {
|
145 |
|
|
Error("UpdateRunInfoTree", "Ptr to current file is null");
|
146 |
|
|
return;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
// run info tree
|
150 |
|
|
fRunTree = dynamic_cast<TTree*>(f->Get(Names::gkRunTreeName));
|
151 |
|
|
if (!fRunTree) {
|
152 |
|
|
Fatal("UpdateRunInfoTree", "Can not find run info tree with name %s", Names::gkRunTreeName);
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
// set branches
|
156 |
|
|
if (fRunTree->GetBranch(Names::gkRunInfoBrn)) {
|
157 |
|
|
fRunTree->SetBranchAddress(Names::gkRunInfoBrn, &fRunInfo);
|
158 |
|
|
} else {
|
159 |
|
|
Fatal("UpdateRunInfoTree", "Can not find run info branch with name %s", Names::gkRunInfoBrn);
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
// look-ahead tree
|
163 |
|
|
fLATree = dynamic_cast<TTree*>(f->Get(Names::gkLATreeName));
|
164 |
|
|
if (!fLATree) {
|
165 |
|
|
Fatal("UpdateRunInfoTree", "Can not find look-ahead tree with name %s", Names::gkLATreeName);
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
// set branches
|
169 |
|
|
if (fLATree->GetBranch(Names::gkLAHeaderBrn)) {
|
170 |
|
|
fLATree->SetBranchAddress(Names::gkLAHeaderBrn, &fLAHeader);
|
171 |
|
|
} else {
|
172 |
|
|
Fatal("UpdateRunInfoTree", "Can not find look-ahead branch with name %s", Names::gkLAHeaderBrn);
|
173 |
|
|
}
|
174 |
|
|
}
|