source: trunk/MagicSoft/Mars/mbase/MStatusArray.cc@ 5250

Last change on this file since 5250 was 4981, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.4 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 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
42ClassImp(MStatusArray);
43
44using namespace std;
45
46TObject *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
65TObject *MStatusArray::FindObjectInPad(TVirtualPad *pad, const char *object, TClass *cls) const
66{
67 TObject *o = pad->FindObject(object);
68 if (o && o->InheritsFrom(cls))
69 return o;
70
71 TIter Next(pad->GetListOfPrimitives());
72 while ((o=Next()))
73 {
74 if (o==pad || !o->InheritsFrom(TVirtualPad::Class()))
75 continue;
76
77 if ((o = FindObjectInPad((TVirtualPad*)o, object, cls)))
78 if (o->InheritsFrom(cls))
79 return o;
80 }
81 return 0;
82}
83
84// FIXME: Move to a general class MMARS (TROOT) and unify with MParContainer
85TClass *MStatusArray::GetClass(const char *name) const
86{
87 TClass *cls = gROOT->GetClass(name);
88 Int_t rc = 0;
89 if (!cls)
90 rc =1;
91 else
92 {
93 if (!cls->Property())
94 rc = 5;
95 if (!cls->Size())
96 rc = 4;
97 if (!cls->IsLoaded())
98 rc = 3;
99 if (!cls->HasDefaultConstructor())
100 rc = 2;
101 }
102
103 if (rc==0)
104 return cls;
105
106 gLog << err << dbginf << "Class '" << name << "' not in dictionary: ";
107 switch (rc)
108 {
109 case 1:
110 gLog << "gROOT->GetClass() returned NULL." << endl;
111 return NULL;
112 case 2:
113 gLog << "no default constructor." << endl;
114 return NULL;
115 case 3:
116 gLog << "not loaded." << endl;
117 return NULL;
118 case 4:
119 gLog << "zero size." << endl;
120 return NULL;
121 case 5:
122 gLog << "no property." << endl;
123 return NULL;
124 }
125
126 gLog << "THIS SHOULD NEVER HAPPEN!" << endl;
127
128 return 0;
129}
130
131TCanvas *MStatusArray::FindCanvas(const char *name) const
132{
133 TObject *o = TObjArray::FindObject(name);
134 if (!o)
135 return 0;
136
137 return o->InheritsFrom(TCanvas::Class()) ? (TCanvas*)o : 0;
138}
139
140
141TObject *MStatusArray::FindObjectInCanvas(const char *object, const char *base, const char *canvas) const
142{
143 TClass *cls = GetClass(base);
144 if (!cls)
145 return 0;
146
147 TCanvas *c = canvas ? FindCanvas(canvas) : 0;
148 if (canvas)
149 {
150 if (!c)
151 return 0;
152
153 TObject *o = FindObjectInPad(c, object, cls);
154 if (!o)
155 return 0;
156
157 return o->InheritsFrom(cls) ? o : 0;
158 }
159
160 TObject *o=0;
161 TIter Next(this);
162 while ((o=Next()))
163 {
164 if (!o->InheritsFrom(TVirtualPad::Class()))
165 continue;
166
167 if ((o=FindObjectInPad((TVirtualPad*)c, object, cls)))
168 return o;
169 }
170
171 return NULL;
172}
173
174TObject *MStatusArray::FindObjectInCanvas(const char *object, const char *canvas) const
175{
176 return FindObjectInCanvas(object, object, canvas);
177}
178
179TObject *MStatusArray::FindObject(const char *object, const char *base) const
180{
181 return FindObjectInCanvas(object, base, 0);
182}
183
184TObject *MStatusArray::FindObject(const char *object) const
185{
186 return FindObjectInCanvas(object, object, 0);
187}
Note: See TracBrowser for help on using the repository browser.