| 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  9/2002 <mailto:tbretz@astro.uni-wuerzburg.de> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2002 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | // | 
|---|
| 27 | // MMatrixLoop | 
|---|
| 28 | // | 
|---|
| 29 | // Use this task instead of reading from a file. It loops through the rows | 
|---|
| 30 | // of a given MHMatrix. PreProcessing the task again starts from scratch. | 
|---|
| 31 | // | 
|---|
| 32 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 33 | #include "MMatrixLoop.h" | 
|---|
| 34 |  | 
|---|
| 35 | #include "MHMatrix.h" | 
|---|
| 36 | #include "MLog.h" | 
|---|
| 37 |  | 
|---|
| 38 | ClassImp(MMatrixLoop); | 
|---|
| 39 |  | 
|---|
| 40 | const TString MMatrixLoop::gsDefName  = "MRead"; | 
|---|
| 41 | const TString MMatrixLoop::gsDefTitle = "Loop through a MHMatrix (instead of reading from a file)"; | 
|---|
| 42 |  | 
|---|
| 43 | // -------------------------------------------------------------------------- | 
|---|
| 44 | // | 
|---|
| 45 | //  Default Constructor. Specify the MHMatrix object you want to loop | 
|---|
| 46 | //  through. | 
|---|
| 47 | // | 
|---|
| 48 | MMatrixLoop::MMatrixLoop(MHMatrix *mat, const char *name, const char *title) : fMatrix(mat), fOperationMode(kDefault) | 
|---|
| 49 | { | 
|---|
| 50 | fName  = name  ? name  : gsDefName.Data(); | 
|---|
| 51 | fTitle = title ? title : gsDefTitle.Data(); | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | // -------------------------------------------------------------------------- | 
|---|
| 55 | // | 
|---|
| 56 | // Return the number of events (rows) in the matrix | 
|---|
| 57 | // | 
|---|
| 58 | UInt_t MMatrixLoop::GetEntries() | 
|---|
| 59 | { | 
|---|
| 60 | if (!fMatrix) | 
|---|
| 61 | return 0; | 
|---|
| 62 |  | 
|---|
| 63 | return fOperationMode==kDefault ? fMatrix->GetNumRows() : (fMatrix->GetNumRows()+1)/2; | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | // -------------------------------------------------------------------------- | 
|---|
| 67 | // | 
|---|
| 68 | // Return name of MHMatrix, <n/a> if not available | 
|---|
| 69 | // The name of the matrix must nor contain a '/' | 
|---|
| 70 | // | 
|---|
| 71 | TString MMatrixLoop::GetFullFileName() const | 
|---|
| 72 | { | 
|---|
| 73 | return fMatrix ? fMatrix->GetName() : "<n/a>"; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | // -------------------------------------------------------------------------- | 
|---|
| 77 | // | 
|---|
| 78 | Int_t MMatrixLoop::PreProcess(MParList *plist) | 
|---|
| 79 | { | 
|---|
| 80 | fNumRow = fOperationMode==kOdd ? 1 : 0; | 
|---|
| 81 |  | 
|---|
| 82 | return fMatrix ? kTRUE : kFALSE; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | // -------------------------------------------------------------------------- | 
|---|
| 86 | // | 
|---|
| 87 | // Set the present row of the Matrix, stops the loop when all rows have | 
|---|
| 88 | // been accessed. | 
|---|
| 89 | // | 
|---|
| 90 | Int_t MMatrixLoop::Process() | 
|---|
| 91 | { | 
|---|
| 92 | const Int_t rc = fMatrix->SetNumRow(fNumRow); | 
|---|
| 93 | fNumRow += fOperationMode==kDefault ? 1 : 2; | 
|---|
| 94 | return rc; | 
|---|
| 95 | } | 
|---|