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

Last change on this file since 2942 was 2892, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.7 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-2003
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// Be carefull: The class name of all classes derived from this class
33// should start with 'MReport', see SetupReading
34//
35//////////////////////////////////////////////////////////////////////////////
36#include "MReport.h"
37
38#include "MLogManip.h"
39
40#include "MTime.h"
41#include "MParList.h"
42
43ClassImp(MReport);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Interpretes the beginning of a line which starts like:
50// status hour minute second millisec skip skip skip skip skip
51// The identifier is assumed to be removed.
52//
53// While skip are numbers which won't enter the analysis
54//
55// SetupReading must be called successfully before.
56//
57Bool_t MReport::InterpreteHeader(TString &str)
58{
59 int len, state;
60 int yea, mon, day, hor, min, sec, ms;
61
62 int n = sscanf(str.Data(),
63 fHasReportTime ?
64 " %d %d %d %d %d %d %d %d %*d %*d %*d %*d %*d %*d %*d %*d %n" :
65 " %d %d %d %d %d %d %d %d %n",
66 &state, &yea, &mon, &day, &hor, &min, &sec, &ms, &len);
67 if (n!=8)
68 {
69 *fLog << err << "ERROR - Cannot interprete Body of " << fIdentifier << " (n=" << n << ")" << endl;
70 return kFALSE;
71 }
72
73 fState=state;
74 if (!fTime->Set(yea, mon, day, hor, min, sec, ms))
75 {
76 *fLog << err << "ERROR - Event has invalid time: ";
77 *fLog << Form("%d.%d.%d %02s:%02d:%02d.%03d", day, mon, yea, hor, min, sec, ms);
78 *fLog << "... abort." << endl;
79 return kFALSE;
80 }
81
82 str.Remove(0, len);
83
84 return kTRUE;
85}
86
87// --------------------------------------------------------------------------
88//
89// Report Body must be overwritten. It will get the line idetified to belong
90// to fIdentifier without the leading status and time infomration as an
91// argument.
92//
93Int_t MReport::InterpreteBody(TString &str)
94{
95 *fLog << warn << "No interpreter existing for: " << fIdentifier << endl;
96 return kTRUE;
97}
98
99// --------------------------------------------------------------------------
100//
101// Interprets Header and Body of a report file line. Calls SetReadyToSave()
102// in case the interpretation was successfull. And fTime->SetReadyToSave()
103// when a corresponding time container exists.
104//
105// SetupReading must be called successfully before.
106//
107Int_t MReport::Interprete(TString &str, const MTime &start, const MTime &stop)
108{
109 if (!InterpreteHeader(str))
110 return kFALSE;
111
112 if (start && *fTime<start)
113 return kCONTINUE;
114 if (stop && *fTime>stop)
115 return kCONTINUE;
116
117 const Int_t rc = InterpreteBody(str);
118 if (rc != kTRUE)
119 return rc;
120
121 SetReadyToSave();
122 fTime->SetReadyToSave();
123
124 return kTRUE;
125}
126
127// --------------------------------------------------------------------------
128//
129// Check for the existance of a corresponding MTime in the given parameter
130// list. If it is not found a new one will be created. The name of the
131// MTime object is created by taking the ClassName() of the derived MReport
132// class and stripping the leading MReport
133//
134Bool_t MReport::SetupReading(MParList &plist)
135{
136 fTime = NULL;
137
138 TString id(ClassName());
139 if (!id.BeginsWith("MReport"))
140 {
141 *fLog << warn << " WARNING - Class name '" << id << "' ";
142 *fLog << " doesn't begin with 'MReport'... no MTime assigned." << endl;
143 return kFALSE;
144 }
145
146 id.Remove(0, 7);
147 if (id.IsNull())
148 {
149 *fLog << warn << " WARNING - No postfix existing... no MTime assigned." << endl;
150 return kFALSE;
151 }
152
153 id.Prepend("MTime");
154
155 fTime = (MTime*)plist.FindCreateObj("MTime", id);
156 if (!fTime)
157 return kFALSE;
158
159 return kTRUE;
160}
Note: See TracBrowser for help on using the repository browser.