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 03/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MStatusArray
|
---|
28 | //
|
---|
29 | // Helper class for MStatusDisplay
|
---|
30 | //
|
---|
31 | //////////////////////////////////////////////////////////////////////////////
|
---|
32 | #include "MStatusArray.h"
|
---|
33 |
|
---|
34 | #include <TClass.h>
|
---|
35 | #include <TCanvas.h>
|
---|
36 |
|
---|
37 | #include "MLog.h"
|
---|
38 | #include "MLogManip.h"
|
---|
39 |
|
---|
40 | #include "MStatusDisplay.h"
|
---|
41 |
|
---|
42 | ClassImp(MStatusArray);
|
---|
43 |
|
---|
44 | using namespace std;
|
---|
45 |
|
---|
46 | TObject *MStatusArray::DisplayIn(Option_t *o) const
|
---|
47 | {
|
---|
48 | MStatusDisplay *d = 0;
|
---|
49 | if (TString(o).IsNull())
|
---|
50 | d = new MStatusDisplay;
|
---|
51 |
|
---|
52 | if (!d)
|
---|
53 | d = (MStatusDisplay*)gROOT->GetListOfSpecials()->FindObject(o);
|
---|
54 |
|
---|
55 | if (!d)
|
---|
56 | return 0;
|
---|
57 |
|
---|
58 | if (d->Display(*this))
|
---|
59 | return d;
|
---|
60 |
|
---|
61 | delete d;
|
---|
62 | return 0;
|
---|
63 | }
|
---|
64 |
|
---|
65 | void MStatusArray::DisplayIn(MStatusDisplay &d, const char *tab) const
|
---|
66 | {
|
---|
67 | d.Display(*this, tab);
|
---|
68 | }
|
---|
69 |
|
---|
70 | TObject *MStatusArray::FindObjectInPad(TVirtualPad *pad, const char *object, TClass *cls) const
|
---|
71 | {
|
---|
72 | TObject *o = pad->FindObject(object);
|
---|
73 | if (o && o->InheritsFrom(cls))
|
---|
74 | return o;
|
---|
75 |
|
---|
76 | TIter Next(pad->GetListOfPrimitives());
|
---|
77 | while ((o=Next()))
|
---|
78 | {
|
---|
79 | if (o==pad || !o->InheritsFrom(TVirtualPad::Class()))
|
---|
80 | continue;
|
---|
81 |
|
---|
82 | if ((o = FindObjectInPad((TVirtualPad*)o, object, cls)))
|
---|
83 | if (o->InheritsFrom(cls))
|
---|
84 | return o;
|
---|
85 | }
|
---|
86 | return 0;
|
---|
87 | }
|
---|
88 |
|
---|
89 | // FIXME: Move to a general class MMARS (TROOT) and unify with MParContainer
|
---|
90 | TClass *MStatusArray::GetClass(const char *name) const
|
---|
91 | {
|
---|
92 | TClass *cls = gROOT->GetClass(name);
|
---|
93 | Int_t rc = 0;
|
---|
94 | if (!cls)
|
---|
95 | rc =1;
|
---|
96 | else
|
---|
97 | {
|
---|
98 | if (!cls->Property())
|
---|
99 | rc = 5;
|
---|
100 | if (!cls->Size())
|
---|
101 | rc = 4;
|
---|
102 | if (!cls->IsLoaded())
|
---|
103 | rc = 3;
|
---|
104 | if (!cls->HasDefaultConstructor())
|
---|
105 | rc = 2;
|
---|
106 | }
|
---|
107 |
|
---|
108 | if (rc==0)
|
---|
109 | return cls;
|
---|
110 |
|
---|
111 | gLog << err << dbginf << "Class '" << name << "' not in dictionary: ";
|
---|
112 | switch (rc)
|
---|
113 | {
|
---|
114 | case 1:
|
---|
115 | gLog << "gROOT->GetClass() returned NULL." << endl;
|
---|
116 | return NULL;
|
---|
117 | case 2:
|
---|
118 | gLog << "no default constructor." << endl;
|
---|
119 | return NULL;
|
---|
120 | case 3:
|
---|
121 | gLog << "not loaded." << endl;
|
---|
122 | return NULL;
|
---|
123 | case 4:
|
---|
124 | gLog << "zero size." << endl;
|
---|
125 | return NULL;
|
---|
126 | case 5:
|
---|
127 | gLog << "no property." << endl;
|
---|
128 | return NULL;
|
---|
129 | }
|
---|
130 |
|
---|
131 | gLog << "THIS SHOULD NEVER HAPPEN!" << endl;
|
---|
132 |
|
---|
133 | return 0;
|
---|
134 | }
|
---|
135 |
|
---|
136 | TCanvas *MStatusArray::FindCanvas(const char *name) const
|
---|
137 | {
|
---|
138 | TObject *o = TObjArray::FindObject(name);
|
---|
139 | if (!o)
|
---|
140 | return 0;
|
---|
141 |
|
---|
142 | return o->InheritsFrom(TCanvas::Class()) ? (TCanvas*)o : 0;
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | TObject *MStatusArray::FindObjectInCanvas(const char *object, const char *base, const char *canvas) const
|
---|
147 | {
|
---|
148 | TClass *cls = GetClass(base);
|
---|
149 | if (!cls)
|
---|
150 | return 0;
|
---|
151 |
|
---|
152 | TCanvas *c = canvas ? FindCanvas(canvas) : 0;
|
---|
153 | if (canvas)
|
---|
154 | {
|
---|
155 | if (!c)
|
---|
156 | {
|
---|
157 | gLog << warn << "Canvas '" << canvas << "' not found..." << endl;
|
---|
158 | return 0;
|
---|
159 | }
|
---|
160 |
|
---|
161 | TObject *o = FindObjectInPad(c, object, cls);
|
---|
162 | if (!o)
|
---|
163 | {
|
---|
164 | gLog << warn << "Object '" << object << "' [" << base << "] not found in canvas '" << canvas << "'..." << endl;
|
---|
165 | return 0;
|
---|
166 | }
|
---|
167 |
|
---|
168 | return o; //o->InheritsFrom(cls) ? o : 0;
|
---|
169 | }
|
---|
170 |
|
---|
171 | TObject *o=0;
|
---|
172 | TIter Next(this);
|
---|
173 | while ((o=Next()))
|
---|
174 | {
|
---|
175 | if (!o->InheritsFrom(TVirtualPad::Class()))
|
---|
176 | continue;
|
---|
177 |
|
---|
178 | if ((o=FindObjectInPad((TVirtualPad*)c, object, cls)))
|
---|
179 | return o;
|
---|
180 | }
|
---|
181 |
|
---|
182 | gLog << warn << "Object '" << object << "' [" << base << "] not found in canvas '" << canvas << "'..." << endl;
|
---|
183 | return NULL;
|
---|
184 | }
|
---|
185 |
|
---|
186 | TObject *MStatusArray::FindObjectInCanvas(const char *object, const char *canvas) const
|
---|
187 | {
|
---|
188 | return FindObjectInCanvas(object, object, canvas);
|
---|
189 | }
|
---|
190 |
|
---|
191 | TObject *MStatusArray::FindObject(const char *object, const char *base) const
|
---|
192 | {
|
---|
193 | return FindObjectInCanvas(object, base, 0);
|
---|
194 | }
|
---|
195 |
|
---|
196 | TObject *MStatusArray::FindObject(const char *object) const
|
---|
197 | {
|
---|
198 | return FindObjectInCanvas(object, object, 0);
|
---|
199 | }
|
---|