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

Last change on this file since 9492 was 9462, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 7.6 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// 200812040 | 54814.5 | | 200812140
171// 200902210 | 54968.5 | | 200905170
172//
173Int_t MReport::Interprete(TString &str, const MTime &start, const MTime &stop, Int_t ver)
174{
175 // Interprete header (time, status, etc) of report
176 if (!InterpreteHeader(str, ver))
177 return kFALSE;
178
179 // return -1: This is the special case: out of time limit
180 if (start && *fTime<start)
181 return -1;
182 if (stop && *fTime>stop)
183 return -1;
184
185 // Due to wrong assignment by arehucas the veriosn number for some
186 // cases is replaced.
187 if (ver==200504130 && GetMjd()>53548 && GetMjd()<53567)
188 ver=200506300;
189
190 if (ver==200503170 && GetMjd()>53446.5 && GetMjd()<53447.5)
191 ver=200502240;
192
193 if (ver==200508290 && GetMjd()>53643.5)
194 ver=200509300;
195
196 if (ver==200510250 && GetMjd()>53801.5 && GetMjd()<53813.5)
197 ver=200603080;
198
199 if (ver==200510250 && GetMjd()>53813.5)
200 ver=200603190;
201
202 if (ver==200604010 && GetMjd()>53864.5)
203 ver=200605080;
204
205 if (ver==200805190 && GetMjd()>54711.5)
206 ver=200809030;
207
208 if (ver==200812040 && GetMjd()>54814.5)
209 ver=200812140;
210
211 if (ver==200902210 && GetMjd()>54968.5)
212 ver=200905170;
213
214 // Interprete body (contents) of report
215 const Int_t rc = InterpreteBody(str, ver);
216 if (rc != kTRUE)
217 return rc;
218
219 SetReadyToSave();
220 fTime->SetReadyToSave();
221
222 return kTRUE;
223}
224
225// --------------------------------------------------------------------------
226//
227// Check for the existance of a corresponding MTime in the given parameter
228// list. If it is not found a new one will be created. The name of the
229// MTime object is created by taking the ClassName() of the derived MReport
230// class and stripping the leading MReport
231//
232Bool_t MReport::SetupReading(MParList &plist)
233{
234 fTime = NULL;
235
236 TString id(ClassName());
237 if (!id.BeginsWith("MReport"))
238 {
239 *fLog << warn << " WARNING - Class name '" << id << "' ";
240 *fLog << " doesn't begin with 'MReport'... no MTime assigned." << endl;
241 return kFALSE;
242 }
243
244 id.Remove(0, 7);
245 if (id.IsNull())
246 {
247 *fLog << warn << " WARNING - No postfix existing... no MTime assigned." << endl;
248 return kFALSE;
249 }
250
251 id.Prepend("MTime");
252
253 fTime = (MTime*)plist.FindCreateObj("MTime", id);
254 if (!fTime)
255 return kFALSE;
256
257 return kTRUE;
258}
Note: See TracBrowser for help on using the repository browser.