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 |
|
---|
51 | ClassImp(MReport);
|
---|
52 |
|
---|
53 | using namespace std;
|
---|
54 |
|
---|
55 | // --------------------------------------------------------------------------
|
---|
56 | //
|
---|
57 | // Copy fState and fTime
|
---|
58 | //
|
---|
59 | void 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 | //
|
---|
74 | Bool_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 | //
|
---|
95 | Bool_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 | //
|
---|
144 | Int_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 | //
|
---|
170 | Int_t MReport::Interprete(TString &str, const MTime &start, const MTime &stop, Int_t ver)
|
---|
171 | {
|
---|
172 | // Interprete header (time, status, etc) of report
|
---|
173 | if (!InterpreteHeader(str, ver))
|
---|
174 | return kFALSE;
|
---|
175 |
|
---|
176 | // return -1: This is the special case: out of time limit
|
---|
177 | if (start && *fTime<start)
|
---|
178 | return -1;
|
---|
179 | if (stop && *fTime>stop)
|
---|
180 | return -1;
|
---|
181 |
|
---|
182 | // Due to wrong assignment by arehucas the veriosn number for some
|
---|
183 | // cases is replaced.
|
---|
184 | if (ver==200504130 && GetMjd()>53548 && GetMjd()<53567)
|
---|
185 | ver=200506300;
|
---|
186 |
|
---|
187 | if (ver==200503170 && GetMjd()>53446.5 && GetMjd()<53447.5)
|
---|
188 | ver=200502240;
|
---|
189 |
|
---|
190 | if (ver==200508290 && GetMjd()>53643.5)
|
---|
191 | ver=200509300;
|
---|
192 |
|
---|
193 | if (ver==200510250 && GetMjd()>53801.5 && GetMjd()<53813.5)
|
---|
194 | ver=200603080;
|
---|
195 |
|
---|
196 | if (ver==200510250 && GetMjd()>53813.5)
|
---|
197 | ver=200603190;
|
---|
198 |
|
---|
199 | if (ver==200604010 && GetMjd()>53864.5)
|
---|
200 | ver=200605080;
|
---|
201 |
|
---|
202 | // Interprete body (contents) of report
|
---|
203 | const Int_t rc = InterpreteBody(str, ver);
|
---|
204 | if (rc != kTRUE)
|
---|
205 | return rc;
|
---|
206 |
|
---|
207 | SetReadyToSave();
|
---|
208 | fTime->SetReadyToSave();
|
---|
209 |
|
---|
210 | return kTRUE;
|
---|
211 | }
|
---|
212 |
|
---|
213 | // --------------------------------------------------------------------------
|
---|
214 | //
|
---|
215 | // Check for the existance of a corresponding MTime in the given parameter
|
---|
216 | // list. If it is not found a new one will be created. The name of the
|
---|
217 | // MTime object is created by taking the ClassName() of the derived MReport
|
---|
218 | // class and stripping the leading MReport
|
---|
219 | //
|
---|
220 | Bool_t MReport::SetupReading(MParList &plist)
|
---|
221 | {
|
---|
222 | fTime = NULL;
|
---|
223 |
|
---|
224 | TString id(ClassName());
|
---|
225 | if (!id.BeginsWith("MReport"))
|
---|
226 | {
|
---|
227 | *fLog << warn << " WARNING - Class name '" << id << "' ";
|
---|
228 | *fLog << " doesn't begin with 'MReport'... no MTime assigned." << endl;
|
---|
229 | return kFALSE;
|
---|
230 | }
|
---|
231 |
|
---|
232 | id.Remove(0, 7);
|
---|
233 | if (id.IsNull())
|
---|
234 | {
|
---|
235 | *fLog << warn << " WARNING - No postfix existing... no MTime assigned." << endl;
|
---|
236 | return kFALSE;
|
---|
237 | }
|
---|
238 |
|
---|
239 | id.Prepend("MTime");
|
---|
240 |
|
---|
241 | fTime = (MTime*)plist.FindCreateObj("MTime", id);
|
---|
242 | if (!fTime)
|
---|
243 | return kFALSE;
|
---|
244 |
|
---|
245 | return kTRUE;
|
---|
246 | }
|
---|