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

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