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

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