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

Last change on this file since 4808 was 4694, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 27.2 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 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
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 <fstream> // ofstream, SavePrimitive
44
45#include <TNamed.h>
46#include <TClass.h>
47#include <TOrdCollection.h>
48
49#include "MLog.h"
50#include "MLogManip.h"
51
52#include "MIter.h"
53
54ClassImp(MParList);
55
56using namespace std;
57
58static const TString gsDefName = "MParList";
59static const TString gsDefTitle = "A list of Parameter Containers";
60
61// --------------------------------------------------------------------------
62//
63// default constructor
64// creates an empty list
65//
66MParList::MParList(const char *name, const char *title)
67{
68 fName = name ? name : gsDefName.Data();
69 fTitle = title ? title : gsDefTitle.Data();
70
71 //
72 // This sets a flag that the list is the owner, which means
73 // that the destructor of the list deletes all it's objects
74 //
75 fContainer = new TOrdCollection;
76 fAutodelete = new TOrdCollection;
77
78 gROOT->GetListOfCleanups()->Add(fContainer);
79 gROOT->GetListOfCleanups()->Add(fAutodelete);
80 fContainer->SetBit(kMustCleanup);
81 fAutodelete->SetBit(kMustCleanup);
82}
83
84// --------------------------------------------------------------------------
85//
86// Copy constructor. It copies all entries of the parameter list, but it
87// takes care of, that the automatically created entries are only deleted
88// once. (doesn't copy the list which holds the automatically created
89// entries)
90//
91MParList::MParList(MParList &ts)
92{
93 fContainer->AddAll(ts.fContainer);
94}
95
96// --------------------------------------------------------------------------
97//
98// If the 'IsOwner' bit is set (via SetOwner()) all containers are deleted
99// by the destructor
100//
101MParList::~MParList()
102{
103 //
104 // Case:
105 // 1) MParList is owner of the containers:
106 // All container are stored in fContainer, and become deleted by
107 // 'delete fContainer'. Some of these containers, which were
108 // created automatically are stored in fAutodelete, too. To prevent
109 // double deletion this containers are not deleted by the destructor
110 // of fAutodelete.
111 // 2) MParList is not owner of the containers:
112 // The containers which were Added by AddToList are not touched.
113 // Only the containers which were created automatically are also
114 // automatically deleted.
115 //
116 IsOwner() ? fContainer->SetOwner() : fAutodelete->SetOwner();
117
118 TIter Next(fContainer);
119 TObject *o;
120 while ((o=Next()))
121 if (o->TestBit(kCanDelete))
122 delete fContainer->Remove(o);
123
124 // FIXME? If fContainer is owner do we have to remove the object
125 // from fAutodelete due to the acces when checking for a
126 // garbage collection?
127
128 delete fContainer;
129 delete fAutodelete;
130}
131
132// --------------------------------------------------------------------------
133//
134// If the 'IsOwner' bit is set (via SetOwner()) all containers are deleted
135// by the destructor
136//
137void MParList::SetOwner(Bool_t enable)
138{
139 enable ? SetBit(kIsOwner) : ResetBit(kIsOwner);
140}
141
142// --------------------------------------------------------------------------
143//
144// Set the logging streamer of the parameter list and all contained
145// parameter containers
146//
147void MParList::SetLogStream(MLog *log)
148{
149 fContainer->ForEach(MParContainer, SetLogStream)(log);
150 MParContainer::SetLogStream(log);
151}
152
153void MParList::SetDisplay(MStatusDisplay *d)
154{
155 fContainer->ForEach(MParContainer, SetDisplay)(d);
156 MParContainer::SetDisplay(d);
157}
158
159// --------------------------------------------------------------------------
160//
161// Add a single container to the list.
162//
163// If 'where' is given, the object will be added after this.
164//
165Bool_t MParList::AddToList(MParContainer *cont, MParContainer *where)
166{
167 //
168 // check if the object (you want to add) exists
169 //
170 if (!cont)
171 return kFALSE;
172
173 //
174 // Get Name of new container
175 //
176 const char *name = cont->GetName();
177
178 //
179 // Check if the new container is already existing in the list
180 //
181 const TObject *objn = fContainer->FindObject(name);
182 const TObject *objt = fContainer->FindObject(cont);
183
184 if (objn || objt)
185 {
186 //
187 // If the container is already in the list ignore it.
188 //
189 if (objt || objn==cont)
190 {
191 *fLog << warn << dbginf << "Warning: Container '" << cont->GetName() << ", 0x" << (void*)cont;
192 *fLog << "' already existing in '" << GetName() << "'... ignoring." << endl;
193 return kTRUE;
194 }
195
196 //
197 // Otherwise add it to the list, but print a warning message
198 //
199 *fLog << warn << dbginf << "Warning: Container with the same name '" << cont->GetName();
200 *fLog << "' already existing in '" << GetName() << "'." << endl;
201 *fLog << "You may not be able to get a pointer to container task by name." << endl;
202 }
203
204 //
205 // check if you want to add the new parameter container somewhere
206 // special (in that case you specify "where")
207 //
208 if (where)
209 {
210 if (!fContainer->FindObject(where))
211 {
212 *fLog << dbginf << "Error: Cannot find parameter container after which the new one should be added!" << endl;
213 return kFALSE;
214 }
215 }
216
217 *fLog << inf << "Adding " << name << " to " << GetName() << "... " << flush;
218
219 cont->SetBit(kMustCleanup);
220 fContainer->Add(cont);
221 *fLog << "Done." << endl;
222
223 return kTRUE;
224}
225
226// --------------------------------------------------------------------------
227//
228// Add all entries of the TObjArray to the list.
229//
230void MParList::AddToList(TObjArray *list)
231{
232 //
233 // check if the object (you want to add) exists
234 //
235 if (!list)
236 return;
237
238 MIter Next(list);
239
240 MParContainer *cont = NULL;
241 while ((cont=Next()))
242 {
243 cont->SetBit(kMustCleanup);
244 AddToList(cont);
245 }
246}
247
248// --------------------------------------------------------------------------
249//
250// Find an object with the same name in the list and replace it with
251// the new one. If the kIsOwner flag is set and the object was not
252// created automatically, the object is deleted.
253//
254Bool_t MParList::Replace(MParContainer *cont)
255{
256 //
257 // check if the object (you want to add) exists
258 //
259 if (!cont)
260 return kFALSE;
261
262 TObject *obj = FindObject(cont->GetName());
263 if (!obj)
264 {
265 *fLog << warn << "No object with the same name '";
266 *fLog << cont->GetName() << "' in list... adding." << endl;
267 return AddToList(cont);
268 }
269
270 fContainer->Remove(obj);
271
272 if (IsOwner() && !fAutodelete->FindObject(obj))
273 delete obj;
274
275 *fLog << inf << "MParContainer '" << cont->GetName() << "' found and replaced..." << endl;
276
277 return AddToList(cont);
278}
279
280// --------------------------------------------------------------------------
281//
282// Find an object with the same name in the list and remove it.
283// If the kIsOwner flag is set and the object was not created
284// automatically, the object is deleted.
285//
286void MParList::Remove(MParContainer *cont)
287{
288 //
289 // check if the object (you want to add) exists
290 //
291 if (!cont)
292 return;
293
294 TObject *obj = fContainer->Remove(cont);
295 if (!obj)
296 {
297 *fLog << warn << "Object not found in list..." << endl;
298 return;
299 }
300
301 *fLog << inf << "MParContainer '" << cont->GetName() << "' removed..." << endl;
302
303 if (IsOwner() && !fAutodelete->FindObject(obj))
304 delete obj;
305}
306
307// --------------------------------------------------------------------------
308//
309// Find an object in the list.
310// 'name' is the name of the object you are searching for.
311//
312TObject *MParList::FindObject(const char *name) const
313{
314 return fContainer->FindObject(name);
315}
316
317// --------------------------------------------------------------------------
318//
319// check if the object is in the list or not
320//
321TObject *MParList::FindObject(const TObject *obj) const
322{
323 return fContainer->FindObject(obj);
324}
325
326// --------------------------------------------------------------------------
327//
328// Find an object in the list and check for the correct inheritance.
329// 'name' is the name of the object you are searching for.
330//
331// In words: Find object name and check whether it inherits from classname
332//
333TObject *MParList::FindObject(const char *name, const char *classname) const
334{
335 TObject *obj = fContainer->FindObject(name);
336
337 if (!obj)
338 return NULL;
339
340 if (obj->InheritsFrom(classname))
341 return obj;
342
343 *fLog << dbginf << warn << "Found object '" << name << "' doesn't ";
344 *fLog << "inherit from " << "'" << classname << "'" << endl;
345 return NULL;
346}
347
348// --------------------------------------------------------------------------
349//
350// check if the object is in the list or not and check for the correct
351// inheritance
352//
353TObject *MParList::FindObject(const TObject *obj, const char *classname) const
354{
355 TObject *nobj = fContainer->FindObject(obj);
356
357 if (!nobj)
358 return NULL;
359
360 if (nobj->InheritsFrom(classname))
361 return nobj;
362
363 *fLog << dbginf << warn << "Found object '" << nobj->GetName() << "' ";
364 *fLog << "doesn't inherit from " << "'" << classname << "'" << endl;
365 return NULL;
366}
367
368// --------------------------------------------------------------------------
369//
370// Searches for the tasklist tlist (default: MTaskList) and returns
371// a task with the given name found in this list. If one of both isn't
372// found NULL is returned
373//
374MTask *MParList::FindTask(const char *name, const char *tlist) const
375{
376 TObject *l = FindObject(tlist, "MTaskList");
377 return (MTask*)(l ? l->FindObject(name) : NULL);
378}
379
380// --------------------------------------------------------------------------
381//
382// returns the ClassName without anything which is behind that last ';' in
383// string.
384//
385TString MParList::GetClassName(const char *classname)
386{
387 TString cname(classname);
388 const char *semicolon = strrchr(cname, ';');
389
390 if (semicolon)
391 cname.Remove(semicolon-cname);
392
393 return cname;
394}
395
396// --------------------------------------------------------------------------
397//
398// returns the ObjectName. It is created from a class and object name.
399// If no object name is given the objectname is the same than the
400// class name. Leading dots are removed from the object name
401//
402TString MParList::GetObjectName(const char *classname, const char *objname)
403{
404 TString cname(classname);
405 const char *semicolon = strrchr(cname, ';');
406
407 TString oname(objname ? objname : classname);
408
409 if (semicolon)
410 {
411 //
412 // Remove leading dots from objectname (eg. "MMcTrig;5.")
413 //
414 Int_t sz = oname.Sizeof()-2;
415
416 while (sz>=0 && oname[sz]=='.')
417 oname.Remove(sz--);
418 }
419 return oname;
420}
421
422// --------------------------------------------------------------------------
423//
424// Find an object in the list.
425// 'name' is the name of the object you are searching for.
426// If the object doesn't exist we try to create one from the
427// dictionary. If this isn't possible NULL is returned.
428//
429// An object which was created automatically is deleted automatically in
430// the destructor of the parameter list, too. This means, that if an
431// object should survive (eg. Histograms) you MUST create it by yourself
432// and add it to the parameter list.
433//
434// By default (you don't specify an object name) the object name is
435// the same as the classname
436//
437// If the classname (default classname) is of the structure
438// "Name;something" - containing a semicolon - evarything which is
439// after the last appearance of a semicolon is stripped to get the
440// Name of the Class. Normally this is used to number your objects.
441// "Name;1", "Name;2", ... If a semicolon is detected leading dots
442// are stripped from the object-name (eg. "name;5.")
443//
444// In words: Create object of type classname and set its name to objname.
445// If an object with objname already exists return it.
446//
447MParContainer *MParList::FindCreateObj(const char *classname, const char *objname)
448{
449 //
450 // If now object name (name of the object to identify it in the
451 // List) is given use it's classname as the objectname
452 //
453
454 //
455 // Check if the classname is a 'numbered' name (like: "MTime;2")
456 // if so strip the number from the classname.
457 //
458 // Becareful: We check for the last occurance of a ';' only and we
459 // also don't check if a number follows or something else.
460 //
461 // Rem: I use a TString to make the code more readyble and to get
462 // the new object deleted automatically
463 //
464 TString cname = GetClassName(classname);
465 TString oname = GetObjectName(classname, objname);
466
467 //
468 // Try to find a object with this object name which is already
469 // in the List. If we can find one we are done.
470 //
471 MParContainer *pcont = (MParContainer*)FindObject(oname);
472
473 if (pcont)
474 {
475 if (pcont->InheritsFrom(cname))
476 return pcont;
477
478 *fLog << err << "Warning: Object '" << oname << "' found in list doesn't inherit from " << cname << "." << endl;
479 return NULL;
480 }
481
482 //
483 // if object is not existing in the list try to create one
484 //
485 *fLog << inf << "Object '" << oname << "' [" << cname << "] not yet in " << GetName() << "... creating." << endl;
486
487 //
488 // try to get class from root environment
489 //
490 TClass *cls = gROOT->GetClass(cname);
491 Int_t rc = 0;
492 if (!cls)
493 rc =1;
494 else
495 {
496 if (!cls->Property())
497 rc = 5;
498 if (!cls->Size())
499 rc = 4;
500 if (!cls->IsLoaded())
501 rc = 3;
502 if (!cls->HasDefaultConstructor())
503 rc = 2;
504 }
505
506 if (rc)
507 {
508 *fLog << err << dbginf << "Cannot create new instance of class '" << cname << "': ";
509 switch (rc)
510 {
511 case 1:
512 *fLog << "gROOT->GetClass() returned NULL." << endl;
513 return NULL;
514 case 2:
515 *fLog << "no default constructor." << endl;
516 return NULL;
517 case 3:
518 *fLog << "not loaded." << endl;
519 return NULL;
520 case 4:
521 *fLog << "zero size." << endl;
522 return NULL;
523 case 5:
524 *fLog << "no property." << endl;
525 return NULL;
526 }
527 }
528
529 if (!cls->InheritsFrom(MParContainer::Class()))
530 {
531 *fLog << " - Class doesn't inherit from MParContainer." << endl;
532 return NULL;
533 }
534
535 //
536 // create the parameter container of the the given class type
537 //
538 pcont = (MParContainer*)cls->New();
539 if (!pcont)
540 {
541 *fLog << " - Class has no default constructor." << endl;
542 *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
543 return NULL;
544 }
545
546 //
547 // Set the name of the container
548 //
549 pcont->SetName(oname);
550
551 //
552 // Now add the object to the parameter list
553 //
554 AddToList(pcont);
555
556 //
557 // The object was automatically created. This makes sure, that such an
558 // object is deleted together with the list
559 //
560 fAutodelete->Add(pcont);
561
562 //
563 // Find an object in the list.
564 // 'name' is the name of the object you are searching for.
565 //
566 return pcont;
567}
568
569// --------------------------------------------------------------------------
570//
571// print some information about the current status of MParList
572//
573void MParList::Print(Option_t *t) const
574{
575 *fLog << all << underline << GetDescriptor() << ":" << endl;
576
577 MParContainer *obj = NULL;
578 MIter Next(fContainer);
579 while ((obj=Next()))
580 {
581 *fLog << " " << obj->GetDescriptor();
582 if (fAutodelete->FindObject(obj))
583 *fLog << " <autodel>";
584 *fLog << endl;
585 }
586 *fLog << endl;
587}
588
589// --------------------------------------------------------------------------
590//
591// Sets the flags off all containers in the list (and the list
592// itself) to unchanged
593//
594void MParList::SetReadyToSave(Bool_t flag)
595{
596 fContainer->ForEach(MParContainer, SetReadyToSave)(flag);
597 MParContainer::SetReadyToSave(flag);
598}
599
600// --------------------------------------------------------------------------
601//
602// Reset all containers in the list
603//
604void MParList::Reset()
605{
606 fContainer->ForEach(MParContainer, Reset)();
607}
608
609// --------------------------------------------------------------------------
610//
611// This finds numbered objects. The objects are returned in a copy of a
612// TObjArray.
613//
614// If from only is given (or to=0) object are assumed numbered
615// from 1 to from.
616//
617TObjArray MParList::FindObjectList(const char *name, UInt_t first, const UInt_t last) const
618{
619 TObjArray list;
620
621 if (first>0 && last<first)
622 {
623 *fLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
624 return list;
625 }
626
627 const UInt_t len = strlen(name);
628
629 char *auxname = new char[len+7];
630 strcpy(auxname, name);
631
632 if (first==0 && last!=0)
633 first = 1;
634
635 //
636 // If only 'from' is specified the number of entries are ment
637 //
638 for (UInt_t i=first; i<=last; i++)
639 {
640 if (first!=0 || last!=0)
641 sprintf(auxname+len, ";%d", i);
642
643 TObject *obj = FindObject(auxname);
644 if (!obj)
645 continue;
646
647 list.AddLast(obj);
648 }
649 delete auxname;
650
651 return list;
652}
653
654// --------------------------------------------------------------------------
655//
656// This finds numbered objects. The objects are returned in a copy of a
657// TObjArray. If one of the objects doesn't exist it is created from the
658// meaning of cname and oname (s. FindCreateObj)
659//
660// If from only is given (or to=0) object are assumed numbered
661// from 1 to from.
662//
663TObjArray MParList::FindCreateObjList(const char *cname, UInt_t first, const UInt_t last, const char *oname)
664{
665 TObjArray list;
666
667 if (first>0 && last<first)
668 {
669 *fLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
670 return list;
671 }
672
673 const UInt_t len = strlen(cname);
674
675 char *auxname = new char[len+7];
676 strcpy(auxname, cname);
677
678 //
679 // If only 'from' is specified the number of entries are ment
680 //
681 if (first==0 && last!=0)
682 first = 1;
683
684 for (UInt_t i=first; i<=last; i++)
685 {
686 if (first!=0 || last!=0)
687 sprintf(auxname+len, ";%d", i);
688
689 TObject *obj = FindCreateObj(auxname, oname);
690 if (!obj)
691 break;
692
693 list.AddLast(obj);
694 }
695 delete auxname;
696
697 return list;
698}
699
700// --------------------------------------------------------------------------
701//
702// This finds numbered objects. The objects are returned in a copy of a
703// TObjArray. If one of the objects doesn't exist it is created from the
704// meaning of cname and oname (s. FindCreateObj)
705//
706// If from only is given (or to=0) object are assumed numbered
707// from 1 to from.
708//
709// Remark: Because it is static the object are only created and not added to
710// the parameter list. You must also take care of deleting these objects!
711// This function is mainly made for use in root macros. Don't use it in
712// compiled programs if you are not 100% sure what you are doing.
713//
714TObjArray MParList::CreateObjList(const char *cname, UInt_t first, const UInt_t last, const char *oname)
715{
716 TObjArray list;
717
718 if (first>0 && last<first)
719 {
720 gLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
721 return list;
722 }
723
724 //
725 // try to get class from root environment
726 //
727 TClass *cls = gROOT->GetClass(cname);
728 if (!cls)
729 {
730 //
731 // if class is not existing in the root environment
732 //
733 gLog << dbginf << "Class '" << cname << "' not existing in dictionary." << endl;
734 return list;
735 }
736
737 const UInt_t len = strlen(cname);
738
739 char *auxname = new char[len+7];
740 strcpy(auxname, cname);
741
742 //
743 // If only 'from' is specified the number of entries are ment
744 //
745 if (first==0 && last!=0)
746 first = 1;
747
748 for (UInt_t i=first; i<=last; i++)
749 {
750 if (first!=0 || last!=0)
751 sprintf(auxname+len, ";%d", i);
752
753 //
754 // create the parameter container of the the given class type
755 //
756 MParContainer *pcont = (MParContainer*)cls->New();
757 if (!pcont)
758 {
759 gLog << err << dbginf << "Cannot create new instance of class '" << cname << "' (Maybe no def. constructor)" << endl;
760 return list;
761 }
762
763 //
764 // Set the name of the container
765 //
766 pcont->SetName(auxname);
767
768 //
769 // Add new object to the return list
770 //
771 list.AddLast(pcont);
772 }
773 delete auxname;
774
775 return list;
776}
777
778void MParList::SavePrimitive(ofstream &out, Option_t *o)
779{
780 Bool_t saved = IsSavedAsPrimitive();
781
782 MParContainer::SavePrimitive(out);
783
784 MIter Next(fContainer);
785
786 MParContainer *cont = NULL;
787 while ((cont=Next()))
788 {
789 //
790 // Because it was automatically created don't store its primitive
791 // I guess it will be automatically created again
792 //
793 if (fAutodelete->FindObject(cont) || cont->IsSavedAsPrimitive())
794 continue;
795
796 cont->SavePrimitive(out, "");
797
798 out << " " << GetUniqueName() << ".";
799 out << (cont->InheritsFrom("MTaskList") && saved ? "Replace" : "AddToList");
800 out << "(&" << cont->GetUniqueName() << ");" << endl << endl;
801 }
802}
803
804// --------------------------------------------------------------------------
805//
806// Implementation of SavePrimitive. Used to write the call to a constructor
807// to a macro. In the original root implementation it is used to write
808// gui elements to a macro-file.
809//
810void MParList::StreamPrimitive(ofstream &out) const
811{
812 out << " MParList " << GetUniqueName();
813 if (fName!=gsDefName || fTitle!=gsDefTitle)
814 {
815 out << "(\"" << fName << "\"";
816 if (fTitle!=gsDefTitle)
817 out << ", \"" << fTitle << "\"";
818 out <<")";
819 }
820 out << ";" << endl << endl;
821}
822
823// --------------------------------------------------------------------------
824//
825// Adds one TNamed object per object in the list. The TNamed object must
826// be deleted by the user.
827//
828void MParList::GetNames(TObjArray &arr) const
829{
830 MParContainer::GetNames(arr);
831 fContainer->ForEach(MParContainer, GetNames)(arr);
832}
833
834// --------------------------------------------------------------------------
835//
836// Sets name and title of each object in the list from the objects in
837// the array.
838//
839void MParList::SetNames(TObjArray &arr)
840{
841 MParContainer::SetNames(arr);
842 fContainer->ForEach(MParContainer, SetNames)(arr);
843}
844
845// --------------------------------------------------------------------------
846//
847// Read the contents/setup of a parameter container/task from a TEnv
848// instance (steering card/setup file).
849// The key to search for in the file should be of the syntax:
850// prefix.vname
851// While vname is a name which is specific for a single setup date
852// (variable) of this container and prefix is something like:
853// evtloopname.name
854// While name is the name of the containers/tasks in the parlist/tasklist
855//
856// eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
857// Job4.MImgCleanStd.CleaningLevel2: 2.5
858//
859// If this cannot be found the next step is to search for
860// MImgCleanStd.CleaningLevel1: 3.0
861// And if this doesn't exist, too, we search for:
862// CleaningLevel1: 3.0
863//
864// Warning: The programmer is responsible for the names to be unique in
865// all Mars classes.
866//
867Int_t MParList::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
868{
869 if (print)
870 *fLog << all << "MParList::ReadEnv: " << prefix << " (" << (int)print << ")" << endl;
871
872 MParContainer *cont = NULL;
873
874 MIter Next(fContainer);
875 while ((cont=Next()))
876 {
877 if (cont->InheritsFrom("MTaskList"))
878 {
879 if (cont->ReadEnv(env, prefix, print)==kERROR)
880 return kERROR;
881 continue;
882 }
883
884 if (cont->TestEnv(env, prefix, print)==kERROR)
885 return kERROR;
886 }
887
888 return kTRUE;
889}
890
891// --------------------------------------------------------------------------
892//
893// Write the contents/setup of a parameter container/task to a TEnv
894// instance (steering card/setup file).
895// The key to search for in the file should be of the syntax:
896// prefix.vname
897// While vname is a name which is specific for a single setup date
898// (variable) of this container and prefix is something like:
899// evtloopname.name
900// While name is the name of the containers/tasks in the parlist/tasklist
901//
902// eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
903// Job4.MImgCleanStd.CleaningLevel2: 2.5
904//
905// If this cannot be found the next step is to search for
906// MImgCleanStd.CleaningLevel1: 3.0
907// And if this doesn't exist, too, we search for:
908// CleaningLevel1: 3.0
909//
910// Warning: The programmer is responsible for the names to be unique in
911// all Mars classes.
912//
913Bool_t MParList::WriteEnv(TEnv &env, TString prefix, Bool_t print) const
914{
915 MParContainer *cont = NULL;
916
917 MIter Next(fContainer);
918 while ((cont=Next()))
919 if (!cont->WriteEnv(env, prefix, print))
920 return kFALSE;
921 return kTRUE;
922}
923
924// --------------------------------------------------------------------------
925//
926// Can be used to create an iterator over all containers, eg:
927// MParList plist;
928// TIter Next(plist); // Be aware: Use a object here rather than a pointer!
929// TObject *o=0;
930// while ((o=Next()))
931// {
932// [...]
933// }
934//
935MParList::operator TIterator*() const
936{
937 return new TOrdCollectionIter(fContainer);
938}
Note: See TracBrowser for help on using the repository browser.