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