source: trunk/MagicSoft/Mars/mdata/MDataElement.cc@ 8681

Last change on this file since 8681 was 8001, checked in by tbretz, 18 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 <fstream>
41
42#include "MHMatrix.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MParList.h"
48
49ClassImp(MDataElement);
50
51using namespace std;
52
53// --------------------------------------------------------------------------
54//
55// Specify the name of the MHMatrix-object and the column you want to
56// access.
57//
58MDataElement::MDataElement(const char *member, Int_t col)
59 : fMatrixName(member), fNumCol(col), fMatrix(NULL)
60{
61 if (fNumCol>=0)
62 return;
63
64 const Int_t pos = fMatrixName.First('[');
65 if (pos<=0)
66 return;
67
68 fNumCol = atoi(fMatrixName.Data()+pos+1);
69 fMatrixName = fMatrixName(0, pos);
70}
71
72// --------------------------------------------------------------------------
73//
74// Specify the pointer of the MHMatrix-object and the column you want to
75// access.
76//
77MDataElement::MDataElement(MHMatrix *mat, Int_t col)
78 : fMatrixName(mat->GetName()), fNumCol(col), fMatrix(mat)
79{
80}
81
82// --------------------------------------------------------------------------
83//
84// returns the value you requested
85//
86Double_t MDataElement::GetValue() const
87{
88 return fMatrix ? (*fMatrix)[fNumCol] : 0;
89}
90
91// --------------------------------------------------------------------------
92//
93// If the pointer to the MHMatrix isn't yet set search for it in the
94// parameter list.
95//
96Bool_t MDataElement::PreProcess(const MParList *plist)
97{
98 if (fMatrix)
99 return kTRUE;
100
101 fMatrix = (MHMatrix*)plist->FindObject(fMatrixName, "MHMatrix");
102 if (!fMatrix)
103 {
104 *fLog << err << "MHMatrix '" << fMatrixName << "' not in parameter list... aborting." << endl;
105 return kFALSE;
106 }
107
108 return kTRUE;
109}
110
111// --------------------------------------------------------------------------
112//
113// Returns the ready-to-save flag of the data member container
114//
115Bool_t MDataElement::IsReadyToSave() const
116{
117 return IsValid() ? fMatrix->IsReadyToSave() : kFALSE;
118}
119
120// --------------------------------------------------------------------------
121//
122// Return the rule used to identify this object in a datachain
123//
124TString MDataElement::GetRule() const
125{
126 TString rule = fMatrixName + "[";
127 rule += fNumCol;
128 rule += "]";
129 return rule;
130}
Note: See TracBrowser for help on using the repository browser.