Changeset 3497 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 03/15/04 12:04:09 (21 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MTask.cc
r2858 r3497 90 90 91 91 #include <fstream> 92 #include <TBaseClass.h> 92 93 #include <TBaseClass.h> // OverwritesProcess 94 #include <TStopwatch.h> // TStopwatch 93 95 94 96 #include "MLog.h" … … 103 105 104 106 MTask::MTask(const char *name, const char *title) 105 : fFilter(NULL), fSerialNumber(0), fIsPreprocessed(kFALSE), fNumExecutions(0) 107 : fFilter(NULL), fSerialNumber(0), fIsPreprocessed(kFALSE), 108 fNumExecutions(0), fStopwatch(0) 106 109 { 107 110 fName = name ? name : "MTask"; … … 110 113 fListOfBranches = new TList; 111 114 fListOfBranches->SetOwner(); 115 116 fStopwatch = new TStopwatch; 112 117 } 113 118 114 119 MTask::~MTask() 115 120 { 121 delete fStopwatch; 116 122 delete fListOfBranches; 117 123 } … … 184 190 // Mapper function for PreProcess. 185 191 // Sets the preprocessed flag dependend on the return value of PreProcess. 192 // Resets number of executions and cpu consumtion timer. 186 193 // 187 194 Int_t MTask::CallPreProcess(MParList *plist) 188 195 { 189 196 fNumExecutions = 0; 197 fStopwatch->Reset(); 190 198 191 199 *fLog << all << fName << "... " << flush; … … 218 226 // return value. 219 227 // If Process is executed, the execution counter is increased. 228 // Count cpu consumtion time. 220 229 // 221 230 Int_t MTask::CallProcess() … … 232 241 233 242 fNumExecutions++; 234 return Process(); 243 244 fStopwatch->Start(kFALSE); 245 const Int_t rc = Process(); 246 fStopwatch->Stop(); 247 248 return rc; 235 249 } 236 250 … … 332 346 // -------------------------------------------------------------------------- 333 347 // 334 // Prints the number of times all the tasks in the list has been. 348 // Return total CPU execution time of task 349 // 350 Double_t MTask::GetCpuTime() const 351 { 352 return fStopwatch->CpuTime(); 353 } 354 355 // -------------------------------------------------------------------------- 356 // 357 // Return total real execution time of task 358 // 359 Double_t MTask::GetRealTime() const 360 { 361 return fStopwatch->RealTime(); 362 } 363 364 // -------------------------------------------------------------------------- 365 // 366 // Prints the relative time spent in Process() (relative means relative to 367 // its parent Tasklist) and the number of times Process() was executed. 335 368 // For convinience the lvl argument results in a number of spaces at the 336 369 // beginning of the line. So that the structur of a tasklist can be … … 338 371 // filter is printer in <>-brackets behind the number of executions. 339 372 // Use MTaskList::PrintStatistics without an argument. 340 // 341 void MTask::PrintStatistics(const Int_t lvl, Bool_t title) const 342 { 343 *fLog << all << setfill(' ') << setw(lvl) << " " << GetDescriptor() << "\t"; 373 // For tasks which don't overwrite Process() no action is perfomed. 374 // 375 void MTask::PrintStatistics(const Int_t lvl, Bool_t title, Double_t time) const 376 { 377 if (!OverwritesProcess()) 378 return; 379 380 *fLog << all << setfill(' ') << setw(lvl) << " "; 381 if (fStopwatch->CpuTime()>0 && time>0) 382 *fLog << setw(3) << (Int_t)(fStopwatch->CpuTime()/time*100+.5) << "% "; 383 else 384 *fLog << " "; 385 *fLog << GetDescriptor() << "\t"; 344 386 *fLog << dec << fNumExecutions; 345 387 if (fFilter) -
trunk/MagicSoft/Mars/mbase/MTask.h
r2589 r3497 15 15 16 16 class TList; 17 class TStopwatch; 17 18 18 19 class MFilter; … … 29 30 Bool_t fIsPreprocessed; //! Indicates the success of the PreProcessing (set by MTaskList) 30 31 UInt_t fNumExecutions; //! Number of Excutions 32 33 TStopwatch *fStopwatch; //! 31 34 32 35 virtual Int_t PreProcess(MParList *pList); … … 66 69 virtual ~MTask(); 67 70 71 const TList *GetListOfBranches() const { return fListOfBranches; } 72 Bool_t OverwritesProcess(TClass *cls=NULL) const; 73 74 // Filter functions 68 75 virtual void SetFilter(MFilter *filter) { fFilter=filter; } 69 76 const MFilter *GetFilter() const { return fFilter; } 70 77 MFilter *GetFilter() { return fFilter; } // for MContinue only 71 78 79 // Display functions 72 80 void SetDisplay(MStatusDisplay *d); 73 virtual void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE) const;74 81 82 // Function for parallel executions 75 83 static TString AddSerialNumber(const char *str, UInt_t num) { TString s(str); if (num==0) return s; s += ";"; s += num; return s; } 76 84 static TString AddSerialNumber(const TString &str, UInt_t num) { return AddSerialNumber((const char*)str, num); } … … 83 91 const char *GetDescriptor() const; 84 92 93 // Task execution statistics 85 94 UInt_t GetNumExecutions() const { return fNumExecutions; } 95 Double_t GetCpuTime() const; 96 Double_t GetRealTime() const; 97 virtual void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE, Double_t time=0) const; 86 98 99 // Task overwrite functions 87 100 virtual Bool_t ReInit(MParList *pList); 88 101 … … 90 103 virtual Int_t CallProcess(); 91 104 virtual Int_t CallPostProcess(); 92 93 const TList *GetListOfBranches() const { return fListOfBranches; }94 95 Bool_t OverwritesProcess(TClass *cls=NULL) const;96 105 97 106 void SavePrimitive(ofstream &out, Option_t *o=""); -
trunk/MagicSoft/Mars/mbase/MTaskList.cc
r2958 r3497 16 16 ! 17 17 ! 18 ! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@ uni-sw.gwdg.de>18 ! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 120 ! Copyright: MAGIC Software Development, 2000-2004 21 21 ! 22 22 ! … … 24 24 25 25 ///////////////////////////////////////////////////////////////////////////// 26 // //27 // MTaskList //28 // //29 // Collection of tasks. //30 // //31 // A tasklist is necessary to run the eventloop. It contains the scheduled //32 // tasks, which should be executed in your program. //33 // //34 // To add a task use AddToList. //35 // //36 // The tasklist itself is a task, too. You can add a tasklist to another //37 // tasklist. This makes sense, if you want to filter the execution of //38 // more than one task of your tasklist using the same filter. //39 // //40 // The tasks in the list are idetified by their names. If more than one //41 // task has the same name, the tasklist will still work correctly, but //42 // you might run into trouble trying to get a pointer to a task by name //43 // from the list. //44 // //45 // Warning: //46 // Be carefull if you are writing your tasklist //47 // (eg. MWriteRootFile("file.root", "MTaskList")) to a file. You may //48 // not be able to initialize a new working tasklist from a file if //49 // a) Two Paramerer containers with the same names are existing in the //50 // MParList. //51 // b) You used a container somewhere which is not part of MParList. //52 // (eg. You specified a pointer to a MH container in MFillH which is //53 // not added to the parameter list. //54 // //26 // 27 // MTaskList 28 // 29 // Collection of tasks. 30 // 31 // A tasklist is necessary to run the eventloop. It contains the scheduled 32 // tasks, which should be executed in your program. 33 // 34 // To add a task use AddToList. 35 // 36 // The tasklist itself is a task, too. You can add a tasklist to another 37 // tasklist. This makes sense, if you want to filter the execution of 38 // more than one task of your tasklist using the same filter. 39 // 40 // The tasks in the list are idetified by their names. If more than one 41 // task has the same name, the tasklist will still work correctly, but 42 // you might run into trouble trying to get a pointer to a task by name 43 // from the list. 44 // 45 // Warning: 46 // Be carefull if you are writing your tasklist 47 // (eg. MWriteRootFile("file.root", "MTaskList")) to a file. You may 48 // not be able to initialize a new working tasklist from a file if 49 // a) Two Paramerer containers with the same names are existing in the 50 // MParList. 51 // b) You used a container somewhere which is not part of MParList. 52 // (eg. You specified a pointer to a MH container in MFillH which is 53 // not added to the parameter list. 54 // 55 55 ///////////////////////////////////////////////////////////////////////////// 56 57 56 #include "MTaskList.h" 58 57 59 #include <fstream> // ofstream, SavePrimitive 60 61 #include <TClass.h> 62 #include <TSystem.h> // gSystem 63 #include <TOrdCollection.h> 58 #include <fstream> // ofstream, SavePrimitive 59 60 #include <TSystem.h> // gSystem 61 #include <TOrdCollection.h> // TOrdCollection 64 62 65 63 #include "MLog.h" … … 627 625 // Use MTaskList::PrintStatistics without an argument. 628 626 // 629 void MTaskList::PrintStatistics(const Int_t lvl, Bool_t title ) const627 void MTaskList::PrintStatistics(const Int_t lvl, Bool_t title, Double_t time) const 630 628 { 631 629 if (lvl==0) 632 630 { 633 *fLog << all << underline << " Execution Statistics:" << endl;631 *fLog << all << underline << "Process execution Statistics:" << endl; 634 632 *fLog << GetDescriptor(); 635 633 if (GetFilter()) … … 640 638 } 641 639 else 642 MTask::PrintStatistics(lvl, title );640 MTask::PrintStatistics(lvl, title, time); 643 641 644 642 // 645 643 // create the Iterator for the TaskList 646 644 // 647 fTasks->ForEach(MTask, PrintStatistics)(lvl+1, title );645 fTasks->ForEach(MTask, PrintStatistics)(lvl+1, title, GetCpuTime()); 648 646 649 647 if (lvl==0) … … 651 649 } 652 650 653 654 // -------------------------------------------------------------------------- 651 // -------------------------------------------------------------------------- 652 // 653 // Call 'Print()' of all tasks 654 // 655 655 void MTaskList::Print(Option_t *t) const 656 656 { -
trunk/MagicSoft/Mars/mbase/MTaskList.h
r2470 r3497 70 70 71 71 void Print(Option_t *opt = "") const; 72 void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE ) const;72 void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE, Double_t time=0) const; 73 73 void SetOwner(Bool_t enable=kTRUE); 74 74
Note:
See TracChangeset
for help on using the changeset viewer.