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

Last change on this file since 666 was 666, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.4 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
24ClassImp(MParList)
25
26MParList::MParList()
27{
28 //
29 // default constructor
30 // creates an empty list
31 //
32
33}
34
35MParList::MParList(MParList &ts)
36{
37 //
38 // copy constructor
39 //
40
41 fContainer.AddAll(&ts.fContainer);
42}
43
44void MParList::SetLogStream(MLog *log)
45{
46 //
47 // create the Iterator over the tasklist
48 //
49 TIter Next(&fContainer);
50
51 MParContainer *cont=NULL;
52
53 //
54 // loop over all tasks for preproccesing
55 //
56 while ( (cont=(MParContainer*)Next()) )
57 cont->SetLogStream(log);
58
59 MParContainer::SetLogStream(log);
60}
61
62Bool_t MParList::AddToList(MParContainer *obj, MParContainer *where)
63{
64 //
65 // Add an Container to the list.
66 //
67 // If 'where' is given, the object will be added after this.
68 //
69
70 //
71 // check if the object (you want to add) exists
72 //
73
74 if (!obj) return kTRUE;
75
76 *fLog << "Adding " << obj->GetName() << " to " << GetName() << "... " << flush;
77 //
78 // check if it is in the list yet
79 //
80 if (fContainer.FindObject(obj))
81 {
82 *fLog << "WARNING: MParList::add: Container already added" << endl;
83 return kTRUE;
84 }
85
86 //
87 // check if you want to add the new parameter container somewhere
88 // special (in that case you specify "where")
89 //
90 if (where)
91 {
92 if (!fContainer.FindObject(where))
93 {
94 *fLog << "ERROR: MParList::add: Cannot find parameter container after which the new one should be added!" << endl;
95 return kFALSE;
96 }
97 }
98
99 fContainer.Add(obj);
100 *fLog << "Done." << endl;
101
102 return kTRUE;
103}
104
105TObject *MParList::FindObject(const char *name) const
106{
107 //
108 // Find an object in the list.
109 // 'name' is the name of the object you are searching for.
110 //
111 return (TObject*)fContainer.FindObject(name);
112}
113
114MParContainer *MParList::FindCreateObj(const char *name)
115{
116 //
117 // Find an object in the list.
118 // 'name' is the name of the object you are searching for.
119 // If the object doesn't exist we try to create one from the
120 // dictionary. If this isn't possible NULL is returned
121 //
122 MParContainer *pcont = (MParContainer*)FindObject(name);
123
124 if (pcont)
125 return pcont;
126
127 //
128 // if object is not existing in the list try to create one
129 //
130 *fLog << "MParList::CreateObject - Warning: '" << name << "' not found... creating." << endl;
131
132 //
133 // try to get class from root environment
134 //
135 TClass *cls = gROOT->GetClass(name);
136
137 if (!cls)
138 {
139 //
140 // if class is not existing in the root environment
141 //
142 *fLog << "MParList::CreateObject - Warning: Class '" << name << "' not existing in dictionary." << endl;
143 return NULL;
144 }
145
146 //
147 // create the container and add it to the list
148 //
149 pcont = (MParContainer*)cls->New();
150 AddToList(pcont);
151
152 //
153 // Find an object in the list.
154 // 'name' is the name of the object you are searching for.
155 //
156 return pcont;
157}
158
159void MParList::Print(Option_t *t)
160{
161 //
162 // print some information about the current status of MParList
163 //
164 *fLog << "ParList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
165 *fLog << endl;
166
167}
168
Note: See TracBrowser for help on using the repository browser.