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

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