source: trunk/MagicSoft/Mars/mbase/MParList.cc@ 724

Last change on this file since 724 was 705, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.8 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2// //
3// MParList //
4// //
5// This class contains a list of different parameter containers. //
6// //
7// A parameter container is an object which is derived from //
8// MParContainer. //
9// //
10// Normally a parameter container is used for data exchange between two //
11// tasks at runtime. //
12// //
13// You can add every parameter container (Named object) to the //
14// instance and access it from somewhere else via its Name. //
15// //
16/////////////////////////////////////////////////////////////////////////////
17#include "MParList.h"
18
19#include <TNamed.h>
20#include <TClass.h>
21
22#include "MLog.h"
23#include "MLogManip.h"
24
25ClassImp(MParList)
26
27 //
28 // FIXME: The Automatic created classes are NEVER deleted!!!!!
29 //
30
31MParList::MParList(const char *name, const char *title)
32{
33 //
34 // default constructor
35 // creates an empty list
36 //
37 *fName = name ? name : "MParList";
38 *fTitle = title ? title : "List of Parameter Containers";
39
40 //
41 // This sets a flag that the list is the owner, which means
42 // that the destructor of the list deletes all it's objects
43 //
44 fAutodelete.SetOwner();
45}
46
47MParList::MParList(MParList &ts)
48{
49 //
50 // copy constructor
51 //
52
53 fContainer.AddAll(&ts.fContainer);
54}
55
56void MParList::SetLogStream(MLog *log)
57{
58 //
59 // create the Iterator over the tasklist
60 //
61 TIter Next(&fContainer);
62
63 MParContainer *cont=NULL;
64
65 //
66 // loop over all tasks for preproccesing
67 //
68 while ( (cont=(MParContainer*)Next()) )
69 cont->SetLogStream(log);
70
71 MParContainer::SetLogStream(log);
72}
73
74Bool_t MParList::AddToList(MParContainer *obj, MParContainer *where)
75{
76 //
77 // Add an Container to the list.
78 //
79 // If 'where' is given, the object will be added after this.
80 //
81
82 //
83 // check if the object (you want to add) exists
84 //
85
86 if (!obj) return kTRUE;
87
88 *fLog << "Adding " << obj->GetName() << " to " << GetName() << "... " << flush;
89 //
90 // check if it is in the list yet
91 //
92 if (fContainer.FindObject(obj))
93 {
94 *fLog << dbginf << "Container already added" << endl;
95 return kTRUE;
96 }
97
98 //
99 // check if you want to add the new parameter container somewhere
100 // special (in that case you specify "where")
101 //
102 if (where)
103 {
104 if (!fContainer.FindObject(where))
105 {
106 *fLog << dbginf << "Cannot find parameter container after which the new one should be added!" << endl;
107 return kFALSE;
108 }
109 }
110
111 fContainer.Add(obj);
112 *fLog << "Done." << endl;
113
114 return kTRUE;
115}
116
117TObject *MParList::FindObject(const char *name) const
118{
119 //
120 // Find an object in the list.
121 // 'name' is the name of the object you are searching for.
122 //
123 return (TObject*)fContainer.FindObject(name);
124}
125
126MParContainer *MParList::FindCreateObj(const char *name)
127{
128 //
129 // Find an object in the list.
130 // 'name' is the name of the object you are searching for.
131 // If the object doesn't exist we try to create one from the
132 // dictionary. If this isn't possible NULL is returned
133 //
134 MParContainer *pcont = (MParContainer*)FindObject(name);
135
136 if (pcont)
137 return pcont;
138
139 //
140 // if object is not existing in the list try to create one
141 //
142 *fLog << dbginf << "'" << name << "' not found... creating." << endl;
143
144 //
145 // try to get class from root environment
146 //
147 TClass *cls = gROOT->GetClass(name);
148
149 if (!cls)
150 {
151 //
152 // if class is not existing in the root environment
153 //
154 *fLog << dbginf << "Class '" << name << "' not existing in dictionary." << endl;
155 return NULL;
156 }
157
158 //
159 // create the container and add it to the list
160 //
161 pcont = (MParContainer*)cls->New();
162 AddToList(pcont);
163
164 fAutodelete.Add(pcont);
165
166 //
167 // Find an object in the list.
168 // 'name' is the name of the object you are searching for.
169 //
170 return pcont;
171}
172
173void MParList::Print(Option_t *t)
174{
175 //
176 // print some information about the current status of MParList
177 //
178 *fLog << dbginf << "ParList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
179 *fLog << endl;
180
181}
182
Note: See TracBrowser for help on using the repository browser.