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 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MParContainer
|
---|
28 | //
|
---|
29 | // The MParContainer class is the base class for all MARS parameter
|
---|
30 | // containers. At the moment it is almost the same than ROOT's TNamed.
|
---|
31 | // A TNamed contains the essential elements (name, title)
|
---|
32 | // to identify a derived object in lists like our MParList or MTaskList.
|
---|
33 | // The main difference is that the name and title isn't stored and read
|
---|
34 | // to and from root files ("//!")
|
---|
35 | //
|
---|
36 | // MParContainer has several enhancements compared to TNamed:
|
---|
37 | // - GetDescriptor(): returns name and class type
|
---|
38 | // - GetUniqueName(): returns a unique name (used in StreamPrimitive)
|
---|
39 | // - SetLogStream(MLog *lg): Set a logging stream to which loggingis stored
|
---|
40 | // - Reset(): Reset content of class in an eventloop
|
---|
41 | // - IsReadyToSave(): The contents are ready to be saved to a file
|
---|
42 | // - IsSavedAsPrimitive(): A unique name for this instance is already
|
---|
43 | // existing
|
---|
44 | // - SetVariables(): Can be overloaded if the containers stores
|
---|
45 | // coefficients (to be used in fits)
|
---|
46 | // - SetDisplay(): Set a display for redirecting graphical output
|
---|
47 | // - GetNames(): Get Name/Title from instance and store it in
|
---|
48 | // a TObjArray (used to store the names of the
|
---|
49 | // conteiners in a file
|
---|
50 | // - SetNames(): vice versa
|
---|
51 | // - ReadEnv(), WriteEnv(): Function which is used for automatical setup
|
---|
52 | // IsEnvDefined() from a TEnv file
|
---|
53 | //
|
---|
54 | //////////////////////////////////////////////////////////////////////////////
|
---|
55 | #include "MParContainer.h"
|
---|
56 |
|
---|
57 | #include <ctype.h> // isdigit
|
---|
58 | #include <fstream> // ofstream
|
---|
59 |
|
---|
60 | #include <TEnv.h> // Env::Lookup
|
---|
61 | #include <TClass.h> // IsA
|
---|
62 | #include <TObjArray.h> // TObjArray
|
---|
63 | #include <TBaseClass.h> // GetClassPointer
|
---|
64 | #include <TMethodCall.h> // TMethodCall, AsciiWrite
|
---|
65 | #include <TDataMember.h> // TDataMember, AsciiWrite
|
---|
66 | #include <TVirtualPad.h> // gPad
|
---|
67 |
|
---|
68 | #include "MString.h"
|
---|
69 |
|
---|
70 | #include "MLog.h"
|
---|
71 | #include "MLogManip.h"
|
---|
72 |
|
---|
73 | TList *gListOfPrimitives; // forard declaration in MParContainer.h
|
---|
74 |
|
---|
75 | #undef DEBUG
|
---|
76 | //#define DEBUG
|
---|
77 |
|
---|
78 | ClassImp(MParContainer);
|
---|
79 |
|
---|
80 | using namespace std;
|
---|
81 |
|
---|
82 | MParContainer::MParContainer(const char *name, const char *title) :
|
---|
83 | fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE)
|
---|
84 | {
|
---|
85 | }
|
---|
86 |
|
---|
87 | MParContainer::MParContainer(const TString &name, const TString &title) :
|
---|
88 | fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE)
|
---|
89 | {
|
---|
90 | }
|
---|
91 |
|
---|
92 | // --------------------------------------------------------------------------
|
---|
93 | //
|
---|
94 | // MParContainer copy ctor
|
---|
95 | //
|
---|
96 | MParContainer::MParContainer(const MParContainer &named)
|
---|
97 | {
|
---|
98 | fName = named.fName;
|
---|
99 | fTitle = named.fTitle;
|
---|
100 |
|
---|
101 | fLog = named.fLog;
|
---|
102 |
|
---|
103 | fReadyToSave = named.fReadyToSave;
|
---|
104 |
|
---|
105 | fDisplay = named.fDisplay;
|
---|
106 | }
|
---|
107 |
|
---|
108 | MParContainer::~MParContainer()
|
---|
109 | {
|
---|
110 | #ifdef DEBUG
|
---|
111 | if (fName.IsNull() || fName==(TString)"MTime")
|
---|
112 | return;
|
---|
113 |
|
---|
114 | *fLog << all << "Deleting " << GetDescriptor() << endl;
|
---|
115 | if (TestBit(kMustCleanup) && gROOT && gROOT->MustClean())
|
---|
116 | {
|
---|
117 | *fLog << "Recursive Remove..." << flush;
|
---|
118 | if (TestBit(kCanDelete))
|
---|
119 | *fLog << "kCanDelete..." << flush;
|
---|
120 | TIter Next(gROOT->GetListOfCleanups());
|
---|
121 | TObject *o=0;
|
---|
122 | while ((o=Next()))
|
---|
123 | *fLog << dbg << o->GetName() << " [" << o->ClassName() << "]" << endl;
|
---|
124 | *fLog << dbg << "Removing..." << flush;
|
---|
125 | gROOT->GetListOfCleanups()->RecursiveRemove(this);
|
---|
126 | *fLog << "Removed." << endl;
|
---|
127 | }
|
---|
128 | #endif
|
---|
129 | }
|
---|
130 |
|
---|
131 | // --------------------------------------------------------------------------
|
---|
132 | //
|
---|
133 | // MParContainer assignment operator.
|
---|
134 | //
|
---|
135 | MParContainer& MParContainer::operator=(const MParContainer& rhs)
|
---|
136 | {
|
---|
137 | if (this == &rhs)
|
---|
138 | return *this;
|
---|
139 |
|
---|
140 | TObject::operator=(rhs);
|
---|
141 |
|
---|
142 | fName = rhs.fName;
|
---|
143 | fTitle = rhs.fTitle;
|
---|
144 |
|
---|
145 | fLog = rhs.fLog;
|
---|
146 | fReadyToSave = rhs.fReadyToSave;
|
---|
147 |
|
---|
148 | return *this;
|
---|
149 | }
|
---|
150 |
|
---|
151 | // --------------------------------------------------------------------------
|
---|
152 | //
|
---|
153 | // Make a clone of an object using the Streamer facility.
|
---|
154 | // If newname is specified, this will be the name of the new object
|
---|
155 | //
|
---|
156 | TObject *MParContainer::Clone(const char *newname) const
|
---|
157 | {
|
---|
158 |
|
---|
159 | MParContainer *named = (MParContainer*)TObject::Clone();
|
---|
160 | if (newname && strlen(newname)) named->SetName(newname);
|
---|
161 | return named;
|
---|
162 | }
|
---|
163 |
|
---|
164 | // --------------------------------------------------------------------------
|
---|
165 | //
|
---|
166 | // Compare two MParContainer objects. Returns 0 when equal, -1 when this is
|
---|
167 | // smaller and +1 when bigger (like strcmp).
|
---|
168 | //
|
---|
169 | Int_t MParContainer::Compare(const TObject *obj) const
|
---|
170 | {
|
---|
171 | if (this == obj) return 0;
|
---|
172 | return fName.CompareTo(obj->GetName());
|
---|
173 | }
|
---|
174 |
|
---|
175 | // --------------------------------------------------------------------------
|
---|
176 | //
|
---|
177 | // Copy this to obj.
|
---|
178 | //
|
---|
179 | void MParContainer::Copy(TObject &obj)
|
---|
180 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
|
---|
181 | const
|
---|
182 | #endif
|
---|
183 | {
|
---|
184 | MParContainer &cont = (MParContainer&)obj;
|
---|
185 |
|
---|
186 | TObject::Copy(obj);
|
---|
187 |
|
---|
188 | cont.fName = fName;
|
---|
189 | cont.fTitle = fTitle;
|
---|
190 |
|
---|
191 | cont.fLog = fLog;
|
---|
192 | cont.fReadyToSave = fReadyToSave;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // --------------------------------------------------------------------------
|
---|
196 | //
|
---|
197 | // Encode MParContainer into output buffer.
|
---|
198 | //
|
---|
199 | void MParContainer::FillBuffer(char *&buffer)
|
---|
200 | {
|
---|
201 | fName.FillBuffer(buffer);
|
---|
202 | fTitle.FillBuffer(buffer);
|
---|
203 | }
|
---|
204 |
|
---|
205 | // --------------------------------------------------------------------------
|
---|
206 | //
|
---|
207 | // Returns the name of the object. If the name of the object is not the
|
---|
208 | // class name it returns the object name and in []-brackets the class name.
|
---|
209 | //
|
---|
210 | const TString MParContainer::GetDescriptor() const
|
---|
211 | {
|
---|
212 | return GetDescriptor(*this);
|
---|
213 | }
|
---|
214 |
|
---|
215 | // --------------------------------------------------------------------------
|
---|
216 | //
|
---|
217 | // Returns the name of the object. If the name of the object is not the
|
---|
218 | // class name it returns the object name and in []-brackets the class name.
|
---|
219 | //
|
---|
220 | const TString MParContainer::GetDescriptor(const TObject &o)
|
---|
221 | {
|
---|
222 | //
|
---|
223 | // Because it returns a (const char*) we cannot return a casted
|
---|
224 | // local TString. The pointer would - immediatly after return -
|
---|
225 | // point to a random memory segment, because the TString has gone.
|
---|
226 | //
|
---|
227 | MString desc;
|
---|
228 | desc.Print("%s [%s]", o.GetName(), o.ClassName());
|
---|
229 | return (TString)o.GetName()==o.ClassName() ? o.ClassName() : desc;
|
---|
230 | }
|
---|
231 |
|
---|
232 | // --------------------------------------------------------------------------
|
---|
233 | //
|
---|
234 | // Return a unique name for this container. It is created from
|
---|
235 | // the container name and the unique Id. (This is mostly used
|
---|
236 | // in the StreamPrimitive member functions)
|
---|
237 | //
|
---|
238 | const TString MParContainer::GetUniqueName() const
|
---|
239 | {
|
---|
240 | TString ret = ToLower(fName);
|
---|
241 |
|
---|
242 | if (isdigit(ret[ret.Length()-1]))
|
---|
243 | ret+="_";
|
---|
244 |
|
---|
245 | ret+=GetUniqueID();
|
---|
246 |
|
---|
247 | return ret;
|
---|
248 | }
|
---|
249 |
|
---|
250 | // --------------------------------------------------------------------------
|
---|
251 | //
|
---|
252 | // List MParContainer name and title.
|
---|
253 | //
|
---|
254 | void MParContainer::ls(Option_t *) const
|
---|
255 | {
|
---|
256 | TROOT::IndentLevel();
|
---|
257 | *fLog << all << GetDescriptor() << " " << GetTitle() << ": kCanDelete=";
|
---|
258 | *fLog << Int_t(TestBit(kCanDelete)) << endl;
|
---|
259 | }
|
---|
260 |
|
---|
261 | // --------------------------------------------------------------------------
|
---|
262 | //
|
---|
263 | // Print MParContainer name and title.
|
---|
264 | //
|
---|
265 | void MParContainer::Print(Option_t *) const
|
---|
266 | {
|
---|
267 | *fLog << all << GetDescriptor() << " " << GetTitle() << endl;
|
---|
268 | }
|
---|
269 |
|
---|
270 | // --------------------------------------------------------------------------
|
---|
271 | //
|
---|
272 | // Change (i.e. set) the name of the MParContainer.
|
---|
273 | // WARNING !!
|
---|
274 | // If the object is a member of a THashTable, THashList container
|
---|
275 | // The HashTable must be Rehashed after SetName
|
---|
276 | // For example the list of objects in the current directory is a THashList
|
---|
277 | //
|
---|
278 | void MParContainer::SetName(const char *name)
|
---|
279 | {
|
---|
280 | fName = name;
|
---|
281 | ResetBit(kIsSavedAsPrimitive);
|
---|
282 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
---|
283 | }
|
---|
284 |
|
---|
285 | // --------------------------------------------------------------------------
|
---|
286 | //
|
---|
287 | // Change (i.e. set) all the MParContainer parameters (name and title).
|
---|
288 | // See also WARNING in SetName
|
---|
289 | //
|
---|
290 | void MParContainer::SetObject(const char *name, const char *title)
|
---|
291 | {
|
---|
292 | fName = name;
|
---|
293 | fTitle = title;
|
---|
294 | ResetBit(kIsSavedAsPrimitive);
|
---|
295 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
---|
296 | }
|
---|
297 |
|
---|
298 | // --------------------------------------------------------------------------
|
---|
299 | //
|
---|
300 | // Change (i.e. set) the title of the MParContainer.
|
---|
301 | //
|
---|
302 | void MParContainer::SetTitle(const char *title)
|
---|
303 | {
|
---|
304 | fTitle = title;
|
---|
305 | ResetBit(kIsSavedAsPrimitive);
|
---|
306 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
---|
307 | }
|
---|
308 |
|
---|
309 | // --------------------------------------------------------------------------
|
---|
310 | //
|
---|
311 | // Return size of the MParContainer part of the TObject.
|
---|
312 | //
|
---|
313 | Int_t MParContainer::Sizeof() const
|
---|
314 | {
|
---|
315 | Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
|
---|
316 | return nbytes;
|
---|
317 | }
|
---|
318 |
|
---|
319 | // --------------------------------------------------------------------------
|
---|
320 | //
|
---|
321 | // If you want to use Ascii-Input/-Output (eg. MWriteAsciiFile) of a
|
---|
322 | // container, overload this function.
|
---|
323 | //
|
---|
324 | void MParContainer::AsciiRead(istream &fin)
|
---|
325 | {
|
---|
326 | *fLog << warn << "To use the the ascii input of " << GetName();
|
---|
327 | *fLog << " you have to overload " << ClassName() << "::AsciiRead." << endl;
|
---|
328 | }
|
---|
329 |
|
---|
330 | // --------------------------------------------------------------------------
|
---|
331 | //
|
---|
332 | // Write out a data member given as a TDataMember object to an output stream.
|
---|
333 | //
|
---|
334 | Bool_t MParContainer::WriteDataMember(ostream &out, const TDataMember *member, Double_t scale) const
|
---|
335 | {
|
---|
336 | if (!member)
|
---|
337 | return kFALSE;
|
---|
338 |
|
---|
339 | if (!member->IsPersistent() || member->Property()&kIsStatic)
|
---|
340 | return kFALSE;
|
---|
341 |
|
---|
342 | /*const*/ TMethodCall *call = ((TDataMember*)member)->GetterMethod(); //FIXME: Root
|
---|
343 | if (!call)
|
---|
344 | {
|
---|
345 | *fLog << warn << "Sorry, no getter method found for " << member->GetName() << endl;
|
---|
346 | return kFALSE;
|
---|
347 | }
|
---|
348 |
|
---|
349 | // For debugging: out << member->GetName() << ":";
|
---|
350 |
|
---|
351 | switch (call->ReturnType())
|
---|
352 | {
|
---|
353 | case TMethodCall::kLong:
|
---|
354 | Long_t l;
|
---|
355 | call->Execute((void*)this, l); // FIXME: const, root
|
---|
356 | out << l << " ";
|
---|
357 | return kTRUE;
|
---|
358 |
|
---|
359 | case TMethodCall::kDouble:
|
---|
360 | Double_t d;
|
---|
361 | call->Execute((void*)this, d); // FIXME: const, root
|
---|
362 | out << (scale*d) << " ";
|
---|
363 | return kTRUE;
|
---|
364 |
|
---|
365 | default:
|
---|
366 | //case TMethodCall::kString:
|
---|
367 | //case TMethodCall::kOther:
|
---|
368 | /* someone may want to enhance this? */
|
---|
369 | return kFALSE;
|
---|
370 | }
|
---|
371 | }
|
---|
372 |
|
---|
373 | // --------------------------------------------------------------------------
|
---|
374 | //
|
---|
375 | // Write out a data member given by name to an output stream.
|
---|
376 | //
|
---|
377 | Bool_t MParContainer::WriteDataMember(ostream &out, const char *member, Double_t scale) const
|
---|
378 | {
|
---|
379 | /*const*/ TClass *cls = IsA()->GetBaseDataMember(member);
|
---|
380 | if (!cls)
|
---|
381 | return kFALSE;
|
---|
382 |
|
---|
383 | return WriteDataMember(out, cls->GetDataMember(member), scale);
|
---|
384 | }
|
---|
385 |
|
---|
386 | // --------------------------------------------------------------------------
|
---|
387 | //
|
---|
388 | // Write out a data member from a given TList of TDataMembers.
|
---|
389 | // returns kTRUE when at least one member was successfully written
|
---|
390 | //
|
---|
391 | Bool_t MParContainer::WriteDataMember(ostream &out, const TList *list) const
|
---|
392 | {
|
---|
393 | Bool_t rc = kFALSE;
|
---|
394 |
|
---|
395 | TDataMember *data = NULL;
|
---|
396 |
|
---|
397 | TIter Next(list);
|
---|
398 | while ((data=(TDataMember*)Next()))
|
---|
399 | rc |= WriteDataMember(out, data);
|
---|
400 |
|
---|
401 | return rc;
|
---|
402 | }
|
---|
403 |
|
---|
404 | // --------------------------------------------------------------------------
|
---|
405 | //
|
---|
406 | // If you want to use Ascii-Input/-Output (eg. MWriteAsciiFile) of a
|
---|
407 | // container, you may overload this function. If you don't overload it
|
---|
408 | // the data member of a class are written to the file in the order of
|
---|
409 | // appearance in the class header (be more specfic: root dictionary)
|
---|
410 | // Only data members which are of integer (Bool_t, Int_t, ...) or
|
---|
411 | // floating point (Float_t, Double_t, ...) type are written.
|
---|
412 | // returns kTRUE when at least one member was successfully written
|
---|
413 | //
|
---|
414 | Bool_t MParContainer::AsciiWrite(ostream &out) const
|
---|
415 | {
|
---|
416 | // *fLog << warn << "To use the the ascii output of " << GetName();
|
---|
417 | // *fLog << " you have to overload " << ClassName() << "::AsciiWrite." << endl;
|
---|
418 |
|
---|
419 | Bool_t rc = WriteDataMember(out, IsA()->GetListOfDataMembers());
|
---|
420 |
|
---|
421 | TIter NextBaseClass(IsA()->GetListOfBases());
|
---|
422 | TBaseClass *base;
|
---|
423 | while ((base = (TBaseClass*) NextBaseClass()))
|
---|
424 | {
|
---|
425 | /*const*/ TClass *cls = base->GetClassPointer();
|
---|
426 |
|
---|
427 | if (!cls)
|
---|
428 | continue;
|
---|
429 |
|
---|
430 | if (cls->GetClassVersion())
|
---|
431 | rc |= WriteDataMember(out, cls->GetListOfDataMembers());
|
---|
432 | }
|
---|
433 |
|
---|
434 | return rc;
|
---|
435 | }
|
---|
436 |
|
---|
437 | // --------------------------------------------------------------------------
|
---|
438 | //
|
---|
439 | // This virtual function is called for all parameter containers which are
|
---|
440 | // found in the parameter list automatically each time the tasklist is
|
---|
441 | // executed.
|
---|
442 | //
|
---|
443 | // By overwriting this function you can invalidate the contents of a
|
---|
444 | // container before each execution of the tasklist:
|
---|
445 | //
|
---|
446 | // For example:
|
---|
447 | // void MHillas::Reset()
|
---|
448 | // {
|
---|
449 | // fWidth = -1;
|
---|
450 | // }
|
---|
451 | //
|
---|
452 | // (While -1 is obviously a impossible value for fWidth you can immediatly
|
---|
453 | // see - if you Print() the contents of this container - that MHillasCalc
|
---|
454 | // has not caluclated the width in this runthrough of the tasklist)
|
---|
455 | //
|
---|
456 | // Overwriting MParConatiner::Reset() in your container makes it
|
---|
457 | // unnecessary to call any Clear() or Reset() manually in your task and
|
---|
458 | // you make sure, that you don't keep results of previous runs of your
|
---|
459 | // tasklist by chance.
|
---|
460 | //
|
---|
461 | // MParContainer::Reset() itself does nothing.
|
---|
462 | //
|
---|
463 | void MParContainer::Reset()
|
---|
464 | {
|
---|
465 | }
|
---|
466 |
|
---|
467 | TMethodCall *MParContainer::GetterMethod(const char *name) const
|
---|
468 | {
|
---|
469 | const TString n(name);
|
---|
470 | const Int_t pos1 = n.First('.');
|
---|
471 |
|
---|
472 | const TString part1 = pos1<0 ? n : n(0, pos1);
|
---|
473 | const TString part2 = pos1<0 ? TString("") : n(pos1+1, n.Length());
|
---|
474 |
|
---|
475 | TClass *cls = IsA()->GetBaseDataMember(part1);
|
---|
476 | if (cls)
|
---|
477 | {
|
---|
478 | TDataMember *member = cls->GetDataMember(part1);
|
---|
479 | if (!member)
|
---|
480 | {
|
---|
481 | *fLog << err << "Datamember '" << part1 << "' not in " << GetDescriptor() << endl;
|
---|
482 | return NULL;
|
---|
483 | }
|
---|
484 |
|
---|
485 | // This handles returning references of contained objects, eg
|
---|
486 | // class X { TObject fO; TObject &GetO() { return fO; } };
|
---|
487 | if (!member->IsBasic() && !part2.IsNull())
|
---|
488 | {
|
---|
489 | cls = gROOT->GetClass(member->GetTypeName());
|
---|
490 | if (!cls)
|
---|
491 | {
|
---|
492 | *fLog << err << "Datamember " << part1 << " [";
|
---|
493 | *fLog << member->GetTypeName() << "] not in dictionary." << endl;
|
---|
494 | return NULL;
|
---|
495 | }
|
---|
496 | if (!cls->InheritsFrom(MParContainer::Class()))
|
---|
497 | {
|
---|
498 | *fLog << err << "Datamember " << part1 << " [";
|
---|
499 | *fLog << member->GetTypeName() << "] does not inherit from ";
|
---|
500 | *fLog << "MParContainer." << endl;
|
---|
501 | return NULL;
|
---|
502 | }
|
---|
503 |
|
---|
504 | const MParContainer *sub = (MParContainer*)((ULong_t)this+member->GetOffset());
|
---|
505 | return sub->GetterMethod(part2);
|
---|
506 | }
|
---|
507 |
|
---|
508 | if (member->IsaPointer())
|
---|
509 | {
|
---|
510 | *fLog << warn << "Data-member " << part1 << " is a pointer..." << endl;
|
---|
511 | *fLog << dbginf << "Not yet implemented!" << endl;
|
---|
512 | //TClass *test = gROOT->GetClass(member->GetTypeName());
|
---|
513 | return 0;
|
---|
514 | }
|
---|
515 |
|
---|
516 | TMethodCall *call = member->GetterMethod();
|
---|
517 | if (call)
|
---|
518 | return call;
|
---|
519 | }
|
---|
520 |
|
---|
521 | *fLog << warn << "No standard access for '" << part1 << "' in ";
|
---|
522 | *fLog << GetDescriptor() << " or one of its base classes." << endl;
|
---|
523 |
|
---|
524 | TMethodCall *call = NULL;
|
---|
525 |
|
---|
526 | *fLog << warn << "Trying to find MethodCall '" << ClassName();
|
---|
527 | *fLog << "::Get" << part1 << "' instead <LEAKS MEMORY>" << endl;
|
---|
528 | call = new TMethodCall(IsA(), (TString)"Get"+part1, "");
|
---|
529 | if (call->GetMethod())
|
---|
530 | return call;
|
---|
531 |
|
---|
532 | delete call;
|
---|
533 |
|
---|
534 | *fLog << warn << "Trying to find MethodCall '" << ClassName();
|
---|
535 | *fLog << "::" << part1 << "' instead <LEAKS MEMORY>" << endl;
|
---|
536 | call = new TMethodCall(IsA(), part1, "");
|
---|
537 | if (call->GetMethod())
|
---|
538 | return call;
|
---|
539 |
|
---|
540 | delete call;
|
---|
541 |
|
---|
542 | *fLog << err << "Sorry, no getter method found for " << part1 << endl;
|
---|
543 | return NULL;
|
---|
544 | }
|
---|
545 |
|
---|
546 | // --------------------------------------------------------------------------
|
---|
547 | //
|
---|
548 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
549 | // to a macro. In the original root implementation it is used to write
|
---|
550 | // gui elements to a macro-file.
|
---|
551 | //
|
---|
552 | void MParContainer::SavePrimitive(ofstream &out, Option_t *o)
|
---|
553 | {
|
---|
554 | static UInt_t uid = 0;
|
---|
555 |
|
---|
556 | if (IsSavedAsPrimitive())
|
---|
557 | return;
|
---|
558 |
|
---|
559 | SetUniqueID(uid++);
|
---|
560 | SetBit(kIsSavedAsPrimitive);
|
---|
561 |
|
---|
562 | if (gListOfPrimitives && !gListOfPrimitives->FindObject(this))
|
---|
563 | gListOfPrimitives->Add(this);
|
---|
564 |
|
---|
565 | StreamPrimitive(out);
|
---|
566 | }
|
---|
567 |
|
---|
568 | // --------------------------------------------------------------------------
|
---|
569 | //
|
---|
570 | // Creates the string written by SavePrimitive and returns it.
|
---|
571 | //
|
---|
572 | void MParContainer::StreamPrimitive(ofstream &out) const
|
---|
573 | {
|
---|
574 | out << " // Using MParContainer::StreamPrimitive" << endl;
|
---|
575 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
576 | out << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
577 | }
|
---|
578 |
|
---|
579 | void MParContainer::GetNames(TObjArray &arr) const
|
---|
580 | {
|
---|
581 | arr.AddLast(new TNamed(fName, fTitle));
|
---|
582 | }
|
---|
583 |
|
---|
584 | void MParContainer::SetNames(TObjArray &arr)
|
---|
585 | {
|
---|
586 | TNamed *name = (TNamed*)arr.First();
|
---|
587 |
|
---|
588 | fName = name->GetName();
|
---|
589 | fTitle = name->GetTitle();
|
---|
590 |
|
---|
591 | delete arr.Remove(name);
|
---|
592 | arr.Compress();
|
---|
593 | }
|
---|
594 |
|
---|
595 | // --------------------------------------------------------------------------
|
---|
596 | //
|
---|
597 | // Creates a new instance of this class. The idea is to create a clone of
|
---|
598 | // this class in its initial state.
|
---|
599 | //
|
---|
600 | MParContainer *MParContainer::New() const
|
---|
601 | {
|
---|
602 | return (MParContainer*)IsA()->New();
|
---|
603 | }
|
---|
604 |
|
---|
605 | // --------------------------------------------------------------------------
|
---|
606 | //
|
---|
607 | // Read the contents/setup of a parameter container/task from a TEnv
|
---|
608 | // instance (steering card/setup file).
|
---|
609 | // The key to search for in the file should be of the syntax:
|
---|
610 | // prefix.vname
|
---|
611 | // While vname is a name which is specific for a single setup date
|
---|
612 | // (variable) of this container and prefix is something like:
|
---|
613 | // evtloopname.name
|
---|
614 | // While name is the name of the containers/tasks in the parlist/tasklist
|
---|
615 | //
|
---|
616 | // eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
|
---|
617 | // Job4.MImgCleanStd.CleaningLevel2: 2.5
|
---|
618 | //
|
---|
619 | // If this cannot be found the next step is to search for
|
---|
620 | // MImgCleanStd.CleaningLevel1: 3.0
|
---|
621 | // And if this doesn't exist, too, we should search for:
|
---|
622 | // CleaningLevel1: 3.0
|
---|
623 | //
|
---|
624 | // Warning: The programmer is responsible for the names to be unique in
|
---|
625 | // all Mars classes.
|
---|
626 | //
|
---|
627 | // Return values:
|
---|
628 | // kTRUE: Environment string found
|
---|
629 | // kFALSE: Environment string not found
|
---|
630 | // kERROR: Error occured, eg. environment invalid
|
---|
631 | //
|
---|
632 | // Overload this if you don't want to control the level of setup-string. In
|
---|
633 | // this case ReadEnv gets called with the different possibilities, see TestEnv.
|
---|
634 | //
|
---|
635 | Int_t MParContainer::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
636 | {
|
---|
637 | if (!IsEnvDefined(env, prefix, "", print))
|
---|
638 | return kFALSE;
|
---|
639 |
|
---|
640 | *fLog << warn << "WARNING - Resource " << prefix+fName << " found, but no " << ClassName() << "::ReadEnv." << endl;
|
---|
641 | return kTRUE;
|
---|
642 | }
|
---|
643 |
|
---|
644 | // --------------------------------------------------------------------------
|
---|
645 | //
|
---|
646 | // Write the contents/setup of a parameter container/task to a TEnv
|
---|
647 | // instance (steering card/setup file).
|
---|
648 | // The key to search for in the file should be of the syntax:
|
---|
649 | // prefix.vname
|
---|
650 | // While vname is a name which is specific for a single setup date
|
---|
651 | // (variable) of this container and prefix is something like:
|
---|
652 | // evtloopname.name
|
---|
653 | // While name is the name of the containers/tasks in the parlist/tasklist
|
---|
654 | //
|
---|
655 | // eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
|
---|
656 | // Job4.MImgCleanStd.CleaningLevel2: 2.5
|
---|
657 | //
|
---|
658 | // If this cannot be found the next step is to search for
|
---|
659 | // MImgCleanStd.CleaningLevel1: 3.0
|
---|
660 | // And if this doesn't exist, too, we should search for:
|
---|
661 | // CleaningLevel1: 3.0
|
---|
662 | //
|
---|
663 | // Warning: The programmer is responsible for the names to be unique in
|
---|
664 | // all Mars classes.
|
---|
665 | //
|
---|
666 | Bool_t MParContainer::WriteEnv(TEnv &env, TString prefix, Bool_t print) const
|
---|
667 | {
|
---|
668 | if (!IsEnvDefined(env, prefix, "", print))
|
---|
669 | return kFALSE;
|
---|
670 |
|
---|
671 | *fLog << warn << "WARNING - Resource " << prefix+fName << " found, but " << ClassName() << "::WriteEnv not overloaded." << endl;
|
---|
672 | return kTRUE;
|
---|
673 | }
|
---|
674 |
|
---|
675 | // --------------------------------------------------------------------------
|
---|
676 | //
|
---|
677 | // Take the prefix and call ReadEnv for:
|
---|
678 | // prefix.containername
|
---|
679 | // prefix.classname
|
---|
680 | // containername
|
---|
681 | // classname
|
---|
682 | //
|
---|
683 | // The existance of an environment variable is done in this order. If
|
---|
684 | // ReadEnv return kTRUE the existance of the container setup is assumed and
|
---|
685 | // the other tests are skipped. If kFALSE is assumed the sequence is
|
---|
686 | // continued. In case of kERROR failing of the setup from a file is assumed.
|
---|
687 | //
|
---|
688 | // Overload this if you want to control the handling of level of setup-string
|
---|
689 | // mentioned above. In this case ReadEnv gets never called if you don't call
|
---|
690 | // it explicitly.
|
---|
691 | //
|
---|
692 | Int_t MParContainer::TestEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
693 | {
|
---|
694 | if (print)
|
---|
695 | *fLog << all << "Testing Prefix+ContName: " << prefix+GetName() << endl;
|
---|
696 | Int_t rc = ReadEnv(env, prefix+GetName(), print);
|
---|
697 | if (rc==kERROR || rc==kTRUE)
|
---|
698 | return rc;
|
---|
699 |
|
---|
700 | // Check For: Job4.MClassName.Varname
|
---|
701 | if (print)
|
---|
702 | *fLog << all << "Testing Prefix+ClasName: " << prefix+ClassName() << endl;
|
---|
703 | rc = ReadEnv(env, prefix+ClassName(), print);
|
---|
704 | if (rc==kERROR || rc==kTRUE)
|
---|
705 | return rc;
|
---|
706 |
|
---|
707 | // Check For: ContainerName.Varname
|
---|
708 | if (print)
|
---|
709 | *fLog << all << "Testing ContName: " << GetName() << endl;
|
---|
710 | rc = ReadEnv(env, GetName(), print);
|
---|
711 | if (rc==kERROR || rc==kTRUE)
|
---|
712 | return rc;
|
---|
713 |
|
---|
714 | // Check For: MClassName.Varname
|
---|
715 | if (print)
|
---|
716 | *fLog << all << "Testing ClassName: " << ClassName() << endl;
|
---|
717 | rc = ReadEnv(env, ClassName(), print);
|
---|
718 | if (rc==kERROR || rc==kTRUE)
|
---|
719 | return rc;
|
---|
720 |
|
---|
721 | // Not found
|
---|
722 | return kFALSE;
|
---|
723 | }
|
---|
724 |
|
---|
725 | Bool_t MParContainer::IsEnvDefined(const TEnv &env, TString prefix, TString postfix, Bool_t print) const
|
---|
726 | {
|
---|
727 | if (!postfix.IsNull())
|
---|
728 | postfix.Insert(0, ".");
|
---|
729 |
|
---|
730 | return IsEnvDefined(env, prefix+postfix, print);
|
---|
731 | }
|
---|
732 |
|
---|
733 | Bool_t MParContainer::IsEnvDefined(const TEnv &env, TString name, Bool_t print) const
|
---|
734 | {
|
---|
735 | if (print)
|
---|
736 | *fLog << all << GetDescriptor() << " - " << name << "... " << flush;
|
---|
737 |
|
---|
738 | if (!((TEnv&)env).Defined(name))
|
---|
739 | {
|
---|
740 | if (print)
|
---|
741 | *fLog << "not found." << endl;
|
---|
742 | return kFALSE;
|
---|
743 | }
|
---|
744 |
|
---|
745 | if (print)
|
---|
746 | *fLog << "found." << endl;
|
---|
747 |
|
---|
748 | return kTRUE;
|
---|
749 | }
|
---|
750 |
|
---|
751 | Int_t MParContainer::GetEnvValue(const TEnv &env, TString prefix, TString postfix, Int_t dflt) const
|
---|
752 | {
|
---|
753 | return GetEnvValue(env, prefix+"."+postfix, dflt);
|
---|
754 | }
|
---|
755 |
|
---|
756 | Double_t MParContainer::GetEnvValue(const TEnv &env, TString prefix, TString postfix, Double_t dflt) const
|
---|
757 | {
|
---|
758 | return GetEnvValue(env, prefix+"."+postfix, dflt);
|
---|
759 | }
|
---|
760 |
|
---|
761 | const char *MParContainer::GetEnvValue(const TEnv &env, TString prefix, TString postfix, const char *dflt) const
|
---|
762 | {
|
---|
763 | return GetEnvValue(env, prefix+"."+postfix, dflt);
|
---|
764 | }
|
---|
765 |
|
---|
766 | Int_t MParContainer::GetEnvValue(const TEnv &env, TString prefix, Int_t dflt) const
|
---|
767 | {
|
---|
768 | return ((TEnv&)env).GetValue(prefix, dflt);
|
---|
769 | }
|
---|
770 |
|
---|
771 | Double_t MParContainer::GetEnvValue(const TEnv &env, TString prefix, Double_t dflt) const
|
---|
772 | {
|
---|
773 | return ((TEnv&)env).GetValue(prefix, dflt);
|
---|
774 | }
|
---|
775 |
|
---|
776 | const char *MParContainer::GetEnvValue(const TEnv &env, TString prefix, const char *dflt) const
|
---|
777 | {
|
---|
778 | return ((TEnv&)env).GetValue(prefix, dflt);
|
---|
779 | }
|
---|