source: trunk/src/ExRootFactory.cc@ 10

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

first commit

File size: 3.3 KB
Line 
1
2/** \class ExRootFactory
3 *
4 * Class handling creation of ExRootCandidate,
5 * ExRootCandList and all other objects.
6 *
7 * $Date: 2008-06-04 13:57:55 $
8 * $Revision: 1.1 $
9 *
10 *
11 * \author P. Demin - UCL, Louvain-la-Neuve
12 *
13 */
14
15#include "ExRootAnalysis/ExRootTreeWriter.h"
16#include "ExRootAnalysis/ExRootTreeBranch.h"
17
18#include "ExRootAnalysis/ExRootFactory.h"
19
20#include "ExRootAnalysis/ExRootCandidate.h"
21#include "ExRootAnalysis/ExRootCandList.h"
22
23#include "TClass.h"
24#include "TObjArray.h"
25
26using namespace std;
27
28//------------------------------------------------------------------------------
29
30ExRootFactory::ExRootFactory() :
31 fTreeWriter(0), fPermanentObjArrays(0)
32{
33 fTreeWriter = new ExRootTreeWriter();
34 fPermanentObjArrays = fTreeWriter->NewFactory("PermanentObjArrays", TObjArray::Class());
35}
36
37//------------------------------------------------------------------------------
38
39ExRootFactory::~ExRootFactory()
40{
41 if(fTreeWriter) delete fTreeWriter;
42}
43
44//------------------------------------------------------------------------------
45
46void ExRootFactory::Clear()
47{
48 map<const TClass *, ExRootTreeBranch *>::iterator it_map;
49 for(it_map = fMakers.begin(); it_map != fMakers.end(); ++it_map)
50 {
51 it_map->second->Clear();
52 }
53
54 set<TObject *>::iterator it_set;
55 for(it_set = fPool.begin(); it_set != fPool.end(); ++it_set)
56 {
57 (*it_set)->Clear();
58 }
59}
60
61//------------------------------------------------------------------------------
62
63TObjArray *ExRootFactory::NewArray()
64{
65 return New<TObjArray>();
66}
67
68//------------------------------------------------------------------------------
69
70TObjArray *ExRootFactory::NewPermanentArray()
71{
72 TObjArray *array = static_cast<TObjArray *>(fPermanentObjArrays->NewEntry());
73 fPool.insert(array);
74 return array;
75}
76
77//------------------------------------------------------------------------------
78
79ExRootCandList *ExRootFactory::NewCandList()
80{
81 ExRootCandList *object = New<ExRootCandList>();
82 object->SetFactory(this);
83 return object;
84}
85
86//------------------------------------------------------------------------------
87
88ExRootCandidate *ExRootFactory::NewCandidate()
89{
90 ExRootCandidate *object = New<ExRootCandidate>();
91 object->SetFactory(this);
92 TProcessID::AssignID(object);
93 return object;
94}
95
96//------------------------------------------------------------------------------
97
98ExRootCandList *ExRootFactory::NewPermanentCandList()
99{
100 ExRootCandList *object = static_cast<ExRootCandList *>(fPermanentCandLists->NewEntry());
101 object->SetFactory(this);
102 fPool.insert(object);
103 return object;
104}
105
106//------------------------------------------------------------------------------
107
108ExRootCandidate *ExRootFactory::NewPermanentCandidate()
109{
110 ExRootCandidate *object = static_cast<ExRootCandidate *>(fPermanentCandidates->NewEntry());
111 object->SetFactory(this);
112 TProcessID::AssignID(object);
113 fPool.insert(object);
114 return object;
115}
116
117//------------------------------------------------------------------------------
118
119TObject *ExRootFactory::New(TClass *cl)
120{
121 ExRootTreeBranch *maker = 0;
122 map<const TClass *, ExRootTreeBranch *>::iterator it = fMakers.find(cl);
123
124 if(it != fMakers.end())
125 {
126 maker = it->second;
127 }
128 else
129 {
130 maker = fTreeWriter->NewFactory(cl->GetName(), cl);
131 fMakers.insert(make_pair(cl, maker));
132 }
133
134 return maker->NewEntry();
135}
136
137//------------------------------------------------------------------------------
138
Note: See TracBrowser for help on using the repository browser.