source: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc@ 2041

Last change on this file since 2041 was 2015, checked in by tbretz, 22 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-2001
21!
22!
23\* ======================================================================== */
24
25
26//////////////////////////////////////////////////////////////////////////////
27// //
28// MEvtLoop //
29// //
30// This class is the core of each event processing. //
31// First you must set the parameter list to use. The parameter list //
32// must contain the task list (MTaskList) to use. The name of the task //
33// list can be specified if you call Eventloop. The standard name is //
34// "MTaskList". The name you specify must match the name of the MTaskList //
35// object. //
36// //
37// If you call Eventloop first all PreProcess functions - with the //
38// parameter list as an argument - of the tasks in the task list are //
39// executed. If one of them returns kFALSE then the execution is stopped. //
40// If the preprocessing was ok. The Process funtion of the tasks are //
41// as long as one function returns kSTOP. Only the tasks which are marked //
42// marked as "All" or with a string which matches the MInputStreamID of //
43// MTaskList are executed. If one tasks returns kCONTINUE the pending //
44// tasks in the list are skipped and the execution in continued with //
45// the first one in the list. //
46// Afterwards the PostProcess functions are executed. //
47// //
48// If you want to display the progress in a gui you can use SetProgressBar //
49// and a TGProgressBar or a MProgressBar. If you set a MStatusDisplay //
50// using SetDisplay, the Progress bar from this display is used. //
51// //
52// You can create a macro from a completely setup eventloop by: //
53// evtloop.MakeMacro("mymacro.C"); //
54// //
55// You will always need to check the macro, it will not run, but it //
56// should have al important information. //
57// //
58// //
59// You can also write all this information to a root file: //
60// TFile file("myfile.root"); //
61// evtloop.Write("MyEvtloopKey"); //
62// //
63// You can afterwards read the information from an open file by: //
64// evtloop.Read("MyEvtloopKey"); //
65// //
66// To lookup the information write it to a file using MakeMacro //
67// //
68//////////////////////////////////////////////////////////////////////////////
69#include "MEvtLoop.h"
70
71#include <time.h> // time_t
72#include <fstream.h> // ofstream, SavePrimitive
73#include <iostream.h>
74
75#include <TTime.h> // TTime
76#include <TFile.h> // gFile
77#include <TSystem.h> // gSystem
78#include <TStopwatch.h>
79#include <TGProgressBar.h>
80
81#include "MLog.h"
82#include "MLogManip.h"
83
84#include "MParList.h"
85#include "MTaskList.h"
86#ifdef __MARS__
87#include "MRead.h" // for setting progress bar
88#include "MProgressBar.h" // MProgressBar::GetBar
89#include "MStatusDisplay.h" // MStatusDisplay::GetBar
90#endif
91
92ClassImp(MEvtLoop);
93
94
95//!
96//! Maybe we can add a static parameter list to MEvtLoop
97//! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too
98//!
99
100TList *gListOfPrimitives; // forard declaration in MParContainer.h
101
102// --------------------------------------------------------------------------
103//
104// default constructor
105//
106MEvtLoop::MEvtLoop(const char *name) : fParList(NULL), fProgress(NULL)
107{
108 fName = name;
109
110 *fLog << inf << "Instantiated MEvtLoop (" << name << "), using ROOT v" << ROOTVER << endl;
111}
112
113// --------------------------------------------------------------------------
114//
115// destructor
116//
117MEvtLoop::~MEvtLoop()
118{
119 if (TestBit(kIsOwner) && fParList)
120 delete fParList;
121}
122
123// --------------------------------------------------------------------------
124//
125// if you set the Eventloop as owner the destructor of the given parameter
126// list is calles by the destructor of MEvtLoop, otherwise not.
127//
128void MEvtLoop::SetOwner(Bool_t enable)
129{
130 enable ? SetBit(kIsOwner) : ResetBit(kIsOwner);
131}
132
133#ifdef __MARS__
134// --------------------------------------------------------------------------
135//
136// Specify an existing MProgressBar object. It will display the progress
137// graphically. This will make thing about 1-2% slower.
138//
139void MEvtLoop::SetProgressBar(MProgressBar *bar)
140{
141 fProgress = bar->GetBar();
142}
143#endif
144
145// --------------------------------------------------------------------------
146//
147// The proprocessing part of the eventloop. Be careful, this is
148// for developers or use in special jobs only!
149//
150Bool_t MEvtLoop::PreProcess(const char *tlist)
151{
152 //
153 // check if the needed parameter list is set.
154 //
155 if (!fParList)
156 {
157 *fLog << err << dbginf << "Parlist not initialized." << endl;
158 return kFALSE;
159 }
160
161 //
162 // check for the existance of the specified task list
163 // the default name is "MTaskList"
164 //
165 fTaskList = (MTaskList*)fParList->FindObject(tlist, "MTaskList");
166 if (!fTaskList)
167 {
168 *fLog << err << dbginf << "Cannot find tasklist '" << tlist << "' in parameter list." << endl;
169 return kFALSE;
170 }
171
172 if (fLog != &gLog)
173 fParList->SetLogStream(fLog);
174
175#ifdef __MARS__
176 //
177 // Check whether display is still existing
178 //
179 if (fDisplay && !gROOT->GetListOfSpecials()->FindObject(fDisplay))
180 fDisplay = NULL;
181 if (fDisplay)
182 {
183 // Lock display to prevent user from deleting it
184 fDisplay->Lock();
185 // Get pointer to update Progress bar
186 fProgress = fDisplay->GetBar();
187 // Don't display context menus
188 fDisplay->SetNoContextMenu();
189 // Set window and icon name
190 fDisplay->SetWindowName(TString("Status Display: ")+fName);
191 fDisplay->SetIconName(fName);
192 // Set status lines
193 fDisplay->SetStatusLine1("PreProcessing...");
194 fDisplay->SetStatusLine2("");
195 // Start automatic update
196 fDisplay->StartUpdate();
197 // Cascade display through childs
198 fParList->SetDisplay(fDisplay);
199 }
200#endif
201
202 //
203 // execute the preprocess of all tasks
204 // connect the different tasks with the right containers in
205 // the parameter list
206 //
207 if (!fTaskList->PreProcess(fParList))
208 {
209 *fLog << err << "Error detected while PreProcessing" << endl;
210 return kFALSE;
211 }
212
213 *fLog << endl;
214
215 return kTRUE;
216}
217
218Bool_t MEvtLoop::ProcessGuiEvents(Int_t num)
219{
220 if (!fProgress)
221 return kTRUE;
222
223 //
224 // Check status of display
225 //
226 Bool_t rc = kTRUE;
227
228 if (fDisplay)
229 switch (fDisplay->CheckStatus())
230 {
231 case MStatusDisplay::kLoopNone:
232 break;
233 case MStatusDisplay::kLoopStop:
234 rc = kFALSE;
235 fDisplay->ClearStatus();
236 break;
237 case MStatusDisplay::kFileExit:
238 fParList->SetDisplay(NULL);
239 delete fDisplay;
240 SetDisplay(NULL);
241 fProgress = NULL;
242 gSystem->ProcessEvents();
243 return kTRUE;
244 default:
245 fDisplay->ClearStatus();
246 *fLog << warn << "Display shows unknown status... cleared." << endl;
247 break;
248 }
249
250 //
251 // Check System time (don't loose too much time by updates)
252 //
253
254 // FIXME: Not thread safe
255 static Int_t start = num;
256 static TTime t1 = gSystem->Now();
257 static TTime t2 = t1;
258
259 //
260 // No update < 20ms
261 //
262 const TTime t0 = gSystem->Now();
263 if (t0-t1 < (TTime)20)
264 return rc;
265 t1 = t0;
266
267 //
268 // Update current speed each second
269 //
270 if (t0-t2 > (TTime)1000)
271 {
272 const Int_t speed = 1000*(num-start)/(long int)(t0-t2);
273 TString txt = "Processing...";
274 if (speed>0)
275 {
276 txt += " (";
277 txt += speed;
278 txt += "Evts/s)";
279 }
280 fDisplay->SetStatusLine1(txt);
281 start = num;
282 t2 = t1;
283 }
284
285 //
286 // Set new progress bar position
287 //
288 fProgress->SetPosition(num);
289
290 //
291 // Handle GUI events (display changes)
292 //
293#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
294 gSystem->ProcessEvents();
295#else
296 if (fDisplay)
297 gSystem->ProcessEvents();
298 else
299 gClient->ProcessEventsFor(fProgress);
300#endif
301
302 return rc;
303}
304
305// --------------------------------------------------------------------------
306//
307// The processing part of the eventloop. Be careful, this is
308// for developers or use in special jobs only!
309//
310Bool_t MEvtLoop::Process(Int_t maxcnt)
311{
312 //
313 // loop over all events and process all tasks for
314 // each event
315 //
316 *fLog << all <<"Eventloop running (";
317
318 if (maxcnt<0)
319 *fLog << "all";
320 else
321 *fLog << dec << maxcnt;
322
323 *fLog << " events)..." << flush;
324
325 Int_t entries = INT_MAX;
326
327 if (fProgress)
328 {
329 fProgress->Reset();
330#ifdef __MARS__
331 // limits.h
332 MRead *read = (MRead*)fTaskList->FindObject("MRead");
333 if (read && read->GetEntries()>0)
334 entries = read->GetEntries();
335#endif
336
337 if (maxcnt>0)
338 fProgress->SetRange(0, TMath::Min(maxcnt, entries));
339 else
340 if (entries!=INT_MAX)
341 fProgress->SetRange(0, entries);
342 }
343
344 if (fDisplay)
345 {
346 fDisplay->SetStatusLine1("Processing...");
347 fDisplay->SetStatusLine2("");
348 }
349
350 Int_t dummy = maxcnt<0 ? 0 : maxcnt;
351
352 //
353 // start a stopwatch
354 //
355 TStopwatch clock;
356 clock.Start();
357
358 //
359 // This is the MAIN EVENTLOOP which processes the data
360 // if maxcnt<0 the number of processed events is counted
361 // else only maxcnt events are processed
362 //
363 Int_t numcnts = 0;
364
365 Bool_t rc = kTRUE;
366 if (maxcnt<0)
367 // process first and increment if sucessfull
368 while ((rc=fTaskList->Process())==kTRUE)
369 {
370 numcnts++;
371 if (!ProcessGuiEvents(++dummy))
372 break;
373 }
374 else
375 // check for number and break if unsuccessfull
376 while (dummy-- && (rc=fTaskList->Process())==kTRUE)
377 {
378 numcnts++;
379 if (!ProcessGuiEvents(maxcnt - dummy))
380 break;
381 }
382
383 //
384 // stop stop-watch, print results
385 //
386 clock.Stop();
387
388 if (fProgress)
389 {
390 fProgress->SetPosition(maxcnt>0 ? TMath::Min(maxcnt, entries) : entries);
391#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
392 gSystem->ProcessEvents();
393#else
394 gClient->ProcessEventsFor(fDisplay ? fDisplay->GetBar() : fProgress);
395#endif
396 }
397
398 *fLog << all << "Ready!" << endl << endl;
399
400 *fLog << dec << endl << "CPU - "
401 << "Time: " << clock.CpuTime() << "s"
402 << " for " << numcnts << " Events"
403 << " --> " << numcnts/clock.CpuTime() << " Events/s"
404 << endl;
405 *fLog << "Real - "
406 << "Time: " << clock.RealTime() << "s"
407 << " for " << numcnts << " Events"
408 << " --> " << numcnts/clock.RealTime() << " Events/s"
409 << endl << endl;
410
411 return rc!=kERROR;
412}
413
414// --------------------------------------------------------------------------
415//
416// The postprocessing part of the eventloop. Be careful, this is
417// for developers or use in special jobs only!
418//
419Bool_t MEvtLoop::PostProcess() const
420{
421 //
422 // execute the post process of all tasks
423 //
424 if (fDisplay)
425 {
426 // Set status lines
427 fDisplay->SetStatusLine1("PostProcessing...");
428 fDisplay->SetStatusLine2("");
429 }
430 return fTaskList->PostProcess();
431}
432
433// --------------------------------------------------------------------------
434//
435// See class description above.
436//
437Bool_t MEvtLoop::Eventloop(Int_t maxcnt, const char *tlist)
438{
439 Bool_t rc = PreProcess();
440
441 //
442 // If all Tasks were PreProcesses successfully start Processing.
443 //
444 if (rc)
445 rc = Process(maxcnt);
446
447 //
448 // Now postprocess all tasks. Only successfully preprocessed tasks are
449 // postprocessed. If the Postprocessing of one task fail return an error.
450 //
451 if (!PostProcess())
452 return kFALSE;
453
454 if (!fDisplay)
455 return rc;
456
457 // Set status lines
458 fDisplay->SetStatusLine1(fName);
459 fDisplay->SetStatusLine2(rc ? "Done." : "ERROR");
460 // Stop automatic update
461 fDisplay->StopUpdate();
462 // Reallow context menus
463 fDisplay->SetNoContextMenu(kFALSE);
464 // Reallow user to exit window by File menu
465 fDisplay->UnLock();
466
467 //
468 // If postprocessing of all preprocessed tasks was sucefully return rc.
469 // This gives an error in case the preprocessing has failed already.
470 // Otherwise the eventloop is considered: successfully.
471 //
472 return rc;
473}
474
475// --------------------------------------------------------------------------
476//
477// After you setup (or read) an Evtloop you can use this to write the
478// eventloop setup as a macro. The default name is "evtloop.C". The default
479// extension is .C If the extension is not given, .C is added.
480// I the last character in the argument is a '+' the file is not closed.
481// This is usefull if you have an eventloop which runs three times and
482// you want to write one macro. If the first character is a '+' no
483// opening is written, eg:
484//
485// MEvtLoop evtloop;
486// // some setup
487// evtloop.MakeMacro("mymacro+");
488// // replace the tasklist the first time
489// evtloop.MakeMacro("+mymacro+");
490// // replace the tasklist the second time
491// evtloop.MakeMacro("+mymacro");
492//
493void MEvtLoop::MakeMacro(const char *filename)
494{
495 TString name(filename);
496
497 name = name.Strip(TString::kBoth);
498
499 Bool_t open = kTRUE;
500 Bool_t close = kTRUE;
501 if (name[0]=='+')
502 {
503 open = kFALSE;
504 name.Remove(0, 1);
505 name = name.Strip(TString::kBoth);
506 }
507
508 if (name[name.Length()-1]=='+')
509 {
510 close = kFALSE;
511 name.Remove(name.Length()-1, 1);
512 name = name.Strip(TString::kBoth);
513 }
514
515 if (!name.EndsWith(".C"))
516 name += ".C";
517
518 ofstream fout;
519
520 if (!open)
521 {
522 fout.open(name, ios::app);
523 fout << endl;
524 fout << " // ----------------------------------------------------------------------" << endl;
525 fout << endl;
526 }
527 else
528 {
529 fout.open(name);
530
531 time_t t = time(NULL);
532 fout <<
533 "/* ======================================================================== *\\" << endl <<
534 "!" << endl <<
535 "! *" << endl <<
536 "! * This file is part of MARS, the MAGIC Analysis and Reconstruction" << endl <<
537 "! * Software. It is distributed to you in the hope that it can be a useful" << endl <<
538 "! * and timesaving tool in analysing Data of imaging Cerenkov telescopes." << endl <<
539 "! * It is distributed WITHOUT ANY WARRANTY." << endl <<
540 "! *" << endl <<
541 "! * Permission to use, copy, modify and distribute this software and its" << endl <<
542 "! * documentation for any purpose is hereby granted without fee," << endl <<
543 "! * provided that the above copyright notice appear in all copies and" << endl <<
544 "! * that both that copyright notice and this permission notice appear" << endl <<
545 "! * in supporting documentation. It is provided \"as is\" without express" << endl <<
546 "! * or implied warranty." << endl <<
547 "! *" << endl <<
548 "!" << endl <<
549 "!" << endl <<
550 "! Author(s): Thomas Bretz et al. <mailto:tbretz@astro.uni-wuerzburg.de>" << endl <<
551 "!" << endl <<
552 "! Copyright: MAGIC Software Development, 2000-2002" << endl <<
553 "!" << endl <<
554 "!" << endl <<
555 "\\* ======================================================================== */" << endl << endl <<
556 "// ------------------------------------------------------------------------" << endl <<
557 "//" << endl <<
558 "// This macro was automatically created on" << endl<<
559 "// " << ctime(&t) <<
560 "// with the MEvtLoop::MakeMacro tool." << endl <<
561 "//" << endl <<
562 "// ------------------------------------------------------------------------" << endl << endl <<
563 "void " << name(0, name.Length()-2) << "()" << endl <<
564 "{" << endl;
565 }
566
567 SavePrimitive(fout, (TString)"" + (open?"open":"") + (close?"close":""));
568
569 if (!close)
570 return;
571
572 fout << "}" << endl;
573
574 *fLog << inf << "Macro '" << name << "' written." << endl;
575}
576
577// --------------------------------------------------------------------------
578//
579// Implementation of SavePrimitive. Used to write the call to a constructor
580// to a macro. In the original root implementation it is used to write
581// gui elements to a macro-file.
582//
583void MEvtLoop::StreamPrimitive(ofstream &out) const
584{
585 out << " MEvtLoop " << GetUniqueName();
586 if (fName!="Evtloop")
587 out << "(\"" << fName << "\")";
588 out << ";" << endl;
589}
590
591// --------------------------------------------------------------------------
592//
593//
594void MEvtLoop::SavePrimitive(ofstream &out, Option_t *opt)
595{
596 TString options = opt;
597 options.ToLower();
598
599 if (HasDuplicateNames("MEvtLoop::SavePrimitive"))
600 {
601 out << " // !" << endl;
602 out << " // ! WARNING - Your eventloop (MParList, MTaskList, ...) contains more than" << endl;
603 out << " // ! one object (MParContainer, MTask, ...) with the same name. The created macro" << endl;
604 out << " // ! may need manual intervention before it can be used." << endl;
605 out << " // !" << endl;
606 out << endl;
607 }
608
609 if (!options.Contains("open"))
610 {
611 if (gListOfPrimitives)
612 {
613 *fLog << err << "MEvtLoop::SavePrimitive - Error: old file not closed." << endl;
614 gListOfPrimitives->ForEach(TObject, ResetBit)(BIT(15));
615 delete gListOfPrimitives;
616 }
617 gListOfPrimitives = new TList;
618 }
619
620 if (fParList)
621 fParList->SavePrimitive(out);
622
623 MParContainer::SavePrimitive(out);
624
625 if (fParList)
626 out << " " << GetUniqueName() << ".SetParList(&" << fParList->GetUniqueName() << ");" << endl;
627 else
628 out << " // fParList empty..." << endl;
629 out << " if (!" << GetUniqueName() << ".Eventloop())" << endl;
630 out << " return;" << endl;
631
632 if (!options.Contains("close"))
633 return;
634
635 gListOfPrimitives->ForEach(TObject, ResetBit)(BIT(15));
636 delete gListOfPrimitives;
637 gListOfPrimitives = 0;
638}
639
640// --------------------------------------------------------------------------
641//
642// Get a list of all conmtainer names which are somehow part of the
643// eventloop. Chack for duplicate members and print a warning if
644// duplicates are found. Return kTRUE if duplicates are found, otherwise
645// kFALSE;
646//
647Bool_t MEvtLoop::HasDuplicateNames(TObjArray &arr, const TString txt) const
648{
649 arr.Sort();
650
651 TIter Next(&arr);
652 TObject *obj;
653 TString name;
654 Bool_t found = kFALSE;
655 while ((obj=Next()))
656 {
657 if (name==obj->GetName())
658 {
659 if (!found)
660 {
661 *fLog << warn << endl;
662 *fLog << " ! WARNING (" << txt << ")" << endl;
663 *fLog << " ! Your eventloop (MParList, MTaskList, ...) contains more than" << endl;
664 *fLog << " ! one object (MParContainer, MTask, ...) with the same name." << endl;
665 *fLog << " ! Creating a macro from it using MEvtLoop::MakeMacro may create" << endl;
666 *fLog << " ! a macro which needs manual intervention before it can be used." << endl;
667 found = kTRUE;
668 }
669 *fLog << " ! Please rename: " << obj->GetName() << endl;
670 }
671 name = obj->GetName();
672 }
673
674 return found;
675}
676
677// --------------------------------------------------------------------------
678//
679// Get a list of all conmtainer names which are somehow part of the
680// eventloop. Chack for duplicate members and print a warning if
681// duplicates are found. Return kTRUE if duplicates are found, otherwise
682// kFALSE;
683//
684Bool_t MEvtLoop::HasDuplicateNames(const TString txt) const
685{
686 if (!fParList)
687 return kFALSE;
688
689 TObjArray list;
690 list.SetOwner();
691
692 fParList->GetNames(list);
693
694 return HasDuplicateNames(list, txt);
695}
696
697// --------------------------------------------------------------------------
698//
699// Reads a saved eventloop from a file. The default name is "Evtloop".
700// Therefor an open file must exist (See TFile for more information)
701//
702// eg:
703// TFile file("myfile.root", "READ");
704// MEvtLoop evtloop;
705// evtloop.Read();
706// evtloop.MakeMacro("mymacro");
707//
708Int_t MEvtLoop::Read(const char *name)
709{
710 if (!gFile)
711 {
712 *fLog << err << "MEvtloop::Read: No file found. Please create a TFile first." << endl;
713 return 0;
714 }
715
716 if (!gFile->IsOpen())
717 {
718 *fLog << err << "MEvtloop::Read: File not open. Please open the TFile first." << endl;
719 return 0;
720 }
721
722 Int_t n = 0;
723 TObjArray list;
724
725 n += TObject::Read(name);
726
727 if (n==0)
728 {
729 *fLog << err << "MEvtloop::Read: No objects read." << endl;
730 return 0;
731 }
732
733 n += list.Read((TString)name+"_names");
734
735 fParList->SetNames(list);
736
737 HasDuplicateNames(list, "MEvtLoop::Read");
738
739 *fLog << inf << "Eventloop '" << name << "' read from file." << endl;
740
741 return n;
742}
743
744// --------------------------------------------------------------------------
745//
746// If available print the contents of the parameter list.
747//
748void MEvtLoop::Print(Option_t *opt) const
749{
750 if (fParList)
751 fParList->Print();
752 else
753 *fLog << all << "MEvtloop: No Parameter List available." << endl;
754}
755
756// --------------------------------------------------------------------------
757//
758// Writes a eventloop to a file. The default name is "Evtloop".
759// Therefor an open file must exist (See TFile for more information)
760//
761// eg:
762// TFile file("myfile.root", "RECREATE");
763// MEvtLoop evtloop;
764// evtloop.Write();
765// file.Close();
766//
767Int_t MEvtLoop::Write(const char *name, Int_t option, Int_t bufsize)
768{
769 if (!gFile)
770 {
771 *fLog << err << "MEvtloop::Write: No file found. Please create a TFile first." << endl;
772 return 0;
773 }
774
775 if (!gFile->IsOpen())
776 {
777 *fLog << err << "MEvtloop::Write: File not open. Please open the TFile first." << endl;
778 return 0;
779 }
780
781 if (!gFile->IsWritable())
782 {
783 *fLog << err << "MEvtloop::Write: File not writable." << endl;
784 return 0;
785 }
786
787 Int_t n = 0;
788
789 TObjArray list;
790 list.SetOwner();
791
792 fParList->GetNames(list);
793
794 n += TObject::Write(name, option, bufsize);
795
796 if (n==0)
797 {
798 *fLog << err << "MEvtloop::Read: No objects written." << endl;
799 return 0;
800 }
801
802 n += list.Write((TString)name+"_names", kSingleKey);
803
804 HasDuplicateNames(list, "MEvtLoop::Write");
805
806 *fLog << inf << "Eventloop written to file as " << name << "." << endl;
807
808 return n;
809}
810
811// --------------------------------------------------------------------------
812//
813// Read the contents/setup of a parameter container/task from a TEnv
814// instance (steering card/setup file).
815// The key to search for in the file should be of the syntax:
816// prefix.vname
817// While vname is a name which is specific for a single setup date
818// (variable) of this container and prefix is something like:
819// evtloopname.name
820// While name is the name of the containers/tasks in the parlist/tasklist
821//
822// eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
823// Job4.MImgCleanStd.CleaningLevel2: 2.5
824//
825// If this cannot be found the next step is to search for
826// MImgCleanStd.CleaningLevel1: 3.0
827// And if this doesn't exist, too, we should search for:
828// CleaningLevel1: 3.0
829//
830// Warning: The programmer is responsible for the names to be unique in
831// all Mars classes.
832//
833Bool_t MEvtLoop::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
834{
835 if (!prefix.IsNull())
836 *fLog << warn << "WARNING - Second argument in MEvtLoop::ReadEnv has no meaning... ignored." << endl;
837
838 prefix = fName;
839 prefix += ".";
840
841 *fLog << inf << "Reading resources for " << prefix /*TEnv::fRcName << " from " << env.GetRcName()*/ << endl;
842
843 if (fParList->ReadEnv(env, prefix, print)==kERROR)
844 {
845 *fLog << err << "ERROR - Reading Environment file." << endl;
846 return kFALSE;
847 }
848
849 return kTRUE;
850}
851
852// --------------------------------------------------------------------------
853//
854// Write the contents/setup of a parameter container/task to a TEnv
855// instance (steering card/setup file).
856// The key to search for in the file should be of the syntax:
857// prefix.vname
858// While vname is a name which is specific for a single setup date
859// (variable) of this container and prefix is something like:
860// evtloopname.name
861// While name is the name of the containers/tasks in the parlist/tasklist
862//
863// eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
864// Job4.MImgCleanStd.CleaningLevel2: 2.5
865//
866// If this cannot be found the next step is to search for
867// MImgCleanStd.CleaningLevel1: 3.0
868// And if this doesn't exist, too, we should search for:
869// CleaningLevel1: 3.0
870//
871// Warning: The programmer is responsible for the names to be unique in
872// all Mars classes.
873//
874Bool_t MEvtLoop::WriteEnv(TEnv &env, TString prefix, Bool_t print) const
875{
876 if (!prefix.IsNull())
877 *fLog << warn << "WARNING - Second argument in MEvtLoop::WriteEnv has no meaning... ignored." << endl;
878
879 prefix = fName;
880 prefix += ".";
881
882 *fLog << inf << "Writing resources: " << prefix /*TEnv::fRcName << " to " << env.GetRcName()*/ << endl;
883
884 if (fParList->WriteEnv(env, prefix, print)!=kTRUE)
885 {
886 *fLog << err << "ERROR - Writing Environment file." << endl;
887 return kFALSE;
888 }
889
890 return kTRUE;
891}
Note: See TracBrowser for help on using the repository browser.