source: branches/Corsika7500Compatibility/mdata/MDataElement.cc@ 18481

Last change on this file since 18481 was 9195, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 3.6 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 04/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MDataElement
28//
29// This MData class is used for accessing a column of an MHMatrix object.
30// eg. MDataElement("Matrix", 5)
31// will return the 5th column of the MHMatrix object called Matrix.
32//
33// The row which is accessed must be set before by using
34// MHMatrix::SetNumRow. If you want to loop through a matrix use
35// MMatrixLoop.
36//
37/////////////////////////////////////////////////////////////////////////////
38#include "MDataElement.h"
39
40#include <stdlib.h> // atoi (Ubuntu 8.10)
41
42#include <fstream>
43
44#include "MHMatrix.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50
51ClassImp(MDataElement);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Specify the name of the MHMatrix-object and the column you want to
58// access.
59//
60MDataElement::MDataElement(const char *member, Int_t col)
61 : fMatrixName(member), fNumCol(col), fMatrix(NULL)
62{
63 if (fNumCol>=0)
64 return;
65
66 const Int_t pos = fMatrixName.First('[');
67 if (pos<=0)
68 return;
69
70 fNumCol = atoi(fMatrixName.Data()+pos+1);
71 fMatrixName = fMatrixName(0, pos);
72}
73
74// --------------------------------------------------------------------------
75//
76// Specify the pointer of the MHMatrix-object and the column you want to
77// access.
78//
79MDataElement::MDataElement(MHMatrix *mat, Int_t col)
80 : fMatrixName(mat->GetName()), fNumCol(col), fMatrix(mat)
81{
82}
83
84// --------------------------------------------------------------------------
85//
86// returns the value you requested
87//
88Double_t MDataElement::GetValue() const
89{
90 return fMatrix ? (*fMatrix)[fNumCol] : 0;
91}
92
93// --------------------------------------------------------------------------
94//
95// If the pointer to the MHMatrix isn't yet set search for it in the
96// parameter list.
97//
98Bool_t MDataElement::PreProcess(const MParList *plist)
99{
100 if (fMatrix)
101 return kTRUE;
102
103 fMatrix = (MHMatrix*)plist->FindObject(fMatrixName, "MHMatrix");
104 if (!fMatrix)
105 {
106 *fLog << err << "MHMatrix '" << fMatrixName << "' not in parameter list... aborting." << endl;
107 return kFALSE;
108 }
109
110 return kTRUE;
111}
112
113// --------------------------------------------------------------------------
114//
115// Returns the ready-to-save flag of the data member container
116//
117Bool_t MDataElement::IsReadyToSave() const
118{
119 return IsValid() ? fMatrix->IsReadyToSave() : kFALSE;
120}
121
122// --------------------------------------------------------------------------
123//
124// Return the rule used to identify this object in a datachain
125//
126TString MDataElement::GetRule() const
127{
128 TString rule = fMatrixName + "[";
129 rule += fNumCol;
130 rule += "]";
131 return rule;
132}
Note: See TracBrowser for help on using the repository browser.