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

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