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-2007
|
---|
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 <TAttMarker.h>
|
---|
42 | #include <THashList.h> // needed since root v5.10/00 (TEnv::GetTable)
|
---|
43 |
|
---|
44 | #include "MLog.h"
|
---|
45 | #include "MLogManip.h"
|
---|
46 |
|
---|
47 | ClassImp(MEnv);
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | //---------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // (Default) constructor. If the given file cannot be accessed SetRcName("")
|
---|
54 | // is called which can then be checked by IsValid()
|
---|
55 | //
|
---|
56 | MEnv::MEnv(const char *name) : TEnv(name)
|
---|
57 | {
|
---|
58 | fChecked.SetOwner();
|
---|
59 |
|
---|
60 | if (!IsValid())
|
---|
61 | return;
|
---|
62 |
|
---|
63 | TString fname(name);
|
---|
64 | gSystem->ExpandPathName(fname);
|
---|
65 |
|
---|
66 | if (gSystem->AccessPathName(fname, kFileExists))
|
---|
67 | fname = "";
|
---|
68 |
|
---|
69 | SetRcName(fname);
|
---|
70 |
|
---|
71 | if (GetEntries()<=0 && !fname.IsNull() && fname!=name)
|
---|
72 | ReadFile(fname, kEnvLocal);;
|
---|
73 | }
|
---|
74 |
|
---|
75 | //---------------------------------------------------------------------------
|
---|
76 | //
|
---|
77 | // Make sure that the name used for writing doesn't contain a full path
|
---|
78 | //
|
---|
79 | const char *MEnv::GetName() const
|
---|
80 | {
|
---|
81 | const char *pos = strrchr(GetRcName(), '/');
|
---|
82 | return pos>0 ? pos+1 : GetRcName();
|
---|
83 | }
|
---|
84 |
|
---|
85 | //---------------------------------------------------------------------------
|
---|
86 | //
|
---|
87 | // Return the total number of entries in the table
|
---|
88 | //
|
---|
89 | Int_t MEnv::GetEntries() const
|
---|
90 | {
|
---|
91 | if (!GetTable())
|
---|
92 | return -1;
|
---|
93 |
|
---|
94 | return GetTable()->GetEntries();
|
---|
95 | }
|
---|
96 |
|
---|
97 | //---------------------------------------------------------------------------
|
---|
98 | //
|
---|
99 | // Compile str+post and make sure that in between there is a unique dot.
|
---|
100 | //
|
---|
101 | TString MEnv::Compile(TString str, const char *post) const
|
---|
102 | {
|
---|
103 | if (!str.IsNull() && !str.EndsWith("."))
|
---|
104 | str += ".";
|
---|
105 |
|
---|
106 | str += post;
|
---|
107 |
|
---|
108 | return str;
|
---|
109 | }
|
---|
110 |
|
---|
111 | //---------------------------------------------------------------------------
|
---|
112 | //
|
---|
113 | // Get the value from the table and remember the value as checked
|
---|
114 | //
|
---|
115 | Int_t MEnv::GetValue(const char *name, Int_t dflt)
|
---|
116 | {
|
---|
117 | if (!fChecked.FindObject(name))
|
---|
118 | fChecked.Add(new TObjString(name));
|
---|
119 | return TEnv::GetValue(name, dflt);
|
---|
120 | }
|
---|
121 |
|
---|
122 | //---------------------------------------------------------------------------
|
---|
123 | //
|
---|
124 | // Get the value from the table and remember the value as checked
|
---|
125 | //
|
---|
126 | Double_t MEnv::GetValue(const char *name, Double_t dflt)
|
---|
127 | {
|
---|
128 | if (!fChecked.FindObject(name))
|
---|
129 | fChecked.Add(new TObjString(name));
|
---|
130 | return TEnv::GetValue(name, dflt);
|
---|
131 | }
|
---|
132 |
|
---|
133 | //---------------------------------------------------------------------------
|
---|
134 | //
|
---|
135 | // Get the value from the table and remember the value as checked
|
---|
136 | //
|
---|
137 | const char *MEnv::GetValue(const char *name, const char *dflt)
|
---|
138 | {
|
---|
139 | if (!fChecked.FindObject(name))
|
---|
140 | fChecked.Add(new TObjString(name));
|
---|
141 | return TEnv::GetValue(name, dflt);
|
---|
142 | }
|
---|
143 |
|
---|
144 | //---------------------------------------------------------------------------
|
---|
145 | //
|
---|
146 | // TEnv doen't have a streamer --> cannot be cloned
|
---|
147 | // --> we have to clone it ourself
|
---|
148 | //
|
---|
149 | TObject *MEnv::Clone(const char *) const
|
---|
150 | {
|
---|
151 | MEnv *env = new MEnv("/dev/null");
|
---|
152 | env->SetRcName(GetRcName());
|
---|
153 | env->AddEnv(*this);
|
---|
154 | return env;
|
---|
155 | }
|
---|
156 |
|
---|
157 | //---------------------------------------------------------------------------
|
---|
158 | //
|
---|
159 | // Interprete fill style: Hollow, Solid, Hatch, 0%-100%
|
---|
160 | // If no text style is detected the value is converted to an integer.
|
---|
161 | //
|
---|
162 | Int_t MEnv::GetFillStyle(const char *name, Int_t dftl)
|
---|
163 | {
|
---|
164 | TString str = GetValue(name, "");
|
---|
165 | str = str.Strip(TString::kBoth);
|
---|
166 | if (str.IsNull())
|
---|
167 | return dftl;
|
---|
168 |
|
---|
169 | str.ToLower();
|
---|
170 |
|
---|
171 | switch (str.Hash())
|
---|
172 | {
|
---|
173 | case 2374867578U: return 0; // hollow
|
---|
174 | case 764279305U: return 1001; // solid
|
---|
175 | case 1854683492U: return 2001; // hatch
|
---|
176 | }
|
---|
177 |
|
---|
178 | return str.EndsWith("%") ? 4000+str.Atoi() : str.Atoi();
|
---|
179 | }
|
---|
180 |
|
---|
181 | //---------------------------------------------------------------------------
|
---|
182 | //
|
---|
183 | // Interprete line style: Solid, Dashed, Dotted, DashDotted
|
---|
184 | // If no line style is detected the value is converted to an integer.
|
---|
185 | //
|
---|
186 | Int_t MEnv::GetLineStyle(const char *name, Int_t dftl)
|
---|
187 | {
|
---|
188 | TString str = GetValue(name, "");
|
---|
189 | str = str.Strip(TString::kBoth);
|
---|
190 | if (str.IsNull())
|
---|
191 | return dftl;
|
---|
192 |
|
---|
193 | str.ToLower();
|
---|
194 |
|
---|
195 | switch (str.Hash())
|
---|
196 | {
|
---|
197 | case 764279305U: return kSolid;
|
---|
198 | case 241979881U: return kDashed;
|
---|
199 | case 2391642602U: return kDotted;
|
---|
200 | case 1124931659U: return kDashDotted;
|
---|
201 | }
|
---|
202 |
|
---|
203 | return str.Atoi();
|
---|
204 | }
|
---|
205 |
|
---|
206 | //---------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // Interprete alignment: Top, Right, Left, Bottom, Center, tr, cc, bl, ...
|
---|
209 | // If no text align is detected the value is converted to an integer.
|
---|
210 | //
|
---|
211 | // eg.
|
---|
212 | // Top Right
|
---|
213 | // Bottom Center
|
---|
214 | // Center
|
---|
215 | // tr
|
---|
216 | // br
|
---|
217 | // cr
|
---|
218 | //
|
---|
219 | Int_t MEnv::GetAlign(const char *name, Int_t dftl)
|
---|
220 | {
|
---|
221 | TString str = GetValue(name, "");
|
---|
222 | str = str.Strip(TString::kBoth);
|
---|
223 | if (str.IsNull())
|
---|
224 | return dftl;
|
---|
225 |
|
---|
226 | str.ToLower();
|
---|
227 |
|
---|
228 | switch (str.Hash())
|
---|
229 | {
|
---|
230 | case 29746: return 33; // tr
|
---|
231 | case 25379: return 22; // cc
|
---|
232 | case 25132: return 11; // bl
|
---|
233 |
|
---|
234 | case 25388: return 12; // cl
|
---|
235 | case 25394: return 32; // cr
|
---|
236 |
|
---|
237 | case 29731: return 23; // tc
|
---|
238 | case 25123: return 32; // bc
|
---|
239 |
|
---|
240 | case 29740: return 13; // tl
|
---|
241 | case 25138: return 13; // br
|
---|
242 | }
|
---|
243 |
|
---|
244 | Int_t align = 0;
|
---|
245 | if (str.Contains("right", TString::kIgnoreCase))
|
---|
246 | align += 3;
|
---|
247 | if (str.Contains("left", TString::kIgnoreCase))
|
---|
248 | align += 1;
|
---|
249 | if (str.Contains("bottom", TString::kIgnoreCase))
|
---|
250 | align += 10;
|
---|
251 | if (str.Contains("top", TString::kIgnoreCase))
|
---|
252 | align += 30;
|
---|
253 |
|
---|
254 | if (str.Contains("center", TString::kIgnoreCase))
|
---|
255 | {
|
---|
256 | if (align==0)
|
---|
257 | return 22;
|
---|
258 | if (align/10==0)
|
---|
259 | return align+20;
|
---|
260 | if (align%10==0)
|
---|
261 | return align+2;
|
---|
262 | }
|
---|
263 |
|
---|
264 | return align>0 ? align : str.Atoi();
|
---|
265 | }
|
---|
266 |
|
---|
267 | //---------------------------------------------------------------------------
|
---|
268 | //
|
---|
269 | // Interprete color: Black, White, Red, Green, Blue, Yellow, Magenta,
|
---|
270 | // Cyan, Gray1-5, Grey1-5.
|
---|
271 | // If no text color is detected the value is converted to an integer.
|
---|
272 | //
|
---|
273 | // eg.
|
---|
274 | // Red
|
---|
275 | // Light Red
|
---|
276 | // Dark Red
|
---|
277 | //
|
---|
278 | Int_t MEnv::GetColor(const char *name, Int_t dftl)
|
---|
279 | {
|
---|
280 | TString str = GetValue(name, "");
|
---|
281 |
|
---|
282 | str = str.Strip(TString::kBoth);
|
---|
283 | if (str.IsNull())
|
---|
284 | return dftl;
|
---|
285 |
|
---|
286 | str.ToLower();
|
---|
287 |
|
---|
288 | Int_t offset=0;
|
---|
289 | if (str.Contains("dark"))
|
---|
290 | {
|
---|
291 | str.ReplaceAll("dark", "");
|
---|
292 | str = str.Strip(TString::kBoth);
|
---|
293 | offset = 100;
|
---|
294 | }
|
---|
295 | if (str.Contains("light"))
|
---|
296 | {
|
---|
297 | str.ReplaceAll("light", "");
|
---|
298 | str = str.Strip(TString::kBoth);
|
---|
299 | offset = 150;
|
---|
300 | }
|
---|
301 |
|
---|
302 | switch (str.Hash())
|
---|
303 | {
|
---|
304 | case 2368543371U: return kWhite+offset;
|
---|
305 | case 1814927399U: return kBlack+offset;
|
---|
306 | case 7496964U: return kRed+offset;
|
---|
307 | case 2897107074U: return kGreen+offset;
|
---|
308 | case 1702194402U: return kBlue+offset;
|
---|
309 | case 2374817882U: return kYellow+offset;
|
---|
310 | case 2894218701U: return kMagenta+offset;
|
---|
311 | case 1851881955U: return kCyan+offset;
|
---|
312 | case 749623518U: return 19; // grey1
|
---|
313 | case 749623517U: return 18; // grey2
|
---|
314 | case 749623516U: return 17; // grey3
|
---|
315 | case 749623515U: return 16; // grey4
|
---|
316 | case 749623514U: return 15; // grey5
|
---|
317 | case 749623513U: return 14; // grey6
|
---|
318 | case 749623512U: return 13; // grey7
|
---|
319 | case 749623511U: return 12; // grey8
|
---|
320 | case 741234910U: return 19; // gray1
|
---|
321 | case 741234909U: return 18; // gray2
|
---|
322 | case 741234908U: return 17; // gray3
|
---|
323 | case 741234907U: return 16; // gray4
|
---|
324 | case 741234906U: return 15; // gray5
|
---|
325 | case 741234905U: return 14; // gray6
|
---|
326 | case 741234904U: return 13; // gray7
|
---|
327 | case 741234903U: return 12; // gray8
|
---|
328 | }
|
---|
329 | return str.Atoi();
|
---|
330 | }
|
---|
331 |
|
---|
332 | //---------------------------------------------------------------------------
|
---|
333 | //
|
---|
334 | // As possible convert the color col into a text string which can be
|
---|
335 | // interpreted by GetColor before setting the resource value
|
---|
336 | //
|
---|
337 | void MEnv::SetColor(const char *name, Int_t col)
|
---|
338 | {
|
---|
339 | TString val;
|
---|
340 |
|
---|
341 | if (col>99 && col<101+kCyan)
|
---|
342 | {
|
---|
343 | val = "Dark ";
|
---|
344 | col -= 100;
|
---|
345 | }
|
---|
346 | if (col>150 && col<151+kCyan)
|
---|
347 | {
|
---|
348 | val = "Light ";
|
---|
349 | col -= 150;
|
---|
350 | }
|
---|
351 |
|
---|
352 | switch (col)
|
---|
353 | {
|
---|
354 | case kWhite: val += "White"; break;
|
---|
355 | case kBlack: val += "Black"; break;
|
---|
356 | case kRed: val += "Red"; break;
|
---|
357 | case kGreen: val += "Green"; break;
|
---|
358 | case kBlue: val += "Blue"; break;
|
---|
359 | case kYellow: val += "Yellow"; break;
|
---|
360 | case kMagenta: val += "Magenta"; break;
|
---|
361 | case kCyan: val += "Cyan"; break;
|
---|
362 | case 19: val += "Grey1"; break;
|
---|
363 | case 18: val += "Grey2"; break;
|
---|
364 | case 17: val += "Grey3"; break;
|
---|
365 | case 16: val += "Grey4"; break;
|
---|
366 | case 15: val += "Grey5"; break;
|
---|
367 | case 14: val += "Grey6"; break;
|
---|
368 | case 13: val += "Grey7"; break;
|
---|
369 | case 12: val += "Grey8"; break;
|
---|
370 | }
|
---|
371 |
|
---|
372 | if (val.IsNull())
|
---|
373 | val += col;
|
---|
374 |
|
---|
375 | SetValue(name, val);
|
---|
376 | }
|
---|
377 |
|
---|
378 | //---------------------------------------------------------------------------
|
---|
379 | //
|
---|
380 | // As possible convert the alignment align into a text string which can be
|
---|
381 | // interpreted by GetAlign before setting the resource value
|
---|
382 | //
|
---|
383 | void MEnv::SetAlign(const char *name, Int_t align)
|
---|
384 | {
|
---|
385 | TString val;
|
---|
386 | if (align==22)
|
---|
387 | {
|
---|
388 | SetValue(name, "Center");
|
---|
389 | return;
|
---|
390 | }
|
---|
391 |
|
---|
392 | switch (align%10)
|
---|
393 | {
|
---|
394 | case 1: val += "Left"; break;
|
---|
395 | case 2: val += "Center"; break;
|
---|
396 | case 3: val += "Right"; break;
|
---|
397 | }
|
---|
398 |
|
---|
399 | switch (align/10)
|
---|
400 | {
|
---|
401 | case 1: val += "Bottom"; break;
|
---|
402 | case 2: val += "Center"; break;
|
---|
403 | case 3: val += "Top"; break;
|
---|
404 | }
|
---|
405 |
|
---|
406 | SetValue(name, val);
|
---|
407 | }
|
---|
408 |
|
---|
409 | //---------------------------------------------------------------------------
|
---|
410 | //
|
---|
411 | // As possible convert the fill style style into a text string which can be
|
---|
412 | // interpreted by GetFillStyle before setting the resource value
|
---|
413 | //
|
---|
414 | void MEnv::SetFillStyle(const char *name, Int_t style)
|
---|
415 | {
|
---|
416 | TString val;
|
---|
417 |
|
---|
418 | if (style>3999 && style<4101)
|
---|
419 | val = Form("%d%%", style-4000);
|
---|
420 |
|
---|
421 | switch (style)
|
---|
422 | {
|
---|
423 | case 0: val = "Hollow"; break;
|
---|
424 | case 1001: val = "Solid"; break;
|
---|
425 | case 2001: val = "Hatch"; break;
|
---|
426 | }
|
---|
427 |
|
---|
428 | if (val.IsNull())
|
---|
429 | val += style;
|
---|
430 |
|
---|
431 | SetValue(name, val);
|
---|
432 | }
|
---|
433 |
|
---|
434 | //---------------------------------------------------------------------------
|
---|
435 | //
|
---|
436 | // As possible convert the line style style into a text string which can be
|
---|
437 | // interpreted by GetLineStyle before setting the resource value
|
---|
438 | //
|
---|
439 | void MEnv::SetLineStyle(const char *name, Int_t style)
|
---|
440 | {
|
---|
441 | TString val;
|
---|
442 | switch (style)
|
---|
443 | {
|
---|
444 | case kSolid: val = "Solid"; break;
|
---|
445 | case kDashed: val = "Dashed"; break;
|
---|
446 | case kDotted: val = "Dotted"; break;
|
---|
447 | case kDashDotted: val = "DashDotted"; break;
|
---|
448 | }
|
---|
449 |
|
---|
450 | if (val.IsNull())
|
---|
451 | val += style;
|
---|
452 |
|
---|
453 | SetValue(name, val);
|
---|
454 | }
|
---|
455 |
|
---|
456 | //---------------------------------------------------------------------------
|
---|
457 | //
|
---|
458 | // As possible convert the marker style style into a text string which can be
|
---|
459 | // interpreted by GetLineStyle before setting the resource value
|
---|
460 | //
|
---|
461 | void MEnv::SetMarkerStyle(const char *name, Int_t style)
|
---|
462 | {
|
---|
463 | TString val;
|
---|
464 | switch (style)
|
---|
465 | {
|
---|
466 | case kDot: val = "dot";
|
---|
467 | case kPlus: val = "plus";
|
---|
468 | case kCircle: val = "circle";
|
---|
469 | case kMultiply: val = "multiply";
|
---|
470 | case kFullDotSmall: val = "fulldotsmall";
|
---|
471 | case kFullDotMedium: val = "fulldotmedium";
|
---|
472 | case kFullDotLarge: val = "fulldotlarge";
|
---|
473 | case kOpenTriangleDown: val = "opentriangledown";
|
---|
474 | case kFullCross: val = "fullcross";
|
---|
475 | case kFullCircle: val = "fullcircle";
|
---|
476 | case kFullSquare: val = "fullsquare";
|
---|
477 | case kFullTriangleDown: val = "fulltriangledown";
|
---|
478 | case kOpenCircle: val = "opencircle";
|
---|
479 | case kOpenSquare: val = "opensquare";
|
---|
480 | case kOpenTriangleUp: val = "opentriangleup";
|
---|
481 | case kOpenDiamond: val = "opendiamond";
|
---|
482 | case kOpenCross: val = "opencross";
|
---|
483 | case kFullStar: val = "fullstar";
|
---|
484 | case kOpenStar: val = "openstar";
|
---|
485 | }
|
---|
486 |
|
---|
487 | if (val.IsNull())
|
---|
488 | val += style;
|
---|
489 |
|
---|
490 | SetValue(name, val);
|
---|
491 | }
|
---|
492 |
|
---|
493 | //---------------------------------------------------------------------------
|
---|
494 | //
|
---|
495 | // Get the attributed from a TAttLine (if dftl is given use it as default)
|
---|
496 | // name.LineColor <see also GetColor>
|
---|
497 | // name.LineStyle
|
---|
498 | // name.LineWidth
|
---|
499 | // For more details on the meaning see TAttLine
|
---|
500 | //
|
---|
501 | void MEnv::GetAttLine(const char *name, TAttLine &line, TAttLine *dftl)
|
---|
502 | {
|
---|
503 | const TString color = Compile(name, "LineColor");
|
---|
504 | const TString style = Compile(name, "LineStyle");
|
---|
505 | const TString width = Compile(name, "LineWidth");
|
---|
506 |
|
---|
507 | if (!dftl)
|
---|
508 | dftl = &line;
|
---|
509 |
|
---|
510 | const Color_t col = GetColor(color, dftl->GetLineColor());
|
---|
511 | const Style_t sty = GetLineStyle(style, dftl->GetLineStyle());
|
---|
512 | const Style_t wid = GetValue(width, dftl->GetLineWidth());
|
---|
513 |
|
---|
514 | line.SetLineColor(col);
|
---|
515 | line.SetLineStyle(sty);
|
---|
516 | line.SetLineWidth(wid);
|
---|
517 | }
|
---|
518 |
|
---|
519 | //---------------------------------------------------------------------------
|
---|
520 | //
|
---|
521 | // Get the attributed from a TAttText (if dftl is given use it as default)
|
---|
522 | // name.TextColor <see also GetColor>
|
---|
523 | // name.TextAlign <see also GetAlign>
|
---|
524 | // name.TextAngle
|
---|
525 | // name.TextFont
|
---|
526 | // name.TextSize
|
---|
527 | // For more details on the meaning see TAttText
|
---|
528 | //
|
---|
529 | void MEnv::GetAttText(const char *name, TAttText &text, TAttText *dftl)
|
---|
530 | {
|
---|
531 | const TString color = Compile(name, "TextColor");
|
---|
532 | const TString align = Compile(name, "TextAlign");
|
---|
533 | const TString angle = Compile(name, "TextAngle");
|
---|
534 | const TString font = Compile(name, "TextFont");
|
---|
535 | const TString size = Compile(name, "TextSize");
|
---|
536 |
|
---|
537 | if (!dftl)
|
---|
538 | dftl = &text;
|
---|
539 |
|
---|
540 | const Color_t col = GetColor(color, dftl->GetTextColor());
|
---|
541 | const Short_t ali = GetAlign(align, dftl->GetTextAlign());
|
---|
542 | const Float_t ang = GetValue(angle, dftl->GetTextAngle());
|
---|
543 | const Font_t fon = GetValue(font, dftl->GetTextFont());
|
---|
544 | const Float_t siz = GetValue(size, dftl->GetTextSize());
|
---|
545 |
|
---|
546 | text.SetTextColor(col);
|
---|
547 | text.SetTextAlign(ali);
|
---|
548 | text.SetTextAngle(ang);
|
---|
549 | text.SetTextFont(fon);
|
---|
550 | text.SetTextSize(siz);
|
---|
551 | }
|
---|
552 |
|
---|
553 | //---------------------------------------------------------------------------
|
---|
554 | //
|
---|
555 | // Get the attributed from a TAttFill (if dftl is given use it as default)
|
---|
556 | // name.FillColor <see also GetColor>
|
---|
557 | // name.FillStyle <see also GetFillStyle>
|
---|
558 | // For more details on the meaning see TAttFill
|
---|
559 | //
|
---|
560 | void MEnv::GetAttFill(const char *name, TAttFill &fill, TAttFill *dftl)
|
---|
561 | {
|
---|
562 | const TString color = Compile(name, "FillColor");
|
---|
563 | const TString style = Compile(name, "FillStyle");
|
---|
564 |
|
---|
565 | if (!dftl)
|
---|
566 | dftl = &fill;
|
---|
567 |
|
---|
568 | const Color_t col = GetColor(color, dftl->GetFillColor());
|
---|
569 | const Style_t sty = GetFillStyle(style, dftl->GetFillStyle());
|
---|
570 |
|
---|
571 | fill.SetFillColor(col);
|
---|
572 | fill.SetFillStyle(sty);
|
---|
573 | }
|
---|
574 |
|
---|
575 | //---------------------------------------------------------------------------
|
---|
576 | //
|
---|
577 | // Get the attributed from a TAttMarker (if dftl is given use it as default)
|
---|
578 | // name.MarkerColor <see also GetColor>
|
---|
579 | // name.MarkerStyle
|
---|
580 | // name.MarkerSize
|
---|
581 | // For more details on the meaning see TAttMarker
|
---|
582 | //
|
---|
583 | void MEnv::GetAttMarker(const char *name, TAttMarker &marker, TAttMarker *dftl)
|
---|
584 | {
|
---|
585 | const TString color = Compile(name, "MarkerColor");
|
---|
586 | const TString style = Compile(name, "MarkerStyle");
|
---|
587 | const TString size = Compile(name, "MarkerSize");
|
---|
588 |
|
---|
589 | if (!dftl)
|
---|
590 | dftl = ▮
|
---|
591 |
|
---|
592 | const Color_t col = GetColor(color, dftl->GetMarkerColor());
|
---|
593 | const Style_t sty = GetValue(style, dftl->GetMarkerStyle());
|
---|
594 | const Size_t siz = GetValue(size, dftl->GetMarkerSize());
|
---|
595 |
|
---|
596 | marker.SetMarkerColor(col);
|
---|
597 | marker.SetMarkerStyle(sty);
|
---|
598 | marker.SetMarkerSize(siz);
|
---|
599 | }
|
---|
600 |
|
---|
601 | //---------------------------------------------------------------------------
|
---|
602 | //
|
---|
603 | // Get the attributed from a TPave (if dftl is given use it as default)
|
---|
604 | // name.CornerRadius
|
---|
605 | // name.BorderSize
|
---|
606 | // name.Option
|
---|
607 | // Also all resources from TAttLine and TAttFill are supported.
|
---|
608 | //
|
---|
609 | // For your conveinience: If the CornerRadius is greater than 0 "arc" is
|
---|
610 | // added to the options. If it is equal or less than 0 "arc" is removed
|
---|
611 | // from the options.
|
---|
612 | //
|
---|
613 | // For more details on the meaning see TPave
|
---|
614 | //
|
---|
615 | void MEnv::GetAttPave(const char *str, TPave &pave, TPave *dftl)
|
---|
616 | {
|
---|
617 | const TString post(str);
|
---|
618 |
|
---|
619 | TString name(pave.GetName());
|
---|
620 | if (!name.IsNull() && name!=pave.ClassName())
|
---|
621 | name = Compile(name, post);
|
---|
622 |
|
---|
623 | GetAttLine(name, pave, dftl);
|
---|
624 | GetAttFill(name, pave, dftl);
|
---|
625 |
|
---|
626 | const TString corner = Compile(name, "CornerRadius");
|
---|
627 | const TString border = Compile(name, "BorderSize");
|
---|
628 | const TString option = Compile(name, "Option");
|
---|
629 |
|
---|
630 | if (!dftl)
|
---|
631 | dftl = &pave;
|
---|
632 |
|
---|
633 | const Double_t cor = GetValue(corner, dftl->GetCornerRadius());
|
---|
634 | const Int_t bor = GetValue(border, dftl->GetBorderSize());
|
---|
635 |
|
---|
636 | pave.SetCornerRadius(cor);
|
---|
637 | pave.SetBorderSize(bor);
|
---|
638 |
|
---|
639 | TString opt = GetValue(option, dftl->GetOption());
|
---|
640 | opt.ToLower();
|
---|
641 |
|
---|
642 | const Bool_t has = pave.GetCornerRadius()>0;
|
---|
643 |
|
---|
644 | if (has && !opt.Contains("arc"))
|
---|
645 | opt += "arc";
|
---|
646 |
|
---|
647 | if (!has && opt.Contains("arc"))
|
---|
648 | opt.ReplaceAll("arc", "");
|
---|
649 |
|
---|
650 | pave.SetOption(opt);
|
---|
651 |
|
---|
652 | }
|
---|
653 |
|
---|
654 | //---------------------------------------------------------------------------
|
---|
655 | //
|
---|
656 | // Get the attributed for the TObject obj. Use dftl for default attributes
|
---|
657 | // if given.
|
---|
658 | //
|
---|
659 | // There is support for:
|
---|
660 | // TPave <see GetAttPave>
|
---|
661 | // TAttLine <see GetAttLine>
|
---|
662 | // TAttText <see GetAttText>
|
---|
663 | // TAttFill <see GetAttFill>
|
---|
664 | // TAttMarker <see GetAttMarker>
|
---|
665 | //
|
---|
666 | void MEnv::GetAttributes(const char *name, TObject *obj, TObject *dftl)
|
---|
667 | {
|
---|
668 | //TAttAxis *line = dynamic_cast<TAttAxis*>(obj);
|
---|
669 | //TAtt3D *line = dynamic_cast<TAtt3D*>(obj);
|
---|
670 | //TAttCanvas *line = dynamic_cast<TAttCanvas*>(obj);
|
---|
671 | //TAttFillCanvas *line = dynamic_cast<TAttFillEitor*>(obj);
|
---|
672 | //TAttLineCanvas *line = dynamic_cast<TAttLineCanvas*>(obj);
|
---|
673 | //TAttLineEditor *line = dynamic_cast<TAttLineEditor*>(obj);
|
---|
674 | //TAttMarkerCanvas *line = dynamic_cast<TAttMarkerCanvas*>(obj);
|
---|
675 | //TAttMarkerEditor *line = dynamic_cast<TAttMarkerEditor*>(obj);
|
---|
676 | //TAttPad *line = dynamic_cast<TAttPad*>(obj);
|
---|
677 | //TAttParticle *line = dynamic_cast<TAttParticle*>(obj);
|
---|
678 | //TAttTextCanvas *line = dynamic_cast<TAttTextCanvas*>(obj);
|
---|
679 | //TAttTextEditor *line = dynamic_cast<TAttTextEditor*>(obj);
|
---|
680 |
|
---|
681 | TPave *pave = dynamic_cast<TPave*>(obj);
|
---|
682 | TAttLine *line = dynamic_cast<TAttLine*>(obj);
|
---|
683 | TAttText *text = dynamic_cast<TAttText*>(obj);
|
---|
684 | TAttFill *fill = dynamic_cast<TAttFill*>(obj);
|
---|
685 | TAttMarker *mark = dynamic_cast<TAttMarker*>(obj);
|
---|
686 |
|
---|
687 | if (pave)
|
---|
688 | {
|
---|
689 | GetAttPave(name, *pave, dynamic_cast<TPave*>(dftl));
|
---|
690 | return;
|
---|
691 | }
|
---|
692 |
|
---|
693 | if (line)
|
---|
694 | GetAttLine(name, *line, dynamic_cast<TAttLine*>(dftl));
|
---|
695 | if (text)
|
---|
696 | GetAttText(name, *text, dynamic_cast<TAttText*>(dftl));
|
---|
697 | if (fill)
|
---|
698 | GetAttFill(name, *fill, dynamic_cast<TAttFill*>(dftl));
|
---|
699 | if (mark)
|
---|
700 | GetAttMarker(name, *mark, dynamic_cast<TAttMarker*>(dftl));
|
---|
701 | }
|
---|
702 |
|
---|
703 | //---------------------------------------------------------------------------
|
---|
704 | //
|
---|
705 | // Set the resources from a TAttLine:
|
---|
706 | // name.LineColor <see also SetColor>
|
---|
707 | // name.LineStyle
|
---|
708 | // name.LineWidth
|
---|
709 | //
|
---|
710 | void MEnv::SetAttLine(const char *name, const TAttLine &line)
|
---|
711 | {
|
---|
712 | const TString color = Compile(name, "LineColor");
|
---|
713 | const TString style = Compile(name, "LineStyle");
|
---|
714 | const TString width = Compile(name, "LineWidth");
|
---|
715 |
|
---|
716 | SetColor(color, line.GetLineColor());
|
---|
717 | SetLineStyle(style, line.GetLineStyle());
|
---|
718 | SetValue(width, line.GetLineWidth());
|
---|
719 | }
|
---|
720 |
|
---|
721 | //---------------------------------------------------------------------------
|
---|
722 | //
|
---|
723 | // Set the resources from a TAttText:
|
---|
724 | // name.TextColor <see also SetColor>
|
---|
725 | // name.TextAlign <see also SetAlign>
|
---|
726 | // name.TextAngle
|
---|
727 | // name.TextFont
|
---|
728 | // name.TextSize
|
---|
729 | //
|
---|
730 | void MEnv::SetAttText(const char *name, const TAttText &text)
|
---|
731 | {
|
---|
732 | const TString color = Compile(name, "TextColor");
|
---|
733 | const TString align = Compile(name, "TextAlign");
|
---|
734 | const TString angle = Compile(name, "TextAngle");
|
---|
735 | const TString font = Compile(name, "TextFont");
|
---|
736 | const TString size = Compile(name, "TextSize");
|
---|
737 |
|
---|
738 | SetColor(color, text.GetTextColor());
|
---|
739 | SetAlign(align, text.GetTextAlign());
|
---|
740 | SetValue(angle, text.GetTextAngle());
|
---|
741 | SetValue(font, text.GetTextFont());
|
---|
742 | SetValue(size, text.GetTextSize());
|
---|
743 | }
|
---|
744 |
|
---|
745 | //---------------------------------------------------------------------------
|
---|
746 | //
|
---|
747 | // Set the resources from a TAttFill:
|
---|
748 | // name.FillColor <see also SetColor>
|
---|
749 | // name.FillStyle <see also SetFillStyle>
|
---|
750 | //
|
---|
751 | void MEnv::SetAttFill(const char *name, const TAttFill &fill)
|
---|
752 | {
|
---|
753 | const TString color = Compile(name, "FillColor");
|
---|
754 | const TString style = Compile(name, "FillStyle");
|
---|
755 |
|
---|
756 | SetColor(color, fill.GetFillColor());
|
---|
757 | SetFillStyle(style, fill.GetFillStyle());
|
---|
758 | }
|
---|
759 |
|
---|
760 | //---------------------------------------------------------------------------
|
---|
761 | //
|
---|
762 | // Set the resources from a TAttMarker:
|
---|
763 | // name.MarkerColor <see also SetColor>
|
---|
764 | // name.MarkerStyle
|
---|
765 | // name.MarkerSize
|
---|
766 | //
|
---|
767 | void MEnv::SetAttMarker(const char *name, const TAttMarker &marker)
|
---|
768 | {
|
---|
769 | const TString color = Compile(name, "MarkerColor");
|
---|
770 | const TString style = Compile(name, "MarkerStyle");
|
---|
771 | const TString size = Compile(name, "MarkerSize");
|
---|
772 |
|
---|
773 | SetColor(color, marker.GetMarkerColor());
|
---|
774 | SetMarkerStyle(style, marker.GetMarkerStyle());
|
---|
775 | SetValue(size, marker.GetMarkerSize());
|
---|
776 | }
|
---|
777 |
|
---|
778 | //---------------------------------------------------------------------------
|
---|
779 | //
|
---|
780 | // Set the resources from a TPave:
|
---|
781 | // name.CornerRadius
|
---|
782 | // name.BorderSize
|
---|
783 | // name.Option
|
---|
784 | // Also all resources from TAttLine and TAttFill are supported.
|
---|
785 | //
|
---|
786 | void MEnv::SetAttPave(const char *str, const TPave &pave)
|
---|
787 | {
|
---|
788 | const TString name(str);
|
---|
789 |
|
---|
790 | SetAttLine(name, pave);
|
---|
791 | SetAttFill(name, pave);
|
---|
792 |
|
---|
793 | const TString corner = Compile(name, "CornerRadius");
|
---|
794 | const TString border = Compile(name, "BorderSize");
|
---|
795 | const TString option = Compile(name, "Option");
|
---|
796 |
|
---|
797 | SetValue(corner, const_cast<TPave&>(pave).GetCornerRadius());
|
---|
798 | SetValue(border, const_cast<TPave&>(pave).GetBorderSize());
|
---|
799 | SetValue(option, pave.GetOption());
|
---|
800 | }
|
---|
801 |
|
---|
802 | //---------------------------------------------------------------------------
|
---|
803 | //
|
---|
804 | // Set the attributed for the TObject obj.
|
---|
805 | //
|
---|
806 | // There is support for:
|
---|
807 | // TPave <see SetAttPave>
|
---|
808 | // TAttLine <see SetAttLine>
|
---|
809 | // TAttText <see SetAttText>
|
---|
810 | // TAttFill <see SetAttFill>
|
---|
811 | // TAttMarker <see SetAttMarker>
|
---|
812 | //
|
---|
813 | void MEnv::SetAttributes(const char *name, const TObject *obj)
|
---|
814 | {
|
---|
815 | const TPave *pave = dynamic_cast<const TPave*>(obj);
|
---|
816 | const TAttLine *line = dynamic_cast<const TAttLine*>(obj);
|
---|
817 | const TAttText *text = dynamic_cast<const TAttText*>(obj);
|
---|
818 | const TAttFill *fill = dynamic_cast<const TAttFill*>(obj);
|
---|
819 | const TAttMarker *mark = dynamic_cast<const TAttMarker*>(obj);
|
---|
820 |
|
---|
821 | if (pave)
|
---|
822 | {
|
---|
823 | SetAttPave(name, *pave);
|
---|
824 | return;
|
---|
825 | }
|
---|
826 |
|
---|
827 | if (line)
|
---|
828 | SetAttLine(name, *line);
|
---|
829 | if (text)
|
---|
830 | SetAttText(name, *text);
|
---|
831 | if (fill)
|
---|
832 | SetAttFill(name, *fill);
|
---|
833 | if (mark)
|
---|
834 | SetAttMarker(name, *mark);
|
---|
835 | }
|
---|
836 |
|
---|
837 | //---------------------------------------------------------------------------
|
---|
838 | //
|
---|
839 | // Add all values from TEnv env the this MEnv. To not overwrite existing
|
---|
840 | // values set overwrite to kFALSE
|
---|
841 | //
|
---|
842 | void MEnv::AddEnv(const TEnv &env, Bool_t overwrite)
|
---|
843 | {
|
---|
844 | if (!GetTable() || !env.GetTable())
|
---|
845 | return;
|
---|
846 |
|
---|
847 | TIter Next(env.GetTable());
|
---|
848 |
|
---|
849 | TEnvRec *er;
|
---|
850 | while ((er = (TEnvRec*)Next()))
|
---|
851 | {
|
---|
852 | if (overwrite || !Defined(er->GetName()))
|
---|
853 | SetValue(er->GetName(), er->GetValue(), er->GetLevel(), er->GetType());
|
---|
854 | }
|
---|
855 | }
|
---|
856 |
|
---|
857 | //---------------------------------------------------------------------------
|
---|
858 | //
|
---|
859 | // Add name and full path to output
|
---|
860 | //
|
---|
861 | void MEnv::PrintEnv(EEnvLevel level) const
|
---|
862 | {
|
---|
863 | cout << "# Path: " << GetRcName() << endl;
|
---|
864 | cout << "# Name: " << GetName() << endl;
|
---|
865 | TEnv::PrintEnv(level);
|
---|
866 | }
|
---|
867 |
|
---|
868 | //---------------------------------------------------------------------------
|
---|
869 | //
|
---|
870 | // Print resources which have never been touched (for debugging)
|
---|
871 | //
|
---|
872 | void MEnv::PrintUntouched() const
|
---|
873 | {
|
---|
874 | int i=0;
|
---|
875 | gLog << inf << flush;
|
---|
876 |
|
---|
877 | TString sep = "Untouched Resources - ";
|
---|
878 | sep += GetRcName();
|
---|
879 | gLog.Separator(sep);
|
---|
880 | TIter Next(GetTable());
|
---|
881 | TObject *o=0;
|
---|
882 |
|
---|
883 | while ((o=Next()))
|
---|
884 | if (!fChecked.FindObject(o->GetName()))
|
---|
885 | {
|
---|
886 | gLog << warn << " - Resource " << o->GetName() << " not touched" << endl;
|
---|
887 | i++;
|
---|
888 | }
|
---|
889 | if (i==0)
|
---|
890 | gLog << inf << "None." << endl;
|
---|
891 | else
|
---|
892 | gLog << inf << i << " resources have not been touched." << endl;
|
---|
893 | }
|
---|
894 |
|
---|
895 | //---------------------------------------------------------------------------
|
---|
896 | //
|
---|
897 | // Return number of resources which have not been touched.
|
---|
898 | //
|
---|
899 | Int_t MEnv::GetNumUntouched() const
|
---|
900 | {
|
---|
901 | int i=0;
|
---|
902 | TIter Next(GetTable());
|
---|
903 | TObject *o=0;
|
---|
904 | while ((o=Next()))
|
---|
905 | if (!fChecked.FindObject(o->GetName()))
|
---|
906 | i++;
|
---|
907 | return i;
|
---|
908 | }
|
---|