source: trunk/MagicSoft/Mars/mbase/MEnv.cc@ 7434

Last change on this file since 7434 was 7432, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 7.5 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 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 <TAttText.h>
40#include <TAttFill.h>
41#include <TAttLine.h>
42#include <TAttMarker.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47ClassImp(MEnv);
48
49using namespace std;
50
51Int_t MEnv::GetValue(const char *name, Int_t dflt)
52{
53 if (!fChecked.FindObject(name))
54 fChecked.Add(new TObjString(name));
55 return TEnv::GetValue(name, dflt);
56}
57
58Double_t MEnv::GetValue(const char *name, Double_t dflt)
59{
60 if (!fChecked.FindObject(name))
61 fChecked.Add(new TObjString(name));
62 return TEnv::GetValue(name, dflt);
63}
64
65const char *MEnv::GetValue(const char *name, const char *dflt)
66{
67 if (!fChecked.FindObject(name))
68 fChecked.Add(new TObjString(name));
69 return TEnv::GetValue(name, dflt);
70}
71
72Int_t MEnv::GetColor(const char *name, Int_t dftl)
73{
74 TString str = GetValue(name, "");
75
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)-1926423925/*2368543371*/: return kWhite;
85 case 1814927399: return kBlack;
86 case 7496964: return kRed;
87 case (unsigned)-1397860222/*2897107074*/: return kGreen;
88 case 1702194402: return kBlue;
89 case (unsigned)-1920149414/* 2374817882*/: return kYellow;
90 case (unsigned)-1400748595/*2894218701*/: return kMagenta;
91 case 1851881955: return kCyan;
92 case 749623518: return 18; // grey1
93 case 749623517: return 17; // grey2
94 case 749623516: return 16; // grey3
95 case 749623515: return 15; // grey4
96 case 749623514: return 14; // grey5
97 case 741234910: return 18; // gray1
98 case 741234909: return 17; // gray2
99 case 741234908: return 16; // gray3
100 case 741234907: return 15; // gray4
101 case 741234906: return 14; // gray5
102 }
103 return str.Atoi();
104}
105
106TString MEnv::Compile(TString str, const char *post) const
107{
108 if (!str.IsNull() && str[str.Length()-1]!='.')
109 str += ".";
110
111 str += post;
112
113 return str;
114}
115
116void MEnv::GetAttLine(const char *name, TAttLine &line, TAttLine *dftl)
117{
118 const TString color = Compile(name, "LineColor");
119 const TString style = Compile(name, "LineStyle");
120 const TString width = Compile(name, "LineWidth");
121
122 if (!dftl)
123 dftl = &line;
124
125 const Color_t col = GetColor(color, dftl->GetLineColor());
126 const Style_t sty = GetValue(style, dftl->GetLineStyle());
127 const Style_t wid = GetValue(width, dftl->GetLineWidth());
128
129 line.SetLineColor(col);
130 line.SetLineStyle(sty);
131 line.SetLineWidth(wid);
132}
133
134void MEnv::GetAttText(const char *name, TAttText &text, TAttText *dftl)
135{
136 const TString color = Compile(name, "TextColor");
137 const TString align = Compile(name, "TextAlign");
138 const TString angle = Compile(name, "TextAngle");
139 const TString font = Compile(name, "TextFont");
140 const TString size = Compile(name, "TextSize");
141
142 if (!dftl)
143 dftl = &text;
144
145 const Color_t col = GetColor(color, dftl->GetTextColor());
146 const Short_t ali = GetValue(align, dftl->GetTextAlign());
147 const Float_t ang = GetValue(angle, dftl->GetTextAngle());
148 const Font_t fon = GetValue(font, dftl->GetTextFont());
149 const Float_t siz = GetValue(size, dftl->GetTextSize());
150
151 text.SetTextColor(col);
152 text.SetTextAlign(ali);
153 text.SetTextAngle(ang);
154 text.SetTextFont(fon);
155 text.SetTextSize(siz);
156}
157
158void MEnv::GetAttFill(const char *name, TAttFill &fill, TAttFill *dftl)
159{
160 const TString color = Compile(name, "FillColor");
161 const TString style = Compile(name, "FillStyle");
162
163 if (!dftl)
164 dftl = &fill;
165
166 const Color_t col = GetColor(color, dftl->GetFillColor());
167 const Style_t sty = GetValue(style, dftl->GetFillStyle());
168
169 fill.SetFillColor(col);
170 fill.SetFillStyle(sty);
171}
172
173void MEnv::GetAttMarker(const char *name, TAttMarker &marker, TAttMarker *dftl)
174{
175 const TString color = Compile(name, "MarkerColor");
176 const TString style = Compile(name, "MarkerStyle");
177 const TString size = Compile(name, "MarkerSize");
178
179 if (!dftl)
180 dftl = &marker;
181
182 const Color_t col = GetColor(color, dftl->GetMarkerColor());
183 const Style_t sty = GetValue(style, dftl->GetMarkerStyle());
184 const Size_t siz = GetValue(size, dftl->GetMarkerSize());
185
186 marker.SetMarkerColor(col);
187 marker.SetMarkerStyle(sty);
188 marker.SetMarkerSize(siz);
189}
190
191void MEnv::GetAttributes(const char *name, TObject *obj, TObject *dftl)
192{
193 //TAttAxis *line = dynamic_cast<TAttAxis*>(obj);
194 //TAtt3D *line = dynamic_cast<TAtt3D*>(obj);
195 //TAttCanvas *line = dynamic_cast<TAttCanvas*>(obj);
196 //TAttFillCanvas *line = dynamic_cast<TAttFillEitor*>(obj);
197 //TAttLineCanvas *line = dynamic_cast<TAttLineCanvas*>(obj);
198 //TAttLineEditor *line = dynamic_cast<TAttLineEditor*>(obj);
199 //TAttMarkerCanvas *line = dynamic_cast<TAttMarkerCanvas*>(obj);
200 //TAttMarkerEditor *line = dynamic_cast<TAttMarkerEditor*>(obj);
201 //TAttPad *line = dynamic_cast<TAttPad*>(obj);
202 //TAttParticle *line = dynamic_cast<TAttParticle*>(obj);
203 //TAttTextCanvas *line = dynamic_cast<TAttTextCanvas*>(obj);
204 //TAttTextEditor *line = dynamic_cast<TAttTextEditor*>(obj);
205
206 TAttLine *line = dynamic_cast<TAttLine*>(/*(TAttLine*)*/obj);
207 TAttText *text = dynamic_cast<TAttText*>(/*(TAttText*)*/obj);
208 TAttFill *fill = dynamic_cast<TAttFill*>(/*(TAttFill*)*/obj);
209 TAttMarker *mark = dynamic_cast<TAttMarker*>(/*(TAttMarker*)*/obj);
210
211 cout << line << " " << text << " " << fill << " " << mark << endl;
212
213 if (line)
214 GetAttLine(name, *line, dynamic_cast<TAttLine*>(/*(TAttLine*)*/dftl));
215 if (text)
216 GetAttText(name, *text, dynamic_cast<TAttText*>(/*(TAttText*)*/dftl));
217 if (fill)
218 GetAttFill(name, *fill, dynamic_cast<TAttFill*>(/*(TAttFill*)*/dftl));
219 if (mark)
220 GetAttMarker(name, *mark, dynamic_cast<TAttMarker*>(/*(TAttMarker*)*/dftl));
221}
222
223void MEnv::PrintUntouched() const
224{
225 int i=0;
226 gLog << inf << flush;
227 gLog.Separator("Untouched Resources");
228 TIter Next(GetTable());
229 TObject *o=0;
230 while ((o=Next()))
231 if (!fChecked.FindObject(o->GetName()))
232 {
233 gLog << warn << " - Resource " << o->GetName() << " not touched" << endl;
234 i++;
235 }
236 if (i==0)
237 gLog << inf << "None." << endl;
238 else
239 gLog << inf << i << " resources have not been touched." << endl;
240}
Note: See TracBrowser for help on using the repository browser.