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

Last change on this file since 4379 was 3568, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 27.3 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//
331// In words: Find object name and check whether it inherits from classname
332//
333TObject *MParList::FindObject(const char *name, const char *classname) const
334{
335 TObject *obj = fContainer->FindObject(name);
336
337 if (!obj)
338 return NULL;
339
340 if (obj->InheritsFrom(classname))
341 return obj;
342
343 *fLog << dbginf << warn << "Found object '" << name << "' doesn't ";
344 *fLog << "inherit from " << "'" << classname << "'" << endl;
345 return NULL;
346}
347
348// --------------------------------------------------------------------------
349//
350// check if the object is in the list or not and check for the correct
351// inheritance
352//
353TObject *MParList::FindObject(const TObject *obj, const char *classname) const
354{
355 TObject *nobj = fContainer->FindObject(obj);
356
357 if (!nobj)
358 return NULL;
359
360 if (nobj->InheritsFrom(classname))
361 return nobj;
362
363 *fLog << dbginf << warn << "Found object '" << nobj->GetName() << "' ";
364 *fLog << "doesn't inherit from " << "'" << classname << "'" << endl;
365 return NULL;
366}
367
368// --------------------------------------------------------------------------
369//
370// returns the ClassName without anything which is behind that last ';' in
371// string.
372//
373TString MParList::GetClassName(const char *classname)
374{
375 TString cname(classname);
376 const char *semicolon = strrchr(cname, ';');
377
378 if (semicolon)
379 cname.Remove(semicolon-cname);
380
381 return cname;
382}
383
384// --------------------------------------------------------------------------
385//
386// returns the ObjectName. It is created from a class and object name.
387// If no object name is given the objectname is the same than the
388// class name. Leading dots are removed from the object name
389//
390TString MParList::GetObjectName(const char *classname, const char *objname)
391{
392 TString cname(classname);
393 const char *semicolon = strrchr(cname, ';');
394
395 TString oname(objname ? objname : classname);
396
397 if (semicolon)
398 {
399 //
400 // Remove leading dots from objectname (eg. "MMcTrig;5.")
401 //
402 Int_t sz = oname.Sizeof()-2;
403
404 while (sz>=0 && oname[sz]=='.')
405 oname.Remove(sz--);
406 }
407 return oname;
408}
409
410// --------------------------------------------------------------------------
411//
412// Find an object in the list.
413// 'name' is the name of the object you are searching for.
414// If the object doesn't exist we try to create one from the
415// dictionary. If this isn't possible NULL is returned.
416//
417// An object which was created automatically is deleted automatically in
418// the destructor of the parameter list, too. This means, that if an
419// object should survive (eg. Histograms) you MUST create it by yourself
420// and add it to the parameter list.
421//
422// By default (you don't specify an object name) the object name is
423// the same as the classname
424//
425// If the classname (default classname) is of the structure
426// "Name;something" - containing a semicolon - evarything which is
427// after the last appearance of a semicolon is stripped to get the
428// Name of the Class. Normally this is used to number your objects.
429// "Name;1", "Name;2", ... If a semicolon is detected leading dots
430// are stripped from the object-name (eg. "name;5.")
431//
432// In words: Create object of type classname and set its name to objname.
433// If an object with objname already exists return it.
434//
435MParContainer *MParList::FindCreateObj(const char *classname, const char *objname)
436{
437 //
438 // If now object name (name of the object to identify it in the
439 // List) is given use it's classname as the objectname
440 //
441
442 //
443 // Check if the classname is a 'numbered' name (like: "MTime;2")
444 // if so strip the number from the classname.
445 //
446 // Becareful: We check for the last occurance of a ';' only and we
447 // also don't check if a number follows or something else.
448 //
449 // Rem: I use a TString to make the code more readyble and to get
450 // the new object deleted automatically
451 //
452 TString cname = GetClassName(classname);
453 TString oname = GetObjectName(classname, objname);
454
455 //
456 // Try to find a object with this object name which is already
457 // in the List. If we can find one we are done.
458 //
459 MParContainer *pcont = (MParContainer*)FindObject(oname);
460
461 if (pcont)
462 {
463 if (pcont->InheritsFrom(cname))
464 return pcont;
465
466 *fLog << err << "Warning: Object '" << oname << "' found in list doesn't inherit from " << cname << "." << endl;
467 return NULL;
468 }
469
470 //
471 // if object is not existing in the list try to create one
472 //
473 *fLog << inf << "Object '" << oname << "' [" << cname << "] not yet in " << GetName() << "... creating." << endl;
474
475 //
476 // try to get class from root environment
477 //
478 TClass *cls = gROOT->GetClass(cname);
479 Int_t rc = 0;
480 if (!cls)
481 rc =1;
482 else
483 {
484 if (!cls->Property())
485 rc = 5;
486 if (!cls->Size())
487 rc = 4;
488 if (!cls->IsLoaded())
489 rc = 3;
490 if (!cls->HasDefaultConstructor())
491 rc = 2;
492 }
493
494 if (rc)
495 {
496 *fLog << err << dbginf << "Cannot create new instance of class '" << cname << "': ";
497 switch (rc)
498 {
499 case 1:
500 *fLog << "gROOT->GetClass() returned NULL." << endl;
501 return NULL;
502 case 2:
503 *fLog << "no default constructor." << endl;
504 return NULL;
505 case 3:
506 *fLog << "not loaded." << endl;
507 return NULL;
508 case 4:
509 *fLog << "zero size." << endl;
510 return NULL;
511 case 5:
512 *fLog << "no property." << endl;
513 return NULL;
514 }
515 }
516
517 //
518 // create the parameter container of the the given class type
519 //
520 pcont = (MParContainer*)cls->New();
521 if (!pcont)
522 {
523 *fLog << " - Class has no default constructor." << endl;
524 *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
525 return NULL;
526 }
527
528 //
529 // Set the name of the container
530 //
531 pcont->SetName(oname);
532
533 //
534 // Now add the object to the parameter list
535 //
536 AddToList(pcont);
537
538 //
539 // The object was automatically created. This makes sure, that such an
540 // object is deleted together with the list
541 //
542 fAutodelete->Add(pcont);
543
544 //
545 // Find an object in the list.
546 // 'name' is the name of the object you are searching for.
547 //
548 return pcont;
549}
550
551// --------------------------------------------------------------------------
552//
553// print some information about the current status of MParList
554//
555void MParList::Print(Option_t *t) const
556{
557 *fLog << all << underline << GetDescriptor() << ":" << endl;
558
559 MParContainer *obj = NULL;
560 MIter Next(fContainer);
561 while ((obj=Next()))
562 {
563 *fLog << " " << obj->GetDescriptor();
564 if (fAutodelete->FindObject(obj))
565 *fLog << " <autodel>";
566 *fLog << endl;
567 }
568 *fLog << endl;
569}
570
571// --------------------------------------------------------------------------
572//
573// Sets the flags off all containers in the list (and the list
574// itself) to unchanged
575//
576void MParList::SetReadyToSave(Bool_t flag)
577{
578 fContainer->ForEach(MParContainer, SetReadyToSave)(flag);
579 MParContainer::SetReadyToSave(flag);
580}
581
582// --------------------------------------------------------------------------
583//
584// Reset all containers in the list
585//
586void MParList::Reset()
587{
588 fContainer->ForEach(MParContainer, Reset)();
589}
590
591// --------------------------------------------------------------------------
592//
593// This finds numbered objects. The objects are returned in a copy of a
594// TObjArray.
595//
596// If from only is given (or to=0) object are assumed numbered
597// from 1 to from.
598//
599TObjArray MParList::FindObjectList(const char *name, UInt_t first, const UInt_t last) const
600{
601 TObjArray list;
602
603 if (first>0 && last<first)
604 {
605 *fLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
606 return list;
607 }
608
609 const UInt_t len = strlen(name);
610
611 char *auxname = new char[len+7];
612 strcpy(auxname, name);
613
614 if (first==0 && last!=0)
615 first = 1;
616
617 //
618 // If only 'from' is specified the number of entries are ment
619 //
620 for (UInt_t i=first; i<=last; i++)
621 {
622 if (first!=0 || last!=0)
623 sprintf(auxname+len, ";%d", i);
624
625 TObject *obj = FindObject(auxname);
626 if (!obj)
627 continue;
628
629 list.AddLast(obj);
630 }
631 delete auxname;
632
633 return list;
634}
635
636// --------------------------------------------------------------------------
637//
638// This finds numbered objects. The objects are returned in a copy of a
639// TObjArray. If one of the objects doesn't exist it is created from the
640// meaning of cname and oname (s. FindCreateObj)
641//
642// If from only is given (or to=0) object are assumed numbered
643// from 1 to from.
644//
645TObjArray MParList::FindCreateObjList(const char *cname, UInt_t first, const UInt_t last, const char *oname)
646{
647 TObjArray list;
648
649 if (first>0 && last<first)
650 {
651 *fLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
652 return list;
653 }
654
655 const UInt_t len = strlen(cname);
656
657 char *auxname = new char[len+7];
658 strcpy(auxname, cname);
659
660 //
661 // If only 'from' is specified the number of entries are ment
662 //
663 if (first==0 && last!=0)
664 first = 1;
665
666 for (UInt_t i=first; i<=last; i++)
667 {
668 if (first!=0 || last!=0)
669 sprintf(auxname+len, ";%d", i);
670
671 TObject *obj = FindCreateObj(auxname, oname);
672 if (!obj)
673 break;
674
675 list.AddLast(obj);
676 }
677 delete auxname;
678
679 return list;
680}
681
682// --------------------------------------------------------------------------
683//
684// This finds numbered objects. The objects are returned in a copy of a
685// TObjArray. If one of the objects doesn't exist it is created from the
686// meaning of cname and oname (s. FindCreateObj)
687//
688// If from only is given (or to=0) object are assumed numbered
689// from 1 to from.
690//
691// Remark: Because it is static the object are only created and not added to
692// the parameter list. You must also take care of deleting these objects!
693// This function is mainly made for use in root macros. Don't use it in
694// compiled programs if you are not 100% sure what you are doing.
695//
696TObjArray MParList::CreateObjList(const char *cname, UInt_t first, const UInt_t last, const char *oname)
697{
698 TObjArray list;
699
700 if (first>0 && last<first)
701 {
702 gLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
703 return list;
704 }
705
706 //
707 // try to get class from root environment
708 //
709 TClass *cls = gROOT->GetClass(cname);
710 if (!cls)
711 {
712 //
713 // if class is not existing in the root environment
714 //
715 gLog << dbginf << "Class '" << cname << "' not existing in dictionary." << endl;
716 return list;
717 }
718
719 const UInt_t len = strlen(cname);
720
721 char *auxname = new char[len+7];
722 strcpy(auxname, cname);
723
724 //
725 // If only 'from' is specified the number of entries are ment
726 //
727 if (first==0 && last!=0)
728 first = 1;
729
730 for (UInt_t i=first; i<=last; i++)
731 {
732 if (first!=0 || last!=0)
733 sprintf(auxname+len, ";%d", i);
734
735 //
736 // create the parameter container of the the given class type
737 //
738 MParContainer *pcont = (MParContainer*)cls->New();
739 if (!pcont)
740 {
741 gLog << err << dbginf << "Cannot create new instance of class '" << cname << "' (Maybe no def. constructor)" << endl;
742 return list;
743 }
744
745 //
746 // Set the name of the container
747 //
748 pcont->SetName(auxname);
749
750 //
751 // Add new object to the return list
752 //
753 list.AddLast(pcont);
754 }
755 delete auxname;
756
757 return list;
758}
759
760void MParList::SavePrimitive(ofstream &out, Option_t *o)
761{
762 Bool_t saved = IsSavedAsPrimitive();
763
764 MParContainer::SavePrimitive(out);
765
766 MIter Next(fContainer);
767
768 MParContainer *cont = NULL;
769 while ((cont=Next()))
770 {
771 //
772 // Because it was automatically created don't store its primitive
773 // I guess it will be automatically created again
774 //
775 if (fAutodelete->FindObject(cont) || cont->IsSavedAsPrimitive())
776 continue;
777
778 cont->SavePrimitive(out, "");
779
780 out << " " << GetUniqueName() << ".";
781 out << (cont->InheritsFrom("MTaskList") && saved ? "Replace" : "AddToList");
782 out << "(&" << cont->GetUniqueName() << ");" << endl << endl;
783 }
784}
785
786// --------------------------------------------------------------------------
787//
788// Implementation of SavePrimitive. Used to write the call to a constructor
789// to a macro. In the original root implementation it is used to write
790// gui elements to a macro-file.
791//
792void MParList::StreamPrimitive(ofstream &out) const
793{
794 out << " MParList " << GetUniqueName();
795 if (fName!=gsDefName || fTitle!=gsDefTitle)
796 {
797 out << "(\"" << fName << "\"";
798 if (fTitle!=gsDefTitle)
799 out << ", \"" << fTitle << "\"";
800 out <<")";
801 }
802 out << ";" << endl << endl;
803}
804
805// --------------------------------------------------------------------------
806//
807// Adds one TNamed object per object in the list. The TNamed object must
808// be deleted by the user.
809//
810void MParList::GetNames(TObjArray &arr) const
811{
812 MParContainer::GetNames(arr);
813 fContainer->ForEach(MParContainer, GetNames)(arr);
814}
815
816// --------------------------------------------------------------------------
817//
818// Sets name and title of each object in the list from the objects in
819// the array.
820//
821void MParList::SetNames(TObjArray &arr)
822{
823 MParContainer::SetNames(arr);
824 fContainer->ForEach(MParContainer, SetNames)(arr);
825}
826
827// --------------------------------------------------------------------------
828//
829// Read the contents/setup of a parameter container/task from a TEnv
830// instance (steering card/setup file).
831// The key to search for in the file should be of the syntax:
832// prefix.vname
833// While vname is a name which is specific for a single setup date
834// (variable) of this container and prefix is something like:
835// evtloopname.name
836// While name is the name of the containers/tasks in the parlist/tasklist
837//
838// eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
839// Job4.MImgCleanStd.CleaningLevel2: 2.5
840//
841// If this cannot be found the next step is to search for
842// MImgCleanStd.CleaningLevel1: 3.0
843// And if this doesn't exist, too, we search for:
844// CleaningLevel1: 3.0
845//
846// Warning: The programmer is responsible for the names to be unique in
847// all Mars classes.
848//
849Bool_t MParList::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
850{
851 if (print)
852 *fLog << all << "MParList::ReadEnv: " << prefix << " (" << (int)print << ")" << endl;
853
854 MParContainer *cont = NULL;
855
856 MIter Next(fContainer);
857 while ((cont=Next()))
858 {
859 if (cont->InheritsFrom("MTaskList"))
860 {
861 if (cont->ReadEnv(env, prefix, print)==kERROR)
862 return kERROR;
863 continue;
864 }
865
866 // Check For: Job4.ContainerName.Varname
867 if (print)
868 *fLog << all << "Testing: " << prefix+cont->GetName() << endl;
869 Bool_t rc = cont->ReadEnv(env, prefix+cont->GetName(), print);
870 if (rc==kERROR)
871 return kERROR;
872 if (rc==kTRUE)
873 continue;
874
875 // Check For: Job4.MClassName.Varname
876 if (print)
877 *fLog << all << "Testing: " << prefix+cont->ClassName() << endl;
878 rc = cont->ReadEnv(env, prefix+cont->ClassName(), print);
879 if (rc==kERROR)
880 return kERROR;
881 if (rc==kTRUE)
882 continue;
883
884 // Check For: ContainerName.Varname
885 if (print)
886 *fLog << all << "Testing: " << cont->GetName() << endl;
887 rc = cont->ReadEnv(env, cont->GetName(), print);
888 if (rc==kERROR)
889 return kERROR;
890 if (rc==kTRUE)
891 continue;
892
893 // Check For: MClassName.Varname
894 if (print)
895 *fLog << all << "Testing: " << cont->ClassName() << endl;
896 rc = cont->ReadEnv(env, cont->ClassName(), print);
897 if (rc==kERROR)
898 return kERROR;
899 if (rc==kTRUE)
900 continue;
901 }
902
903 return kTRUE;
904}
905
906// --------------------------------------------------------------------------
907//
908// Write the contents/setup of a parameter container/task to a TEnv
909// instance (steering card/setup file).
910// The key to search for in the file should be of the syntax:
911// prefix.vname
912// While vname is a name which is specific for a single setup date
913// (variable) of this container and prefix is something like:
914// evtloopname.name
915// While name is the name of the containers/tasks in the parlist/tasklist
916//
917// eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
918// Job4.MImgCleanStd.CleaningLevel2: 2.5
919//
920// If this cannot be found the next step is to search for
921// MImgCleanStd.CleaningLevel1: 3.0
922// And if this doesn't exist, too, we search for:
923// CleaningLevel1: 3.0
924//
925// Warning: The programmer is responsible for the names to be unique in
926// all Mars classes.
927//
928Bool_t MParList::WriteEnv(TEnv &env, TString prefix, Bool_t print) const
929{
930 MParContainer *cont = NULL;
931
932 MIter Next(fContainer);
933 while ((cont=Next()))
934 if (!cont->WriteEnv(env, prefix, print))
935 return kFALSE;
936 return kTRUE;
937}
Note: See TracBrowser for help on using the repository browser.