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

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