source: trunk/MagicSoft/Mars/mreport/MReportCC.cc@ 8512

Last change on this file since 8512 was 8287, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 8.9 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, 12/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MReportCC
28//
29// This is the class interpreting and storing the CC-REPORT information.
30//
31// From here maily weather station data is decoded such as
32// temperature, humidity, wind-speed and solar radiation
33//
34// Class Version 2:
35// ----------------
36// + Float_t fUPSStatus; // arbitrary units (still not properly defined)
37// + Float_t fDifRubGPS; // [us] Difference between the Rubidium clock time and the time provided by the GPS receiver
38//
39//
40//////////////////////////////////////////////////////////////////////////////
41#include "MReportCC.h"
42
43#include "MLogManip.h"
44
45#include "MParList.h"
46
47#include "MCameraTH.h"
48#include "MCameraTD.h"
49#include "MCameraRecTemp.h"
50
51ClassImp(MReportCC);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Default construtor. Initialize identifier to "CC-REPORT" Report
58// is expected to have no 'subsystem' time.
59//
60MReportCC::MReportCC() : MReport("CC-REPORT", kFALSE)
61{
62 fName = "MReportCC";
63 fTitle = "Class for CC-REPORT information";
64}
65
66// --------------------------------------------------------------------------
67//
68// FindCreate the following objects:
69// - MCameraTH
70//
71Bool_t MReportCC::SetupReading(MParList &plist)
72{
73 fTH = (MCameraTH*)plist.FindCreateObj("MCameraTH");
74 if (!fTH)
75 return kFALSE;
76
77 fTD = (MCameraTD*)plist.FindCreateObj("MCameraTD");
78 if (!fTD)
79 return kFALSE;
80
81 fRecTemp = (MCameraRecTemp*)plist.FindCreateObj("MCameraRecTemp");
82 if (!fRecTemp)
83 return kFALSE;
84
85 return MReport::SetupReading(plist);
86}
87
88// --------------------------------------------------------------------------
89//
90// Check whether the given TString begins with the given tag. Remove
91// the tag from the string.
92//
93Bool_t MReportCC::CheckTag(TString &str, const char *tag) const
94{
95 if (!str.BeginsWith(tag))
96 {
97 *fLog << warn << "WARNING - '" << tag << "' tag not found." << endl;
98 return kFALSE;
99 }
100 str.Remove(0, strlen(tag)); // Remove Tag
101 return kTRUE;
102}
103
104
105// --------------------------------------------------------------------------
106//
107// Interprete the body of the CC-REPORT string
108//
109Bool_t MReportCC::InterpreteCC(TString &str, Int_t ver)
110{
111 const Int_t skip = ver<200407270 ? 30 : 31;
112
113 // Remove the 30/31 tokens of the subsystem status
114 // table 12.1 p59
115 for (int i=0; i<skip; i++)
116 str.Remove(0, str.First(' ')+1);
117
118 Int_t len;
119 const Int_t n=sscanf(str.Data(),
120 "%*f %*f %*f %*f %f %f %f %f %f %f %n",
121 &fTemperature, &fSolarRadiation, &fWindSpeed,
122 &fHumidity, &fUPSStatus, &fDifRubGPS, &len);
123 if (n!=6)
124 {
125 *fLog << warn << "WARNING - Wrong number of arguments." << endl;
126 return kFALSE;
127 }
128
129 str.Remove(0, len);
130
131 return kTRUE;
132}
133
134// --------------------------------------------------------------------------
135//
136// Interprete the TH (discriminator thresholds) part of the report
137//
138Bool_t MReportCC::InterpreteTH(TString &str, Int_t ver)
139{
140 if (!CheckTag(str, "TH "))
141 return kFALSE;
142
143 // Skip the TH (discriminator thresholds) part of the report (for old
144 // CC files with wrong or nonsense number of TH-Bytes)
145 if (ver<200507190)
146 {
147 Ssiz_t pr = str.First(' ');
148 if (pr<0)
149 {
150 *fLog << warn << "WARNING - No TH information found at all." << endl;
151 return kFALSE;
152 }
153 if (pr!=1154)
154 {
155 fTD->Invalidate();
156
157 str.Remove(0, pr);
158 str=str.Strip(TString::kLeading);
159 return kTRUE;
160 }
161 }
162
163 const char *pos = str.Data();
164 const char *end = str.Data()+577*2;
165
166 Int_t i=0;
167 while (pos<end)
168 {
169 const Char_t hex[3] = { pos[0], pos[1], 0 };
170 pos += 2;
171
172 const Int_t n=sscanf(hex, "%2hhx", &fTH->fTH[i++]);
173 if (n==1)
174 continue;
175
176 *fLog << warn << "WARNING - Reading hexadecimal TH information." << endl;
177 return kFALSE;
178 }
179
180 fTH->SetValid();
181
182 str.Remove(0, end-str.Data()); // Remove TH
183 str=str.Strip(TString::kLeading);
184 return kTRUE;
185}
186
187// --------------------------------------------------------------------------
188//
189// Interprete the TD (discriminator delays) part of the report
190//
191Bool_t MReportCC::InterpreteTD(TString &str, Int_t ver)
192{
193 if (!CheckTag(str, "TD "))
194 return kFALSE;
195
196 // Skip the TD (discriminator delays) part of the report (for old
197 // CC files with wrong or nonsense number of TD-Bytes)
198 if (ver<200412210)
199 {
200 Ssiz_t pr = str.First(' ');
201 if (pr<0)
202 {
203 *fLog << warn << "WARNING - No TD information found at all." << endl;
204 return kFALSE;
205 }
206 if (pr!=1000)
207 {
208 fTD->Invalidate();
209
210 str.Remove(0, pr);
211 str=str.Strip(TString::kLeading);
212 return kTRUE;
213 }
214 }
215
216 // Older files have less bytes (pixels) stored
217 const Int_t numpix = ver<200510250 ? 500 : 577;
218
219 const char *pos = str.Data();
220 const char *end = str.Data()+numpix*2;
221
222 Int_t i=0;
223 while (pos<end)
224 {
225 const Char_t hex[3] = { pos[0], pos[1], 0 };
226 pos += 2;
227
228 const Int_t n=sscanf(hex, "%2hhx", &fTD->fTD[i++]);
229 if (n==1)
230 continue;
231
232 *fLog << warn << "WARNING - Reading hexadecimal TD information." << endl;
233 return kFALSE;
234 }
235
236 fTD->SetValid();
237
238 str.Remove(0, end-str.Data()); // Remove TD
239 str=str.Strip(TString::kLeading);
240
241 return kTRUE;
242}
243
244
245// --------------------------------------------------------------------------
246//
247// Interprete the receiver board temperature part of the report
248//
249Bool_t MReportCC::InterpreteRecTemp(TString &str)
250{
251 if (!CheckTag(str, "RECTEMP "))
252 return kFALSE;
253
254 Int_t len;
255 for (Int_t i=0; i<76; i++)
256 {
257 const Int_t n=sscanf(str.Data(), "%f %n", &fRecTemp->fRecTemp[i], &len);
258 str.Remove(0, len);
259
260 if (n==1)
261 continue;
262
263 if (n==0 && i==0)
264 {
265 *fLog << inf << "Receiver Board Temperatures empty." << endl;
266 fRecTemp->Invalidate();
267 break;
268 }
269
270 *fLog << warn << "WARNING - Reading Receiver Board Temperature information." << endl;
271 return kFALSE;
272 }
273
274 return kTRUE;
275}
276
277// --------------------------------------------------------------------------
278//
279// Interprete the body of the CC-REPORT string
280//
281Int_t MReportCC::InterpreteBody(TString &str, Int_t ver)
282{
283 if (ver<200404070)
284 {
285 *fLog << err << "ERROR - MReportCC::InterpreteBody not prepared for ";
286 *fLog << " report-files with version<200404070" << endl;
287 return kFALSE;
288 }
289
290 if (!InterpreteCC(str, ver))
291 return kCONTINUE;
292
293 if (str.BeginsWith("RECEIVERS-COM-ERROR"))
294 {
295 *fLog << inf << "Receiver Com-error... threshold setting and receiver board temp. invalid." << endl;
296 fTD->Invalidate();
297 fTH->Invalidate();
298 fRecTemp->Invalidate();
299 str.Remove(0, 19);
300 }
301 else
302 {
303 if (!InterpreteTH(str, ver))
304 return kCONTINUE;
305
306 if (!InterpreteTD(str, ver))
307 return kCONTINUE;
308
309 if (ver>=200510250)
310 if (!InterpreteRecTemp(str))
311 return kCONTINUE;
312 }
313
314 if (str.Strip(TString::kBoth)!=(TString)"OVER")
315 {
316 *fLog << warn << "WARNING - 'OVER' tag not found." << endl;
317 return kCONTINUE;
318 }
319
320 return kTRUE;
321}
322
323// --------------------------------------------------------------------------
324//
325// Print contents of report
326//
327void MReportCC::Print(Option_t *opt) const
328{
329 *fLog << all << GetDescriptor() << ": Status=" << (int)GetState();
330 *fLog << " Hum=" << Form("%3.0f", fHumidity);
331 *fLog << "% Temp=" << Form("%+3.0f", fTemperature);
332 *fLog << "°C Wind=" << Form("%3.0f", fWindSpeed);
333 *fLog << "km/h SolarRad=" << Form("%4.0f", fSolarRadiation) << "W/m^2" << endl;
334}
Note: See TracBrowser for help on using the repository browser.