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

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