source: trunk/src/ExRootModule.cc@ 10

Last change on this file since 10 was 2, checked in by Pavel Demin, 16 years ago

first commit

File size: 4.5 KB
Line 
1
2/** \class ExRootModule
3 *
4 * Base class for analysis modules
5 *
6 * $Date: 2008-06-04 13:57:55 $
7 * $Revision: 1.1 $
8 *
9 *
10 * \author P. Demin - UCL, Louvain-la-Neuve
11 *
12 */
13
14#include "ExRootAnalysis/ExRootTreeReader.h"
15#include "ExRootAnalysis/ExRootTreeBranch.h"
16#include "ExRootAnalysis/ExRootTreeWriter.h"
17#include "ExRootAnalysis/ExRootResult.h"
18
19#include "ExRootAnalysis/ExRootModule.h"
20#include "ExRootAnalysis/ExRootFactory.h"
21
22#include "TROOT.h"
23#include "TClass.h"
24#include "TFolder.h"
25#include "TObjArray.h"
26
27#include <iostream>
28
29using namespace std;
30
31ExRootModule::ExRootModule() :
32 fTreeReader(0), fTreeWriter(0),
33 fFactory(0), fPlots(0),
34 fPlotFolder(0), fExportFolder(0)
35
36{
37}
38
39//------------------------------------------------------------------------------
40
41ExRootModule::~ExRootModule()
42{
43}
44
45//------------------------------------------------------------------------------
46
47void ExRootModule::Init()
48{
49}
50
51//------------------------------------------------------------------------------
52
53void ExRootModule::Process()
54{
55}
56
57//------------------------------------------------------------------------------
58
59void ExRootModule::Finish()
60{
61}
62
63//------------------------------------------------------------------------------
64
65const TObjArray *ExRootModule::ImportArray(const char *name)
66{
67 TObjArray *object;
68
69 object = static_cast<TObjArray *>(GetObject(Form("Export/%s", name), TObjArray::Class()));
70 if(!object)
71 {
72 cout << "** ERROR: cannot access input list '" << name << "'" << endl;
73 return 0;
74 }
75
76 return object;
77}
78
79//------------------------------------------------------------------------------
80
81TObjArray *ExRootModule::ExportArray(const char *name)
82{
83 TObjArray *array;
84 if(!fExportFolder)
85 {
86 fExportFolder = NewFolder("Export");
87 }
88
89 array = GetFactory()->NewPermanentArray();
90
91 array->SetName(name);
92 fExportFolder->Add(array);
93
94 return array;
95}
96
97//------------------------------------------------------------------------------
98
99ExRootTreeBranch *ExRootModule::NewBranch(const char *name, TClass *cl)
100{
101 if(!fTreeWriter)
102 {
103 fTreeWriter = static_cast<ExRootTreeWriter *>(GetObject("TreeWriter", ExRootTreeWriter::Class()));
104 if(!fTreeWriter)
105 {
106 cout << "** ERROR: cannot access tree writer" << endl;
107 return 0;
108 }
109 }
110 return fTreeWriter->NewBranch(name, cl);
111}
112
113//------------------------------------------------------------------------------
114
115TClonesArray *ExRootModule::UseBranch(const char *name)
116{
117 ExRootTreeReader *reader = GetTreeReader();
118 return reader ? reader->UseBranch(name) : 0;
119}
120
121//------------------------------------------------------------------------------
122
123TFolder *ExRootModule::NewFolder(const char *name)
124{
125 TFolder *folder;
126 folder = static_cast<TFolder *>(GetObject(name, TFolder::Class()));
127 if(!folder) folder = GetFolder()->AddFolder(name, "");
128 if(!folder)
129 {
130 cout << "** ERROR: cannot create folder '" << name << "'" << endl;
131 return 0;
132 }
133 folder = folder->AddFolder(GetName(), GetTitle());
134 if(!folder)
135 {
136 cout << "** ERROR: cannot create folder '";
137 cout << name << "/" << GetName() << "'" << endl;
138 return 0;
139 }
140 return folder;
141}
142
143//------------------------------------------------------------------------------
144
145TObject *ExRootModule::GetObject(const char *name, TClass *cl)
146{
147 TObject *object = GetFolder()->FindObject(name);
148 if(object && object->IsA() != cl)
149 {
150 cout << "** ERROR: object '" << name;
151 cout << "' is not of class '" << cl->GetName() << "'" << endl;
152 return 0;
153 }
154 return object;
155}
156
157//------------------------------------------------------------------------------
158
159ExRootResult *ExRootModule::GetPlots()
160{
161 if(!fPlots)
162 {
163 fPlots = new ExRootResult();
164 fPlots->SetFolder(GetFolder());
165 }
166 return fPlots;
167}
168
169//------------------------------------------------------------------------------
170
171ExRootFactory *ExRootModule::GetFactory()
172{
173 if(!fFactory)
174 {
175 fFactory = static_cast<ExRootFactory *>(GetObject("ObjectFactory", ExRootFactory::Class()));
176 if(!fFactory)
177 {
178 cout << "** ERROR: cannot access factory" << endl;
179 return 0;
180 }
181 }
182 return fFactory;
183}
184
185//------------------------------------------------------------------------------
186
187ExRootTreeReader *ExRootModule::GetTreeReader()
188{
189 if(!fTreeReader)
190 {
191 fTreeReader = static_cast<ExRootTreeReader *>(GetObject("TreeReader", ExRootTreeReader::Class()));
192 if(!fTreeReader)
193 {
194 cout << "** ERROR: cannot access tree reader" << endl;
195 return 0;
196 }
197 }
198 return fTreeReader;
199}
200
201
Note: See TracBrowser for help on using the repository browser.