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

Last change on this file since 8042 was 7808, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 28.9 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 << " - Class doesn't inherit from MParContainer." << endl;
597 return NULL;
598 }
599
600 //
601 // create the parameter container of the the given class type
602 //
603 pcont = (MParContainer*)cls->New();
604 if (!pcont)
605 {
606 *fLog << " - Class has no default constructor." << endl;
607 *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
608 return NULL;
609 }
610
611 //
612 // Set the name of the container
613 //
614 pcont->SetName(oname);
615
616 //
617 // Now add the object to the parameter list
618 //
619 AddToList(pcont);
620
621 //
622 // The object was automatically created. This makes sure, that such an
623 // object is deleted together with the list
624 //
625 fAutodelete->Add(pcont);
626
627 //
628 // Find an object in the list.
629 // 'name' is the name of the object you are searching for.
630 //
631 return pcont;
632}
633
634// --------------------------------------------------------------------------
635//
636// print some information about the current status of MParList
637//
638void MParList::Print(Option_t *) const
639{
640 *fLog << all << underline << GetDescriptor() << ":" << endl;
641
642 MParContainer *obj = NULL;
643 MIter Next(fContainer);
644 while ((obj=Next()))
645 {
646 *fLog << " " << obj->GetDescriptor();
647 if (fAutodelete->FindObject(obj))
648 *fLog << " <autodel>";
649 *fLog << endl;
650 }
651 *fLog << endl;
652}
653
654// --------------------------------------------------------------------------
655//
656// Sets the flags off all containers in the list (and the list
657// itself) to unchanged
658//
659void MParList::SetReadyToSave(Bool_t flag)
660{
661 fContainer->R__FOR_EACH(MParContainer, SetReadyToSave)(flag);
662 MParContainer::SetReadyToSave(flag);
663}
664
665// --------------------------------------------------------------------------
666//
667// Reset all containers in the list
668//
669void MParList::Reset()
670{
671 fContainer->R__FOR_EACH(MParContainer, Reset)();
672}
673
674// --------------------------------------------------------------------------
675//
676// This finds numbered objects. The objects are returned in a copy of a
677// TObjArray.
678//
679// If from only is given (or to=0) object are assumed numbered
680// from 1 to from.
681//
682TObjArray MParList::FindObjectList(const char *name, UInt_t first, const UInt_t last) const
683{
684 TObjArray list;
685
686 if (first>0 && last<first)
687 {
688 *fLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
689 return list;
690 }
691
692 const UInt_t len = strlen(name);
693
694 char *auxname = new char[len+7];
695 strcpy(auxname, name);
696
697 if (first==0 && last!=0)
698 first = 1;
699
700 //
701 // If only 'from' is specified the number of entries are ment
702 //
703 for (UInt_t i=first; i<=last; i++)
704 {
705 if (first!=0 || last!=0)
706 sprintf(auxname+len, ";%d", i);
707
708 TObject *obj = FindObject(auxname);
709 if (!obj)
710 continue;
711
712 list.AddLast(obj);
713 }
714 delete auxname;
715
716 return list;
717}
718
719// --------------------------------------------------------------------------
720//
721// This finds numbered objects. The objects are returned in a copy of a
722// TObjArray. If one of the objects doesn't exist it is created from the
723// meaning of cname and oname (s. FindCreateObj)
724//
725// If from only is given (or to=0) object are assumed numbered
726// from 1 to from.
727//
728TObjArray MParList::FindCreateObjList(const char *cname, UInt_t first, const UInt_t last, const char *oname)
729{
730 TObjArray list;
731
732 if (first>0 && last<first)
733 {
734 *fLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
735 return list;
736 }
737
738 const UInt_t len = strlen(cname);
739
740 char *auxname = new char[len+7];
741 strcpy(auxname, cname);
742
743 //
744 // If only 'from' is specified the number of entries are ment
745 //
746 if (first==0 && last!=0)
747 first = 1;
748
749 for (UInt_t i=first; i<=last; i++)
750 {
751 if (first!=0 || last!=0)
752 sprintf(auxname+len, ";%d", i);
753
754 TObject *obj = FindCreateObj(auxname, oname);
755 if (!obj)
756 break;
757
758 list.AddLast(obj);
759 }
760 delete auxname;
761
762 return list;
763}
764
765// --------------------------------------------------------------------------
766//
767// This finds numbered objects. The objects are returned in a copy of a
768// TObjArray. If one of the objects doesn't exist it is created from the
769// meaning of cname and oname (s. FindCreateObj)
770//
771// If from only is given (or to=0) object are assumed numbered
772// from 1 to from.
773//
774// Remark: Because it is static the object are only created and not added to
775// the parameter list. You must also take care of deleting these objects!
776// This function is mainly made for use in root macros. Don't use it in
777// compiled programs if you are not 100% sure what you are doing.
778//
779TObjArray MParList::CreateObjList(const char *cname, UInt_t first, const UInt_t last, const char *)
780{
781 TObjArray list;
782
783 if (first>0 && last<first)
784 {
785 gLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
786 return list;
787 }
788
789 //
790 // try to get class from root environment
791 //
792 TClass *cls = gROOT->GetClass(cname);
793 if (!cls)
794 {
795 //
796 // if class is not existing in the root environment
797 //
798 gLog << dbginf << "Class '" << cname << "' not existing in dictionary." << endl;
799 return list;
800 }
801
802 const UInt_t len = strlen(cname);
803
804 char *auxname = new char[len+7];
805 strcpy(auxname, cname);
806
807 //
808 // If only 'from' is specified the number of entries are ment
809 //
810 if (first==0 && last!=0)
811 first = 1;
812
813 for (UInt_t i=first; i<=last; i++)
814 {
815 if (first!=0 || last!=0)
816 sprintf(auxname+len, ";%d", i);
817
818 //
819 // create the parameter container of the the given class type
820 //
821 MParContainer *pcont = (MParContainer*)cls->New();
822 if (!pcont)
823 {
824 gLog << err << dbginf << "Cannot create new instance of class '" << cname << "' (Maybe no def. constructor)" << endl;
825 return list;
826 }
827
828 //
829 // Set the name of the container
830 //
831 pcont->SetName(auxname);
832
833 //
834 // Add new object to the return list
835 //
836 list.AddLast(pcont);
837 }
838 delete auxname;
839
840 return list;
841}
842
843void MParList::SavePrimitive(ostream &out, Option_t *)
844{
845 Bool_t saved = IsSavedAsPrimitive();
846
847 MParContainer::SavePrimitive(out);
848
849 MIter Next(fContainer);
850
851 MParContainer *cont = NULL;
852 while ((cont=Next()))
853 {
854 //
855 // Because it was automatically created don't store its primitive
856 // I guess it will be automatically created again
857 //
858 if (fAutodelete->FindObject(cont) || cont->IsSavedAsPrimitive())
859 continue;
860
861 cont->SavePrimitive(out, "");
862
863 out << " " << GetUniqueName() << ".";
864 out << (cont->InheritsFrom("MTaskList") && saved ? "Replace" : "AddToList");
865 out << "(&" << cont->GetUniqueName() << ");" << endl << endl;
866 }
867}
868
869void MParList::SavePrimitive(ofstream &out, Option_t *o)
870{
871 SavePrimitive(static_cast<ostream&>(out), o);
872}
873
874// --------------------------------------------------------------------------
875//
876// Implementation of SavePrimitive. Used to write the call to a constructor
877// to a macro. In the original root implementation it is used to write
878// gui elements to a macro-file.
879//
880void MParList::StreamPrimitive(ostream &out) const
881{
882 out << " MParList " << GetUniqueName();
883 if (fName!=gsDefName || fTitle!=gsDefTitle)
884 {
885 out << "(\"" << fName << "\"";
886 if (fTitle!=gsDefTitle)
887 out << ", \"" << fTitle << "\"";
888 out <<")";
889 }
890 out << ";" << endl << endl;
891}
892
893// --------------------------------------------------------------------------
894//
895// Adds one TNamed object per object in the list. The TNamed object must
896// be deleted by the user.
897//
898void MParList::GetNames(TObjArray &arr) const
899{
900 MParContainer::GetNames(arr);
901 fContainer->R__FOR_EACH(MParContainer, GetNames)(arr);
902}
903
904// --------------------------------------------------------------------------
905//
906// Sets name and title of each object in the list from the objects in
907// the array.
908//
909void MParList::SetNames(TObjArray &arr)
910{
911 MParContainer::SetNames(arr);
912 fContainer->R__FOR_EACH(MParContainer, SetNames)(arr);
913}
914
915// --------------------------------------------------------------------------
916//
917// Read the contents/setup of a parameter container/task from a TEnv
918// instance (steering card/setup file).
919// The key to search for in the file should be of the syntax:
920// prefix.vname
921// While vname is a name which is specific for a single setup date
922// (variable) of this container and prefix is something like:
923// evtloopname.name
924// While name is the name of the containers/tasks in the parlist/tasklist
925//
926// eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
927// Job4.MImgCleanStd.CleaningLevel2: 2.5
928//
929// If this cannot be found the next step is to search for
930// MImgCleanStd.CleaningLevel1: 3.0
931// And if this doesn't exist, too, we search for:
932// CleaningLevel1: 3.0
933//
934// Warning: The programmer is responsible for the names to be unique in
935// all Mars classes.
936//
937Int_t MParList::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
938{
939 if (print)
940 *fLog << all << "MParList::ReadEnv: " << prefix << endl;
941
942 MParContainer *cont = NULL;
943
944 MIter Next(fContainer);
945 while ((cont=Next()))
946 {
947 if (cont->InheritsFrom("MTaskList"))
948 {
949 if (cont->ReadEnv(env, prefix, print)==kERROR)
950 return kERROR;
951 continue;
952 }
953
954 if (cont->TestEnv(env, prefix, print)==kERROR)
955 return kERROR;
956 }
957
958 return kTRUE;
959}
960
961// --------------------------------------------------------------------------
962//
963// Write the contents/setup of a parameter container/task to a TEnv
964// instance (steering card/setup file).
965// The key to search for in the file should be of the syntax:
966// prefix.vname
967// While vname is a name which is specific for a single setup date
968// (variable) of this container and prefix is something like:
969// evtloopname.name
970// While name is the name of the containers/tasks in the parlist/tasklist
971//
972// eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
973// Job4.MImgCleanStd.CleaningLevel2: 2.5
974//
975// If this cannot be found the next step is to search for
976// MImgCleanStd.CleaningLevel1: 3.0
977// And if this doesn't exist, too, we search for:
978// CleaningLevel1: 3.0
979//
980// Warning: The programmer is responsible for the names to be unique in
981// all Mars classes.
982//
983Bool_t MParList::WriteEnv(TEnv &env, TString prefix, Bool_t print) const
984{
985 MParContainer *cont = NULL;
986
987 MIter Next(fContainer);
988 while ((cont=Next()))
989 if (!cont->WriteEnv(env, prefix, print))
990 return kFALSE;
991 return kTRUE;
992}
993
994// --------------------------------------------------------------------------
995//
996// Can be used to create an iterator over all containers, eg:
997// MParList plist;
998// TIter Next(plist); // Be aware: Use a object here rather than a pointer!
999// TObject *o=0;
1000// while ((o=Next()))
1001// {
1002// [...]
1003// }
1004//
1005MParList::operator TIterator*() const
1006{
1007 return new TOrdCollectionIter(fContainer);
1008}
Note: See TracBrowser for help on using the repository browser.