source: trunk/MagicSoft/Mars/mreport/MReport.cc@ 9384

Last change on this file since 9384 was 9146, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 7.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, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2008
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MReport
28//
29// This is a base class for all reports comming from subsystems stored in
30// a report file.
31//
32//
33// Due to wrong assignment by arehucas the veriosn number for some
34// cases is replaced.
35//
36// Old Version | MjdMin | MjdMax | New Version
37// -------------+---------+---------+-------------
38// see MReport::Interprete()
39//
40// Be carefull: The class name of all classes derived from this class
41// should start with 'MReport', see SetupReading
42//
43//////////////////////////////////////////////////////////////////////////////
44#include "MReport.h"
45
46#include "MLogManip.h"
47
48#include "MTime.h"
49#include "MParList.h"
50
51ClassImp(MReport);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Copy fState and fTime
58//
59void MReport::Copy(TObject &obj) const
60{
61 MReport &rep = static_cast<MReport&>(obj);
62
63 rep.fState = fState;
64
65 if (rep.fTime && fTime)
66 *rep.fTime = *fTime;
67}
68
69// --------------------------------------------------------------------------
70//
71// Check whether the given TString begins with the given tag. Remove
72// the tag from the string.
73//
74Bool_t MReport::CheckTag(TString &str, const char *tag) const
75{
76 if (!str.BeginsWith(tag))
77 {
78 *fLog << warn << "WARNING - '" << tag << "' tag not found." << endl;
79 return kFALSE;
80 }
81 str.Remove(0, strlen(tag)); // Remove Tag
82 return kTRUE;
83}
84
85// --------------------------------------------------------------------------
86//
87// Interpretes the beginning of a line which starts like:
88// status hour minute second millisec skip skip skip skip skip
89// The identifier is assumed to be removed.
90//
91// While skip are numbers which won't enter the analysis
92//
93// SetupReading must be called successfully before.
94//
95Bool_t MReport::InterpreteHeader(TString &str, Int_t ver)
96{
97 int len, state;
98 int yea, mon, day, hor, min, sec, ms;
99
100 TString fmt(fHasReportTime ?
101 " %d %d %d %d %d %d %d %d %*d %*d %*d %*d %*d %*d %*d %*d %n" :
102 " %d %d %d %d %d %d %d %d %n");
103
104 // M1/M2 telescope number (FIXME: Readout, check?)
105 if (ver>=200805190)
106 fmt.Prepend(" %*c%*d");
107
108 int n = sscanf(str.Data(), fmt.Data(),
109 &state, &yea, &mon, &day, &hor, &min, &sec, &ms, &len);
110 if (n!=8)
111 {
112 *fLog << err << "ERROR - Cannot interprete header of " << fIdentifier << " (n=" << n << ")" << endl;
113 return kFALSE;
114 }
115
116 if (ms==1000)
117 {
118 *fLog << warn << "WARNING - Milliseconds in timestamp of " << fIdentifier;
119 *fLog << Form(" %d.%d.%d %02d:%02d:%02d.%03d", day, mon, yea, hor, min, sec, ms);
120 *fLog << " reset to 999." << endl;
121 ms = 999;
122 }
123
124 fState=state;
125 if (!fTime->Set(yea, mon, day, hor, min, sec, ms))
126 {
127 *fLog << err << "ERROR - Event " << fIdentifier << " has invalid time ";
128 *fLog << Form("%d.%d.%d %02d:%02d:%02d.%03d", day, mon, yea, hor, min, sec, ms);
129 *fLog << "... abort." << endl;
130 return kFALSE;
131 }
132
133 str.Remove(0, len);
134
135 return kTRUE;
136}
137
138// --------------------------------------------------------------------------
139//
140// Report Body must be overwritten. It will get the line idetified to belong
141// to fIdentifier without the leading status and time infomration as an
142// argument.
143//
144Int_t MReport::InterpreteBody(TString &str, Int_t ver)
145{
146 *fLog << warn << "No interpreter existing for: " << fIdentifier << endl;
147 return kTRUE;
148}
149
150// --------------------------------------------------------------------------
151//
152// Interprets Header and Body of a report file line. Calls SetReadyToSave()
153// in case the interpretation was successfull. And fTime->SetReadyToSave()
154// when a corresponding time container exists.
155//
156// SetupReading must be called successfully before.
157//
158// Due to wrong assignment by arehucas the veriosn number for some
159// cases is replaced.
160//
161// Old Version | MjdMin | MjdMax | New Version
162// -------------+---------+---------+-------------
163// 200504130 | 53548.0 | 53567.0 | 200506300
164// 200503170 | 53446.5 | 53447.5 | 200502240
165// 200508290 | 53643.5 | | 200509300
166// 200510250 | 53801.5 | 53813.5 | 200603080
167// 200510250 | 53813.5 | | 200603190
168// 200604010 | 53863.5 | | 200605080
169// 200805190 | 54711.5 | | 200809030
170//
171Int_t MReport::Interprete(TString &str, const MTime &start, const MTime &stop, Int_t ver)
172{
173 // Interprete header (time, status, etc) of report
174 if (!InterpreteHeader(str, ver))
175 return kFALSE;
176
177 // return -1: This is the special case: out of time limit
178 if (start && *fTime<start)
179 return -1;
180 if (stop && *fTime>stop)
181 return -1;
182
183 // Due to wrong assignment by arehucas the veriosn number for some
184 // cases is replaced.
185 if (ver==200504130 && GetMjd()>53548 && GetMjd()<53567)
186 ver=200506300;
187
188 if (ver==200503170 && GetMjd()>53446.5 && GetMjd()<53447.5)
189 ver=200502240;
190
191 if (ver==200508290 && GetMjd()>53643.5)
192 ver=200509300;
193
194 if (ver==200510250 && GetMjd()>53801.5 && GetMjd()<53813.5)
195 ver=200603080;
196
197 if (ver==200510250 && GetMjd()>53813.5)
198 ver=200603190;
199
200 if (ver==200604010 && GetMjd()>53864.5)
201 ver=200605080;
202
203 if (ver==200805190 && GetMjd()>54711.5)
204 ver=200809030;
205
206 // Interprete body (contents) of report
207 const Int_t rc = InterpreteBody(str, ver);
208 if (rc != kTRUE)
209 return rc;
210
211 SetReadyToSave();
212 fTime->SetReadyToSave();
213
214 return kTRUE;
215}
216
217// --------------------------------------------------------------------------
218//
219// Check for the existance of a corresponding MTime in the given parameter
220// list. If it is not found a new one will be created. The name of the
221// MTime object is created by taking the ClassName() of the derived MReport
222// class and stripping the leading MReport
223//
224Bool_t MReport::SetupReading(MParList &plist)
225{
226 fTime = NULL;
227
228 TString id(ClassName());
229 if (!id.BeginsWith("MReport"))
230 {
231 *fLog << warn << " WARNING - Class name '" << id << "' ";
232 *fLog << " doesn't begin with 'MReport'... no MTime assigned." << endl;
233 return kFALSE;
234 }
235
236 id.Remove(0, 7);
237 if (id.IsNull())
238 {
239 *fLog << warn << " WARNING - No postfix existing... no MTime assigned." << endl;
240 return kFALSE;
241 }
242
243 id.Prepend("MTime");
244
245 fTime = (MTime*)plist.FindCreateObj("MTime", id);
246 if (!fTime)
247 return kFALSE;
248
249 return kTRUE;
250}
Note: See TracBrowser for help on using the repository browser.