ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/Selector.cc
Revision: 1.8
Committed: Thu Dec 4 14:13:44 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.7: +1 -2 lines
Log Message:
Remove debug printout.

File Contents

# User Rev Content
1 loizides 1.8 // $Id: Selector.cc,v 1.7 2008/12/04 13:50:15 loizides Exp $
2 loizides 1.1
3     #include "MitAna/TreeMod/interface/Selector.h"
4 loizides 1.2 #include "MitAna/DataTree/interface/Names.h"
5 loizides 1.6 #include "MitAna/TreeMod/interface/OutputMod.h"
6 loizides 1.2 #include <TProcessID.h>
7     #include <TFile.h>
8     #include <TTree.h>
9    
10 loizides 1.1 using namespace mithep;
11    
12     ClassImp(mithep::Selector)
13    
14 loizides 1.4 //--------------------------------------------------------------------------------------------------
15 loizides 1.2 Selector::Selector() :
16     fDoRunInfo(kTRUE),
17 loizides 1.5 fEvtHdrName(Names::gkEvtHeaderBrn),
18     fRunTreeName(Names::gkRunTreeName),
19     fRunInfoName(Names::gkRunInfoBrn),
20 loizides 1.6 fAllEvtHdrBrn(Names::gkAllEvtHeaderBrn),
21 loizides 1.5 fLATreeName(Names::gkLATreeName),
22     fLAHdrName(Names::gkLAHeaderBrn),
23 loizides 1.6 fAllEvtTreeName(Names::gkAllEvtTreeName),
24 loizides 1.2 fRunTree(0),
25     fEventHeader(0),
26     fRunInfo(0),
27     fLATree(0),
28 loizides 1.3 fLAHeader(0),
29     fCurRunNum(UInt_t(-1))
30 loizides 1.1 {
31 loizides 1.5 // Constructor.
32 loizides 1.7
33     fOutputMods.SetOwner(kFALSE);
34 loizides 1.1 }
35    
36 loizides 1.4 //--------------------------------------------------------------------------------------------------
37 loizides 1.1 Selector::~Selector()
38     {
39 loizides 1.5 // Destructor.
40    
41     fRunTree = 0;
42     fEventHeader = 0;
43     fRunInfo = 0;
44     fLATree = 0;
45     fLAHeader = 0;
46     fCurRunNum = UInt_t(-1);
47 loizides 1.1 }
48 loizides 1.2
49 loizides 1.4 //--------------------------------------------------------------------------------------------------
50 loizides 1.2 Bool_t Selector::BeginRun()
51     {
52     // Determines whether we are at beginning of a new run.
53    
54     if (!fDoRunInfo)
55     return kFALSE;
56    
57 loizides 1.5 LoadBranch(fEvtHdrName);
58 loizides 1.2 if (!fEventHeader)
59     return kFALSE;
60    
61     if (ConsistentRunNum())
62     return kFALSE;
63    
64     UpdateRunInfo();
65     return ValidRunNum();
66     }
67    
68 loizides 1.4 //--------------------------------------------------------------------------------------------------
69 loizides 1.2 Bool_t Selector::EndRun()
70     {
71 loizides 1.6 // Determines whether we are at the end of a run. Also, do treat special case of output module
72 loizides 1.7 // here so that in any case it can process the event.
73    
74     if (IsAModAborted() || IsEventAborted()) { // deal with output module if needed: Do this here,
75     TIter it(fOutputMods.MakeIterator()); // avoids having to copy/rewrite large parts of
76     OutputMod *o = 0; // TAMSelector::Process and interaction with TAModule
77     while ((o=static_cast<OutputMod*>(it.Next())) != 0)
78     o->ProcessAll();
79     }
80 loizides 1.2
81     if (!fDoRunInfo)
82     return kFALSE;
83    
84     if (!ValidRunNum())
85     return kFALSE;
86    
87     // determine if run will end
88     if (fCurEvt+1==fTree->GetTree()->GetEntries())
89     return kTRUE; // we are at last entry in current file
90    
91     fLAHeader=0;
92     Int_t ret = fLATree->GetEvent(fCurEvt);
93     if (ret<0 || fLAHeader==0) {
94     Error("EndRun", "Could not get entry lookahead entry for next event,"
95     " assuming end of run %ld reached!", fCurRunNum);
96     return kTRUE;
97     }
98    
99     return (fLAHeader->RunNum()!=fCurRunNum);
100     }
101    
102 loizides 1.4 //--------------------------------------------------------------------------------------------------
103 loizides 1.2 Bool_t Selector::Notify()
104     {
105 loizides 1.5 // The Notify() function is called when a new file is opened.
106     // Here, we check for a new run info tree.
107 loizides 1.2
108     if (!GetCurrentFile())
109     return kTRUE;
110    
111     if (fDoRunInfo)
112     UpdateRunInfoTree();
113    
114     return TAMSelector::Notify();
115     }
116    
117 loizides 1.4 //--------------------------------------------------------------------------------------------------
118 loizides 1.7 void Selector::SearchOutputMods(const TAModule *mod)
119     {
120     // Search for output module among list of modules.
121    
122     if (!mod)
123     return;
124    
125     const OutputMod *o = dynamic_cast<const OutputMod*>(mod);
126     if (o)
127     fOutputMods.Add(const_cast<OutputMod*>(o));
128    
129     const TList *tasks = mod->GetSubModules();
130     if (!tasks)
131     return;
132    
133     TIter it(tasks->MakeIterator());
134     TObject *ob = 0;
135     while ((ob=it.Next()) != 0) {
136     TAModule *nmod = dynamic_cast<TAModule*>(ob);
137     if (nmod)
138     SearchOutputMods(nmod);
139     }
140     }
141    
142     //--------------------------------------------------------------------------------------------------
143 loizides 1.6 void Selector::SlaveBegin(TTree *tree)
144 loizides 1.2 {
145     // The SlaveBegin() function is called after the Begin() function and can be used to setup
146     // analysis on the slaves. Here, we request the event header branch.
147    
148     if (fDoRunInfo) {
149 loizides 1.7 ReqBranch(fEvtHdrName, fEventHeader);
150 loizides 1.2 }
151    
152 loizides 1.7 SearchOutputMods(GetTopModule());
153    
154 loizides 1.2 TAMSelector::SlaveBegin(tree);
155     }
156    
157 loizides 1.4 //--------------------------------------------------------------------------------------------------
158 loizides 1.2 void Selector::UpdateRunInfo()
159     {
160     // Update the run info to be consistent with the information from the event header.
161    
162     fRunInfo = 0;
163    
164     if (!fRunTree)
165     return;
166    
167     Int_t ret = fRunTree->GetEvent(fEventHeader->RunEntry());
168     if (ret<0 || fRunInfo==0) {
169     Error("UpdateRunInfo", "Error updating run info for run %ld, entry %ld, return value %d",
170     fEventHeader->RunNum(), fEventHeader->RunEntry(), ret);
171     return;
172     }
173    
174     fCurRunNum = fEventHeader->RunNum();
175     if (!ValidRunInfo()) {
176     Error("UpdateRunInfo", "Error updating run info, run values do not match %d %d",
177     fCurRunNum, fRunInfo->RunNum());
178     return;
179     }
180     }
181    
182 loizides 1.4 //--------------------------------------------------------------------------------------------------
183 loizides 1.2 void Selector::UpdateRunInfoTree()
184     {
185     // Get the run info tree from current file and set our branches.
186    
187     // first erase previous entries
188     fRunTree = 0;
189     fRunInfo = 0;
190     fCurRunNum = UInt_t(-1);
191     fLATree = 0;
192     fLAHeader = 0;
193    
194     // get current file and retrieve trees
195     TFile *f = GetCurrentFile();
196     if (!f) {
197     Error("UpdateRunInfoTree", "Ptr to current file is null");
198     return;
199     }
200    
201     // run info tree
202 loizides 1.5 fRunTree = dynamic_cast<TTree*>(f->Get(fRunTreeName));
203 loizides 1.2 if (!fRunTree) {
204 loizides 1.5 Fatal("UpdateRunInfoTree", "Can not find run info tree with name %s", fRunTreeName.Data());
205 loizides 1.2 }
206    
207     // set branches
208 loizides 1.5 if (fRunTree->GetBranch(fRunInfoName)) {
209     fRunTree->SetBranchAddress(fRunInfoName, &fRunInfo);
210 loizides 1.2 } else {
211 loizides 1.5 Fatal("UpdateRunInfoTree", "Can not find run info branch with name %s", fRunInfoName.Data());
212 loizides 1.2 }
213    
214     // look-ahead tree
215 loizides 1.5 fLATree = dynamic_cast<TTree*>(f->Get(fLATreeName));
216 loizides 1.2 if (!fLATree) {
217 loizides 1.5 Fatal("UpdateRunInfoTree", "Can not find look-ahead tree with name %s", fLATreeName.Data());
218 loizides 1.2 }
219    
220     // set branches
221 loizides 1.5 if (fLATree->GetBranch(fLAHdrName)) {
222     fLATree->SetBranchAddress(fLAHdrName, &fLAHeader);
223 loizides 1.2 } else {
224 loizides 1.5 Fatal("UpdateRunInfoTree", "Can not find look-ahead branch with name %s", fLAHdrName.Data());
225 loizides 1.2 }
226     }