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, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MReadReports //
|
---|
28 | //
|
---|
29 | /////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MReadReports.h"
|
---|
31 |
|
---|
32 | #include <TChain.h>
|
---|
33 | #include <TChainElement.h>
|
---|
34 |
|
---|
35 | #include "MLog.h"
|
---|
36 | #include "MLogManip.h"
|
---|
37 |
|
---|
38 | #include "MTime.h"
|
---|
39 | #include "MParList.h"
|
---|
40 | #include "MReadTree.h"
|
---|
41 | #include "MTaskList.h"
|
---|
42 |
|
---|
43 | ClassImp(MReadReports);
|
---|
44 |
|
---|
45 | using namespace std;
|
---|
46 |
|
---|
47 | MReadReports::MReadReports()
|
---|
48 | {
|
---|
49 | fName = "MRead";
|
---|
50 | fTitle = "MReadReports";
|
---|
51 |
|
---|
52 | fTrees = new MTaskList("MReadReports");
|
---|
53 | fChains = new TList;
|
---|
54 |
|
---|
55 | fTrees->SetOwner();
|
---|
56 | fChains->SetOwner();
|
---|
57 | }
|
---|
58 |
|
---|
59 | MReadReports::~MReadReports()
|
---|
60 | {
|
---|
61 | TObject *o=0;
|
---|
62 | TIter NextC(fChains);
|
---|
63 | while ((o=NextC()))
|
---|
64 | {
|
---|
65 | delete *GetTime((TChain*)o);
|
---|
66 | delete GetTime((TChain*)o);
|
---|
67 | }
|
---|
68 |
|
---|
69 | delete fTrees;
|
---|
70 | delete fChains;
|
---|
71 | }
|
---|
72 |
|
---|
73 | void MReadReports::AddToBranchList(const char *name)
|
---|
74 | {
|
---|
75 | MTask::AddToBranchList(name);
|
---|
76 | }
|
---|
77 |
|
---|
78 | void MReadReports::AddTree(const char *tree, const char *time)
|
---|
79 | {
|
---|
80 | /*
|
---|
81 | if (fTrees->GetNumTasks()>0)
|
---|
82 | {
|
---|
83 | *fLog << warn << "WARNING - AddTree must be called before AddFile... ignored." << endl;
|
---|
84 | *fLog << dbg << fTrees->GetNumTasks() << endl;
|
---|
85 | return kFALSE;
|
---|
86 | }
|
---|
87 | */
|
---|
88 | MReadTree *t = new MReadTree(tree);
|
---|
89 | t->SetName(tree);
|
---|
90 | t->SetTitle(time?time:"");
|
---|
91 |
|
---|
92 | //FIXME!
|
---|
93 | //t->DisableAutoScheme();
|
---|
94 |
|
---|
95 | fTrees->AddToList(t);
|
---|
96 | // return kTRUE;
|
---|
97 | }
|
---|
98 |
|
---|
99 | Int_t MReadReports::AddFile(const char *fname, Int_t entries)
|
---|
100 | {
|
---|
101 | Int_t n=0;
|
---|
102 |
|
---|
103 | TIter NextT(fTrees->GetList());
|
---|
104 | MReadTree *tree=0;
|
---|
105 | while ((tree=(MReadTree*)NextT()))
|
---|
106 | n += tree->AddFile(fname, entries);
|
---|
107 |
|
---|
108 | return n;
|
---|
109 | }
|
---|
110 |
|
---|
111 | Int_t MReadReports::PreProcess(MParList *plist)
|
---|
112 | {
|
---|
113 | fList = (MTask*)plist->FindObject("MTaskList");
|
---|
114 |
|
---|
115 | fChains->Delete();
|
---|
116 |
|
---|
117 | Int_t i=0;
|
---|
118 |
|
---|
119 | TIter NextT(fTrees->GetList());
|
---|
120 | MReadTree *tree=0;
|
---|
121 | while ((tree=(MReadTree*)NextT()))
|
---|
122 | {
|
---|
123 | TString tn(tree->GetTitle());
|
---|
124 | if (tn.IsNull())
|
---|
125 | {
|
---|
126 | tn += "MTime";
|
---|
127 | tn += tree->GetName();
|
---|
128 | tn += ".";
|
---|
129 | }
|
---|
130 |
|
---|
131 | TString tn2(tn);
|
---|
132 | tn2 += "*";
|
---|
133 |
|
---|
134 | // FIXME: Should be tree->AddToBranchList such that
|
---|
135 | // each run a new 'table' is created, but
|
---|
136 | // MRead is searching for MTaskList in the
|
---|
137 | // parameter list.
|
---|
138 | //AddToBranchList((const char*)tn2);
|
---|
139 |
|
---|
140 | //
|
---|
141 | // SetBranchStatus wants to have a pointer to a pointer
|
---|
142 | //
|
---|
143 | MTime **tx = new MTime*;
|
---|
144 | *tx = new MTime;
|
---|
145 |
|
---|
146 | TChain *c=new TChain(tree->GetName());
|
---|
147 | c->SetBranchStatus("*", 0);
|
---|
148 | c->SetBranchAddress(tn, tx);
|
---|
149 | tn+="*";
|
---|
150 | c->SetBranchStatus(tn, 1);
|
---|
151 | c->Add((TChain*)tree->fChain);
|
---|
152 | c->GetEntry(0);
|
---|
153 |
|
---|
154 | fChains->Add(c);
|
---|
155 |
|
---|
156 | i++;
|
---|
157 | }
|
---|
158 |
|
---|
159 | fPos.Set(i);
|
---|
160 |
|
---|
161 | return fTrees->CallPreProcess(plist);
|
---|
162 | }
|
---|
163 |
|
---|
164 | MTime** MReadReports::GetTime(TChain *c) const
|
---|
165 | {
|
---|
166 | TChainElement *e=(TChainElement*)c->GetStatus()->At(1);
|
---|
167 | return (MTime**)e->GetBaddress();
|
---|
168 | }
|
---|
169 |
|
---|
170 | Int_t MReadReports::Process()
|
---|
171 | {
|
---|
172 | while (fChains->GetSize())
|
---|
173 | {
|
---|
174 | Int_t i=0;
|
---|
175 |
|
---|
176 | MTime tmin;
|
---|
177 |
|
---|
178 | Int_t nmin=0;
|
---|
179 |
|
---|
180 | TIter NextC(fChains);
|
---|
181 | TChain *c=0;
|
---|
182 | while ((c=(TChain*)NextC()))
|
---|
183 | {
|
---|
184 | MTime &t = **GetTime(c);
|
---|
185 |
|
---|
186 | if (t.GetHour()<12)
|
---|
187 | t.SetTime((Byte_t)(t.GetHour()+24), t.GetMin(), t.GetSec(), t.GetNanoSec());
|
---|
188 |
|
---|
189 | if (i==0)
|
---|
190 | tmin = t;
|
---|
191 |
|
---|
192 | if (t < tmin)
|
---|
193 | {
|
---|
194 | tmin = t;
|
---|
195 | nmin = i;
|
---|
196 | }
|
---|
197 | i++;
|
---|
198 | }
|
---|
199 |
|
---|
200 | TChain *chain = (TChain*)fChains->At(nmin);
|
---|
201 |
|
---|
202 | chain->GetEntry(++fPos[nmin]);
|
---|
203 |
|
---|
204 | // FIXME: Use Stream ID and call CallProcess() ?
|
---|
205 | if (((MTask*)fTrees->GetList()->At(nmin))->CallProcess())
|
---|
206 | {
|
---|
207 | /*
|
---|
208 | *fLog << dbg << ((MReadTree*)fTrees->At(nmin))->GetTreeName() << " " << flush;
|
---|
209 |
|
---|
210 | if (tmin.GetHour()>=24)
|
---|
211 | tmin.SetTime((Byte_t)(tmin.GetHour()-24), tmin.GetMin(), tmin.GetSec(), tmin.GetNanoSec());
|
---|
212 | tmin.Print();
|
---|
213 | */
|
---|
214 |
|
---|
215 | fList->SetStreamId(fTrees->GetList()->At(nmin)->GetName());
|
---|
216 | return kTRUE;
|
---|
217 | }
|
---|
218 |
|
---|
219 | delete *GetTime(chain);
|
---|
220 | delete GetTime(chain);
|
---|
221 | // FIXME: Is it really deleted?
|
---|
222 | fChains->Remove(chain);
|
---|
223 | }
|
---|
224 |
|
---|
225 | return kFALSE;
|
---|
226 | }
|
---|
227 |
|
---|
228 | Int_t MReadReports::PostProcess()
|
---|
229 | {
|
---|
230 | return fTrees->CallPostProcess();
|
---|
231 | }
|
---|
232 |
|
---|
233 | void MReadReports::PrintStatistics(const Int_t lvl, Bool_t title) const
|
---|
234 | {
|
---|
235 | MRead::PrintStatistics(lvl, title);
|
---|
236 | fTrees->PrintStatistics(lvl, title);
|
---|
237 | }
|
---|