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

Last change on this file since 752 was 752, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MParList //
28// //
29// This class contains a list of different parameter containers. //
30// //
31// A parameter container is an object which is derived from //
32// MParContainer. //
33// //
34// Normally a parameter container is used for data exchange between two //
35// tasks at runtime. //
36// //
37// You can add every parameter container (Named object) to the //
38// instance and access it from somewhere else via its Name. //
39// //
40/////////////////////////////////////////////////////////////////////////////
41#include "MParList.h"
42
43#include <TNamed.h>
44#include <TClass.h>
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49ClassImp(MParList)
50
51// --------------------------------------------------------------------------
52//
53// default constructor
54// creates an empty list
55//
56MParList::MParList(const char *name, const char *title)
57{
58 *fName = name ? name : "MParList";
59 *fTitle = title ? title : "List of Parameter Containers";
60
61 //
62 // This sets a flag that the list is the owner, which means
63 // that the destructor of the list deletes all it's objects
64 //
65 fAutodelete.SetOwner();
66}
67
68// --------------------------------------------------------------------------
69//
70// copy constructor
71//
72MParList::MParList(MParList &ts)
73{
74 fContainer.AddAll(&ts.fContainer);
75}
76
77// --------------------------------------------------------------------------
78//
79// create the Iterator over the tasklist
80//
81void MParList::SetLogStream(MLog *log)
82{
83 TIter Next(&fContainer);
84
85 MParContainer *cont=NULL;
86
87 //
88 // loop over all tasks for preproccesing
89 //
90 while ( (cont=(MParContainer*)Next()) )
91 cont->SetLogStream(log);
92
93 MParContainer::SetLogStream(log);
94}
95
96// --------------------------------------------------------------------------
97//
98// Add an Container to the list.
99//
100// If 'where' is given, the object will be added after this.
101//
102Bool_t MParList::AddToList(MParContainer *obj, MParContainer *where)
103{
104 //
105 // check if the object (you want to add) exists
106 //
107
108 if (!obj) return kTRUE;
109
110 *fLog << "Adding " << obj->GetName() << " to " << GetName() << "... " << flush;
111 //
112 // check if it is in the list yet
113 //
114 if (fContainer.FindObject(obj))
115 {
116 *fLog << dbginf << "Container already added" << endl;
117 return kTRUE;
118 }
119
120 //
121 // check if you want to add the new parameter container somewhere
122 // special (in that case you specify "where")
123 //
124 if (where)
125 {
126 if (!fContainer.FindObject(where))
127 {
128 *fLog << dbginf << "Cannot find parameter container after which the new one should be added!" << endl;
129 return kFALSE;
130 }
131 }
132
133 fContainer.Add(obj);
134 *fLog << "Done." << endl;
135
136 return kTRUE;
137}
138
139// --------------------------------------------------------------------------
140//
141// Find an object in the list.
142// 'name' is the name of the object you are searching for.
143//
144TObject *MParList::FindObject(const char *name) const
145{
146 return (TObject*)fContainer.FindObject(name);
147}
148
149// --------------------------------------------------------------------------
150//
151// Find an object in the list.
152// 'name' is the name of the object you are searching for.
153// If the object doesn't exist we try to create one from the
154// dictionary. If this isn't possible NULL is returned
155//
156MParContainer *MParList::FindCreateObj(const char *classname, const char *objname)
157{
158 //
159 // If now object name (name of the object to identify it in the
160 // List) is given use it's classname as the objectname
161 //
162 if (!objname)
163 objname = classname;
164
165 //
166 // Try to find a object with this object name which is already
167 // in the List. If we can find one we are done.
168 //
169 MParContainer *pcont = (MParContainer*)FindObject(objname);
170
171 if (pcont)
172 return pcont;
173
174 //
175 // if object is not existing in the list try to create one
176 //
177 *fLog << dbginf << "'" << classname << "' not found... creating." << endl;
178
179 //
180 // try to get class from root environment
181 //
182 TClass *cls = gROOT->GetClass(classname);
183
184 if (!cls)
185 {
186 //
187 // if class is not existing in the root environment
188 //
189 *fLog << dbginf << "Class '" << classname << "' not existing in dictionary." << endl;
190 return NULL;
191 }
192
193 //
194 // create the parameter container of the the given class type
195 //
196 pcont = (MParContainer*)cls->New();
197
198 //
199 // If a name different to the classname was given,
200 // set the new object name of the object
201 //
202 pcont->SetName(objname);
203
204 //
205 // Now add the object to the parameter list
206 //
207 AddToList(pcont);
208
209 //
210 // The object was automatically created. This makes sure, that such an
211 // object is deleted together with the list
212 //
213 fAutodelete.Add(pcont);
214
215 //
216 // Find an object in the list.
217 // 'name' is the name of the object you are searching for.
218 //
219 return pcont;
220}
221
222// --------------------------------------------------------------------------
223//
224// print some information about the current status of MParList
225//
226void MParList::Print(Option_t *t)
227{
228 *fLog << dbginf << "ParList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
229 *fLog << endl;
230
231}
232
Note: See TracBrowser for help on using the repository browser.