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 2/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MEnv
|
---|
28 | //
|
---|
29 | // It is a slightly changed version of TEnv. It logs all resources which are
|
---|
30 | // touched, so that you can print all untouched resources by
|
---|
31 | // PrintUntouched()
|
---|
32 | //
|
---|
33 | //////////////////////////////////////////////////////////////////////////////
|
---|
34 | #include "MEnv.h"
|
---|
35 |
|
---|
36 | #include <Gtypes.h>
|
---|
37 | #include <TObjString.h>
|
---|
38 |
|
---|
39 | #include <TPave.h>
|
---|
40 | #include <TAttText.h>
|
---|
41 | //#include <TAttFill.h>
|
---|
42 | //#include <TAttLine.h>
|
---|
43 | #include <TAttMarker.h>
|
---|
44 |
|
---|
45 | #include "MLog.h"
|
---|
46 | #include "MLogManip.h"
|
---|
47 |
|
---|
48 | ClassImp(MEnv);
|
---|
49 |
|
---|
50 | using namespace std;
|
---|
51 |
|
---|
52 | Int_t MEnv::GetValue(const char *name, Int_t dflt)
|
---|
53 | {
|
---|
54 | if (!fChecked.FindObject(name))
|
---|
55 | fChecked.Add(new TObjString(name));
|
---|
56 | return TEnv::GetValue(name, dflt);
|
---|
57 | }
|
---|
58 |
|
---|
59 | Double_t MEnv::GetValue(const char *name, Double_t dflt)
|
---|
60 | {
|
---|
61 | if (!fChecked.FindObject(name))
|
---|
62 | fChecked.Add(new TObjString(name));
|
---|
63 | return TEnv::GetValue(name, dflt);
|
---|
64 | }
|
---|
65 |
|
---|
66 | const char *MEnv::GetValue(const char *name, const char *dflt)
|
---|
67 | {
|
---|
68 | if (!fChecked.FindObject(name))
|
---|
69 | fChecked.Add(new TObjString(name));
|
---|
70 | return TEnv::GetValue(name, dflt);
|
---|
71 | }
|
---|
72 |
|
---|
73 | Int_t MEnv::GetFillStyle(const char *name, Int_t dftl)
|
---|
74 | {
|
---|
75 | TString str = GetValue(name, "");
|
---|
76 | str = str.Strip(TString::kBoth);
|
---|
77 | if (str.IsNull())
|
---|
78 | return dftl;
|
---|
79 |
|
---|
80 | str.ToLower();
|
---|
81 |
|
---|
82 | switch (str.Hash())
|
---|
83 | {
|
---|
84 | case (unsigned)-1920099718/*2374867578*/: return 0;// hollow
|
---|
85 | case 764279305: return 1001;// solid
|
---|
86 | case 1854683492: return 2001; // hatch
|
---|
87 | }
|
---|
88 |
|
---|
89 | return str.EndsWith("%") ? 4000+str.Atoi() : str.Atoi();
|
---|
90 | }
|
---|
91 |
|
---|
92 | Int_t MEnv::GetColor(const char *name, Int_t dftl)
|
---|
93 | {
|
---|
94 | TString str = GetValue(name, "");
|
---|
95 |
|
---|
96 | str = str.Strip(TString::kBoth);
|
---|
97 | if (str.IsNull())
|
---|
98 | return dftl;
|
---|
99 |
|
---|
100 | str.ToLower();
|
---|
101 |
|
---|
102 | switch (str.Hash())
|
---|
103 | {
|
---|
104 | case (unsigned)-1926423925/*2368543371*/: return kWhite;
|
---|
105 | case 1814927399: return kBlack;
|
---|
106 | case 7496964: return kRed;
|
---|
107 | case (unsigned)-1397860222/*2897107074*/: return kGreen;
|
---|
108 | case 1702194402: return kBlue;
|
---|
109 | case (unsigned)-1920149414/* 2374817882*/: return kYellow;
|
---|
110 | case (unsigned)-1400748595/*2894218701*/: return kMagenta;
|
---|
111 | case 1851881955: return kCyan;
|
---|
112 | case 749623518: return 18; // grey1
|
---|
113 | case 749623517: return 17; // grey2
|
---|
114 | case 749623516: return 16; // grey3
|
---|
115 | case 749623515: return 15; // grey4
|
---|
116 | case 749623514: return 14; // grey5
|
---|
117 | case 741234910: return 18; // gray1
|
---|
118 | case 741234909: return 17; // gray2
|
---|
119 | case 741234908: return 16; // gray3
|
---|
120 | case 741234907: return 15; // gray4
|
---|
121 | case 741234906: return 14; // gray5
|
---|
122 | }
|
---|
123 | return str.Atoi();
|
---|
124 | }
|
---|
125 |
|
---|
126 | TString MEnv::Compile(TString str, const char *post) const
|
---|
127 | {
|
---|
128 | if (!str.IsNull() && !str.EndsWith("."))
|
---|
129 | str += ".";
|
---|
130 |
|
---|
131 | str += post;
|
---|
132 |
|
---|
133 | return str;
|
---|
134 | }
|
---|
135 |
|
---|
136 | void MEnv::GetAttLine(const char *name, TAttLine &line, TAttLine *dftl)
|
---|
137 | {
|
---|
138 | const TString color = Compile(name, "LineColor");
|
---|
139 | const TString style = Compile(name, "LineStyle");
|
---|
140 | const TString width = Compile(name, "LineWidth");
|
---|
141 |
|
---|
142 | if (!dftl)
|
---|
143 | dftl = &line;
|
---|
144 |
|
---|
145 | const Color_t col = GetColor(color, dftl->GetLineColor());
|
---|
146 | const Style_t sty = GetValue(style, dftl->GetLineStyle());
|
---|
147 | const Style_t wid = GetValue(width, dftl->GetLineWidth());
|
---|
148 |
|
---|
149 | line.SetLineColor(col);
|
---|
150 | line.SetLineStyle(sty);
|
---|
151 | line.SetLineWidth(wid);
|
---|
152 | }
|
---|
153 |
|
---|
154 | void MEnv::GetAttText(const char *name, TAttText &text, TAttText *dftl)
|
---|
155 | {
|
---|
156 | const TString color = Compile(name, "TextColor");
|
---|
157 | const TString align = Compile(name, "TextAlign");
|
---|
158 | const TString angle = Compile(name, "TextAngle");
|
---|
159 | const TString font = Compile(name, "TextFont");
|
---|
160 | const TString size = Compile(name, "TextSize");
|
---|
161 |
|
---|
162 | if (!dftl)
|
---|
163 | dftl = &text;
|
---|
164 |
|
---|
165 | const Color_t col = GetColor(color, dftl->GetTextColor());
|
---|
166 | const Short_t ali = GetValue(align, dftl->GetTextAlign());
|
---|
167 | const Float_t ang = GetValue(angle, dftl->GetTextAngle());
|
---|
168 | const Font_t fon = GetValue(font, dftl->GetTextFont());
|
---|
169 | const Float_t siz = GetValue(size, dftl->GetTextSize());
|
---|
170 |
|
---|
171 | text.SetTextColor(col);
|
---|
172 | text.SetTextAlign(ali);
|
---|
173 | text.SetTextAngle(ang);
|
---|
174 | text.SetTextFont(fon);
|
---|
175 | text.SetTextSize(siz);
|
---|
176 | }
|
---|
177 |
|
---|
178 | void MEnv::GetAttFill(const char *name, TAttFill &fill, TAttFill *dftl)
|
---|
179 | {
|
---|
180 | const TString color = Compile(name, "FillColor");
|
---|
181 | const TString style = Compile(name, "FillStyle");
|
---|
182 |
|
---|
183 | if (!dftl)
|
---|
184 | dftl = &fill;
|
---|
185 |
|
---|
186 | const Color_t col = GetColor(color, dftl->GetFillColor());
|
---|
187 | const Style_t sty = GetFillStyle(style, dftl->GetFillStyle());
|
---|
188 |
|
---|
189 | fill.SetFillColor(col);
|
---|
190 | fill.SetFillStyle(sty);
|
---|
191 | }
|
---|
192 |
|
---|
193 | void MEnv::GetAttMarker(const char *name, TAttMarker &marker, TAttMarker *dftl)
|
---|
194 | {
|
---|
195 | const TString color = Compile(name, "MarkerColor");
|
---|
196 | const TString style = Compile(name, "MarkerStyle");
|
---|
197 | const TString size = Compile(name, "MarkerSize");
|
---|
198 |
|
---|
199 | if (!dftl)
|
---|
200 | dftl = ▮
|
---|
201 |
|
---|
202 | const Color_t col = GetColor(color, dftl->GetMarkerColor());
|
---|
203 | const Style_t sty = GetValue(style, dftl->GetMarkerStyle());
|
---|
204 | const Size_t siz = GetValue(size, dftl->GetMarkerSize());
|
---|
205 |
|
---|
206 | marker.SetMarkerColor(col);
|
---|
207 | marker.SetMarkerStyle(sty);
|
---|
208 | marker.SetMarkerSize(siz);
|
---|
209 | }
|
---|
210 |
|
---|
211 | void MEnv::GetAttPave(const char *str, TPave &pave, TPave *dftl)
|
---|
212 | {
|
---|
213 | const TString post(str);
|
---|
214 |
|
---|
215 | TString name(pave.GetName());
|
---|
216 | if (!name.IsNull() && name!=pave.ClassName())
|
---|
217 | name = Compile(name, post);
|
---|
218 |
|
---|
219 | GetAttLine(name, pave, dftl);
|
---|
220 | GetAttFill(name, pave, dftl);
|
---|
221 |
|
---|
222 | const TString corner = Compile(name, "CornerRadius");
|
---|
223 | const TString border = Compile(name, "BorderSize");
|
---|
224 | const TString option = Compile(name, "Option");
|
---|
225 |
|
---|
226 | if (!dftl)
|
---|
227 | dftl = &pave;
|
---|
228 |
|
---|
229 | const Double_t cor = GetValue(corner, dftl->GetCornerRadius());
|
---|
230 | const Int_t bor = GetValue(border, dftl->GetBorderSize());
|
---|
231 |
|
---|
232 | pave.SetCornerRadius(cor);
|
---|
233 | pave.SetBorderSize(bor);
|
---|
234 |
|
---|
235 | TString opt = GetValue(option, dftl->GetOption());
|
---|
236 | opt.ToLower();
|
---|
237 |
|
---|
238 | const Bool_t has = pave.GetCornerRadius()>0;
|
---|
239 |
|
---|
240 | if (has && !opt.Contains("arc"))
|
---|
241 | opt += "arc";
|
---|
242 |
|
---|
243 | if (!has && opt.Contains("arc"))
|
---|
244 | opt.ReplaceAll("arc", "");
|
---|
245 |
|
---|
246 | pave.SetOption(opt);
|
---|
247 |
|
---|
248 | }
|
---|
249 |
|
---|
250 | void MEnv::GetAttributes(const char *name, TObject *obj, TObject *dftl)
|
---|
251 | {
|
---|
252 | //TAttAxis *line = dynamic_cast<TAttAxis*>(obj);
|
---|
253 | //TAtt3D *line = dynamic_cast<TAtt3D*>(obj);
|
---|
254 | //TAttCanvas *line = dynamic_cast<TAttCanvas*>(obj);
|
---|
255 | //TAttFillCanvas *line = dynamic_cast<TAttFillEitor*>(obj);
|
---|
256 | //TAttLineCanvas *line = dynamic_cast<TAttLineCanvas*>(obj);
|
---|
257 | //TAttLineEditor *line = dynamic_cast<TAttLineEditor*>(obj);
|
---|
258 | //TAttMarkerCanvas *line = dynamic_cast<TAttMarkerCanvas*>(obj);
|
---|
259 | //TAttMarkerEditor *line = dynamic_cast<TAttMarkerEditor*>(obj);
|
---|
260 | //TAttPad *line = dynamic_cast<TAttPad*>(obj);
|
---|
261 | //TAttParticle *line = dynamic_cast<TAttParticle*>(obj);
|
---|
262 | //TAttTextCanvas *line = dynamic_cast<TAttTextCanvas*>(obj);
|
---|
263 | //TAttTextEditor *line = dynamic_cast<TAttTextEditor*>(obj);
|
---|
264 |
|
---|
265 | TPave *pave = dynamic_cast<TPave*>(/*(TAttLine*)*/obj);
|
---|
266 | TAttLine *line = dynamic_cast<TAttLine*>(/*(TAttLine*)*/obj);
|
---|
267 | TAttText *text = dynamic_cast<TAttText*>(/*(TAttText*)*/obj);
|
---|
268 | TAttFill *fill = dynamic_cast<TAttFill*>(/*(TAttFill*)*/obj);
|
---|
269 | TAttMarker *mark = dynamic_cast<TAttMarker*>(/*(TAttMarker*)*/obj);
|
---|
270 |
|
---|
271 | cout << line << " " << text << " " << fill << " " << mark << endl;
|
---|
272 |
|
---|
273 | if (pave)
|
---|
274 | {
|
---|
275 | GetAttPave(name, *pave, dynamic_cast<TPave*>(dftl));
|
---|
276 | return;
|
---|
277 | }
|
---|
278 |
|
---|
279 | if (line)
|
---|
280 | GetAttLine(name, *line, dynamic_cast<TAttLine*>(/*(TAttLine*)*/dftl));
|
---|
281 | if (text)
|
---|
282 | GetAttText(name, *text, dynamic_cast<TAttText*>(/*(TAttText*)*/dftl));
|
---|
283 | if (fill)
|
---|
284 | GetAttFill(name, *fill, dynamic_cast<TAttFill*>(/*(TAttFill*)*/dftl));
|
---|
285 | if (mark)
|
---|
286 | GetAttMarker(name, *mark, dynamic_cast<TAttMarker*>(/*(TAttMarker*)*/dftl));
|
---|
287 | }
|
---|
288 |
|
---|
289 | void MEnv::PrintUntouched() const
|
---|
290 | {
|
---|
291 | int i=0;
|
---|
292 | gLog << inf << flush;
|
---|
293 | gLog.Separator("Untouched Resources");
|
---|
294 | TIter Next(GetTable());
|
---|
295 | TObject *o=0;
|
---|
296 |
|
---|
297 | while ((o=Next()))
|
---|
298 | if (!fChecked.FindObject(o->GetName()))
|
---|
299 | {
|
---|
300 | gLog << warn << " - Resource " << o->GetName() << " not touched" << endl;
|
---|
301 | i++;
|
---|
302 | }
|
---|
303 | if (i==0)
|
---|
304 | gLog << inf << "None." << endl;
|
---|
305 | else
|
---|
306 | gLog << inf << i << " resources have not been touched." << endl;
|
---|
307 | }
|
---|