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

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