source: trunk/MagicSoft/Mars/mdata/MDataArray.cc@ 2178

Last change on this file since 2178 was 2173, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 5.2 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 08/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MDataArray
28//
29// An Array of MData derived classes.
30// It can be used, eg, in MHMatrix for description of the columns.
31//
32/////////////////////////////////////////////////////////////////////////////
33#include "MDataArray.h"
34
35#include <fstream>
36
37#include <TVector.h>
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MDataChain.h"
43
44ClassImp(MDataArray);
45
46using namespace std;
47
48static const TString gsDefName = "MDataArray";
49static const TString gsDefTitle = "Array to store MData cntainers";
50
51// --------------------------------------------------------------------------
52//
53// Constructor
54//
55MDataArray::MDataArray(const char *name, const char *title)
56{
57 fName = name ? name : gsDefName.Data();
58 fTitle = title ? title : gsDefTitle.Data();
59}
60
61// --------------------------------------------------------------------------
62//
63// Add a new data rule as a new entry (MDataChain)
64//
65void MDataArray::AddEntry(const TString rule)
66{
67 TObject *obj = new MDataChain(rule);
68 obj->SetBit(kCanDelete);
69 fList.Add(obj);
70}
71
72// --------------------------------------------------------------------------
73//
74// Add a new data as a new entry (MData). If the destructor of MDataArray
75// should delete the object set its bit kCanDelete
76//
77void MDataArray::AddEntry(MData *data)
78{
79 fList.Add(data);
80}
81
82// --------------------------------------------------------------------------
83//
84// Return the i-th entry
85//
86MData &MDataArray::operator[](Int_t i) const
87{
88 return (MData&)*((TObjArray)fList)[i];
89}
90
91// --------------------------------------------------------------------------
92//
93// Return the data value of the i-th entry
94//
95Double_t MDataArray::operator()(Int_t i) const
96{
97 return (*this)[i].GetValue();
98}
99
100// --------------------------------------------------------------------------
101//
102// PreProcesses all members in the list
103//
104Bool_t MDataArray::PreProcess(const MParList *plist)
105{
106 if (fList.GetSize()==0)
107 {
108 *fLog << err << "Error - No Column specified... aborting." << endl;
109 return kFALSE;
110 }
111
112 TIter Next(&fList);
113 MData *data = NULL;
114 while ((data=(MData*)Next()))
115 if (!data->PreProcess(plist))
116 return kFALSE;
117
118 return kTRUE;
119}
120
121// --------------------------------------------------------------------------
122//
123// Print the rules for all entries of the array
124//
125void MDataArray::Print(Option_t *opt) const
126{
127 Int_t n=0;
128
129 TIter Next(&fList);
130 MData *data = NULL;
131 while ((data=(MData*)Next()))
132 {
133 *fLog << all << " Line " << setw(3) << n++ << ": " << flush;
134 data->Print();
135 *fLog << endl;
136 }
137}
138
139Bool_t MDataArray::AsciiWrite(ostream &out) const
140{
141 ((TObjArray)fList).ForEach(MParContainer, AsciiWrite)(out);
142 return kTRUE;
143}
144
145// --------------------------------------------------------------------------
146//
147// Implementation of SavePrimitive. Used to write the call to a constructor
148// to a macro. In the original root implementation it is used to write
149// gui elements to a macro-file.
150//
151void MDataArray::StreamPrimitive(ofstream &out) const
152{
153 out << " MDataArray " << GetUniqueName();
154
155 if (fName!=gsDefName)
156 {
157 out << "(\"" << fName << "\"";
158 if (fTitle!=gsDefTitle)
159 out << ", \"" << fTitle << "\")";
160 }
161 out << ";" << endl;
162
163 TIter Next(&fList);
164 MData *data = NULL;
165 while ((data=(MData*)Next()))
166 out << " " << GetUniqueName() << ".AddEntry(\"" << data->GetRule() << "\");" << endl;
167}
168
169TString MDataArray::GetRule(int i) const
170{
171 return (*this)[i].GetRule();
172}
173
174// --------------------------------------------------------------------------
175//
176// Return the data members existing in this array in a comma-seperated list
177// (This is mainly used for MTask::AddToBranchList)
178//
179TString MDataArray::GetDataMember() const
180{
181 TString str;
182
183 TIter Next(&fList);
184 MData *data = NULL;
185 while ((data=(MData*)Next()))
186 {
187 if (data->GetDataMember().IsNull())
188 continue;
189
190 str += ",";
191 str += data->GetDataMember();
192 }
193 return str;
194}
195
196void MDataArray::GetData(TVector &v) const
197{
198 Int_t ncols = GetNumEntries();
199
200 v.ResizeTo(ncols);
201
202 // same as: for (int i=0; i<ncols; i++) <should be faster>
203 while (ncols--)
204 v(ncols) = (*this)(ncols);
205}
Note: See TracBrowser for help on using the repository browser.