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