1 |
|
---|
2 | /** \class ExRootAnalysis
|
---|
3 | *
|
---|
4 | * Analysis steering class.
|
---|
5 | * Implements events loop and modules management.
|
---|
6 | *
|
---|
7 | * $Date: 2008-06-04 13:57:53 $
|
---|
8 | * $Revision: 1.1 $
|
---|
9 | *
|
---|
10 | *
|
---|
11 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
12 | *
|
---|
13 | */
|
---|
14 |
|
---|
15 | #include "ExRootAnalysis/ExRootAnalysis.h"
|
---|
16 | #include "ExRootAnalysis/ExRootFactory.h"
|
---|
17 |
|
---|
18 | #include "ExRootAnalysis/ExRootConfReader.h"
|
---|
19 | #include "ExRootAnalysis/ExRootTreeReader.h"
|
---|
20 | #include "ExRootAnalysis/ExRootTreeWriter.h"
|
---|
21 |
|
---|
22 | #include "ExRootAnalysis/ExRootUtilities.h"
|
---|
23 | #include "ExRootAnalysis/ExRootProgressBar.h"
|
---|
24 |
|
---|
25 | #include "TROOT.h"
|
---|
26 | #include "TClass.h"
|
---|
27 | #include "TSystem.h"
|
---|
28 | #include "TFolder.h"
|
---|
29 | #include "TObjArray.h"
|
---|
30 |
|
---|
31 | #include <iostream>
|
---|
32 |
|
---|
33 | #include <string.h>
|
---|
34 | #include <stdio.h>
|
---|
35 |
|
---|
36 | using namespace std;
|
---|
37 |
|
---|
38 | ExRootAnalysis::ExRootAnalysis() :
|
---|
39 | fTreeFile(0), fInfoFile(0), fAllEntries(0)
|
---|
40 | {
|
---|
41 | TFolder *folder = new TFolder("", "");
|
---|
42 | SetFolder(folder);
|
---|
43 |
|
---|
44 | fChains = new TObjArray;
|
---|
45 | fChains->SetOwner();
|
---|
46 |
|
---|
47 | ExRootConfReader *confReader = new ExRootConfReader;
|
---|
48 | SetConfReader(confReader);
|
---|
49 |
|
---|
50 | fTreeReader = new ExRootTreeReader();
|
---|
51 |
|
---|
52 | fTreeWriter = new ExRootTreeWriter();
|
---|
53 |
|
---|
54 | fFactory = new ExRootFactory();
|
---|
55 |
|
---|
56 | }
|
---|
57 |
|
---|
58 | //------------------------------------------------------------------------------
|
---|
59 |
|
---|
60 | ExRootAnalysis::~ExRootAnalysis()
|
---|
61 | {
|
---|
62 | delete fFactory;
|
---|
63 | delete fTreeWriter;
|
---|
64 | delete fTreeReader;
|
---|
65 | delete GetConfReader();
|
---|
66 | delete fChains;
|
---|
67 | delete GetFolder();
|
---|
68 | }
|
---|
69 |
|
---|
70 | //------------------------------------------------------------------------------
|
---|
71 |
|
---|
72 | Long64_t ExRootAnalysis::GetEntries() const
|
---|
73 | {
|
---|
74 | return fTreeReader ? fTreeReader->GetEntries() : 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | //------------------------------------------------------------------------------
|
---|
78 |
|
---|
79 | Bool_t ExRootAnalysis::ReadEvent(Long64_t entry)
|
---|
80 | {
|
---|
81 | return fTreeReader ? fTreeReader->ReadEntry(entry) : kFALSE;
|
---|
82 | }
|
---|
83 |
|
---|
84 | //------------------------------------------------------------------------------
|
---|
85 |
|
---|
86 | void ExRootAnalysis::ProcessTask()
|
---|
87 | {
|
---|
88 | Clear();
|
---|
89 | ExRootTask::ProcessTask();
|
---|
90 | if(fTreeWriter) fTreeWriter->Fill();
|
---|
91 | }
|
---|
92 |
|
---|
93 | //------------------------------------------------------------------------------
|
---|
94 |
|
---|
95 | void ExRootAnalysis::Loop()
|
---|
96 | {
|
---|
97 | Long64_t entry;
|
---|
98 |
|
---|
99 | if(fAllEntries > 0)
|
---|
100 | {
|
---|
101 | ExRootProgressBar progressBar(fAllEntries);
|
---|
102 | // Loop over all events
|
---|
103 | for(entry = 0; entry < fAllEntries; ++entry)
|
---|
104 | // for(entry = 541; entry < 542; ++entry)
|
---|
105 | {
|
---|
106 | if(!ReadEvent(entry))
|
---|
107 | {
|
---|
108 | cout << "** ERROR: cannot read event " << entry << endl;
|
---|
109 | break;
|
---|
110 | }
|
---|
111 |
|
---|
112 | ProcessTask();
|
---|
113 |
|
---|
114 | progressBar.Update(entry);
|
---|
115 | }
|
---|
116 | progressBar.Finish();
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | //------------------------------------------------------------------------------
|
---|
121 |
|
---|
122 | void ExRootAnalysis::Init()
|
---|
123 | {
|
---|
124 | ExRootConfReader *confReader = GetConfReader();
|
---|
125 |
|
---|
126 | confReader->ReadFile(fTclFileName);
|
---|
127 |
|
---|
128 | TString name = confReader->GetString("::AppName", "ExRootAnalysis");
|
---|
129 |
|
---|
130 | TFolder *folder = GetFolder();
|
---|
131 | folder->SetName(name);
|
---|
132 | gROOT->GetListOfBrowsables()->Add(folder);
|
---|
133 |
|
---|
134 | SetName(name);
|
---|
135 | folder->Add(this);
|
---|
136 |
|
---|
137 | confReader->SetName("ConfReader");
|
---|
138 | folder->Add(confReader);
|
---|
139 |
|
---|
140 | ExRootConfParam param = confReader->GetParam("::InputCollection");
|
---|
141 | Long_t i, size;
|
---|
142 | TChain *chain = 0, *firstChain = 0;
|
---|
143 | size = param.GetSize();
|
---|
144 | if(size > 0)
|
---|
145 | {
|
---|
146 | for(i = 0; i < size; ++i)
|
---|
147 | {
|
---|
148 | chain = new TChain("", "");
|
---|
149 | fChains->Add(chain);
|
---|
150 | name = param[i][0].GetString();
|
---|
151 | chain->SetName(name);
|
---|
152 | FillChain(chain, param[i][1].GetString());
|
---|
153 | if(i == 0)
|
---|
154 | {
|
---|
155 | firstChain = chain;
|
---|
156 | }
|
---|
157 | else
|
---|
158 | {
|
---|
159 | firstChain->AddFriend(chain, name + i);
|
---|
160 | }
|
---|
161 | }
|
---|
162 | fTreeReader->SetTree(firstChain);
|
---|
163 | }
|
---|
164 | fTreeReader->SetName("TreeReader");
|
---|
165 | folder->Add(fTreeReader);
|
---|
166 |
|
---|
167 | cout << "** Calculating number of events to process. Please wait..." << endl;
|
---|
168 | fAllEntries = GetEntries();
|
---|
169 | cout << "** Chain contains " << fAllEntries << " events" << endl;
|
---|
170 |
|
---|
171 | if(fAllEntries <= 0)
|
---|
172 | {
|
---|
173 | cout << "** ERROR: cannot read any event for analysis" << endl;
|
---|
174 | return;
|
---|
175 | }
|
---|
176 |
|
---|
177 | name = confReader->GetString("::OutputFile", "Analysis");
|
---|
178 | name.ReplaceAll(".root", "");
|
---|
179 | fTreeFile = TFile::Open(name + "Tree.root", "RECREATE");
|
---|
180 | if(!fTreeFile)
|
---|
181 | {
|
---|
182 | cout << "** ERROR: cannot create output tree file" << endl;
|
---|
183 | return;
|
---|
184 | }
|
---|
185 |
|
---|
186 | fInfoFile = TFile::Open(name + "Info.root", "RECREATE");
|
---|
187 | if(!fInfoFile)
|
---|
188 | {
|
---|
189 | cout << "** ERROR: cannot create output info file" << endl;
|
---|
190 | return;
|
---|
191 | }
|
---|
192 |
|
---|
193 | name = confReader->GetString("::TreeName", "Analysis");
|
---|
194 |
|
---|
195 | fTreeWriter->SetTreeFile(fTreeFile);
|
---|
196 | fTreeWriter->SetTreeName(name);
|
---|
197 | fTreeWriter->SetName("TreeWriter");
|
---|
198 | folder->Add(fTreeWriter);
|
---|
199 |
|
---|
200 | fFactory->SetName("ObjectFactory");
|
---|
201 | folder->Add(fFactory);
|
---|
202 |
|
---|
203 | ExRootTask *task;
|
---|
204 | const ExRootConfReader::ExRootTaskMap *modules = confReader->GetModules();
|
---|
205 | ExRootConfReader::ExRootTaskMap::const_iterator itModules;
|
---|
206 |
|
---|
207 | param = confReader->GetParam("::ExecutionPath");
|
---|
208 | size = param.GetSize();
|
---|
209 |
|
---|
210 | for(i = 0; i < size; ++i)
|
---|
211 | {
|
---|
212 | name = param[i].GetString();
|
---|
213 | itModules = modules->find(name);
|
---|
214 | if(itModules != modules->end())
|
---|
215 | {
|
---|
216 | cout << itModules->second << " \t " << itModules->first << endl;
|
---|
217 | task = NewTask(itModules->second, itModules->first);
|
---|
218 | if(task)
|
---|
219 | {
|
---|
220 | task->SetFolder(GetFolder());
|
---|
221 | Add(task);
|
---|
222 | }
|
---|
223 | }
|
---|
224 | else
|
---|
225 | {
|
---|
226 | cout << "** ERROR: module '" << name;
|
---|
227 | cout << "' is specified in ExecutionPath but not configured.";
|
---|
228 | return;
|
---|
229 | }
|
---|
230 |
|
---|
231 | }
|
---|
232 |
|
---|
233 | }
|
---|
234 |
|
---|
235 | //------------------------------------------------------------------------------
|
---|
236 |
|
---|
237 | void ExRootAnalysis::Process()
|
---|
238 | {
|
---|
239 | }
|
---|
240 |
|
---|
241 | //------------------------------------------------------------------------------
|
---|
242 |
|
---|
243 | void ExRootAnalysis::Finish()
|
---|
244 | {
|
---|
245 | if(fTreeWriter) fTreeWriter->Write();
|
---|
246 | }
|
---|
247 |
|
---|
248 | //------------------------------------------------------------------------------
|
---|
249 |
|
---|
250 | void ExRootAnalysis::Clear()
|
---|
251 | {
|
---|
252 | if(fTreeWriter) fTreeWriter->Clear();
|
---|
253 | if(fFactory) fFactory->Clear();
|
---|
254 | }
|
---|
255 |
|
---|
256 | //------------------------------------------------------------------------------
|
---|
257 |
|
---|